]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr: load persistent device metadata on mgr stat
authorSage Weil <sage@redhat.com>
Tue, 5 Jun 2018 18:57:09 +0000 (13:57 -0500)
committerSage Weil <sage@redhat.com>
Mon, 11 Jun 2018 12:28:50 +0000 (07:28 -0500)
Prune DeviceState when there is no persistent metadata and no daemon
references.  Load persistent metadata from config-key.

Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/DaemonState.cc
src/mgr/DaemonState.h
src/mgr/Mgr.cc
src/mgr/PyModuleRegistry.cc

index 690426ec47cce21befc4bd5f5bf11f46568eadb2..e8daf7dfd0e663eb5e5b89cc6d03c50f4b2aef57 100644 (file)
@@ -50,7 +50,7 @@ void DaemonStateIndex::_erase(const DaemonKey& dmk)
     auto d = _get_or_create_device(devid);
     assert(d->daemons.count(dmk));
     d->daemons.erase(dmk);
-    if (d->daemons.empty()) {
+    if (d->empty()) {
       _erase_device(d);
     }
   }
index 8dc1cf922c21c5aa00d22cb9036898a6a2a29169..654c12beb7e8584e62340e12ad0a83b7e812181e 100644 (file)
@@ -191,7 +191,16 @@ struct DeviceState : public RefCountedObject
   std::string server;
   std::set<DaemonKey> daemons;
 
+  std::map<string,string> metadata;  ///< persistent metadata
+
   DeviceState(const std::string& n) : devid(n) {}
+
+  void set_metadata(map<string,string>&& m);
+
+  /// true of we can be safely forgotten/removed from memory
+  bool empty() const {
+    return daemons.empty() && metadata.empty();
+  }
 };
 
 typedef boost::intrusive_ptr<DeviceState> DeviceStateRef;
index cc14eac3a0f21806cf5f66a0e1ce98a6e5b008ad..cf055e9177356c7ed495e452a83e7b133eec098d 100644 (file)
@@ -174,8 +174,10 @@ std::map<std::string, std::string> Mgr::load_store()
     dout(20) << "saw key '" << key << "'" << dendl;
 
     const std::string config_prefix = PyModule::config_prefix;
+    const std::string device_prefix = "device/";
 
-    if (key.substr(0, config_prefix.size()) == config_prefix) {
+    if (key.substr(0, config_prefix.size()) == config_prefix ||
+       key.substr(0, device_prefix.size()) == device_prefix) {
       dout(20) << "fetching '" << key << "'" << dendl;
       Command get_cmd;
       std::ostringstream cmd_json;
@@ -185,7 +187,26 @@ std::map<std::string, std::string> Mgr::load_store()
       get_cmd.wait();
       lock.Lock();
       if (get_cmd.r == 0) { // tolerate racing config-key change
-       loaded[key] = get_cmd.outbl.to_str();
+       if (key.substr(0, device_prefix.size()) == device_prefix) {
+         // device/
+         string devid = key.substr(device_prefix.size());
+         map<string,string> meta;
+         ostringstream ss;
+         string val = get_cmd.outbl.to_str();
+         int r = get_json_str_map(val, ss, &meta, false);
+         if (r < 0) {
+           derr << __func__ << " failed to parse " << val << ": " << ss.str()
+                << dendl;
+         } else {
+           daemon_state.with_device_create(
+             devid, [&meta] (DeviceState& dev) {
+               dev.set_metadata(std::move(meta));
+             });
+         }
+       } else {
+         // config/
+         loaded[key] = get_cmd.outbl.to_str();
+       }
       }
     }
   }
index 3ceb4d0e93934f5d21d85dbf7e0ec8a43b7d8140..af1fdebbb9034ff98495b1544c6aa226589a35cd 100644 (file)
@@ -412,7 +412,7 @@ void PyModuleRegistry::upgrade_config(
     dout(1) << "Upgrading module configuration for Mimic" << dendl;
     // Upgrade luminous->mimic: migrate config-key configuration
     // into main configuration store
-    for(auto &i : old_config) {
+    for (auto &i : old_config) {
       auto last_slash = i.first.rfind('/');
       const std::string module_name = i.first.substr(4, i.first.substr(4).find('/'));
       const std::string key = i.first.substr(last_slash + 1);