From: Sage Weil Date: Tue, 5 Jun 2018 18:57:09 +0000 (-0500) Subject: mgr: load persistent device metadata on mgr stat X-Git-Tag: v14.0.1~1131^2~14 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=45d4dfed1ded628abcbb9f1c62dfb90095414f0d;p=ceph-ci.git mgr: load persistent device metadata on mgr stat Prune DeviceState when there is no persistent metadata and no daemon references. Load persistent metadata from config-key. Signed-off-by: Sage Weil --- diff --git a/src/mgr/DaemonState.cc b/src/mgr/DaemonState.cc index 690426ec47c..e8daf7dfd0e 100644 --- a/src/mgr/DaemonState.cc +++ b/src/mgr/DaemonState.cc @@ -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); } } diff --git a/src/mgr/DaemonState.h b/src/mgr/DaemonState.h index 8dc1cf922c2..654c12beb7e 100644 --- a/src/mgr/DaemonState.h +++ b/src/mgr/DaemonState.h @@ -191,7 +191,16 @@ struct DeviceState : public RefCountedObject std::string server; std::set daemons; + std::map metadata; ///< persistent metadata + DeviceState(const std::string& n) : devid(n) {} + + void set_metadata(map&& m); + + /// true of we can be safely forgotten/removed from memory + bool empty() const { + return daemons.empty() && metadata.empty(); + } }; typedef boost::intrusive_ptr DeviceStateRef; diff --git a/src/mgr/Mgr.cc b/src/mgr/Mgr.cc index cc14eac3a0f..cf055e91773 100644 --- a/src/mgr/Mgr.cc +++ b/src/mgr/Mgr.cc @@ -174,8 +174,10 @@ std::map 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 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 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(); + } } } } diff --git a/src/mgr/PyModuleRegistry.cc b/src/mgr/PyModuleRegistry.cc index 3ceb4d0e939..af1fdebbb90 100644 --- a/src/mgr/PyModuleRegistry.cc +++ b/src/mgr/PyModuleRegistry.cc @@ -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);