]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
monc: simplify authentication state
authorSage Weil <sage@newdream.net>
Thu, 22 Oct 2009 00:02:12 +0000 (17:02 -0700)
committerSage Weil <sage@newdream.net>
Thu, 22 Oct 2009 00:02:12 +0000 (17:02 -0700)
Go back to a single _reopen_session() function.  If we send a message and
aren't yet authenticated, queue it up, and send it later when we finally
do authenticate.

Make send_auth_messsage() (used by AuthClientHandler) bypass that check so
that its messages always go out immediately.

src/auth/AuthClient.h
src/auth/AuthClientHandler.cc
src/mon/MonClient.cc
src/mon/MonClient.h

index f39fbd910cfb4f3a1553c3a54be80d6f4e15df42..eff01cf7eadf795b1794e37507cff397e2a46632 100644 (file)
@@ -20,7 +20,7 @@ class Message;
 
 class AuthClient {
 public:
-  virtual void send_message(Message *m) = 0;
+  virtual void send_auth_message(Message *m) = 0;
 };
 
 
index 405855fc314ac4ff24cc45c7628ba080833387dd..476200aeb7df51f27caa5d3cf08c80aa1ca2b4a4 100644 (file)
@@ -57,7 +57,7 @@ int AuthClientProtocolHandler::build_request()
 int AuthClientProtocolHandler::do_request(double timeout)
 {
   got_response = false;
-  client->client->send_message(msg);
+  client->client->send_auth_message(msg);
 
   // schedule timeout?
   assert(timeout_event == 0);
@@ -80,7 +80,7 @@ int AuthClientProtocolHandler::do_request(double timeout)
 int AuthClientProtocolHandler::do_async_request(double timeout)
 {
   got_response = false;
-  client->client->send_message(msg);
+  client->client->send_auth_message(msg);
 
 #if 0
   // schedule timeout?
index e93addc28fd1721e0b1ade8150f1a46bec4a05c2..a8ece0c793d8ec3966754f31984c28ae6d4ada5d 100644 (file)
@@ -327,8 +327,11 @@ void MonClient::handle_auth(MAuthReply *m)
       {
         dout(0) << "done authorizing" << dendl;
         state = MC_STATE_HAVE_SESSION;
+       while (!waiting_for_session.empty()) {
+         _send_mon_message(waiting_for_session.front());
+         waiting_for_session.pop_front();
+       }
         authenticate_cond.SignalAll();
-        _open_session();
       }
       break;
     default:
@@ -349,15 +352,14 @@ int MonClient::authenticate(double timeout)
 
 // ---------
 
-void MonClient::_send_mon_message(Message *m)
+void MonClient::_send_mon_message(Message *m, bool force)
 {
   assert(cur_mon >= 0);
-  messenger->send_message(m, monmap.mon_inst[cur_mon]);
-}
-
-void MonClient::send_message(Message *m)
-{
-  _send_mon_message(m);
+  if (force || state == MC_STATE_HAVE_SESSION) {
+    messenger->send_message(m, monmap.mon_inst[cur_mon]);
+  } else {
+    waiting_for_session.push_back(m);
+  }
 }
 
 void MonClient::_pick_new_mon()
@@ -368,42 +370,35 @@ void MonClient::_pick_new_mon()
   dout(10) << "_pick_new_mon picked mon" << cur_mon << dendl;
 }
 
-void MonClient::_open_session()
+void MonClient::_reopen_session()
 {
-  dout(0) << "_open_session" << dendl;
-  if (state == MC_STATE_NONE) {
+  dout(10) << "_reopen_session" << dendl;
+
+  _pick_new_mon();
+
+  // throw out old queued messages
+  while (!waiting_for_session.empty()) {
+    delete waiting_for_session.front();
+    waiting_for_session.pop_front();
+  }
+
+  // restart authentication process?
+  if (state != MC_STATE_HAVE_SESSION) {
     state = MC_STATE_AUTHENTICATING;
+    auth_handler.reset();
+    authorize_handler.reset();
     auth.send_session_request(this, &auth_handler, 30.0);
-    return;
   }
 
-  if (state != MC_STATE_HAVE_SESSION)
-    return;
-
-  if (g_keyring.need_rotating_secrets()) {
+  if (g_keyring.need_rotating_secrets())
     _start_auth_rotating();
-  }
-  dout(0) << "_open_session 2" << dendl;
 
   if (mounting)
     _send_mount();
   if (!sub_have.empty())
     _renew_subs();
-  if (!mounting && sub_have.empty()) {
+  if (!mounting && sub_have.empty())
     _send_mon_message(new MMonGetMap);
-  }
-}
-
-void MonClient::_reopen_session()
-{
-  dout(10) << "_reopen_session" << dendl;
-  if (state != MC_STATE_HAVE_SESSION) {
-    state = MC_STATE_NONE;
-    auth_handler.reset();
-    authorize_handler.reset();
-  }
-  _pick_new_mon();
-  _open_session();
 }
 
 
@@ -445,19 +440,6 @@ void MonClient::tick()
     _start_auth_rotating();
   }
 
-  if (state == MC_STATE_NONE) {
-    state = MC_STATE_AUTHENTICATING;
-    auth.send_session_request(this, &auth_handler, 30.0);
-    return;
-  }
-  if (state != MC_STATE_HAVE_SESSION) {
-    if (hunting) {
-      dout(0) << "continuing hunt" << dendl;
-      _reopen_session();
-    }
-    return;
-  }
-
   if (hunting) {
     dout(0) << "continuing hunt" << dendl;
     _reopen_session();
index c6349477fafbfa73fe12ccf93824345966c36d94..a937b019a4eb6bdcd15bd715f83c7f6095d7f140 100644 (file)
@@ -61,7 +61,6 @@ private:
 
   bool ms_dispatch(Message *m);
   bool ms_handle_reset(Connection *con);
-
   void ms_handle_remote_reset(Connection *con) {}
 
   void handle_monmap(MMonMap *m);
@@ -98,11 +97,12 @@ private:
   Cond authenticate_cond;
   utime_t mount_started;
 
+  list<Message*> waiting_for_session;
+
   void _finish_hunting();
-  void _open_session();
   void _reopen_session();
   void _pick_new_mon();
-  void _send_mon_message(Message *m);
+  void _send_mon_message(Message *m, bool force=false);
   void _send_mount();
   void handle_mount_ack(MClientMountAck* m);
 
@@ -227,7 +227,9 @@ public:
 
   void set_messenger(Messenger *m) { messenger = m; }
 
-  void send_message(Message *m);
+  void send_auth_message(Message *m) {
+    _send_mon_message(m, true);
+  }
 
   void set_want_keys(uint32_t want) {
     auth_handler.set_want_keys(want | CEPHX_PRINCIPAL_MON);