From: Jason Dillaman Date: Mon, 25 Jul 2016 16:42:26 +0000 (-0400) Subject: librbd: helper method for creating and starting AioCompletions X-Git-Tag: v10.2.3~48^2~21 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=47279f8e0158d0483011bca01455ef9735453b34;p=ceph.git librbd: helper method for creating and starting AioCompletions Signed-off-by: Jason Dillaman (cherry picked from commit 3df7213c0a9f0186e3a37c9e4a10f1c8bc84446e) --- diff --git a/src/librbd/AioCompletion.h b/src/librbd/AioCompletion.h index 758b1d8a66938..e259a484698a4 100644 --- a/src/librbd/AioCompletion.h +++ b/src/librbd/AioCompletion.h @@ -50,7 +50,7 @@ namespace librbd { * context or via a thread pool context for cache read hits). */ struct AioCompletion { - Mutex lock; + mutable Mutex lock; Cond cond; aio_state_t state; ssize_t rval; @@ -100,6 +100,15 @@ namespace librbd { return comp; } + template + static AioCompletion *create_and_start(T *obj, ImageCtx *image_ctx, + aio_type_t type) { + AioCompletion *comp = create(obj); + comp->init_time(image_ctx, type); + comp->start_op(); + return comp; + } + AioCompletion() : lock("AioCompletion::lock", true, false), state(STATE_PENDING), rval(0), complete_cb(NULL), complete_arg(NULL), rbd_comp(NULL), @@ -117,6 +126,15 @@ namespace librbd { void finalize(ssize_t rval); + inline bool is_initialized(aio_type_t type) const { + Mutex::Locker locker(lock); + return ((ictx != nullptr) && (aio_type == type)); + } + inline bool is_started() const { + Mutex::Locker locker(lock); + return async_op.started(); + } + void init_time(ImageCtx *i, aio_type_t t); void start_op(bool ignore_type = false); void fail(int r);