]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monclient: fix locking
authorSage Weil <sage@newdream.net>
Fri, 21 Jan 2011 17:35:31 +0000 (09:35 -0800)
committerSage Weil <sage@newdream.net>
Fri, 21 Jan 2011 17:35:31 +0000 (09:35 -0800)
Hold lock in handle_* methods; assert lock held in all _* methods.

Fixes: #731
Signed-off-by: Sage Weil <sage@newdream.net>
src/mon/MonClient.cc

index fc7b15d23b71e374f042c3415276b63cf5b893d2..e3211c04a9e8b4bb6c10897915a9e05dea00e86b 100644 (file)
@@ -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;