From 6955f53fe513d303c1aca9e5b90c255d4610b00c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 21 Oct 2009 17:02:12 -0700 Subject: [PATCH] monc: simplify authentication state 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 | 2 +- src/auth/AuthClientHandler.cc | 4 +- src/mon/MonClient.cc | 72 +++++++++++++---------------------- src/mon/MonClient.h | 10 +++-- 4 files changed, 36 insertions(+), 52 deletions(-) diff --git a/src/auth/AuthClient.h b/src/auth/AuthClient.h index f39fbd910cfb4..eff01cf7eadf7 100644 --- a/src/auth/AuthClient.h +++ b/src/auth/AuthClient.h @@ -20,7 +20,7 @@ class Message; class AuthClient { public: - virtual void send_message(Message *m) = 0; + virtual void send_auth_message(Message *m) = 0; }; diff --git a/src/auth/AuthClientHandler.cc b/src/auth/AuthClientHandler.cc index 405855fc314ac..476200aeb7df5 100644 --- a/src/auth/AuthClientHandler.cc +++ b/src/auth/AuthClientHandler.cc @@ -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? diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index e93addc28fd17..a8ece0c793d8e 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -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(); diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h index c6349477fafbf..a937b019a4eb6 100644 --- a/src/mon/MonClient.h +++ b/src/mon/MonClient.h @@ -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 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); -- 2.39.5