From: Sebastien Ponce Date: Wed, 25 May 2016 07:28:29 +0000 (+0200) Subject: rados : added an asynchronous unlock to the API X-Git-Tag: v11.1.0~355^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=25dd8d2a13fda78f1296d4b3d23704a21b17b444;p=ceph.git rados : added an asynchronous unlock to the API Signed-off-by: Sebastien Ponce --- diff --git a/src/cls/lock/cls_lock_client.cc b/src/cls/lock/cls_lock_client.cc index fc2790b92d7..f56bc52697f 100644 --- a/src/cls/lock/cls_lock_client.cc +++ b/src/cls/lock/cls_lock_client.cc @@ -83,6 +83,15 @@ namespace rados { return ioctx->operate(oid, &op); } + int aio_unlock(IoCtx *ioctx, const string& oid, + const string& name, const string& cookie, + librados::AioCompletion *completion) + { + ObjectWriteOperation op; + unlock(&op, name, cookie); + return ioctx->aio_operate(oid, completion, &op); + } + void break_lock(ObjectWriteOperation *rados_op, const string& name, const string& cookie, const entity_name_t& locker) diff --git a/src/cls/lock/cls_lock_client.h b/src/cls/lock/cls_lock_client.h index 13fb3f154b0..e94606e3e63 100644 --- a/src/cls/lock/cls_lock_client.h +++ b/src/cls/lock/cls_lock_client.h @@ -33,6 +33,10 @@ namespace rados { extern int unlock(librados::IoCtx *ioctx, const std::string& oid, const std::string& name, const std::string& cookie); + extern int aio_unlock(librados::IoCtx *ioctx, const std::string& oid, + const std::string& name, const std::string& cookie, + librados::AioCompletion *completion); + extern void break_lock(librados::ObjectWriteOperation *op, const std::string& name, const std::string& cookie, const entity_name_t& locker); diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index 126cb6a8332..5738290f6d1 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -3086,6 +3086,20 @@ CEPH_RADOS_API int rados_lock_shared(rados_ioctx_t io, const char * o, CEPH_RADOS_API int rados_unlock(rados_ioctx_t io, const char *o, const char *name, const char *cookie); +/** + * Asynchronous release a shared or exclusive lock on an object. + * + * @param io the context to operate in + * @param o the name of the object + * @param name the name of the lock + * @param cookie user-defined identifier for the instance of the lock + * @param completion what to do when operation has been attempted + * @returns 0 on success, negative error code on failure + */ +CEPH_RADOS_API int rados_aio_unlock(rados_ioctx_t io, const char *o, + const char *name, const char *cookie, + rados_completion_t completion); + /** * List clients that have locked the named object lock and information about * the lock. diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index f4ab24dbc2e..7ef5ae3367d 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -983,6 +983,12 @@ namespace librados int aio_exec(const std::string& oid, AioCompletion *c, const char *cls, const char *method, bufferlist& inbl, bufferlist *outbl); + /* + * asynchronous version of unlock + */ + int aio_unlock(const std::string &oid, const std::string &name, + const std::string &cookie, AioCompletion *c); + // compound object operations int operate(const std::string& oid, ObjectWriteOperation *op); int operate(const std::string& oid, ObjectReadOperation *op, bufferlist *pbl); diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 328f76a3cb6..01595ea327c 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -1627,6 +1627,31 @@ int librados::IoCtx::unlock(const std::string &oid, const std::string &name, return rados::cls::lock::unlock(this, oid, name, cookie); } +struct AioUnlockCompletion : public librados::ObjectOperationCompletion { + librados::AioCompletionImpl *completion; + AioUnlockCompletion(librados::AioCompletion *c) : completion(c->pc) { + completion->get(); + }; + void handle_completion(int r, bufferlist& outbl) { + rados_callback_t cb = completion->callback_complete; + void *cb_arg = completion->callback_complete_arg; + cb(completion, cb_arg); + completion->lock.Lock(); + completion->callback_complete = NULL; + completion->cond.Signal(); + completion->put_unlock(); + } +}; + +int librados::IoCtx::aio_unlock(const std::string &oid, const std::string &name, + const std::string &cookie, AioCompletion *c) +{ + librados::AioCompletion *completion = librados::Rados::aio_create_completion(); + int rc = rados::cls::lock::aio_unlock(this, oid, name, cookie, completion); + completion->release(); + return rc; +} + int librados::IoCtx::break_lock(const std::string &oid, const std::string &name, const std::string &client, const std::string &cookie) { @@ -4809,6 +4834,19 @@ extern "C" int rados_unlock(rados_ioctx_t io, const char *o, const char *name, return retval; } +extern "C" int rados_aio_unlock(rados_ioctx_t io, const char *o, const char *name, + const char *cookie, rados_completion_t completion) +{ + tracepoint(librados, rados_aio_unlock_enter, io, o, name, cookie, completion); + librados::IoCtx ctx; + librados::IoCtx::from_rados_ioctx_t(io, ctx); + librados::AioCompletionImpl *comp = (librados::AioCompletionImpl*)completion; + librados::AioCompletion c(comp); + int retval = ctx.aio_unlock(o, name, cookie, &c); + tracepoint(librados, rados_aio_unlock_exit, retval); + return retval; +} + extern "C" ssize_t rados_list_lockers(rados_ioctx_t io, const char *o, const char *name, int *exclusive, char *tag, size_t *tag_len, diff --git a/src/tracing/librados.tp b/src/tracing/librados.tp index 054bc6d9567..837145c5dc2 100644 --- a/src/tracing/librados.tp +++ b/src/tracing/librados.tp @@ -2723,6 +2723,30 @@ TRACEPOINT_EVENT(librados, rados_unlock_exit, ) ) +TRACEPOINT_EVENT(librados, rados_aio_unlock_enter, + TP_ARGS( + rados_ioctx_t, ioctx, + const char*, oid, + const char*, name, + const char*, cookie, + rados_completion_t, completion), + TP_FIELDS( + ctf_integer_hex(rados_ioctx_t, ioctx, ioctx) + ctf_string(oid, oid) + ceph_ctf_string(name, name) + ceph_ctf_string(cookie, cookie) + ctf_integer_hex(rados_completion_t, completion, completion) + ) +) + +TRACEPOINT_EVENT(librados, rados_aio_unlock_exit, + TP_ARGS( + int, retval), + TP_FIELDS( + ctf_integer(int, retval, retval) + ) +) + TRACEPOINT_EVENT(librados, rados_list_lockers_enter, TP_ARGS( rados_ioctx_t, ioctx,