From: Sage Weil Date: Fri, 21 Jan 2011 17:35:31 +0000 (-0800) Subject: monclient: fix locking X-Git-Tag: v0.24.2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=027335afe30127f841a5ea875e173ffc4cd7cf91;p=ceph.git monclient: fix locking Hold lock in handle_* methods; assert lock held in all _* methods. Fixes: #731 Signed-off-by: Sage Weil --- diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index fc7b15d23b71..e3211c04a9e8 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -238,8 +238,8 @@ bool MonClient::ms_dispatch(Message *m) void MonClient::handle_monmap(MMonMap *m) { + Mutex::Locker lock(monc_lock); dout(10) << "handle_monmap " << *m << dendl; - monc_lock.Lock(); assert(!cur_mon.empty()); entity_addr_t cur_mon_addr = monmap.get_addr(cur_mon); @@ -270,7 +270,6 @@ void MonClient::handle_monmap(MMonMap *m) else _finish_hunting(); - monc_lock.Unlock(); m->put(); } @@ -352,6 +351,8 @@ int MonClient::authenticate(double timeout) void MonClient::handle_auth(MAuthReply *m) { + Mutex::Locker lock(monc_lock); + bufferlist::iterator p = m->result_bl.begin(); if (state == MC_STATE_NEGOTIATING) { if (!auth || (int)m->protocol != auth->get_protocol()) { @@ -409,6 +410,7 @@ void MonClient::handle_auth(MAuthReply *m) void MonClient::_send_mon_message(Message *m, bool force) { + assert(monc_lock.is_locked()); assert(!cur_mon.empty()); if (force || state == MC_STATE_HAVE_SESSION) { dout(10) << "_send_mon_message to mon." << cur_mon << " at " << monmap.get_inst(cur_mon) << dendl; @@ -420,6 +422,7 @@ void MonClient::_send_mon_message(Message *m, bool force) void MonClient::_pick_new_mon() { + assert(monc_lock.is_locked()); if (!cur_mon.empty()) messenger->mark_down(monmap.get_addr(cur_mon)); @@ -435,6 +438,7 @@ void MonClient::_pick_new_mon() void MonClient::_reopen_session() { + assert(monc_lock.is_locked()); dout(10) << "_reopen_session" << dendl; _pick_new_mon(); @@ -485,6 +489,7 @@ bool MonClient::ms_handle_reset(Connection *con) void MonClient::_finish_hunting() { + assert(monc_lock.is_locked()); if (hunting) { dout(1) << "found mon." << cur_mon << dendl; hunting = false; @@ -528,6 +533,7 @@ void MonClient::schedule_tick() void MonClient::_renew_subs() { + assert(monc_lock.is_locked()); if (sub_have.empty()) { dout(10) << "renew_subs - empty" << dendl; return; @@ -548,6 +554,8 @@ void MonClient::_renew_subs() void MonClient::handle_subscribe_ack(MMonSubscribeAck *m) { + Mutex::Locker lock(monc_lock); + _finish_hunting(); if (sub_renew_sent != utime_t()) { @@ -564,6 +572,7 @@ void MonClient::handle_subscribe_ack(MMonSubscribeAck *m) int MonClient::_check_auth_tickets() { + assert(monc_lock.is_locked()); if (state == MC_STATE_HAVE_SESSION && auth) { if (auth->need_tickets()) { dout(10) << "_check_auth_tickets getting new tickets!" << dendl; @@ -580,6 +589,7 @@ int MonClient::_check_auth_tickets() int MonClient::_check_auth_rotating() { + assert(monc_lock.is_locked()); if (!rotating_secrets || !auth_principal_needs_rotating_keys(entity_name)) { dout(20) << "_check_auth_rotating not needed by " << entity_name << dendl;