]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: add Mutex and flag to cover execution of handle_map_lock.
authorGreg Farnum <gregf@hq.newdream.net>
Thu, 29 Jul 2010 17:24:14 +0000 (10:24 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Tue, 3 Aug 2010 21:56:01 +0000 (14:56 -0700)
Fixes a crash when the cluster and client messenger both dispatch an
OSDMap and their handling gets intertwined.

src/osd/OSD.cc
src/osd/OSD.h

index fb85fa46145fd4f28cb4e4b81f141db3483f14a0..f6003d7508ec0f1840aada1d9c5ea062584c519b 100644 (file)
@@ -336,6 +336,7 @@ OSD::OSD(int id, Messenger *internal_messenger, Messenger *external_messenger, M
   monc(mc),
   logger(NULL), logger_started(false),
   store(NULL),
+  map_in_progress(false),
   logclient(cluster_messenger, &mc->monmap, mc),
   whoami(id),
   dev_path(dev), journal_path(jdev),
@@ -378,6 +379,9 @@ OSD::OSD(int id, Messenger *internal_messenger, Messenger *external_messenger, M
   remove_wq(this, &disk_tp)
 {
   monc->set_messenger(client_messenger);
+  if (client_messenger != cluster_messenger)
+    handle_map_lock = new Mutex("OSD::handle_map_lock");
+  else handle_map_lock = NULL;
   
   osdmap = 0;
 
@@ -2157,6 +2161,19 @@ void OSD::handle_osd_map(MOSDMap *m)
   if (session)
     session->put();
 
+  if (handle_map_lock) {
+    handle_map_lock->Lock();
+    if (map_in_progress) {
+      dout(15) << "waiting for prior handle_osd_map to complete" << dendl;
+      Cond map_cond;
+      while (map_in_progress)
+        map_cond.Wait(*handle_map_lock);
+    }
+    dout(10) << "locking handle_osd_map permissions" << dendl;
+    map_in_progress = true;
+    handle_map_lock->Unlock();
+  }
+
   if (osdmap) {
     dout(3) << "handle_osd_map epochs [" 
             << m->get_first() << "," << m->get_last() 
@@ -2446,6 +2463,13 @@ void OSD::handle_osd_map(MOSDMap *m)
 
   if (is_booting())
     send_boot();
+
+  if (handle_map_lock) {
+    handle_map_lock->Lock();
+    map_in_progress = false;
+    dout(15) << "unlocking map_in_progress" << dendl;
+    handle_map_lock->Unlock();
+  }
 }
 
 
index 25bb5d74082c6956df4bb73f1288cb246aa7299b..5aa98e6d6563f148afcc9586cff50116d671c34d 100644 (file)
@@ -112,6 +112,9 @@ protected:
   bool         logger_started;
   ObjectStore *store;
 
+  Mutex *handle_map_lock; //to cover OSDMap update data when using multiple msgrs
+  bool map_in_progress;
+
   LogClient   logclient;
 
   int whoami;