]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: introduce nonlocking auth pin
authorYan, Zheng <zheng.z.yan@intel.com>
Sun, 12 Jan 2014 07:13:42 +0000 (15:13 +0800)
committerYan, Zheng <zheng.z.yan@intel.com>
Mon, 17 Feb 2014 01:37:50 +0000 (09:37 +0800)
Add a parameter to Locker::acquire_locks() to enabled nonblocking
auth pin. If nonblocking mode is enabled and an object that can't
be auth pinned is encountered, Locker::acquire_locks() aborts the
MDRequest instead of waiting.

The nonlocking mode is acquired by the cases that we want to acquire
locks after auth pinning a directory or freezing a dirfrag/subtree.

Signed-off-by: Yan, Zheng <zheng.z.yan@intel.com>
src/mds/Locker.cc
src/mds/Locker.h
src/mds/Server.cc
src/messages/MMDSSlaveRequest.h

index e00bddcf1e8ad68efb00479d718943f76269f6cf..341614b27574db9b782da37877c9792a57774626 100644 (file)
@@ -174,7 +174,8 @@ bool Locker::acquire_locks(MDRequest *mdr,
                           set<SimpleLock*> &wrlocks,
                           set<SimpleLock*> &xlocks,
                           map<SimpleLock*,int> *remote_wrlocks,
-                          CInode *auth_pin_freeze)
+                          CInode *auth_pin_freeze,
+                          bool auth_pin_nonblock)
 {
   if (mdr->done_locking &&
       !mdr->is_slave()) {  // not on slaves!  master requests locks piecemeal.
@@ -300,10 +301,15 @@ bool Locker::acquire_locks(MDRequest *mdr,
     }
     if (!object->can_auth_pin()) {
       // wait
-      dout(10) << " can't auth_pin (freezing?), waiting to authpin " << *object << dendl;
-      object->add_waiter(MDSCacheObject::WAIT_UNFREEZE, new C_MDS_RetryRequest(mdcache, mdr));
       mds->locker->drop_locks(mdr);
       mdr->drop_local_auth_pins();
+      if (auth_pin_nonblock) {
+       dout(10) << " can't auth_pin (freezing?) " << *object << ", nonblocking" << dendl;
+       mdr->aborted = true;
+       return false;
+      }
+      dout(10) << " can't auth_pin (freezing?), waiting to authpin " << *object << dendl;
+      object->add_waiter(MDSCacheObject::WAIT_UNFREEZE, new C_MDS_RetryRequest(mdcache, mdr));
       return false;
     }
   }
@@ -349,6 +355,8 @@ bool Locker::acquire_locks(MDRequest *mdr,
          (*q)->set_object_info(req->get_authpin_freeze());
        mdr->pin(*q);
       }
+      if (auth_pin_nonblock)
+       req->mark_nonblock();
       mds->send_message_mds(req, p->first);
 
       // put in waiting list
index 466f7c92f81bebc7ceb8a2aa51755e5c99394f64..a0824537c0cfd52f8a28cbb7256154614b7bff94 100644 (file)
@@ -89,7 +89,8 @@ public:
                     set<SimpleLock*> &wrlocks,
                     set<SimpleLock*> &xlocks,
                     map<SimpleLock*,int> *remote_wrlocks=NULL,
-                    CInode *auth_pin_freeze=NULL);
+                    CInode *auth_pin_freeze=NULL,
+                    bool auth_pin_nonblock=false);
 
   void cancel_locking(Mutation *mut, set<CInode*> *pneed_issue);
   void drop_locks(Mutation *mut, set<CInode*> *pneed_issue=0);
index 401203541ed830186c589e7130f1d08a717bad53..823688ea5f3fe9dc9b221d765976d0e785f0e61d 100644 (file)
@@ -1611,7 +1611,7 @@ void Server::handle_slave_auth_pin(MDRequest *mdr)
   // build list of objects
   list<MDSCacheObject*> objects;
   CInode *auth_pin_freeze = NULL;
-  bool fail = false;
+  bool fail = false, wouldblock = false;
 
   for (vector<MDSCacheObjectInfo>::iterator p = mdr->slave_request->get_authpins().begin();
        p != mdr->slave_request->get_authpins().end();
@@ -1639,6 +1639,12 @@ void Server::handle_slave_auth_pin(MDRequest *mdr)
        break;
       }
       if (!mdr->can_auth_pin(*p)) {
+       if (mdr->slave_request->is_nonblock()) {
+         dout(10) << " can't auth_pin (freezing?) " << **p << " nonblocking" << dendl;
+         fail = true;
+         wouldblock = true;
+         break;
+       }
        // wait
        dout(10) << " waiting for authpinnable on " << **p << dendl;
        (*p)->add_waiter(CDir::WAIT_UNFREEZE, new C_MDS_RetryRequest(mdcache, mdr));
@@ -1707,6 +1713,9 @@ void Server::handle_slave_auth_pin(MDRequest *mdr)
   if (auth_pin_freeze)
     auth_pin_freeze->set_object_info(reply->get_authpin_freeze());
 
+  if (wouldblock)
+    reply->mark_error_wouldblock();
+
   mds->send_message_mds(reply, mdr->slave_to_mds);
   
   // clean up this request
@@ -1749,6 +1758,9 @@ void Server::handle_slave_auth_pin_ack(MDRequest *mdr, MMDSSlaveRequest *ack)
       ++p;
     }
   }
+
+  if (ack->is_error_wouldblock())
+    mdr->aborted = true;
   
   // note slave
   mdr->more()->slaves.insert(from);
index f8f30b273af4fdc658acb6068960c6e522b4023d..67f5c787c496ce59be8547b5299a5de477ed7803 100644 (file)
@@ -94,6 +94,10 @@ class MMDSSlaveRequest : public Message {
   metareqid_t reqid;
   __u32 attempt;
   __s16 op;
+  __u16 flags;
+
+  static const unsigned FLAG_NONBLOCK  = 1;
+  static const unsigned FLAG_WOULDBLOCK        = 2;
 
   // for locking
   __u16 lock_type;  // lock object type
@@ -125,6 +129,10 @@ public:
   MDSCacheObjectInfo &get_authpin_freeze() { return object_info; }
 
   vector<MDSCacheObjectInfo>& get_authpins() { return authpins; }
+  void mark_nonblock() { flags |= FLAG_NONBLOCK; }
+  bool is_nonblock() { return (flags & FLAG_NONBLOCK); }
+  void mark_error_wouldblock() { flags |= FLAG_WOULDBLOCK; }
+  bool is_error_wouldblock() { return (flags & FLAG_WOULDBLOCK); }
 
   void set_lock_type(int t) { lock_type = t; }
 
@@ -133,7 +141,7 @@ public:
   MMDSSlaveRequest() : Message(MSG_MDS_SLAVE_REQUEST) { }
   MMDSSlaveRequest(metareqid_t ri, __u32 att, int o) : 
     Message(MSG_MDS_SLAVE_REQUEST),
-    reqid(ri), attempt(att), op(o) { }
+    reqid(ri), attempt(att), op(o), flags(0) { }
 private:
   ~MMDSSlaveRequest() {}
 
@@ -142,6 +150,7 @@ public:
     ::encode(reqid, payload);
     ::encode(attempt, payload);
     ::encode(op, payload);
+    ::encode(flags, payload);
     ::encode(lock_type, payload);
     ::encode(object_info, payload);
     ::encode(authpins, payload);
@@ -159,6 +168,7 @@ public:
     ::decode(reqid, p);
     ::decode(attempt, p);
     ::decode(op, p);
+    ::decode(flags, p);
     ::decode(lock_type, p);
     ::decode(object_info, p);
     ::decode(authpins, p);