summaryrefslogtreecommitdiffstats
path: root/src/common/config_values.cc
diff options
context:
space:
mode:
authorKefu Chai <kchai@redhat.com>2018-07-06 11:20:32 +0200
committerKefu Chai <kchai@redhat.com>2018-07-10 16:51:22 +0200
commit4718b7cb2fac65b2ac7014f42ba1a10181350f0b (patch)
tree80ed52aeae220a1b3b65778d2c68dca582dacd6a /src/common/config_values.cc
parentMerge PR #22940 into master (diff)
downloadceph-4718b7cb2fac65b2ac7014f42ba1a10181350f0b.tar.xz
ceph-4718b7cb2fac65b2ac7014f42ba1a10181350f0b.zip
common,rbd,rgw,osd: extract config values into ConfigValues
this change introduce three classes: ConfigValues, ConfigProxy and ConfigReader. in seastar port of OSD, each CPU shard will hold its own reference of configuration, and upon changes of settings, each shard will be updated with the new setting in async. so this forces us to be able to keep two set of configuration at the same time. so we need to extract the changeable part of md_config_t out. so we can replace the old one with new one on demand, and let different shards share the same unchanged part, amon the other things, the Options map and the lookup tables. that's why we need ConfigValues. we will add a policy template for this class, so we can specialize for Seastar implementation to allow different ConfigProxy instances to point md_config_impl<> to different ConfigValues. because the observer interface is still using md_config_t, to minimise the impact of this change, handle_conf_change() and handle_subsys_change() are not changed. but as it accepts a `const md_config_t`, which cannot be used to create/reference the ConfigProxy holding it, we need to introduce ConfigReader for reading the updated setting from md_config_t in a simpler way, without exposing the internal "values" member variable. Signed-off-by: Kefu Chai <kchai@redhat.com>
Diffstat (limited to 'src/common/config_values.cc')
-rw-r--r--src/common/config_values.cc84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/common/config_values.cc b/src/common/config_values.cc
new file mode 100644
index 00000000000..24f556e35a2
--- /dev/null
+++ b/src/common/config_values.cc
@@ -0,0 +1,84 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+#include "config_values.h"
+
+#include "config.h"
+
+ConfigValues::set_value_result_t
+ConfigValues::set_value(const std::string& key,
+ Option::value_t&& new_value,
+ int level)
+{
+ if (auto p = values.find(key); p != values.end()) {
+ auto q = p->second.find(level);
+ if (q != p->second.end()) {
+ if (new_value == q->second) {
+ return SET_NO_CHANGE;
+ }
+ q->second = std::move(new_value);
+ } else {
+ p->second[level] = std::move(new_value);
+ }
+ if (p->second.rbegin()->first > level) {
+ // there was a higher priority value; no effect
+ return SET_NO_EFFECT;
+ } else {
+ return SET_HAVE_EFFECT;
+ }
+ } else {
+ values[key][level] = std::move(new_value);
+ return SET_HAVE_EFFECT;
+ }
+}
+
+int ConfigValues::rm_val(const std::string& key, int level)
+{
+ auto i = values.find(key);
+ if (i == values.end()) {
+ return -ENOENT;
+ }
+ auto j = i->second.find(level);
+ if (j == i->second.end()) {
+ return -ENOENT;
+ }
+ bool matters = (j->first == i->second.rbegin()->first);
+ i->second.erase(j);
+ if (matters) {
+ return SET_HAVE_EFFECT;
+ } else {
+ return SET_NO_EFFECT;
+ }
+}
+
+std::pair<Option::value_t, bool>
+ConfigValues::get_value(const std::string& name, int level) const
+{
+ auto p = values.find(name);
+ if (p != values.end() && !p->second.empty()) {
+ // use highest-priority value available (see CONF_*)
+ if (level < 0) {
+ return {p->second.rbegin()->second, true};
+ } else if (auto found = p->second.find(level);
+ found != p->second.end()) {
+ return {found->second, true};
+ }
+ }
+ return {Option::value_t{}, false};
+}
+
+void ConfigValues::set_logging(int which, const char* val)
+{
+ int log, gather;
+ int r = sscanf(val, "%d/%d", &log, &gather);
+ if (r >= 1) {
+ if (r < 2) {
+ gather = log;
+ }
+ subsys.set_log_level(which, log);
+ subsys.set_gather_level(which, gather);
+ }
+}
+
+bool ConfigValues::contains(const std::string& key) const
+{
+ return values.count(key);
+}