From c9c6ec5104ecb3808916049797476df54054f1d6 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 26 Aug 2009 16:11:32 -0700 Subject: [PATCH] auth: monclient auth handling --- src/mon/MonClient.cc | 46 +++++++++++++++++++++++++++++++------------- src/mon/MonClient.h | 17 +++++++++++----- 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/mon/MonClient.cc b/src/mon/MonClient.cc index df2d8c4c6be46..e99bbdf624044 100644 --- a/src/mon/MonClient.cc +++ b/src/mon/MonClient.cc @@ -172,7 +172,7 @@ bool MonClient::dispatch_impl(Message *m) break; case CEPH_MSG_AUTH_REPLY: - op_handler = &auth_handler; + op_handler = cur_auth_handler; break; default: @@ -213,9 +213,21 @@ int MonClient::unmount(double timeout) int MonClient::authorize(double mount_timeout) { - int ret = auth_handler.do_op(mount_timeout); + Mutex::Locker l(auth_lock); + int ret; - dout(0) << "auth ret=" << ret << dendl; + do { + MonClientAuthHandler h(this); + + cur_auth_handler = &h; + + int err = h.do_op(mount_timeout); + if (err < 0) + return err; + + ret = h.get_result(); + dout(0) << "auth ret=" << ret << dendl; + } while (ret == -EAGAIN); return ret; } @@ -258,6 +270,7 @@ int MonClient::MonClientOpHandler::do_op(double timeout) Mutex::Locker lock(op_lock); if (done) { + dout(5) << "op already done" << dendl;; dout(5) << "op already done" << dendl;; return 0; } @@ -275,6 +288,7 @@ int MonClient::MonClientOpHandler::do_op(double timeout) (!itsme && !done)) { // non-doers wait a little longer cond.Wait(op_lock); } + num_waiters--; if (!itsme) { dout(5) << "additional returning" << dendl; @@ -290,6 +304,7 @@ int MonClient::MonClientOpHandler::do_op(double timeout) cond.SignalAll(); // wake up non-doers + return 0; } @@ -346,24 +361,29 @@ Message *MonClient::MonClientAuthHandler::build_request() if (!msg) return NULL; bufferlist& bl = msg->get_auth_payload(); -#if 0 - - EntityName name; - entity_addr_t my_addr; - build_authenticate_request(name, my_addr, bl); -#endif - CephXEnvRequest1 req; - req.init(); - - ::encode(req, bl); + if (client->auth_client_handler.generate_request(bl) < 0) { + delete msg; + return NULL; + } return msg; } void MonClient::MonClientAuthHandler::handle_response(Message *response) { + MAuthReply* m = (MAuthReply *)response; Mutex::Locker lock(op_lock); + + dout(0) << "ret=" << m->result << dendl; + + last_result = (int)m->result; + + if (m->result == 0 || m->result == -EAGAIN) { + client->auth_client_handler.handle_response(m->result_bl); + } + cond.Signal(); return; /* FIXME */ } + diff --git a/src/mon/MonClient.h b/src/mon/MonClient.h index fbf15b1db5a47..c385570d4368c 100644 --- a/src/mon/MonClient.h +++ b/src/mon/MonClient.h @@ -39,6 +39,7 @@ private: bufferlist tgt; Mutex monc_lock; + Mutex auth_lock; bool mounted; int mounters; bool unmounting; @@ -127,18 +128,23 @@ private: class MonClientAuthHandler : public MonClientOpHandler { bool has_data; + int last_result; public: - MonClientAuthHandler(MonClient *c) : MonClientOpHandler(c) {} + MonClientAuthHandler(MonClient *c) : MonClientOpHandler(c) { + last_result = 0; + } ~MonClientAuthHandler() {} Message *build_request(); void handle_response(Message *response); - bool got_response() { return client->tgt.length() != 0; } + bool got_response() { return !client->auth_client_handler.request_pending(); } + int get_result() { return last_result; } }; MonClientMountHandler mount_handler; MonClientUnmountHandler unmount_handler; - MonClientAuthHandler auth_handler; + + MonClientAuthHandler *cur_auth_handler; void _try_mount(double timeout); void _mount_timeout(double timeout); @@ -148,9 +154,10 @@ private: public: MonClient() : messenger(NULL), monc_lock("MonClient::monc_lock"), + auth_lock("MonClient::auth_lock"), mount_handler(this), - unmount_handler(this), - auth_handler(this) { + unmount_handler(this) { + // auth_handler(this) { mounted = false; mounters = 0; unmounting = false; -- 2.39.5