]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon/MgrMonitor: populate options
authorSage Weil <sage@redhat.com>
Tue, 18 Dec 2018 23:20:07 +0000 (17:20 -0600)
committerSage Weil <sage@redhat.com>
Tue, 18 Dec 2018 23:42:59 +0000 (17:42 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/options.h
src/mon/MgrMonitor.cc
src/mon/MgrMonitor.h

index bc1fa6a9e2cd61e50bb73d9ecd714fcd9808973a..ce5671729f7b5201dab060cde799b9f563ab7988 100644 (file)
@@ -333,9 +333,9 @@ struct Option {
     return *this;
   }
 
-  Option& set_enum_allowed(const std::initializer_list<const char*>& allowed)
+  Option& set_enum_allowed(const std::vector<const char*>& allowed)
   {
-    enum_allowed.insert(enum_allowed.end(), allowed);
+    enum_allowed = allowed;
     return *this;
   }
 
index be1ac123abd5199338d7538e3704cea59ead7276..9a2a2a3c82c2fad54ef19c79bb51e4d8609a4795 100644 (file)
@@ -21,6 +21,7 @@
 #include "mgr/MgrContext.h"
 #include "mgr/mgr_commands.h"
 #include "OSDMonitor.h"
+#include "ConfigMonitor.h"
 
 #include "MgrMonitor.h"
 
@@ -134,6 +135,56 @@ void MgrMonitor::update_from_paxos(bool *need_bootstrap)
     }
   }
 
+  // populate module options
+  mgr_module_options.clear();
+  misc_option_strings.clear();
+  for (auto& i : map.available_modules) {
+    for (auto& j : i.module_options) {
+      string name = string("mgr/") + i.name + "/" + j.second.name;
+      auto p = mgr_module_options.emplace(
+       name,
+       Option(name, static_cast<Option::type_t>(j.second.type),
+              static_cast<Option::level_t>(j.second.level)));
+      Option& opt = p.first->second;
+      opt.set_flags(static_cast<Option::flag_t>(j.second.flags));
+      opt.set_description(j.second.desc.c_str());
+      opt.set_long_description(j.second.long_desc.c_str());
+      for (auto& k : j.second.tags) {
+       opt.add_tag(k.c_str());
+      }
+      for (auto& k : j.second.see_also) {
+       if (i.module_options.count(k)) {
+         // another module option
+         misc_option_strings.push_back(string("mgr/") + i.name + "/" + k);
+         opt.add_see_also(misc_option_strings.back().c_str());
+       } else {
+         // ceph option
+         opt.add_see_also(k.c_str());
+       }
+      }
+      Option::value_t v, v2;
+      std::string err;
+      if (j.second.default_value.size() &&
+         !opt.parse_value(j.second.default_value, &v, &err)) {
+       opt.set_default(v);
+      }
+      if (j.second.min.size() &&
+         j.second.max.size() &&
+         !opt.parse_value(j.second.min, &v, &err) &&
+         !opt.parse_value(j.second.max, &v2, &err)) {
+       opt.set_min_max(v, v2);
+      }
+      std::vector<const char *> enum_allowed;
+      for (auto& k : j.second.enum_allowed) {
+       enum_allowed.push_back(k.c_str());
+      }
+      opt.set_enum_allowed(enum_allowed);
+    }
+  }
+  // force ConfigMonitor to refresh, since it uses const Option *
+  // pointers into our mgr_module_options (which we just rebuilt).
+  mon->configmon()->load_config();
+
   // feed our pet MgrClient
   mon->mgr_client.ms_dispatch(new MMgrMap(map));
 }
index b295e4030096ba3e4f0406f035e894a5e037164f..bb330d4f0211ea35064b4201084abffcdc041f96 100644 (file)
@@ -31,6 +31,9 @@ class MgrMonitor: public PaxosService
   std::map<std::string, bufferlist> pending_metadata;
   std::set<std::string>             pending_metadata_rm;
 
+  std::map<std::string,Option> mgr_module_options;
+  std::list<std::string> misc_option_strings;
+
   utime_t first_seen_inactive;
 
   std::map<uint64_t, ceph::coarse_mono_clock::time_point> last_beacon;
@@ -78,6 +81,14 @@ 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;
+  }
+
   bool in_use() const { return map.epoch > 0; }
 
   version_t get_trim_to() const override;