summaryrefslogtreecommitdiffstats
path: root/src/common/config_values.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/common/config_values.cc
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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 00000000..24f556e3
--- /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);
+}