]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
auth: monclient auth handling
authorYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 26 Aug 2009 23:11:32 +0000 (16:11 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 26 Aug 2009 23:11:32 +0000 (16:11 -0700)
src/mon/MonClient.cc
src/mon/MonClient.h

index df2d8c4c6be46a5b16f5b72781e2c2e030b374df..e99bbdf6240440672a65cb8bfe853a1b2ba19642 100644 (file)
@@ -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 */
 }
+
index fbf15b1db5a476e8f6b53e019e7eff05a88e90fb..c385570d4368c80153b2aa4216eb9e26b15fa934 100644 (file)
@@ -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;