]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
uclient: use MonClient for mount + unmount
authorSage Weil <sage@newdream.net>
Thu, 7 May 2009 21:21:16 +0000 (14:21 -0700)
committerSage Weil <sage@newdream.net>
Thu, 7 May 2009 22:32:26 +0000 (15:32 -0700)
src/client/Client.cc
src/client/Client.h
src/mon/MonClient.cc
src/mon/MonClient.h

index 6361cba4eb6d4428e71b2810bf003a72c69d469c..78eb3c6c9424f3d1f443d880217edda97665ad56 100644 (file)
@@ -113,8 +113,6 @@ Client::Client(Messenger *m, MonMap *mm) : timer(client_lock), client_lock("Clie
   tick_event = 0;
 
   mounted = false;
-  mounters = 0;
-  mount_timeout_event = 0;
   unmounting = false;
 
   last_tid = 0;
@@ -133,6 +131,8 @@ Client::Client(Messenger *m, MonMap *mm) : timer(client_lock), client_lock("Clie
   // set up messengers
   messenger = m;
 
+  monclient = new MonClient(monmap, messenger);
+
   // osd interfaces
   osdmap = new OSDMap;     // initially blank.. see mount()
   mdsmap = new MDSMap;
@@ -159,6 +159,10 @@ Client::~Client()
   if (objecter) { delete objecter; objecter = 0; }
   if (osdmap) { delete osdmap; osdmap = 0; }
   if (mdsmap) { delete mdsmap; mdsmap = 0; }
+
+  unlink_dispatcher(monclient);
+  delete monclient;
+
   if (messenger)
     messenger->destroy();
 }
@@ -242,6 +246,10 @@ void Client::init()
 {
   Mutex::Locker lock(client_lock);
 
+  // ok!
+  messenger->set_dispatcher(this);
+  link_dispatcher(monclient);
+
   tick();
 
   // do logger crap only once per process.
@@ -1028,13 +1036,6 @@ bool Client::dispatch_impl(Message *m)
   client_lock.Lock();
 
   switch (m->get_type()) {
-  case CEPH_MSG_MON_MAP:
-    handle_mon_map((MMonMap*)m);
-    break;
-  case CEPH_MSG_CLIENT_MOUNT_ACK:
-    handle_mount_ack((MClientMountAck*)m);
-    break;
-
     // osd
   case CEPH_MSG_OSD_OPREPLY:
     objecter->handle_osd_op_reply((MOSDOpReply*)m);
@@ -1042,16 +1043,12 @@ bool Client::dispatch_impl(Message *m)
 
   case CEPH_MSG_OSD_MAP:
     objecter->handle_osd_map((class MOSDMap*)m);
-    if (!mounted) mount_cond.Signal();
     break;
     
     // mounting and mds sessions
   case CEPH_MSG_MDS_MAP:
     handle_mds_map((MMDSMap*)m);
     break;
-  case CEPH_MSG_CLIENT_UNMOUNT:
-    handle_unmount(m);
-    break;
   case CEPH_MSG_CLIENT_SESSION:
     handle_client_session((MClientSession*)m);
     break;
@@ -2244,27 +2241,6 @@ void Client::handle_cap_grant(Inode *in, int mds, InodeCap *cap, MClientCaps *m)
 // -------------------
 // MOUNT
 
-void Client::_try_mount()
-{
-  dout(10) << "_try_mount" << dendl;
-  int mon = monmap->pick_mon();
-  dout(2) << "sending client_mount to mon" << mon << dendl;
-  messenger->set_dispatcher(this);
-  messenger->send_message(new MClientMount, monmap->get_inst(mon));
-
-  // schedule timeout?
-  assert(mount_timeout_event == 0);
-  mount_timeout_event = new C_MountTimeout(this);
-  timer.add_event_after(g_conf.client_mount_timeout, mount_timeout_event);
-}
-
-void Client::_mount_timeout()
-{
-  dout(10) << "_mount_timeout" << dendl;
-  mount_timeout_event = 0;
-  _try_mount();
-}
-
 int Client::mount()
 {
   Mutex::Locker lock(client_lock);
@@ -2274,33 +2250,18 @@ int Client::mount()
     return 0;
   }
 
-  // only first mounter does the work
-  bool itsme = false;
-  if (!mounters) {
-    itsme = true;
-    objecter->init();
-    _try_mount();
-  } else {
-    dout(5) << "additional mounter" << dendl;
-  }
-  mounters++;
-  
-  while (signed_ticket.length() == 0 ||
-        (!itsme && !mounted))       // non-doers wait a little longer
-    mount_cond.Wait(client_lock);
+  client_lock.Unlock();
+  int r = monclient->mount(30.0);
+  client_lock.Lock();
+  if (r < 0)
+    return r;
   
-  if (!itsme) {
-    dout(5) << "additional mounter returning" << dendl;
-    assert(mounted);
-    return 0; 
-  }
+  whoami = messenger->get_myname().num();
+
+  signed_ticket = monclient->get_signed_ticket();
+  ticket = monclient->get_ticket();
 
-  // finish.
-  timer.cancel_event(mount_timeout_event);
-  mount_timeout_event = 0;
-  
   mounted = true;
-  mount_cond.SignalAll(); // wake up non-doers
   
   dout(2) << "mounted: have osdmap " << osdmap->get_epoch() 
          << " and mdsmap " << mdsmap->get_epoch() 
@@ -2344,46 +2305,13 @@ int Client::mount()
   return 0;
 }
 
-void Client::handle_mon_map(MMonMap *m)
-{
-  dout(10) << "handle_mon_map " << *m << dendl;
-  // just ignore it for now.
-  delete m;
-}
-
-void Client::handle_mount_ack(MClientMountAck* m)
-{
-  dout(10) << "handle_mount_ack " << *m << dendl;
-
-  assert(m->get_source().is_mon());
-  whoami = m->get_dest().num();
-  messenger->reset_myname(entity_name_t::CLIENT(whoami));
-  dout(1) << "handle_mount_ack i am now " << m->get_dest() << dendl;
-  
-  mount_cond.Signal();  // mount might be waiting for this.
-
-  signed_ticket = m->signed_ticket;
-  bufferlist::iterator p = signed_ticket.begin();
-  ::decode(ticket, p);
-
-  mount_cond.Signal();
-}
-
-
 // UNMOUNT
 
-
 int Client::unmount()
 {
   Mutex::Locker lock(client_lock);
 
   assert(mounted);  // caller is confused?
-  assert(mounters > 0);
-  if (--mounters > 0) {
-    dout(0) << "umount -- still " << mounters << " others, doing nothing" << dendl;
-    return -1;  // i'm not the last mounter.
-  }
-
 
   dout(2) << "unmounting" << dendl;
   unmounting = true;
@@ -2484,13 +2412,11 @@ int Client::unmount()
                            mdsmap->get_inst(p->first));
   }
 
-  // send unmount!
-  int mon = monmap->pick_mon();
-  dout(2) << "sending client_unmount to mon" << mon << dendl;
-  messenger->send_message(new MClientUnmount, monmap->get_inst(mon));
-  
-  while (mounted)
-    mount_cond.Wait(client_lock);
+  // leave cluster
+  client_lock.Unlock();
+  monclient->unmount();
+  client_lock.Lock();
+  mounted = false;
 
   dout(2) << "unmounted." << dendl;
 
@@ -2499,15 +2425,6 @@ int Client::unmount()
   return 0;
 }
 
-void Client::handle_unmount(Message* m)
-{
-  dout(1) << "handle_unmount got ack" << dendl;
-
-  mounted = false;
-  mount_cond.Signal();
-
-  delete m;
-}
 
 
 class C_C_Tick : public Context {
index c0da73d514fde714bc4eb0c24dcb7f0edb89aafc..0ac85a65956a79d4875cd9c62e607c506c0af8ae 100644 (file)
@@ -30,6 +30,8 @@ enum {
 #include "osd/OSDMap.h"
 #include "mon/MonMap.h"
 
+#include "mon/MonClient.h"
+
 #include "msg/Message.h"
 #include "msg/Dispatcher.h"
 #include "msg/Messenger.h"
@@ -63,12 +65,10 @@ using namespace __gnu_cxx;
 class MStatfsReply;
 class MClientSession;
 class MClientRequest;
-class MClientMountAck;
 class MClientRequestForward;
 class MClientLease;
 class MClientCaps;
 class MClientCapRelease;
-class MMonMap;
 
 class Filer;
 class Objecter;
@@ -565,6 +565,7 @@ public:
   void tick();
 
  protected:
+  MonClient *monclient;
   Messenger *messenger;  
   int whoami;
   MonMap *monmap;
@@ -638,9 +639,7 @@ public:
   void handle_statfs_reply(MStatfsReply *reply);
 
   bool   mounted;
-  int mounters;
   bool   unmounting;
-  Cond   mount_cond;  
 
   int    unsafe_sync_write;
 public:
@@ -820,6 +819,9 @@ protected:
   ofstream traceout;
 
 
+  Cond mount_cond;
+
+
   // friends
   friend class SyntheticClient;
   bool dispatch_impl(Message *m);
@@ -835,9 +837,6 @@ protected:
   void shutdown();
 
   // messaging
-  void handle_mon_map(MMonMap *m);
-  void handle_mount_ack(MClientMountAck *m);
-  void handle_unmount(Message*);
   void handle_mds_map(class MMDSMap *m);
 
   void handle_lease(MClientLease *m);
@@ -899,18 +898,6 @@ protected:
   // ----------------------
   // fs ops.
 private:
-  void _try_mount();
-  void _mount_timeout();
-  Context *mount_timeout_event;
-
-  class C_MountTimeout : public Context {
-    Client *client;
-  public:
-    C_MountTimeout(Client *c) : client(c) { }
-    void finish(int r) {
-      if (r >= 0) client->_mount_timeout();
-    }
-  };
 
   // some helpers
   int _opendir(Inode *in, DirResult **dirpp, int uid=-1, int gid=-1);
index a27328323ba17df021a6f7fee0ff2651cd5045aa..363e18b45ec866d2899d5bb887eefbac9245f97b 100644 (file)
@@ -174,6 +174,7 @@ void MonClient::handle_monmap(MMonMap *m)
   monmap_bl = m->monmapbl;
   monmap_cond.Signal();
   monmap_lock.Unlock();
+  delete m;
 }
 
 bool MonClient::dispatch_impl(Message *m)
@@ -183,23 +184,22 @@ bool MonClient::dispatch_impl(Message *m)
   switch (m->get_type()) {
   case CEPH_MSG_MON_MAP:
     handle_monmap((MMonMap*)m);
-    break;
-  case CEPH_MSG_OSD_MAP:
-  case CEPH_MSG_MDS_MAP:
-    break;
+    return true;
+
   case CEPH_MSG_CLIENT_MOUNT_ACK:
     handle_mount_ack((MClientMountAck*)m);
-    dout(0) << "got mount ack" << dendl;
-    break;
-  default:
-    return false;
+    return true;
+
+  case CEPH_MSG_CLIENT_UNMOUNT:
+    handle_unmount((MClientUnmount*)m);
+    return true;
   }
 
-  delete m;
-  return true;
+  return false;
 }
 
 
+
 // -------------------
 // MOUNT
 
@@ -274,6 +274,8 @@ void MonClient::handle_mount_ack(MClientMountAck* m)
   messenger->reset_myname(m->get_dest());
 
   mount_cond.Signal();
+
+  delete m;
 }
 
 
index 59e36dde75d51781afb8d950b33e9bcce13937a4..97001ea235456723da66f75d6b2adec4c0988084 100644 (file)
@@ -72,7 +72,12 @@ class MonClient : public Dispatcher {
 
   int mount(double mount_timeout);
   int unmount();
+
   void set_messenger(Messenger *m) { messenger = m; }
+
+  bufferlist& get_signed_ticket() { return signed_ticket; }
+  ceph_client_ticket get_ticket() { return ticket; }
+
 };
 
 #endif