]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_rbd_client: expose locking operations
authorGreg Farnum <greg@inktank.com>
Tue, 12 Jun 2012 22:12:19 +0000 (15:12 -0700)
committerGreg Farnum <greg@inktank.com>
Sat, 16 Jun 2012 00:27:10 +0000 (17:27 -0700)
Signed-off-by: Greg Farnum <greg@inktank.com>
src/librbd/cls_rbd_client.cc
src/librbd/cls_rbd_client.h

index cb42eb7c178c3f31377e6758bad464bc5602bfa5..27159a3cff8a890e2a9f8bf9c2feb9062528b4c7 100644 (file)
@@ -314,5 +314,58 @@ namespace librbd {
 
       return 0;
     }
+
+    int list_locks(librados::IoCtx *ioctx, const std::string &oid,
+                   std::set<std::pair<std::string, std::string> > &locks,
+                   bool &exclusive)
+    {
+      bufferlist in, out;
+      int r = ioctx->exec(oid, "rbd", "list_locks", in, out);
+      if (r < 0) {
+        return r;
+      }
+
+      bufferlist::iterator iter = out.begin();
+      try {
+        ::decode(locks, iter);
+        ::decode(exclusive, iter);
+      } catch (const buffer::error &err) {
+        return -EBADMSG;
+      }
+      return 0;
+    }
+
+    int lock_image_exclusive(librados::IoCtx *ioctx, const std::string &oid,
+                             const std::string &cookie)
+    {
+      bufferlist in, out;
+      ::encode(cookie, in);
+      return ioctx->exec(oid, "rbd", "lock_exclusive", in, out);
+    }
+
+    int lock_image_shared(librados::IoCtx *ioctx, const std::string &oid,
+                          const std::string &cookie)
+    {
+      bufferlist in, out;
+      ::encode(cookie, in);
+      return ioctx->exec(oid, "rbd", "lock_shared", in, out);
+    }
+
+    int unlock_image(librados::IoCtx *ioctx, const std::string& oid,
+                         const std::string &cookie)
+    {
+      bufferlist in, out;
+      ::encode(cookie, in);
+      return ioctx->exec(oid, "rbd", "unlock_image", in, out);
+    }
+    int break_lock(librados::IoCtx *ioctx, const std::string& oid,
+                   const std::string &locker, const std::string &cookie)
+    {
+      bufferlist in, out;
+      ::encode(locker, in);
+      ::encode(cookie, in);
+      return ioctx->exec(oid, "rbd", "break_lock", in, out);
+    }
+
   } // namespace cls_client
 } // namespace librbd
index 79654480546a0c4bfec0a4d9a73753f480c986f9..abc7b4d4ed147939ba79bc94b18cf3f955deec5a 100644 (file)
@@ -49,6 +49,17 @@ namespace librbd {
     int assign_bid(librados::IoCtx *ioctx, const std::string &oid,
                   uint64_t *id);
 
+    int list_locks(librados::IoCtx *ioctx, const std::string &oid,
+                   std::set<std::pair<std::string, std::string> > &locks,
+                   bool &exclusive);
+    int lock_image_exclusive(librados::IoCtx *ioctx, const std::string &oid,
+                             const std::string &cookie);
+    int lock_image_shared(librados::IoCtx *ioctx, const std::string &oid,
+                          const std::string &cookie);
+    int unlock_image(librados::IoCtx *ioctx, const std::string& oid,
+                     const std::string &cookie);
+    int break_lock(librados::IoCtx *ioctx, const std::string& oid,
+                   const std::string &locker, const std::string &cookie);
 
     // class operations on the old format, kept for
     // backwards compatability