]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_lock_client: clean up reference parameters
authorJosh Durgin <josh.durgin@inktank.com>
Fri, 31 Aug 2012 15:18:07 +0000 (08:18 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Tue, 18 Sep 2012 22:36:11 +0000 (15:36 -0700)
These should all be const. The remaining reference parameters
will be converted to pointers in another commit.

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

index 8d47a841313c55b4dd4e86b4c43f51745f82b48f..52a41f8abac74a3f7397c86586a9605c4e0cba58 100644 (file)
@@ -33,10 +33,10 @@ namespace rados {
     namespace lock {
 
       void lock(ObjectWriteOperation& rados_op,
-                string& name, ClsLockType type,
-                string& cookie, string& tag,
-                string description,
-                utime_t& duration, uint8_t flags)
+                const string& name, ClsLockType type,
+                const string& cookie, const string& tag,
+                const string& description,
+                const utime_t& duration, uint8_t flags)
       {
         cls_lock_lock_op op;
         op.name = name;
@@ -52,10 +52,11 @@ namespace rados {
       }
 
       int lock(IoCtx& ioctx,
-               string& oid,
-               string& name, ClsLockType type,
-               string& cookie, string& tag,
-               string description, utime_t& duration, uint8_t flags)
+               const string& oid,
+               const string& name, ClsLockType type,
+               const string& cookie, const string& tag,
+               const string& description, const utime_t& duration,
+              uint8_t flags)
       {
         ObjectWriteOperation op;
         lock(op, name, type, cookie, tag, description, duration, flags);
@@ -63,7 +64,7 @@ namespace rados {
       }
 
       void unlock(ObjectWriteOperation& rados_op,
-                  string& name, string& cookie)
+                  const string& name, const string& cookie)
       {
         cls_lock_unlock_op op;
         op.name = name;
@@ -74,8 +75,8 @@ namespace rados {
         rados_op.exec("lock", "unlock", in);
       }
 
-      int unlock(IoCtx& ioctx, string& oid,
-                 string& name, string& cookie)
+      int unlock(IoCtx& ioctx, const string& oid,
+                 const string& name, const string& cookie)
       {
         ObjectWriteOperation op;
         unlock(op, name, cookie);
@@ -83,8 +84,8 @@ namespace rados {
       }
 
       void break_lock(ObjectWriteOperation& rados_op,
-                      string& name, string& cookie,
-                      entity_name_t& locker)
+                      const string& name, const string& cookie,
+                      const entity_name_t& locker)
       {
         cls_lock_break_op op;
         op.name = name;
@@ -95,16 +96,16 @@ namespace rados {
         rados_op.exec("lock", "break_lock", in);
       }
 
-      int break_lock(IoCtx& ioctx, string& oid,
-                     string& name, string& cookie,
-                     entity_name_t& locker)
+      int break_lock(IoCtx& ioctx, const string& oid,
+                     const string& name, const string& cookie,
+                     const entity_name_t& locker)
       {
         ObjectWriteOperation op;
         break_lock(op, name, cookie, locker);
         return ioctx.operate(oid, &op);
       }
 
-      int list_locks(IoCtx& ioctx, string& oid, list<string> *locks)
+      int list_locks(IoCtx& ioctx, const string& oid, list<string> *locks)
       {
         bufferlist in, out;
         int r = ioctx.exec(oid, "lock", "list_locks", in, out);
@@ -124,7 +125,7 @@ namespace rados {
         return 0;
       }
 
-      int get_lock_info(IoCtx& ioctx, string& oid, string& lock,
+      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)
@@ -166,7 +167,7 @@ namespace rados {
              cookie, tag, description, duration, flags);
       }
 
-      int Lock::lock_shared(IoCtx& ioctx, string& oid)
+      int Lock::lock_shared(IoCtx& ioctx, const string& oid)
       {
         return lock(ioctx, oid, name, LOCK_SHARED,
                     cookie, tag, description, duration, flags);
@@ -178,7 +179,7 @@ namespace rados {
              cookie, tag, description, duration, flags);
       }
 
-      int Lock::lock_exclusive(IoCtx& ioctx, string& oid)
+      int Lock::lock_exclusive(IoCtx& ioctx, const string& oid)
       {
         return lock(ioctx, oid, name, LOCK_EXCLUSIVE,
                     cookie, tag, description, duration, flags);
@@ -189,17 +190,17 @@ namespace rados {
        rados::cls::lock::unlock(op, name, cookie);
       }
 
-      int Lock::unlock(IoCtx& ioctx, string& oid)
+      int Lock::unlock(IoCtx& ioctx, const string& oid)
       {
         return rados::cls::lock::unlock(ioctx, oid, name, cookie);
       }
 
-      void Lock::break_lock(ObjectWriteOperation& op, entity_name_t& locker)
+      void Lock::break_lock(ObjectWriteOperation& op, const entity_name_t& locker)
       {
        rados::cls::lock::break_lock(op, name, cookie, locker);
       }
 
-      int Lock::break_lock(IoCtx& ioctx, string& oid, entity_name_t& locker)
+      int Lock::break_lock(IoCtx& ioctx, const string& oid, const entity_name_t& locker)
       {
           return rados::cls::lock::break_lock(ioctx, oid, name, cookie, locker);
       }
index 4cb08e8692091f0572b637f8891352f7838d561a..29f7a927369dfc6fa3d4ae1315d8afd520483c3e 100644 (file)
@@ -13,33 +13,37 @@ namespace rados {
     namespace lock {
 
       extern void lock(librados::ObjectWriteOperation& rados_op,
-                       std::string& name, ClsLockType type,
-                       std::string& cookie, std::string& tag,
-                       std::string description, utime_t& duration, uint8_t flags);
+                       const std::string& name, ClsLockType type,
+                       const std::string& cookie, const std::string& tag,
+                       const std::string& description, const utime_t& duration,
+                      uint8_t flags);
 
       extern int lock(librados::IoCtx& ioctx,
-                      std::string& oid,
-                      std::string& name, ClsLockType type,
-                      std::string& cookie, std::string& tag,
-                      std::string description, utime_t& duration, uint8_t flags);
+                      const std::string& oid,
+                      const std::string& name, ClsLockType type,
+                      const std::string& cookie, const std::string& tag,
+                      const std::string& description, const utime_t& duration,
+                     uint8_t flags);
 
       extern void unlock(librados::ObjectWriteOperation& rados_op,
-                         std::string& name, std::string& cookie);
+                         const std::string& name, const std::string& cookie);
 
-      extern int unlock(librados::IoCtx& ioctx, std::string& oid,
-                        std::string& name, std::string& cookie);
+      extern int unlock(librados::IoCtx& ioctx, const std::string& oid,
+                        const std::string& name, const std::string& cookie);
 
       extern void break_lock(librados::ObjectWriteOperation& op,
-                             std::string& name, std::string& cookie,
-                             entity_name_t& locker);
-
-      extern int break_lock(librados::IoCtx& ioctx, std::string& oid,
-                            std::string& name, std::string& cookie,
-                            entity_name_t& locker);
-
-      extern int list_locks(librados::IoCtx& ioctx, std::string& oid, list<std::string> *locks);
-      extern int get_lock_info(librados::IoCtx& ioctx, std::string& oid, std::string& lock,
-                               map<locker_id_t, locker_info_t> *lockers,
+                             const std::string& name, const std::string& cookie,
+                             const entity_name_t& locker);
+
+      extern int break_lock(librados::IoCtx& ioctx, const std::string& oid,
+                            const std::string& name, const std::string& cookie,
+                            const entity_name_t& locker);
+
+      extern int list_locks(librados::IoCtx& ioctx, const std::string& oid,
+                           list<std::string> *locks);
+      extern int get_lock_info(librados::IoCtx& ioctx, const std::string& oid,
+                              const std::string& lock,
+                              map<locker_id_t, locker_info_t> *lockers,
                                ClsLockType *lock_type,
                                std::string *tag);
 
@@ -71,13 +75,14 @@ namespace rados {
         void lock_exclusive(librados::ObjectWriteOperation& ioctx);
         void lock_shared(librados::ObjectWriteOperation& ioctx);
         void unlock(librados::ObjectWriteOperation& ioctx);
-        void break_lock(librados::ObjectWriteOperation& ioctx, entity_name_t& locker);
+        void break_lock(librados::ObjectWriteOperation& ioctx, const entity_name_t& locker);
 
         /* IoCtx*/
-        int lock_exclusive(librados::IoCtx& ioctx, std::string& oid);
-        int lock_shared(librados::IoCtx& ioctx, std::string& oid);
-        int unlock(librados::IoCtx& ioctx, std::string& oid);
-        int break_lock(librados::IoCtx& ioctx, std::string& oid, entity_name_t& locker);
+        int lock_exclusive(librados::IoCtx& ioctx, const std::string& oid);
+        int lock_shared(librados::IoCtx& ioctx, const std::string& oid);
+        int unlock(librados::IoCtx& ioctx, const std::string& oid);
+        int break_lock(librados::IoCtx& ioctx, const std::string& oid,
+                      const entity_name_t& locker);
       };
 
     } // namespace lock
index 6a00cdca09ac9972d23ce94b94bd1edd843dc89f..51720c01c65bdc732b27d8ac50224020110dd166 100644 (file)
@@ -60,6 +60,7 @@
  * exist (and those children exist), the parent removal is prevented.
  */
 #define RBD_CHILDREN           "rbd_children"
+#define RBD_LOCK_NAME          "rbd_lock"
 
 #define RBD_DEFAULT_OBJ_ORDER  22   /* 4MB */
 
index dbf2883cd9c32c187af4a4f8d5921c9a5ec2516f..5d5261da241803222a0dec162808c7d7df54831c 100644 (file)
@@ -1940,8 +1940,10 @@ reprotect_and_return_err:
      * checks that we think we will succeed. But for now, let's not
      * duplicate that code.
      */
-    return cls_client::lock_image_exclusive(&ictx->md_ctx,
-                                           ictx->header_oid, cookie);
+    return cls::lock::lock(&ictx->md_ctx, ictx->header_oid,
+                          RBD_LOCK_NAME, LOCK_EXCLUSIVE,
+                          cookie, "", "", utime_t(), 0)
+                          cookie);
   }
 
   int lock_shared(ImageCtx *ictx, const string& cookie)