From: Kefu Chai Date: Sun, 30 Dec 2018 13:46:55 +0000 (+0800) Subject: osd: use unlock_guard for unlock osd temporarily X-Git-Tag: v12.2.11~17^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ab57fc80317c2d1fb3ac111190b56b7a8eec816a;p=ceph.git osd: use unlock_guard for unlock osd temporarily 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 (cherry picked from commit 5c628a1cc9f703351ad3bd708e908df7c9a411bb) Conflicts: src/osd/OSD.cc --- diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 31a821517cd..b7ca0622eca 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -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& cmd, bufferlist& data) { int r = 0; @@ -6671,21 +6687,19 @@ void OSD::do_command(Connection *con, ceph_tid_t tid, vector& cmd, buffe string args = argsvec.front(); for (vector::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 msg;