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