]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
auth: rename ClientAuth to Auth, MonClient basic infrastructure
authorYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 25 Aug 2009 00:22:34 +0000 (17:22 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 25 Aug 2009 00:22:34 +0000 (17:22 -0700)
12 files changed:
src/Makefile.am
src/include/ceph_fs.h
src/messages/MAuth.h [new file with mode: 0644]
src/messages/MAuthReply.h [new file with mode: 0644]
src/messages/MClientAuth.h [deleted file]
src/messages/MClientAuthReply.h [deleted file]
src/mon/ClientMonitor.cc
src/mon/ClientMonitor.h
src/mon/MonClient.cc
src/mon/MonClient.h
src/mon/Monitor.cc
src/msg/Message.cc

index 4768007ff53f17a1aecd337460b38726b733a313..905848f9b5c47081fe43cfd19e6f2b72d8831d71 100644 (file)
@@ -546,7 +546,8 @@ noinst_HEADERS = \
         mds/mds_table_types.h\
         mds/mdstypes.h\
         mds/snap.h\
-        messages/MCacheExpire.h\
+        messages/MAuth.h\
+        messages/MAuthReply.h\
        messages/MClass.h\
        messages/MClassAck.h\
         messages/MClientCaps.h\
index cda382786c4627cfd689a3cf42c3f8c4a984f983..2c57ca45fd282d9fb5705d7404248144b8fb8cd4 100644 (file)
@@ -270,8 +270,8 @@ struct ceph_secret {
 #define CEPH_MSG_CLIENT_UNMOUNT         12
 #define CEPH_MSG_STATFS                 13
 #define CEPH_MSG_STATFS_REPLY           14
-#define CEPH_MSG_CLIENT_AUTH           15
-#define CEPH_MSG_CLIENT_AUTH_REPLY     16
+#define CEPH_MSG_AUTH                  15
+#define CEPH_MSG_AUTH_REPLY            16
 
 /* client <-> mds */
 #define CEPH_MSG_MDS_GETMAP             20
diff --git a/src/messages/MAuth.h b/src/messages/MAuth.h
new file mode 100644 (file)
index 0000000..1f6fbbd
--- /dev/null
@@ -0,0 +1,39 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software 
+ * Foundation.  See file COPYING.
+ * 
+ */
+
+#ifndef __MAUTH_H
+#define __MAUTH_H
+
+#include "messages/PaxosServiceMessage.h"
+
+class MAuth : public PaxosServiceMessage {
+  bufferlist auth_payload;
+public:
+  MAuth() : PaxosServiceMessage(CEPH_MSG_AUTH, 0) { }
+
+  const char *get_type_name() { return "client_auth"; }
+
+  void decode_payload() {
+    bufferlist::iterator p = payload.begin();
+    paxos_decode(p);
+    p.copy(payload.length() - p.get_off(), auth_payload);
+  }
+  void encode_payload() {
+    paxos_encode();
+    payload.append(auth_payload);
+  }
+  bufferlist& get_auth_payload() { return auth_payload; }
+};
+
+#endif
diff --git a/src/messages/MAuthReply.h b/src/messages/MAuthReply.h
new file mode 100644 (file)
index 0000000..89ac8a2
--- /dev/null
@@ -0,0 +1,57 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software 
+ * Foundation.  See file COPYING.
+ * 
+ */
+
+#ifndef __MAUTHREPLY_H
+#define __MAUTHREPLY_H
+
+#include "msg/Message.h"
+
+struct MAuthReply : public Message {
+  __s32 result;
+  cstring result_msg;
+  bufferlist result_bl;
+
+  MAuthReply(bufferlist *bl = NULL, int r = 0, const char *msg = 0) :
+    Message(CEPH_MSG_AUTH_REPLY),
+    result(r),
+    result_msg(msg) {
+    if (bl) {
+      bufferlist::iterator iter = bl->begin();
+      iter.copy(bl->length(), result_bl);
+    }
+  }
+
+  const char *get_type_name() { return "auth_reply"; }
+  void print(ostream& o) {
+    o << "auth_reply(" << result;
+    if (result_msg.length()) o << " " << result_msg;
+    o << ")";
+  }
+
+  void decode_payload() {
+    bufferlist::iterator p = payload.begin();
+    ::decode(result, p);
+    ::decode(result_bl, p);
+    ::decode(result_msg, p);
+  }
+  void encode_payload() {
+    ::encode(result, payload);
+    ::encode(result_bl, payload);
+    ::encode(result_msg, payload);
+
+    dout(0) << "MAuthReply size=" << payload.length() << dendl;
+  }
+};
+
+#endif
diff --git a/src/messages/MClientAuth.h b/src/messages/MClientAuth.h
deleted file mode 100644 (file)
index 32814fb..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
- * Foundation.  See file COPYING.
- * 
- */
-
-#ifndef __MCLIENTAUTH_H
-#define __MCLIENTAUTH_H
-
-#include "messages/PaxosServiceMessage.h"
-
-class MClientAuth : public PaxosServiceMessage {
-  bufferlist auth_payload;
-public:
-  MClientAuth() : PaxosServiceMessage(CEPH_MSG_CLIENT_AUTH, 0) { }
-
-  const char *get_type_name() { return "client_auth"; }
-
-  void decode_payload() {
-    bufferlist::iterator p = payload.begin();
-    paxos_decode(p);
-    p.copy(payload.length() - p.get_off(), auth_payload);
-  }
-  void encode_payload() {
-    paxos_encode();
-    payload.append(auth_payload);
-  }
-  bufferlist& get_auth_payload() { return auth_payload; }
-};
-
-#endif
diff --git a/src/messages/MClientAuthReply.h b/src/messages/MClientAuthReply.h
deleted file mode 100644 (file)
index 360ae07..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
-// vim: ts=8 sw=2 smarttab
-/*
- * Ceph - scalable distributed file system
- *
- * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
- *
- * This is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
- * Foundation.  See file COPYING.
- * 
- */
-
-#ifndef __MCLIENTAUTHREPLY_H
-#define __MCLIENTAUTHREPLY_H
-
-#include "msg/Message.h"
-
-struct MClientAuthReply : public Message {
-  __s32 result;
-  cstring result_msg;
-  bufferlist result_bl;
-
-  MClientAuthReply(bufferlist *bl = NULL, int r = 0, const char *msg = 0) :
-    Message(CEPH_MSG_CLIENT_AUTH_REPLY),
-    result(r),
-    result_msg(msg) {
-    if (bl) {
-      bufferlist::iterator iter = bl->begin();
-      iter.copy(bl->length(), result_bl);
-    }
-  }
-
-  const char *get_type_name() { return "client_auth_reply"; }
-  void print(ostream& o) {
-    o << "client_auth_reply(" << result;
-    if (result_msg.length()) o << " " << result_msg;
-    o << ")";
-  }
-
-  void decode_payload() {
-    bufferlist::iterator p = payload.begin();
-    ::decode(result, p);
-    ::decode(result_bl, p);
-    ::decode(result_msg, p);
-  }
-  void encode_payload() {
-    ::encode(result, payload);
-    ::encode(result_bl, payload);
-    ::encode(result_msg, payload);
-
-    dout(0) << "MClientAuthReply size=" << payload.length() << dendl;
-  }
-};
-
-#endif
index f9b6b521b1f666dc1dbfce4d25da2f529a5ae2fd..12367eb515bb590bf4e2b88d14ec6eed3f6bd2f4 100644 (file)
@@ -20,8 +20,8 @@
 #include "MonitorStore.h"
 
 #include "messages/MMonMap.h"
-#include "messages/MClientAuth.h"
-#include "messages/MClientAuthReply.h"
+#include "messages/MAuth.h"
+#include "messages/MAuthReply.h"
 #include "messages/MClientMount.h"
 #include "messages/MClientMountAck.h"
 #include "messages/MClientUnmount.h"
@@ -157,7 +157,7 @@ bool ClientMonitor::check_mount(MClientMount *m)
     return false;
 }
 
-bool ClientMonitor::check_auth(MClientAuth *m)
+bool ClientMonitor::check_auth(MAuth *m)
 {
   stringstream ss;
   // already mounted?
@@ -170,7 +170,7 @@ bool ClientMonitor::check_auth(MClientAuth *m)
   bufferlist response_bl;
 
   int ret = handler->handle_request(m->get_auth_payload(), response_bl);
-  MClientAuthReply *reply = new MClientAuthReply(&response_bl, ret);
+  MAuthReply *reply = new MAuthReply(&response_bl, ret);
 
   if (reply) {
     mon->messenger->send_message(reply,
@@ -186,9 +186,9 @@ bool ClientMonitor::preprocess_query(PaxosServiceMessage *m)
   dout(10) << "preprocess_query " << *m << " from " << m->get_orig_source_inst() << dendl;
 
   switch (m->get_type()) {
-  case CEPH_MSG_CLIENT_AUTH:
+  case CEPH_MSG_AUTH:
         dout(0) << "YY preprocess_query" << dendl;
-        return check_auth((MClientAuth *)m);
+        return check_auth((MAuth *)m);
 
   case CEPH_MSG_CLIENT_MOUNT:
        return check_mount((MClientMount *)m);
index e1810115cd3d3a42a27fe3e4ce490e91ab81bf3a..0b4fc7234512b371b855539f17259b05fdc9052c 100644 (file)
@@ -35,7 +35,7 @@ using namespace std;
 
 class Monitor;
 class Paxos;
-class MClientAuth;
+class MAuth;
 class MClientMount;
 class MClientUnmount;
 class MMonCommand;
@@ -87,7 +87,7 @@ private:
 
   void committed();
 
-  bool check_auth(MClientAuth *m);
+  bool check_auth(MAuth *m);
   bool check_mount(MClientMount *m);
   void _mounted(int c, MClientMount *m);
   void _unmounted(MClientUnmount *m);
index 917deb8c5e25b9ae01a29b77fbcc1b7c73bb1258..e81d6626787d498b6539b2324acfc62642864890 100644 (file)
@@ -16,6 +16,8 @@
 #include "messages/MMonGetMap.h"
 #include "messages/MMonMap.h"
 #include "messages/MClientMount.h"
+#include "messages/MAuth.h"
+#include "messages/MAuthReply.h"
 
 #include "include/nstring.h"
 
@@ -26,6 +28,8 @@
 #include "MonClient.h"
 #include "MonMap.h"
 
+#include "auth/Auth.h"
+
 #include "config.h"
 
 
@@ -307,3 +311,79 @@ void MonClient::pick_new_mon()
   messenger->mark_down(monmap.get_inst(oldmon).addr);
   monmap.pick_mon(true);
 }
+
+void MonClient::_try_do_op(MonClientOpCtx& ctx, double timeout)
+{
+  dout(10) << "_try_do_op" << dendl;
+  int mon = monmap.pick_mon();
+  dout(2) << "sending client_mount to mon" << mon << dendl;
+
+  MAuth *msg = new MAuth;
+  if (!msg)
+    return;
+
+  bufferlist& bl = msg->get_auth_payload();
+
+  EntityName name;
+  entity_addr_t my_addr;
+
+  build_authenticate_request(name, my_addr, bl);
+  
+  messenger->set_dispatcher(this);
+  messenger->send_message(msg, monmap.get_inst(mon));
+
+  // schedule timeout?
+  assert(ctx.timeout_event == 0);
+  ctx.timeout_event = new C_OpTimeout(this, &ctx, timeout);
+  timer.add_event_after(timeout, ctx.timeout_event);
+}
+
+/*
+  get ticket-granting-ticket for this principle
+*/
+int MonClient::do_op(MonClientOpCtx& ctx, double timeout)
+{
+  Mutex::Locker lock(monc_lock);
+
+  if (ctx.done) {
+    dout(5) << "op already done" << dendl;;
+    return 0;
+  }
+
+  // only the first does the work
+  bool itsme = false;
+  if (!ctx.num_waiters) {
+    itsme = true;
+    _try_do_op(ctx, timeout);
+  } else {
+    dout(5) << "additional get_tgt" << dendl;
+  }
+  ctx.num_waiters++;
+
+  while (!ctx.got_data ||
+        (!itsme && !ctx.done)) // non-doers wait a little longer
+       ctx.cond.Wait(monc_lock);
+
+  if (!itsme) {
+    dout(5) << "additional get_tgt returning" << dendl;
+    assert(ctx.got_data);
+    return 0;
+  }
+
+  // finish.
+  timer.cancel_event(ctx.timeout_event);
+  ctx.timeout_event = 0;
+
+  ctx.got_data = true;
+  ctx.cond.SignalAll(); // wake up non-doers
+
+  return 0;
+}
+
+void MonClient::_op_timeout(MonClientOpCtx& ctx, double timeout)
+{
+  dout(10) << "_op_timeout" << dendl;
+  ctx.timeout_event = 0;
+  _try_do_op(ctx, timeout);
+}
+
index 992217fe266a818e4852295dc646fa9defbb3441..3e2383d1bcd5b40cc04957f7070ba80391943f4d 100644 (file)
@@ -35,6 +35,8 @@ private:
 
   bufferlist signed_ticket;
 
+  bufferlist tgt;
+
   Context *mount_timeout_event;
 
   Mutex monc_lock;
@@ -44,7 +46,6 @@ private:
   bool unmounting;
   Cond mount_cond, map_cond;
 
-
   bool dispatch_impl(Message *m);
   void handle_monmap(MMonMap *m);
 
@@ -59,10 +60,43 @@ private:
     }
   };
 
+  class MonClientOpCtx {
+  public:
+    bool done;
+    int num_waiters;
+    Cond cond;
+    Context *timeout_event;
+    bool got_data;
+
+    MonClientOpCtx() {
+      done = false;
+      num_waiters = 0;
+      got_data = false;
+    }
+  };
+  
+  class C_OpTimeout : public Context {
+    MonClient *client;
+    MonClientOpCtx *op_ctx;
+    double timeout;
+  public:
+    C_OpTimeout(MonClient *c, MonClientOpCtx *opc, double to) :
+                                        client(c), op_ctx(opc), timeout(to) {
+    }
+    void finish(int r) {
+      if (r >= 0) client->_op_timeout(*op_ctx, timeout);
+    }
+  };
+
   void _try_mount(double timeout);
   void _mount_timeout(double timeout);
   void handle_mount_ack(MClientMountAck* m);
   void handle_unmount(Message* m);
+  void _op_timeout(MonClientOpCtx& ctx, double timeout);
+
+  void _try_do_op(MonClientOpCtx& ctx, double timeout);
+  int do_op(MonClientOpCtx& ctx, double timeout);
+
  public:
   MonClient() : messenger(NULL),
                monc_lock("MonClient::monc_lock"),
index 6ad84d48b9a0b1c36790fd6f5d593f4fa330f7be..ff74b9898ede041b7beec09178bfca2eac246763 100644 (file)
@@ -405,7 +405,7 @@ bool Monitor::dispatch_impl(Message *m)
       break;
 
       // clients
-    case CEPH_MSG_CLIENT_AUTH:
+    case CEPH_MSG_AUTH:
       dout(0) << "Monitor::dispatch_impl() got CEPH_MSG_CLIENT_AUTH" << dendl;
     case CEPH_MSG_CLIENT_MOUNT:
     case CEPH_MSG_CLIENT_UNMOUNT:
index 3e12e4f09c76285b25d2a45636d09260d9cb3de3..4777fefc58e8b9041a29655be2c9a3920d085af5 100644 (file)
@@ -63,8 +63,8 @@ using namespace std;
 #include "messages/MMonMap.h"
 #include "messages/MMonGetMap.h"
 
-#include "messages/MClientAuth.h"
-#include "messages/MClientAuthReply.h"
+#include "messages/MAuth.h"
+#include "messages/MAuthReply.h"
 #include "messages/MClientMount.h"
 #include "messages/MClientMountAck.h"
 #include "messages/MClientUnmount.h"
@@ -305,14 +305,15 @@ Message *decode_message(ceph_msg_header& header, ceph_msg_footer& footer,
     m = new MRemoveSnaps;
     break;
 
-
-    // clients
-  case CEPH_MSG_CLIENT_AUTH:
-    m = new MClientAuth;
+   // auth
+  case CEPH_MSG_AUTH:
+    m = new MAuth;
     break;
-  case CEPH_MSG_CLIENT_AUTH_REPLY:
-    m = new MClientAuthReply;
+  case CEPH_MSG_AUTH_REPLY:
+    m = new MAuthReply;
     break;
+
+    // clients
   case CEPH_MSG_CLIENT_MOUNT:
     m = new MClientMount;
     break;