X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Fmgr%2FDaemonState.h;h=0688db81bb1f60dc4407646b1055810bd892b642;hb=20effc670b57271cb089376d6d0800990e5218d5;hp=680d4a0cc2cf5112e13a1b322e67c92f7110ea9e;hpb=11fdf7f228cb605e22a0e495ebabd3329db96b81;p=ceph.git diff --git a/ceph/src/mgr/DaemonState.h b/ceph/src/mgr/DaemonState.h index 680d4a0cc..0688db81b 100644 --- a/ceph/src/mgr/DaemonState.h +++ b/ceph/src/mgr/DaemonState.h @@ -20,25 +20,18 @@ #include #include -#include "common/RWLock.h" #include "include/str_map.h" #include "msg/msg_types.h" // For PerfCounterType #include "messages/MMgrReport.h" +#include "DaemonKey.h" namespace ceph { class Formatter; } -// Unique reference to a daemon within a cluster -typedef std::pair DaemonKey; - -static inline std::string to_string(const DaemonKey& dk) { - return dk.first + "." + dk.second; -} - // An instance of a performance counter type, within // a particular daemon. class PerfCounterInstance @@ -114,7 +107,7 @@ class DaemonPerfCounters std::map instances; - void update(MMgrReport *report); + void update(const MMgrReport& report); void clear() { @@ -126,7 +119,7 @@ class DaemonPerfCounters class DaemonState { public: - Mutex lock = {"DaemonState::lock"}; + ceph::mutex lock = ceph::make_mutex("DaemonState::lock"); DaemonKey key; @@ -140,6 +133,9 @@ class DaemonState /// device ids -> devname, derived from metadata[device_ids] std::map devices; + /// device ids -> by-path, derived from metadata[device_ids] + std::map devices_bypath; + // TODO: this can be generalized to other daemons std::vector daemon_health_metrics; @@ -166,33 +162,8 @@ class DaemonState : perf_counters(types_) { } - - void set_metadata(const std::map& m) { - devices.clear(); - metadata = m; - auto p = m.find("device_ids"); - if (p != m.end()) { - map devs; - get_str_map(p->second, &devs, ",; "); - for (auto& i : devs) { - if (i.second.size()) { // skip blank ids - devices[i.second] = i.first; - } - } - } - } - - const std::map& _get_config_defaults() { - if (config_defaults.empty() && - config_defaults_bl.length()) { - auto p = config_defaults_bl.cbegin(); - try { - decode(config_defaults, p); - } catch (buffer::error& e) { - } - } - return config_defaults; - } + void set_metadata(const std::map& m); + const std::map& _get_config_defaults(); }; typedef std::shared_ptr DaemonStatePtr; @@ -202,24 +173,24 @@ typedef std::map DaemonStateCollection; struct DeviceState : public RefCountedObject { std::string devid; - std::set> devnames; ///< (server,devname) + /// (server,devname,path) + std::set> attachments; std::set daemons; - std::map metadata; ///< persistent metadata + std::map metadata; ///< persistent metadata - pair life_expectancy; ///< when device failure is expected + std::pair life_expectancy; ///< when device failure is expected utime_t life_expectancy_stamp; ///< when life expectency was recorded + float wear_level = -1; ///< SSD wear level (negative if unknown) - DeviceState(const std::string& n) - : RefCountedObject(nullptr, 0), - devid(n) {} - - void set_metadata(map&& m); + void set_metadata(std::map&& m); void set_life_expectancy(utime_t from, utime_t to, utime_t now); void rm_life_expectancy(); - string get_life_expectancy_str(utime_t now) const; + void set_wear_level(float wear); + + std::string get_life_expectancy_str(utime_t now) const; /// true of we can be safely forgotten/removed from memory bool empty() const { @@ -227,10 +198,12 @@ struct DeviceState : public RefCountedObject } void dump(Formatter *f) const; - void print(ostream& out) const; -}; + void print(std::ostream& out) const; -typedef boost::intrusive_ptr DeviceStateRef; +private: + FRIEND_MAKE_REF(DeviceState); + DeviceState(const std::string& n) : devid(n) {} +}; /** * Fuse the collection of per-daemon metadata from Ceph into @@ -240,25 +213,26 @@ typedef boost::intrusive_ptr DeviceStateRef; class DaemonStateIndex { private: - mutable RWLock lock = {"DaemonStateIndex", true, true, true}; + mutable ceph::shared_mutex lock = + ceph::make_shared_mutex("DaemonStateIndex", true, true, true); std::map by_server; DaemonStateCollection all; std::set updating; - std::map devices; + std::map> devices; void _erase(const DaemonKey& dmk); - DeviceStateRef _get_or_create_device(const std::string& dev) { - auto p = devices.find(dev); - if (p != devices.end()) { - return p->second; + ceph::ref_t _get_or_create_device(const std::string& dev) { + auto em = devices.try_emplace(dev, nullptr); + auto& d = em.first->second; + if (em.second) { + d = ceph::make_ref(dev); } - devices[dev] = new DeviceState(dev); - return devices[dev]; + return d; } - void _erase_device(DeviceStateRef d) { + void _erase_device(const ceph::ref_t& d) { devices.erase(d->devid); } @@ -286,7 +260,7 @@ public: template auto with_daemons_by_server(Callback&& cb, Args&&... args) const -> decltype(cb(by_server, std::forward(args)...)) { - RWLock::RLocker l(lock); + std::shared_lock l{lock}; return std::forward(cb)(by_server, std::forward(args)...); } @@ -294,7 +268,7 @@ public: template bool with_device(const std::string& dev, Callback&& cb, Args&&... args) const { - RWLock::RLocker l(lock); + std::shared_lock l{lock}; auto p = devices.find(dev); if (p == devices.end()) { return false; @@ -306,7 +280,7 @@ public: template bool with_device_write(const std::string& dev, Callback&& cb, Args&&... args) { - RWLock::WLocker l(lock); + std::unique_lock l{lock}; auto p = devices.find(dev); if (p == devices.end()) { return false; @@ -321,14 +295,14 @@ public: template void with_device_create(const std::string& dev, Callback&& cb, Args&&... args) { - RWLock::WLocker l(lock); + std::unique_lock l{lock}; auto d = _get_or_create_device(dev); std::forward(cb)(*d, std::forward(args)...); } template void with_devices(Callback&& cb, Args&&... args) const { - RWLock::RLocker l(lock); + std::shared_lock l{lock}; for (auto& i : devices) { std::forward(cb)(*i.second, std::forward(args)...); } @@ -338,7 +312,7 @@ public: void with_devices2(CallbackInitial&& cbi, // with lock taken Callback&& cb, // for each device Args&&... args) const { - RWLock::RLocker l(lock); + std::shared_lock l{lock}; cbi(); for (auto& i : devices) { std::forward(cb)(*i.second, std::forward(args)...); @@ -357,25 +331,25 @@ public: } void notify_updating(const DaemonKey &k) { - RWLock::WLocker l(lock); + std::unique_lock l{lock}; updating.insert(k); } void clear_updating(const DaemonKey &k) { - RWLock::WLocker l(lock); + std::unique_lock l{lock}; updating.erase(k); } bool is_updating(const DaemonKey &k) { - RWLock::RLocker l(lock); + std::shared_lock l{lock}; return updating.count(k) > 0; } void update_metadata(DaemonStatePtr state, - const map& meta) { + const std::map& meta) { // remove and re-insert in case the device metadata changed - RWLock::WLocker l(lock); + std::unique_lock l{lock}; _rm(state->key); { - Mutex::Locker l2(state->lock); + std::lock_guard l2{state->lock}; state->set_metadata(meta); } _insert(state); @@ -389,6 +363,7 @@ public: */ void cull(const std::string& svc_name, const std::set& names_exist); + void cull_services(const std::set& types_exist); }; #endif