]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: use unlock_guard for unlock osd temporarily
authorKefu Chai <kchai@redhat.com>
Sun, 30 Dec 2018 13:46:55 +0000 (21:46 +0800)
committerVenky Shankar <vshankar@redhat.com>
Tue, 8 Jan 2019 08:45:04 +0000 (03:45 -0500)
when OSD::do_command() gets called, osd_lock is acquired. but when
serving some of these commands, we need to call methods which also
acquire the osd_lock by themselves. for instance,
OSD::handle_conf_change() gets called by cct->_conf.apply_changes().
to allow them to do so, we unlock osd_lock before calling those methods,
and re-lock it after done with them.

unlock_guard is introduced to unlock and re-lock the lock in a RAII style.

Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit 5c628a1cc9f703351ad3bd708e908df7c9a411bb)

 Conflicts:
src/osd/OSD.cc

src/osd/OSD.cc

index 31a821517cdc735e8f27856cb1ba309b83a79791..b7ca0622eca9aa85e50260dcef09b9fa707c9f81 100644 (file)
@@ -6598,6 +6598,22 @@ COMMAND("compact",
         "osd", "rw", "cli,rest")
 };
 
+namespace {
+  class unlock_guard {
+    Mutex& m;
+  public:
+    explicit unlock_guard(Mutex& mutex)
+      : m(mutex)
+    {
+      m.Unlock();
+    }
+    unlock_guard(unlock_guard&) = delete;
+    ~unlock_guard() {
+      m.Lock();
+    }
+  };
+}
+
 void OSD::do_command(Connection *con, ceph_tid_t tid, vector<string>& cmd, bufferlist& data)
 {
   int r = 0;
@@ -6671,21 +6687,19 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector<string>& cmd, buffe
     string args = argsvec.front();
     for (vector<string>::iterator a = ++argsvec.begin(); a != argsvec.end(); ++a)
       args += " " + *a;
-    osd_lock.Unlock();
+    unlock_guard unlock{osd_lock};
     r = cct->_conf->injectargs(args, &ss);
-    osd_lock.Lock();
   }
   else if (prefix == "config set") {
     std::string key;
     std::string val;
     cmd_getval(cct, cmdmap, "key", key);
     cmd_getval(cct, cmdmap, "value", val);
-    osd_lock.Unlock();
+    unlock_guard unlock{osd_lock};
     r = cct->_conf->set_val(key, val, true, &ss);
     if (r == 0) {
       cct->_conf->apply_changes(nullptr);
     }
-    osd_lock.Lock();
   }
   else if (prefix == "cluster_log") {
     vector<string> msg;