]>
git.proxmox.com Git - ceph.git/blob - 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"
6 ConfigValues::set_value_result_t
7 ConfigValues::set_value(const std::string
& key
,
8 Option::value_t
&& new_value
,
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
) {
17 q
->second
= std::move(new_value
);
19 p
->second
[level
] = std::move(new_value
);
21 if (p
->second
.rbegin()->first
> level
) {
22 // there was a higher priority value; no effect
25 return SET_HAVE_EFFECT
;
28 values
[key
][level
] = std::move(new_value
);
29 return SET_HAVE_EFFECT
;
33 int ConfigValues::rm_val(const std::string
& key
, int level
)
35 auto i
= values
.find(key
);
36 if (i
== values
.end()) {
39 auto j
= i
->second
.find(level
);
40 if (j
== i
->second
.end()) {
43 bool matters
= (j
->first
== i
->second
.rbegin()->first
);
46 return SET_HAVE_EFFECT
;
52 std::pair
<Option::value_t
, bool>
53 ConfigValues::get_value(const std::string
& name
, int level
) const
55 auto p
= values
.find(name
);
56 if (p
!= values
.end() && !p
->second
.empty()) {
57 // use highest-priority value available (see CONF_*)
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};
65 return {Option::value_t
{}, false};
68 void ConfigValues::set_logging(int which
, const char* val
)
71 int r
= sscanf(val
, "%d/%d", &log
, &gather
);
76 subsys
.set_log_level(which
, log
);
77 subsys
.set_gather_level(which
, gather
);
81 bool ConfigValues::contains(const std::string
& key
) const
83 return values
.count(key
);