]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MgrMonitor: make find_module_option handle localized option names
authorSage Weil <sage@redhat.com>
Wed, 19 Dec 2018 00:05:02 +0000 (18:05 -0600)
committerSage Weil <sage@redhat.com>
Fri, 21 Dec 2018 04:11:40 +0000 (22:11 -0600)
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 <sage@redhat.com>
src/mon/MgrMonitor.cc
src/mon/MgrMonitor.h

index 9a2a2a3c82c2fad54ef19c79bb51e4d8609a4795..9d749d26494b31b66e8712a5a88adc79a024df27 100644 (file)
@@ -54,6 +54,32 @@ const static std::map<uint32_t, std::set<std::string>> 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
 {
index bb330d4f0211ea35064b4201084abffcdc041f96..d8cfc0e5dd0c9d434bc20eb1f649d0875c3fc7b8 100644 (file)
@@ -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; }