]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: fix locking in DaemonMetadata
authorJohn Spray <john.spray@redhat.com>
Thu, 30 Jun 2016 23:12:13 +0000 (00:12 +0100)
committerJohn Spray <john.spray@redhat.com>
Thu, 29 Sep 2016 16:26:57 +0000 (17:26 +0100)
Locks are great but it helps if you actually
bother acquiring them...

Signed-off-by: John Spray <john.spray@redhat.com>
src/mgr/DaemonMetadata.cc
src/mgr/DaemonMetadata.h

index dc3885c96d53d15f4c23534d013ae76b32c9963a..7ac0e3cb611a8c5a01ec7c11951c05ee4fa64f38 100644 (file)
@@ -19,7 +19,9 @@
 
 void DaemonMetadataIndex::insert(DaemonMetadataPtr dm)
 {
-  if (exists(dm->key)) {
+  Mutex::Locker l(lock);
+
+  if (all.count(dm->key)) {
     _erase(dm->key);
   }
 
@@ -43,6 +45,8 @@ void DaemonMetadataIndex::_erase(DaemonKey dmk)
 
 DaemonMetadataCollection DaemonMetadataIndex::get_by_type(uint8_t type) const
 {
+  Mutex::Locker l(lock);
+
   DaemonMetadataCollection result;
 
   for (const auto &i : all) {
@@ -56,6 +60,8 @@ DaemonMetadataCollection DaemonMetadataIndex::get_by_type(uint8_t type) const
 
 DaemonMetadataCollection DaemonMetadataIndex::get_by_server(const std::string &hostname) const
 {
+  Mutex::Locker l(lock);
+
   if (by_server.count(hostname)) {
     return by_server.at(hostname);
   } else {
@@ -65,11 +71,15 @@ DaemonMetadataCollection DaemonMetadataIndex::get_by_server(const std::string &h
 
 bool DaemonMetadataIndex::exists(const DaemonKey &key) const
 {
+  Mutex::Locker l(lock);
+
   return all.count(key) > 0;
 }
 
 DaemonMetadataPtr DaemonMetadataIndex::get(const DaemonKey &key)
 {
+  Mutex::Locker l(lock);
+
   return all.at(key);
 }
 
index 4aa406c5212532bda2edfd21ee12e487acfb5ea1..b5c00a9ada16ad308c97b83d2358df400172b0c1 100644 (file)
@@ -108,7 +108,7 @@ class DaemonMetadataIndex
 
   std::set<DaemonKey> updating;
 
-  Mutex lock;
+  mutable Mutex lock;
 
   public: