From b35f3e29fd07eb9fe59a01dec103a6a053123123 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 18 Dec 2018 18:05:02 -0600 Subject: [PATCH] mon/MgrMonitor: make find_module_option handle localized option names If we get "mgr/$module/$instance/$option", normalize it to "mgr/$module/$option" before looking it up. That's because a 'mgr/dashboard/x/server_port' in our database is really the 'mgr/dashboard/server_port' option. Signed-off-by: Sage Weil --- src/mon/MgrMonitor.cc | 26 ++++++++++++++++++++++++++ src/mon/MgrMonitor.h | 8 +------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/mon/MgrMonitor.cc b/src/mon/MgrMonitor.cc index 9a2a2a3c82c2f..9d749d26494b3 100644 --- a/src/mon/MgrMonitor.cc +++ b/src/mon/MgrMonitor.cc @@ -54,6 +54,32 @@ const static std::map> always_on_modules = { // Prefix for mon store of active mgr's command descriptions const static std::string command_descs_prefix = "mgr_command_descs"; +const Option *MgrMonitor::find_module_option(const string& name) +{ + // we have two forms of names: "mgr/$module/$option" and + // localized "mgr/$module/$instance/$option". normalize to the + // former by stripping out $instance. + string real_name; + if (name.substr(0, 4) != "mgr/") { + return nullptr; + } + auto second_slash = name.find('/', 5); + if (second_slash == std::string::npos) { + return nullptr; + } + auto third_slash = name.find('/', second_slash + 1); + if (third_slash != std::string::npos) { + // drop the $instance part between the second and third slash + real_name = name.substr(0, second_slash) + name.substr(third_slash); + } else { + real_name = name; + } + auto p = mgr_module_options.find(real_name); + if (p != mgr_module_options.end()) { + return &p->second; + } + return nullptr; +} version_t MgrMonitor::get_trim_to() const { diff --git a/src/mon/MgrMonitor.h b/src/mon/MgrMonitor.h index bb330d4f0211e..d8cfc0e5dd0c9 100644 --- a/src/mon/MgrMonitor.h +++ b/src/mon/MgrMonitor.h @@ -81,13 +81,7 @@ public: const MgrMap &get_map() const { return map; } - const Option *find_module_option(const string& name) { - auto p = mgr_module_options.find(name); - if (p != mgr_module_options.end()) { - return &p->second; - } - return nullptr; - } + const Option *find_module_option(const string& name); bool in_use() const { return map.epoch > 0; } -- 2.39.5