From 3de0d4a3b5afcfb46439ca6d2d616c44d832e5d6 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 30 Aug 2012 16:39:23 -0700 Subject: cls_lock: fix some spacing Signed-off-by: Josh Durgin --- src/cls/lock/cls_lock.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/cls') diff --git a/src/cls/lock/cls_lock.cc b/src/cls/lock/cls_lock.cc index 77b6ef958ec..b8641789519 100644 --- a/src/cls/lock/cls_lock.cc +++ b/src/cls/lock/cls_lock.cc @@ -355,7 +355,7 @@ static int break_lock(cls_method_context_t hctx, } - /** +/** * Retrieve lock info: lockers, tag, exclusive * * Input: @@ -400,7 +400,7 @@ static int get_info(cls_method_context_t hctx, bufferlist *in, bufferlist *out) } - /** +/** * Retrieve a list of locks for this object * * Input: @@ -410,7 +410,8 @@ static int get_info(cls_method_context_t hctx, bufferlist *in, bufferlist *out) * @param out contains encoded cls_list_locks_reply * * @return 0 on success, -errno on failure. - */static int list_locks(cls_method_context_t hctx, bufferlist *in, bufferlist *out) + */ +static int list_locks(cls_method_context_t hctx, bufferlist *in, bufferlist *out) { CLS_LOG(20, "list_locks"); -- cgit v1.2.3 From 9c6752e8c1dfe32f10eac9ba2fab99d57067f46a Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Fri, 31 Aug 2012 08:18:07 -0700 Subject: cls_lock_client: clean up reference parameters These should all be const. The remaining reference parameters will be converted to pointers in another commit. Signed-off-by: Josh Durgin --- src/cls/lock/cls_lock_client.cc | 47 ++++++++++++++++++----------------- src/cls/lock/cls_lock_client.h | 55 ++++++++++++++++++++++------------------- src/include/rbd_types.h | 1 + src/librbd/internal.cc | 6 +++-- 4 files changed, 59 insertions(+), 50 deletions(-) (limited to 'src/cls') diff --git a/src/cls/lock/cls_lock_client.cc b/src/cls/lock/cls_lock_client.cc index 8d47a841313..52a41f8abac 100644 --- a/src/cls/lock/cls_lock_client.cc +++ b/src/cls/lock/cls_lock_client.cc @@ -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 *locks) + int list_locks(IoCtx& ioctx, const string& oid, list *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 *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); } diff --git a/src/cls/lock/cls_lock_client.h b/src/cls/lock/cls_lock_client.h index 4cb08e86920..29f7a927369 100644 --- a/src/cls/lock/cls_lock_client.h +++ b/src/cls/lock/cls_lock_client.h @@ -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 *locks); - extern int get_lock_info(librados::IoCtx& ioctx, std::string& oid, std::string& lock, - map *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 *locks); + extern int get_lock_info(librados::IoCtx& ioctx, const std::string& oid, + const std::string& lock, + map *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 diff --git a/src/include/rbd_types.h b/src/include/rbd_types.h index 6a00cdca09a..51720c01c65 100644 --- a/src/include/rbd_types.h +++ b/src/include/rbd_types.h @@ -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 */ diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index b394ddbcda8..f5923c4b61e 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -1938,8 +1938,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) -- cgit v1.2.3 From b4298fc7e60b1fd532dff3ddc1965146eab46832 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Fri, 31 Aug 2012 11:14:22 -0700 Subject: cls_lock_client: change modified reference parameters to pointers This makes it clear which parameters are modified, as our style guide states. Signed-off-by: Josh Durgin --- src/cls/lock/cls_lock_client.cc | 54 +++++++++++++------------- src/cls/lock/cls_lock_client.h | 45 +++++++++++---------- src/rados.cc | 4 +- src/rgw/rgw_gc.cc | 4 +- src/test/rados-api/cls_lock.cc | 86 ++++++++++++++++++++--------------------- 5 files changed, 98 insertions(+), 95 deletions(-) (limited to 'src/cls') diff --git a/src/cls/lock/cls_lock_client.cc b/src/cls/lock/cls_lock_client.cc index 52a41f8abac..c7893afce2b 100644 --- a/src/cls/lock/cls_lock_client.cc +++ b/src/cls/lock/cls_lock_client.cc @@ -32,7 +32,7 @@ namespace rados { namespace cls { namespace lock { - void lock(ObjectWriteOperation& rados_op, + void lock(ObjectWriteOperation *rados_op, const string& name, ClsLockType type, const string& cookie, const string& tag, const string& description, @@ -48,10 +48,10 @@ namespace rados { op.flags = flags; bufferlist in; ::encode(op, in); - rados_op.exec("lock", "lock", in); + rados_op->exec("lock", "lock", in); } - int lock(IoCtx& ioctx, + int lock(IoCtx *ioctx, const string& oid, const string& name, ClsLockType type, const string& cookie, const string& tag, @@ -59,11 +59,11 @@ namespace rados { uint8_t flags) { ObjectWriteOperation op; - lock(op, name, type, cookie, tag, description, duration, flags); - return ioctx.operate(oid, &op); + lock(&op, name, type, cookie, tag, description, duration, flags); + return ioctx->operate(oid, &op); } - void unlock(ObjectWriteOperation& rados_op, + void unlock(ObjectWriteOperation *rados_op, const string& name, const string& cookie) { cls_lock_unlock_op op; @@ -72,18 +72,18 @@ namespace rados { bufferlist in; ::encode(op, in); - rados_op.exec("lock", "unlock", in); + rados_op->exec("lock", "unlock", in); } - int unlock(IoCtx& ioctx, const string& oid, + int unlock(IoCtx *ioctx, const string& oid, const string& name, const string& cookie) { ObjectWriteOperation op; - unlock(op, name, cookie); - return ioctx.operate(oid, &op); + unlock(&op, name, cookie); + return ioctx->operate(oid, &op); } - void break_lock(ObjectWriteOperation& rados_op, + void break_lock(ObjectWriteOperation *rados_op, const string& name, const string& cookie, const entity_name_t& locker) { @@ -93,22 +93,22 @@ namespace rados { op.locker = locker; bufferlist in; ::encode(op, in); - rados_op.exec("lock", "break_lock", in); + rados_op->exec("lock", "break_lock", in); } - int break_lock(IoCtx& ioctx, const string& oid, + 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); + break_lock(&op, name, cookie, locker); + return ioctx->operate(oid, &op); } - int list_locks(IoCtx& ioctx, const string& oid, list *locks) + int list_locks(IoCtx *ioctx, const string& oid, list *locks) { bufferlist in, out; - int r = ioctx.exec(oid, "lock", "list_locks", in, out); + int r = ioctx->exec(oid, "lock", "list_locks", in, out); if (r < 0) return r; @@ -125,7 +125,7 @@ namespace rados { return 0; } - int get_lock_info(IoCtx& ioctx, const string& oid, const string& lock, + int get_lock_info(IoCtx *ioctx, const string& oid, const string& lock, map *lockers, ClsLockType *lock_type, string *tag) @@ -134,7 +134,7 @@ namespace rados { cls_lock_get_info_op op; op.name = lock; ::encode(op, in); - int r = ioctx.exec(oid, "lock", "get_info", in, out); + int r = ioctx->exec(oid, "lock", "get_info", in, out); if (r < 0) return r; @@ -161,46 +161,46 @@ namespace rados { return 0; } - void Lock::lock_shared(ObjectWriteOperation& op) + void Lock::lock_shared(ObjectWriteOperation *op) { lock(op, name, LOCK_SHARED, cookie, tag, description, duration, flags); } - int Lock::lock_shared(IoCtx& ioctx, const string& oid) + int Lock::lock_shared(IoCtx *ioctx, const string& oid) { return lock(ioctx, oid, name, LOCK_SHARED, cookie, tag, description, duration, flags); } - void Lock::lock_exclusive(ObjectWriteOperation& op) + void Lock::lock_exclusive(ObjectWriteOperation *op) { lock(op, name, LOCK_EXCLUSIVE, cookie, tag, description, duration, flags); } - int Lock::lock_exclusive(IoCtx& ioctx, const string& oid) + int Lock::lock_exclusive(IoCtx *ioctx, const string& oid) { return lock(ioctx, oid, name, LOCK_EXCLUSIVE, cookie, tag, description, duration, flags); } - void Lock::unlock(ObjectWriteOperation& op) + void Lock::unlock(ObjectWriteOperation *op) { rados::cls::lock::unlock(op, name, cookie); } - int Lock::unlock(IoCtx& ioctx, const 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, const 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, const string& oid, const 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); } diff --git a/src/cls/lock/cls_lock_client.h b/src/cls/lock/cls_lock_client.h index 29f7a927369..760f9178d4f 100644 --- a/src/cls/lock/cls_lock_client.h +++ b/src/cls/lock/cls_lock_client.h @@ -1,3 +1,6 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + #ifndef CEPH_CLS_LOCK_CLIENT_H #define CEPH_CLS_LOCK_CLIENT_H @@ -12,38 +15,38 @@ namespace rados { namespace cls { namespace lock { - extern void lock(librados::ObjectWriteOperation& rados_op, + extern void lock(librados::ObjectWriteOperation *rados_op, 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); + uint8_t flags); - extern int lock(librados::IoCtx& ioctx, + extern int lock(librados::IoCtx *ioctx, 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); + uint8_t flags); - extern void unlock(librados::ObjectWriteOperation& rados_op, + extern void unlock(librados::ObjectWriteOperation *rados_op, const std::string& name, const std::string& cookie); - extern int unlock(librados::IoCtx& ioctx, const std::string& oid, + 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, + extern void break_lock(librados::ObjectWriteOperation *op, const std::string& name, const std::string& cookie, const entity_name_t& locker); - extern int break_lock(librados::IoCtx& ioctx, const std::string& oid, + 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 *locks); - extern int get_lock_info(librados::IoCtx& ioctx, const std::string& oid, - const std::string& lock, - map *lockers, + extern int list_locks(librados::IoCtx *ioctx, const std::string& oid, + list *locks); + extern int get_lock_info(librados::IoCtx *ioctx, const std::string& oid, + const std::string& lock, + map *lockers, ClsLockType *lock_type, std::string *tag); @@ -72,16 +75,16 @@ namespace rados { } /* ObjectWriteOperation */ - void lock_exclusive(librados::ObjectWriteOperation& ioctx); - void lock_shared(librados::ObjectWriteOperation& ioctx); - void unlock(librados::ObjectWriteOperation& ioctx); - void break_lock(librados::ObjectWriteOperation& ioctx, const entity_name_t& locker); + void lock_exclusive(librados::ObjectWriteOperation *ioctx); + void lock_shared(librados::ObjectWriteOperation *ioctx); + void unlock(librados::ObjectWriteOperation *ioctx); + void break_lock(librados::ObjectWriteOperation *ioctx, const entity_name_t& locker); /* IoCtx*/ - 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, + 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); }; diff --git a/src/rados.cc b/src/rados.cc index 50131e32f94..1ec37224e2b 100644 --- a/src/rados.cc +++ b/src/rados.cc @@ -844,7 +844,7 @@ public: static int do_lock_cmd(std::vector &nargs, const std::map < std::string, std::string > &opts, - IoCtx ioctx, + IoCtx *ioctx, Formatter *formatter) { char buf[128]; @@ -1958,7 +1958,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, if (!formatter) { formatter = new JSONFormatter(pretty_format); } - ret = do_lock_cmd(nargs, opts, io_ctx, formatter); + ret = do_lock_cmd(nargs, opts, &io_ctx, formatter); } else { cerr << "unrecognized command " << nargs[0] << std::endl; usage_exit(); diff --git a/src/rgw/rgw_gc.cc b/src/rgw/rgw_gc.cc index b4f131f6336..2b6a58f428e 100644 --- a/src/rgw/rgw_gc.cc +++ b/src/rgw/rgw_gc.cc @@ -139,7 +139,7 @@ int RGWGC::process(int index, int max_secs) utime_t time(max_secs, 0); l.set_duration(time); - int ret = l.lock_exclusive(store->gc_pool_ctx, obj_names[index]); + int ret = l.lock_exclusive(&store->gc_pool_ctx, obj_names[index]); if (ret == -EBUSY) { /* already locked by another gc processor */ dout(0) << "RGWGC::process() failed to acquire lock on " << obj_names[index] << dendl; return 0; @@ -218,7 +218,7 @@ int RGWGC::process(int index, int max_secs) done: if (remove_tags.size()) remove(index, remove_tags); - l.unlock(store->gc_pool_ctx, obj_names[index]); + l.unlock(&store->gc_pool_ctx, obj_names[index]); delete ctx; return 0; } diff --git a/src/test/rados-api/cls_lock.cc b/src/test/rados-api/cls_lock.cc index bc003df6301..316bc3f596c 100644 --- a/src/test/rados-api/cls_lock.cc +++ b/src/test/rados-api/cls_lock.cc @@ -29,7 +29,7 @@ using namespace librados; using namespace rados::cls::lock; -void lock_info(IoCtx& ioctx, string& oid, string& name, map& lockers, +void lock_info(IoCtx *ioctx, string& oid, string& name, map& lockers, ClsLockType *assert_type, string *assert_tag) { ClsLockType lock_type = LOCK_NONE; @@ -55,7 +55,7 @@ void lock_info(IoCtx& ioctx, string& oid, string& name, map& lockers) +void lock_info(IoCtx *ioctx, string& oid, string& name, map& lockers) { lock_info(ioctx, oid, name, lockers, NULL, NULL); } @@ -85,54 +85,54 @@ TEST(ClsLock, TestMultiLocking) { /* test lock object */ - ASSERT_EQ(0, l.lock_exclusive(ioctx, oid)); + ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid)); /* test exclusive lock */ - ASSERT_EQ(-EEXIST, l.lock_exclusive(ioctx, oid)); + ASSERT_EQ(-EEXIST, l.lock_exclusive(&ioctx, oid)); /* test idempotency */ l.set_renew(true); - ASSERT_EQ(0, l.lock_exclusive(ioctx, oid)); + ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid)); l.set_renew(false); /* test second client */ Lock l2(lock_name); - ASSERT_EQ(-EBUSY, l2.lock_exclusive(ioctx2, oid)); - ASSERT_EQ(-EBUSY, l2.lock_shared(ioctx2, oid)); + ASSERT_EQ(-EBUSY, l2.lock_exclusive(&ioctx2, oid)); + ASSERT_EQ(-EBUSY, l2.lock_shared(&ioctx2, oid)); list locks; - ASSERT_EQ(0, list_locks(ioctx, oid, &locks)); + ASSERT_EQ(0, list_locks(&ioctx, oid, &locks)); ASSERT_EQ(1, (int)locks.size()); list::iterator iter = locks.begin(); map lockers; - lock_info(ioctx, oid, *iter, lockers, &lock_type_exclusive, NULL); + lock_info(&ioctx, oid, *iter, lockers, &lock_type_exclusive, NULL); ASSERT_EQ(1, (int)lockers.size()); /* test unlock */ - ASSERT_EQ(0, l.unlock(ioctx, oid)); + ASSERT_EQ(0, l.unlock(&ioctx, oid)); locks.clear(); - ASSERT_EQ(0, list_locks(ioctx, oid, &locks)); + ASSERT_EQ(0, list_locks(&ioctx, oid, &locks)); /* test shared lock */ - ASSERT_EQ(0, l2.lock_shared(ioctx2, oid)); - ASSERT_EQ(0, l.lock_shared(ioctx, oid)); + ASSERT_EQ(0, l2.lock_shared(&ioctx2, oid)); + ASSERT_EQ(0, l.lock_shared(&ioctx, oid)); locks.clear(); - ASSERT_EQ(0, list_locks(ioctx, oid, &locks)); + ASSERT_EQ(0, list_locks(&ioctx, oid, &locks)); ASSERT_EQ(1, (int)locks.size()); iter = locks.begin(); - lock_info(ioctx, oid, *iter, lockers, &lock_type_shared, NULL); + lock_info(&ioctx, oid, *iter, lockers, &lock_type_shared, NULL); ASSERT_EQ(2, (int)lockers.size()); /* test break locks */ entity_name_t name = entity_name_t::CLIENT(cluster.get_instance_id()); entity_name_t name2 = entity_name_t::CLIENT(cluster2.get_instance_id()); - l2.break_lock(ioctx2, oid, name); - lock_info(ioctx, oid, *iter, lockers); + l2.break_lock(&ioctx2, oid, name); + lock_info(&ioctx, oid, *iter, lockers); ASSERT_EQ(1, (int)lockers.size()); map::iterator liter = lockers.begin(); const locker_id_t& id = liter->first; @@ -141,13 +141,13 @@ TEST(ClsLock, TestMultiLocking) { /* test lock tag */ Lock l_tag(lock_name); l_tag.set_tag("non-default tag"); - ASSERT_EQ(-EBUSY, l_tag.lock_shared(ioctx, oid)); + ASSERT_EQ(-EBUSY, l_tag.lock_shared(&ioctx, oid)); /* test modify description */ string description = "new description"; l.set_description(description); - ASSERT_EQ(0, l.lock_shared(ioctx, oid)); + ASSERT_EQ(0, l.lock_shared(&ioctx, oid)); ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster)); } @@ -172,43 +172,43 @@ TEST(ClsLock, TestMeta) { ASSERT_EQ(0, ioctx.write(oid, bl, bl.length(), 0)); Lock l(lock_name); - ASSERT_EQ(0, l.lock_shared(ioctx, oid)); + ASSERT_EQ(0, l.lock_shared(&ioctx, oid)); /* test lock tag */ Lock l_tag(lock_name); l_tag.set_tag("non-default tag"); - ASSERT_EQ(-EBUSY, l_tag.lock_shared(ioctx2, oid)); + ASSERT_EQ(-EBUSY, l_tag.lock_shared(&ioctx2, oid)); - ASSERT_EQ(0, l.unlock(ioctx, oid)); + ASSERT_EQ(0, l.unlock(&ioctx, oid)); /* test description */ Lock l2(lock_name); string description = "new description"; l2.set_description(description); - ASSERT_EQ(0, l2.lock_shared(ioctx2, oid)); + ASSERT_EQ(0, l2.lock_shared(&ioctx2, oid)); map lockers; - lock_info(ioctx, oid, lock_name, lockers, NULL, NULL); + lock_info(&ioctx, oid, lock_name, lockers, NULL, NULL); ASSERT_EQ(1, (int)lockers.size()); map::iterator iter = lockers.begin(); locker_info_t locker = iter->second; ASSERT_EQ("new description", locker.description); - ASSERT_EQ(0, l2.unlock(ioctx2, oid)); + ASSERT_EQ(0, l2.unlock(&ioctx2, oid)); /* check new tag */ string new_tag = "new_tag"; l.set_tag(new_tag); l.set_renew(true); - ASSERT_EQ(0, l.lock_exclusive(ioctx, oid)); - lock_info(ioctx, oid, lock_name, lockers, NULL, &new_tag); + ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid)); + lock_info(&ioctx, oid, lock_name, lockers, NULL, &new_tag); ASSERT_EQ(1, (int)lockers.size()); l.set_tag(""); - ASSERT_EQ(-EBUSY, l.lock_exclusive(ioctx, oid)); + ASSERT_EQ(-EBUSY, l.lock_exclusive(&ioctx, oid)); l.set_tag(new_tag); - ASSERT_EQ(0, l.lock_exclusive(ioctx, oid)); + ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid)); ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster)); } @@ -224,26 +224,26 @@ TEST(ClsLock, TestCookie) { string lock_name = "mylock"; Lock l(lock_name); - ASSERT_EQ(0, l.lock_exclusive(ioctx, oid)); + ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid)); /* new cookie */ string cookie = "new cookie"; l.set_cookie(cookie); - ASSERT_EQ(-EBUSY, l.lock_exclusive(ioctx, oid)); - ASSERT_EQ(-ENOENT, l.unlock(ioctx, oid)); + ASSERT_EQ(-EBUSY, l.lock_exclusive(&ioctx, oid)); + ASSERT_EQ(-ENOENT, l.unlock(&ioctx, oid)); l.set_cookie(""); - ASSERT_EQ(0, l.unlock(ioctx, oid)); + ASSERT_EQ(0, l.unlock(&ioctx, oid)); map lockers; - lock_info(ioctx, oid, lock_name, lockers); + lock_info(&ioctx, oid, lock_name, lockers); ASSERT_EQ(0, (int)lockers.size()); l.set_cookie(cookie); - ASSERT_EQ(0, l.lock_shared(ioctx, oid)); + ASSERT_EQ(0, l.lock_shared(&ioctx, oid)); l.set_cookie(""); - ASSERT_EQ(0, l.lock_shared(ioctx, oid)); + ASSERT_EQ(0, l.lock_shared(&ioctx, oid)); - lock_info(ioctx, oid, lock_name, lockers); + lock_info(&ioctx, oid, lock_name, lockers); ASSERT_EQ(2, (int)lockers.size()); ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster)); @@ -258,13 +258,13 @@ TEST(ClsLock, TestMultipleLocks) { string oid = "foo"; Lock l("lock1"); - ASSERT_EQ(0, l.lock_exclusive(ioctx, oid)); + ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid)); Lock l2("lock2"); - ASSERT_EQ(0, l2.lock_exclusive(ioctx, oid)); + ASSERT_EQ(0, l2.lock_exclusive(&ioctx, oid)); list locks; - ASSERT_EQ(0, list_locks(ioctx, oid, &locks)); + ASSERT_EQ(0, list_locks(&ioctx, oid, &locks)); ASSERT_EQ(2, (int)locks.size()); @@ -281,11 +281,11 @@ TEST(ClsLock, TestLockDuration) { string oid = "foo"; Lock l("lock"); l.set_duration(utime_t(5, 0)); - ASSERT_EQ(0, l.lock_exclusive(ioctx, oid)); - ASSERT_EQ(-EEXIST, l.lock_exclusive(ioctx, oid)); + ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid)); + ASSERT_EQ(-EEXIST, l.lock_exclusive(&ioctx, oid)); sleep(5); - ASSERT_EQ(0, l.lock_exclusive(ioctx, oid)); + ASSERT_EQ(0, l.lock_exclusive(&ioctx, oid)); ASSERT_EQ(0, destroy_one_pool_pp(pool_name, cluster)); } -- cgit v1.2.3 From 1779d5ab0d04665b76d7f894b4a83f9788b645a9 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Fri, 31 Aug 2012 11:17:17 -0700 Subject: cls_lock_client: fix indentation Add indentation settings to header, and reindent. Signed-off-by: Josh Durgin --- src/cls/lock/cls_lock_client.h | 103 ++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 52 deletions(-) (limited to 'src/cls') diff --git a/src/cls/lock/cls_lock_client.h b/src/cls/lock/cls_lock_client.h index 760f9178d4f..527eefed767 100644 --- a/src/cls/lock/cls_lock_client.h +++ b/src/cls/lock/cls_lock_client.h @@ -16,75 +16,75 @@ namespace rados { namespace lock { extern void lock(librados::ObjectWriteOperation *rados_op, - 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); + 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, - 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); + 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, - const std::string& name, const std::string& cookie); + const std::string& name, const std::string& cookie); extern int unlock(librados::IoCtx *ioctx, const std::string& oid, - const std::string& name, const std::string& cookie); + const std::string& name, const std::string& cookie); extern void break_lock(librados::ObjectWriteOperation *op, - const std::string& name, const std::string& cookie, - const entity_name_t& locker); + 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); + 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 *locks); + list *locks); extern int get_lock_info(librados::IoCtx *ioctx, const std::string& oid, - const std::string& lock, - map *lockers, - ClsLockType *lock_type, - std::string *tag); + const std::string& lock, + map *lockers, + ClsLockType *lock_type, + std::string *tag); class Lock { - std::string name; - std::string cookie; - std::string tag; - std::string description; - utime_t duration; - uint8_t flags; + std::string name; + std::string cookie; + std::string tag; + std::string description; + utime_t duration; + uint8_t flags; public: - Lock(const std::string& _n) : name(_n), flags(0) {} - - void set_cookie(const std::string& c) { cookie = c; } - void set_tag(const std::string& t) { tag = t; } - void set_description(const std::string& desc) { description = desc; } - void set_duration(const utime_t& e) { duration = e; } - void set_renew(bool renew) { - if (renew) { - flags |= LOCK_FLAG_RENEW; - } else { - flags &= ~LOCK_FLAG_RENEW; - } - } - - /* ObjectWriteOperation */ - void lock_exclusive(librados::ObjectWriteOperation *ioctx); - void lock_shared(librados::ObjectWriteOperation *ioctx); - void unlock(librados::ObjectWriteOperation *ioctx); - void break_lock(librados::ObjectWriteOperation *ioctx, const entity_name_t& locker); - - /* IoCtx*/ - 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, + Lock(const std::string& _n) : name(_n), flags(0) {} + + void set_cookie(const std::string& c) { cookie = c; } + void set_tag(const std::string& t) { tag = t; } + void set_description(const std::string& desc) { description = desc; } + void set_duration(const utime_t& e) { duration = e; } + void set_renew(bool renew) { + if (renew) { + flags |= LOCK_FLAG_RENEW; + } else { + flags &= ~LOCK_FLAG_RENEW; + } + } + + /* ObjectWriteOperation */ + void lock_exclusive(librados::ObjectWriteOperation *ioctx); + void lock_shared(librados::ObjectWriteOperation *ioctx); + void unlock(librados::ObjectWriteOperation *ioctx); + void break_lock(librados::ObjectWriteOperation *ioctx, const entity_name_t& locker); + + /* IoCtx */ + 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); }; @@ -93,4 +93,3 @@ namespace rados { } // namespace rados #endif - -- cgit v1.2.3 From dd4b9caa2d1758b7d56d49a9d73e545376609f10 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Fri, 31 Aug 2012 13:06:12 -0700 Subject: cls_lock_client: return error when decoding fails Library code shouldn't be using cerr either. Signed-off-by: Josh Durgin --- src/cls/lock/cls_lock_client.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cls') diff --git a/src/cls/lock/cls_lock_client.cc b/src/cls/lock/cls_lock_client.cc index c7893afce2b..d693431f716 100644 --- a/src/cls/lock/cls_lock_client.cc +++ b/src/cls/lock/cls_lock_client.cc @@ -117,7 +117,7 @@ namespace rados { try { ::decode(ret, iter); } catch (buffer::error& err) { - cerr << __func__ << ": failed to decode response" << std::endl; + return -EBADMSG; } *locks = ret.locks; @@ -143,7 +143,7 @@ namespace rados { try { ::decode(ret, iter); } catch (buffer::error& err) { - cerr << __func__ << ": failed to decode response" << std::endl; + return -EBADMSG; } if (lockers) { -- cgit v1.2.3 From e06031dd1a403f9bc4498c814626eafd5c86d632 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Fri, 31 Aug 2012 16:50:06 -0700 Subject: cls_lock_types: add missing include msg_types defines entity-related types used here. Signed-off-by: Josh Durgin --- src/cls/lock/cls_lock_types.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/cls') diff --git a/src/cls/lock/cls_lock_types.h b/src/cls/lock/cls_lock_types.h index b68ec0a8098..aa60ed142c7 100644 --- a/src/cls/lock/cls_lock_types.h +++ b/src/cls/lock/cls_lock_types.h @@ -1,9 +1,10 @@ #ifndef CEPH_CLS_LOCK_TYPES_H #define CEPH_CLS_LOCK_TYPES_H -#include "include/types.h" #include "include/encoding.h" +#include "include/types.h" #include "include/utime.h" +#include "msg/msg_types.h" /* lock flags */ #define LOCK_FLAG_RENEW 0x1 /* idempotent lock acquire */ -- cgit v1.2.3 From 8578b216717ec43b6c7703e9680db51206728c69 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Fri, 31 Aug 2012 16:51:43 -0700 Subject: cls_lock_client: add ObjectOperation-based get_lock_info 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 --- src/cls/lock/cls_lock_client.cc | 40 +++++++++++++++++++++++++++------------- src/cls/lock/cls_lock_client.h | 11 ++++++++--- 2 files changed, 35 insertions(+), 16 deletions(-) (limited to 'src/cls') diff --git a/src/cls/lock/cls_lock_client.cc b/src/cls/lock/cls_lock_client.cc index d693431f716..54af41cd049 100644 --- a/src/cls/lock/cls_lock_client.cc +++ b/src/cls/lock/cls_lock_client.cc @@ -125,23 +125,23 @@ namespace rados { return 0; } - int get_lock_info(IoCtx *ioctx, const string& oid, const string& lock, - map *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 *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 *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, diff --git a/src/cls/lock/cls_lock_client.h b/src/cls/lock/cls_lock_client.h index 527eefed767..4e2144c79b4 100644 --- a/src/cls/lock/cls_lock_client.h +++ b/src/cls/lock/cls_lock_client.h @@ -44,11 +44,16 @@ namespace rados { extern int list_locks(librados::IoCtx *ioctx, const std::string& oid, list *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 *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 *lockers, - ClsLockType *lock_type, - std::string *tag); + ClsLockType *type, std::string *tag); class Lock { std::string name; -- cgit v1.2.3