From: Sage Weil Date: Tue, 16 Feb 2021 22:06:16 +0000 (-0500) Subject: mon/ConfigMap: factor out parse_key helper X-Git-Tag: v17.1.0~2900^2~7 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ceace016cd02824709bd0da1c13c6c1e56f690f5;p=ceph.git mon/ConfigMap: factor out parse_key helper Signed-off-by: Sage Weil --- diff --git a/src/mon/ConfigMap.cc b/src/mon/ConfigMap.cc index 7fb13841df423..763b8ce9b1731 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 d5991bc1d7f33..2ecdcc0713365 100644 --- a/src/mon/ConfigMap.h +++ b/src/mon/ConfigMap.h @@ -129,6 +129,10 @@ struct ConfigMap { const std::string& device_class, std::map> *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 c316af3284e0f..d305aa4a24295 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? {