]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/mgr/DaemonState.cc
update sources to 12.2.2
[ceph.git] / ceph / src / mgr / DaemonState.cc
index 290fde6513453ebccdc2e1df74ecf17447128120..a7b8f572e1614b3f0a0b420f7685ccdeccb5ecaa 100644 (file)
@@ -13,6 +13,8 @@
 
 #include "DaemonState.h"
 
+#include "MgrSession.h"
+
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_mgr
 #undef dout_prefix
@@ -20,7 +22,7 @@
 
 void DaemonStateIndex::insert(DaemonStatePtr dm)
 {
-  Mutex::Locker l(lock);
+  RWLock::WLocker l(lock);
 
   if (all.count(dm->key)) {
     _erase(dm->key);
@@ -32,7 +34,7 @@ void DaemonStateIndex::insert(DaemonStatePtr dm)
 
 void DaemonStateIndex::_erase(const DaemonKey& dmk)
 {
-  assert(lock.is_locked_by_me());
+  assert(lock.is_wlocked());
 
   const auto to_erase = all.find(dmk);
   assert(to_erase != all.end());
@@ -46,14 +48,15 @@ void DaemonStateIndex::_erase(const DaemonKey& dmk)
   all.erase(to_erase);
 }
 
-DaemonStateCollection DaemonStateIndex::get_by_type(uint8_t type) const
+DaemonStateCollection DaemonStateIndex::get_by_service(
+  const std::string& svc) const
 {
-  Mutex::Locker l(lock);
+  RWLock::RLocker l(lock);
 
   DaemonStateCollection result;
 
   for (const auto &i : all) {
-    if (i.first.first == type) {
+    if (i.first.first == svc) {
       result[i.first] = i.second;
     }
   }
@@ -61,9 +64,10 @@ DaemonStateCollection DaemonStateIndex::get_by_type(uint8_t type) const
   return result;
 }
 
-DaemonStateCollection DaemonStateIndex::get_by_server(const std::string &hostname) const
+DaemonStateCollection DaemonStateIndex::get_by_server(
+  const std::string &hostname) const
 {
-  Mutex::Locker l(lock);
+  RWLock::RLocker l(lock);
 
   if (by_server.count(hostname)) {
     return by_server.at(hostname);
@@ -74,29 +78,34 @@ DaemonStateCollection DaemonStateIndex::get_by_server(const std::string &hostnam
 
 bool DaemonStateIndex::exists(const DaemonKey &key) const
 {
-  Mutex::Locker l(lock);
+  RWLock::RLocker l(lock);
 
   return all.count(key) > 0;
 }
 
 DaemonStatePtr DaemonStateIndex::get(const DaemonKey &key)
 {
-  Mutex::Locker l(lock);
+  RWLock::RLocker l(lock);
 
-  return all.at(key);
+  auto iter = all.find(key);
+  if (iter != all.end()) {
+    return iter->second;
+  } else {
+    return nullptr;
+  }
 }
 
-void DaemonStateIndex::cull(entity_type_t daemon_type,
+void DaemonStateIndex::cull(const std::string& svc_name,
                            const std::set<std::string>& names_exist)
 {
   std::vector<string> victims;
 
-  Mutex::Locker l(lock);
-  auto begin = all.lower_bound({daemon_type, ""});
+  RWLock::WLocker l(lock);
+  auto begin = all.lower_bound({svc_name, ""});
   auto end = all.end();
   for (auto &i = begin; i != end; ++i) {
     const auto& daemon_key = i->first;
-    if (daemon_key.first != daemon_type)
+    if (daemon_key.first != svc_name)
       break;
     if (names_exist.count(daemon_key.second) == 0) {
       victims.push_back(daemon_key.second);
@@ -105,7 +114,7 @@ void DaemonStateIndex::cull(entity_type_t daemon_type,
 
   for (auto &i : victims) {
     dout(4) << "Removing data for " << i << dendl;
-    _erase({daemon_type, i});
+    _erase({svc_name, i});
   }
 }
 
@@ -116,14 +125,18 @@ void DaemonPerfCounters::update(MMgrReport *report)
           << types.size() << " types, got "
            << report->packed.length() << " bytes of data" << dendl;
 
+  // Retrieve session state
+  MgrSessionRef session(static_cast<MgrSession*>(
+        report->get_connection()->get_priv()));
+
   // Load any newly declared types
   for (const auto &t : report->declare_types) {
     types.insert(std::make_pair(t.path, t));
-    declared_types.insert(t.path);
+    session->declared_types.insert(t.path);
   }
   // Remove any old types
   for (const auto &t : report->undeclare_types) {
-    declared_types.erase(t);
+    session->declared_types.erase(t);
   }
 
   const auto now = ceph_clock_now();
@@ -131,7 +144,7 @@ void DaemonPerfCounters::update(MMgrReport *report)
   // Parse packed data according to declared set of types
   bufferlist::iterator p = report->packed.begin();
   DECODE_START(1, p);
-  for (const auto &t_path : declared_types) {
+  for (const auto &t_path : session->declared_types) {
     const auto &t = types.at(t_path);
     uint64_t val = 0;
     uint64_t avgcount = 0;