From: Sage Weil Date: Tue, 5 Jun 2018 13:47:27 +0000 (-0500) Subject: mgr/DaemonState: populate DeviceState structures X-Git-Tag: v14.0.1~1131^2~18 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=38afbae02696afdab973a5ec739c1e68cd45e4d1;p=ceph.git mgr/DaemonState: populate DeviceState structures Track device <-> daemon (and server) mappings. Signed-off-by: Sage Weil --- diff --git a/src/mgr/DaemonState.cc b/src/mgr/DaemonState.cc index 0c4034072c33..690426ec47cc 100644 --- a/src/mgr/DaemonState.cc +++ b/src/mgr/DaemonState.cc @@ -30,6 +30,12 @@ void DaemonStateIndex::insert(DaemonStatePtr dm) by_server[dm->hostname][dm->key] = dm; all[dm->key] = dm; + + for (auto& devid : dm->devids) { + auto d = _get_or_create_device(devid); + d->daemons.insert(dm->key); + d->server = dm->hostname; + } } void DaemonStateIndex::_erase(const DaemonKey& dmk) @@ -39,6 +45,16 @@ void DaemonStateIndex::_erase(const DaemonKey& dmk) const auto to_erase = all.find(dmk); assert(to_erase != all.end()); const auto dm = to_erase->second; + + for (auto& devid : dm->devids) { + auto d = _get_or_create_device(devid); + assert(d->daemons.count(dmk)); + d->daemons.erase(dmk); + if (d->daemons.empty()) { + _erase_device(d); + } + } + auto &server_collection = by_server[dm->hostname]; server_collection.erase(dm->key); if (server_collection.empty()) { diff --git a/src/mgr/DaemonState.h b/src/mgr/DaemonState.h index e8b2a8d5a3d5..8eda23ec94ea 100644 --- a/src/mgr/DaemonState.h +++ b/src/mgr/DaemonState.h @@ -185,7 +185,16 @@ typedef std::shared_ptr DaemonStatePtr; typedef std::map DaemonStateCollection; +struct DeviceState : public RefCountedObject +{ + std::string devid; + std::string server; + std::set daemons; + + DeviceState(const std::string& n) : devid(n) {} +}; +typedef boost::intrusive_ptr DeviceStateRef; /** * Fuse the collection of per-daemon metadata from Ceph into @@ -194,16 +203,30 @@ typedef std::map DaemonStateCollection; */ class DaemonStateIndex { - private: +private: mutable RWLock lock = {"DaemonStateIndex", true, true, true}; std::map by_server; DaemonStateCollection all; std::set updating; + std::map devices; + void _erase(const DaemonKey& dmk); - public: + DeviceStateRef _get_or_create_device(const std::string& dev) { + auto p = devices.find(dev); + if (p != devices.end()) { + return p->second; + } + devices[dev] = new DeviceState(dev); + return devices[dev]; + } + void _erase_device(DeviceStateRef d) { + devices.erase(d->devid); + } + +public: DaemonStateIndex() {} // FIXME: shouldn't really be public, maybe construct DaemonState