]> git.proxmox.com Git - ceph.git/blob - ceph/src/common/config_values.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / common / config_values.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 #include "config_values.h"
3
4 #include "config.h"
5
6 ConfigValues::set_value_result_t
7 ConfigValues::set_value(const std::string& key,
8 Option::value_t&& new_value,
9 int level)
10 {
11 if (auto p = values.find(key); p != values.end()) {
12 auto q = p->second.find(level);
13 if (q != p->second.end()) {
14 if (new_value == q->second) {
15 return SET_NO_CHANGE;
16 }
17 q->second = std::move(new_value);
18 } else {
19 p->second[level] = std::move(new_value);
20 }
21 if (p->second.rbegin()->first > level) {
22 // there was a higher priority value; no effect
23 return SET_NO_EFFECT;
24 } else {
25 return SET_HAVE_EFFECT;
26 }
27 } else {
28 values[key][level] = std::move(new_value);
29 return SET_HAVE_EFFECT;
30 }
31 }
32
33 int ConfigValues::rm_val(const std::string& key, int level)
34 {
35 auto i = values.find(key);
36 if (i == values.end()) {
37 return -ENOENT;
38 }
39 auto j = i->second.find(level);
40 if (j == i->second.end()) {
41 return -ENOENT;
42 }
43 bool matters = (j->first == i->second.rbegin()->first);
44 i->second.erase(j);
45 if (matters) {
46 return SET_HAVE_EFFECT;
47 } else {
48 return SET_NO_EFFECT;
49 }
50 }
51
52 std::pair<Option::value_t, bool>
53 ConfigValues::get_value(const std::string& name, int level) const
54 {
55 auto p = values.find(name);
56 if (p != values.end() && !p->second.empty()) {
57 // use highest-priority value available (see CONF_*)
58 if (level < 0) {
59 return {p->second.rbegin()->second, true};
60 } else if (auto found = p->second.find(level);
61 found != p->second.end()) {
62 return {found->second, true};
63 }
64 }
65 return {Option::value_t{}, false};
66 }
67
68 void ConfigValues::set_logging(int which, const char* val)
69 {
70 int log, gather;
71 int r = sscanf(val, "%d/%d", &log, &gather);
72 if (r >= 1) {
73 if (r < 2) {
74 gather = log;
75 }
76 subsys.set_log_level(which, log);
77 subsys.set_gather_level(which, gather);
78 }
79 }
80
81 bool ConfigValues::contains(const std::string& key) const
82 {
83 return values.count(key);
84 }