From 69ee9afa27a1a9d3111f5b1947f4daaf61edc656 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Fri, 31 Aug 2012 16:51:43 -0700 Subject: [PATCH] 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(-) diff --git a/src/cls/lock/cls_lock_client.cc b/src/cls/lock/cls_lock_client.cc index d693431f716e7..54af41cd04926 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 527eefed767eb..4e2144c79b4ca 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; -- 2.39.5