]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/config_values.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / common / config_values.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2
3 #pragma once
4
5 #include <cstdint>
6 #include <map>
7 #include <set>
8 #include <string>
9 #include <utility>
10
11 #include "common/entity_name.h"
12 #include "common/options.h"
13 #include "log/SubsystemMap.h"
14 #include "msg/msg_types.h"
15
16 // @c ConfigValues keeps track of mappings from the config names to their values,
17 // debug logging settings, and some other "unnamed" settings, like entity name of
18 // the daemon.
19 class ConfigValues {
20 using values_t = std::map<std::string_view, std::map<int32_t,Option::value_t>>;
21 values_t values;
22 // for populating md_config_impl::legacy_values in ctor
23 friend struct md_config_t;
24
25 public:
26 EntityName name;
27 /// cluster name
28 std::string cluster;
29 ceph::logging::SubsystemMap subsys;
30 bool no_mon_config = false;
31 // Set of configuration options that have changed since the last
32 // apply_changes
33 using changed_set_t = std::set<std::string>;
34 changed_set_t changed;
35
36 // This macro block defines C members of the md_config_t struct
37 // corresponding to the definitions in legacy_config_opts.h.
38 // These C members are consumed by code that was written before
39 // the new options.cc infrastructure: all newer code should
40 // be consume options via explicit get() rather than C members.
41 #define OPTION_OPT_INT(name) int64_t name;
42 #define OPTION_OPT_LONGLONG(name) int64_t name;
43 #define OPTION_OPT_STR(name) std::string name;
44 #define OPTION_OPT_DOUBLE(name) double name;
45 #define OPTION_OPT_FLOAT(name) double name;
46 #define OPTION_OPT_BOOL(name) bool name;
47 #define OPTION_OPT_ADDR(name) entity_addr_t name;
48 #define OPTION_OPT_ADDRVEC(name) entity_addrvec_t name;
49 #define OPTION_OPT_U32(name) uint64_t name;
50 #define OPTION_OPT_U64(name) uint64_t name;
51 #define OPTION_OPT_UUID(name) uuid_d name;
52 #define OPTION_OPT_SIZE(name) uint64_t name;
53 #define OPTION(name, ty) \
54 public: \
55 OPTION_##ty(name)
56 #define SAFE_OPTION(name, ty) \
57 protected: \
58 OPTION_##ty(name)
59 #include "common/options/legacy_config_opts.h"
60 #undef OPTION_OPT_INT
61 #undef OPTION_OPT_LONGLONG
62 #undef OPTION_OPT_STR
63 #undef OPTION_OPT_DOUBLE
64 #undef OPTION_OPT_FLOAT
65 #undef OPTION_OPT_BOOL
66 #undef OPTION_OPT_ADDR
67 #undef OPTION_OPT_ADDRVEC
68 #undef OPTION_OPT_U32
69 #undef OPTION_OPT_U64
70 #undef OPTION_OPT_UUID
71 #undef OPTION
72 #undef SAFE_OPTION
73
74 public:
75 enum set_value_result_t {
76 SET_NO_CHANGE,
77 SET_NO_EFFECT,
78 SET_HAVE_EFFECT,
79 };
80 /**
81 * @return true if changed, false otherwise
82 */
83 set_value_result_t set_value(std::string_view key,
84 Option::value_t&& value,
85 int level);
86 int rm_val(const std::string_view key, int level);
87 void set_logging(int which, const char* val);
88 /**
89 * @param level the level of the setting, -1 for the one with the
90 * highest-priority
91 */
92 std::pair<Option::value_t, bool> get_value(const std::string_view name,
93 int level) const;
94 template<typename Func> void for_each(Func&& func) const {
95 for (const auto& [name,configs] : values) {
96 func(name, configs);
97 }
98 }
99 bool contains(const std::string_view key) const;
100 };