]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_lock_client: add ObjectOperation-based get_lock_info
authorJosh Durgin <josh.durgin@inktank.com>
Fri, 31 Aug 2012 23:51:43 +0000 (16:51 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Tue, 18 Sep 2012 22:42:37 +0000 (15:42 -0700)
This will be used by librbd to grab lock info along with
the rest of its header information in a single request.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
src/cls/lock/cls_lock_client.cc
src/cls/lock/cls_lock_client.h

index d693431f716e74f18ff3915b83dafba07a1a07d3..54af41cd049265b060de61a7fb0c0de9edceb621 100644 (file)
@@ -125,23 +125,23 @@ namespace rados {
         return 0;
       }
 
-      int get_lock_info(IoCtx *ioctx, const string& oid, const string& lock,
-                        map<locker_id_t, locker_info_t> *lockers,
-                        ClsLockType *lock_type,
-                        string *tag)
+      void get_lock_info_start(ObjectReadOperation *rados_op,
+                              const string& name)
       {
-        bufferlist in, out;
+        bufferlist in;
         cls_lock_get_info_op op;
-        op.name = lock;
+        op.name = name;
         ::encode(op, in);
-        int r = ioctx->exec(oid, "lock", "get_info", in, out);
-        if (r < 0)
-          return r;
+        rados_op->exec("lock", "get_info", in);
+      }
 
+      int get_lock_info_finish(bufferlist::iterator *iter,
+                              map<locker_id_t, locker_info_t> *lockers,
+                              ClsLockType *type, string *tag)
+      {
         cls_lock_get_info_reply ret;
-        bufferlist::iterator iter = out.begin();
         try {
-          ::decode(ret, iter);
+          ::decode(ret, *iter);
         } catch (buffer::error& err) {
          return -EBADMSG;
         }
@@ -150,8 +150,8 @@ namespace rados {
           *lockers = ret.lockers;
         }
 
-        if (lock_type) {
-          *lock_type = ret.lock_type;
+        if (type) {
+          *type = ret.lock_type;
         }
 
         if (tag) {
@@ -161,6 +161,20 @@ namespace rados {
         return 0;
       }
 
+      int get_lock_info(IoCtx *ioctx, const string& oid, const string& name,
+                        map<locker_id_t, locker_info_t> *lockers,
+                        ClsLockType *type, string *tag)
+      {
+        ObjectReadOperation op;
+        get_lock_info_start(&op, name);
+       bufferlist out;
+        int r = ioctx->operate(oid, &op, &out);
+       if (r < 0)
+         return r;
+       bufferlist::iterator it = out.begin();
+       return get_lock_info_finish(&it, lockers, type, tag);
+      }
+
       void Lock::lock_shared(ObjectWriteOperation *op)
       {
         lock(op, name, LOCK_SHARED,
index 527eefed767ebef0a187704e3ebbdc52984e583e..4e2144c79b4cab0bdebedb0ed35cd6471ba69473 100644 (file)
@@ -44,11 +44,16 @@ namespace rados {
 
       extern int list_locks(librados::IoCtx *ioctx, const std::string& oid,
                            list<std::string> *locks);
+      extern void get_lock_info_start(librados::ObjectReadOperation *rados_op,
+                                     const std::string& name);
+      extern int get_lock_info_finish(ceph::bufferlist::iterator *out,
+                                     map<locker_id_t, locker_info_t> *lockers,
+                                     ClsLockType *type, std::string *tag);
+
       extern int get_lock_info(librados::IoCtx *ioctx, const std::string& oid,
-                              const std::string& lock,
+                              const std::string& name,
                               map<locker_id_t, locker_info_t> *lockers,
-                              ClsLockType *lock_type,
-                              std::string *tag);
+                              ClsLockType *type, std::string *tag);
 
       class Lock {
        std::string name;