summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2021-02-16 23:06:16 +0100
committerSage Weil <sage@newdream.net>2021-02-17 18:27:58 +0100
commitceace016cd02824709bd0da1c13c6c1e56f690f5 (patch)
tree80cd082369c348fc41fc710a974457525bbc4a30
parentmon/ConfigMap: fix stray option leak (diff)
downloadceph-ceace016cd02824709bd0da1c13c6c1e56f690f5.tar.xz
ceph-ceace016cd02824709bd0da1c13c6c1e56f690f5.zip
mon/ConfigMap: factor out parse_key helper
Signed-off-by: Sage Weil <sage@newdream.net>
-rw-r--r--src/mon/ConfigMap.cc17
-rw-r--r--src/mon/ConfigMap.h4
-rw-r--r--src/mon/ConfigMonitor.cc11
3 files changed, 22 insertions, 10 deletions
diff --git a/src/mon/ConfigMap.cc b/src/mon/ConfigMap.cc
index 7fb13841df4..763b8ce9b17 100644
--- a/src/mon/ConfigMap.cc
+++ b/src/mon/ConfigMap.cc
@@ -233,6 +233,23 @@ bool ConfigMap::parse_mask(
return true;
}
+void ConfigMap::parse_key(
+ const std::string& key,
+ std::string *name,
+ std::string *who)
+{
+ auto last_slash = key.rfind('/');
+ if (last_slash == std::string::npos) {
+ *name = key;
+ } else if (auto mgrpos = key.find("/mgr/"); mgrpos != std::string::npos) {
+ *name = key.substr(mgrpos + 1);
+ *who = key.substr(0, mgrpos);
+ } else {
+ *name = key.substr(last_slash + 1);
+ *who = key.substr(0, last_slash);
+ }
+}
+
// --------------
diff --git a/src/mon/ConfigMap.h b/src/mon/ConfigMap.h
index d5991bc1d7f..2ecdcc07133 100644
--- a/src/mon/ConfigMap.h
+++ b/src/mon/ConfigMap.h
@@ -129,6 +129,10 @@ struct ConfigMap {
const std::string& device_class,
std::map<std::string,std::pair<std::string,const MaskedOption*>> *src=0);
+ void parse_key(
+ const std::string& key,
+ std::string *name,
+ std::string *who);
static bool parse_mask(
const std::string& in,
std::string *section,
diff --git a/src/mon/ConfigMonitor.cc b/src/mon/ConfigMonitor.cc
index c316af3284e..d305aa4a242 100644
--- a/src/mon/ConfigMonitor.cc
+++ b/src/mon/ConfigMonitor.cc
@@ -777,18 +777,9 @@ void ConfigMonitor::load_config()
current[key] = it->value();
- auto last_slash = key.rfind('/');
string name;
string who;
- if (last_slash == std::string::npos) {
- name = key;
- } else if (auto mgrpos = key.find("/mgr/"); mgrpos != std::string::npos) {
- name = key.substr(mgrpos + 1);
- who = key.substr(0, mgrpos);
- } else {
- name = key.substr(last_slash + 1);
- who = key.substr(0, last_slash);
- }
+ config_map.parse_key(key, &name, &who);
// has this option been renamed?
{