]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: helper method for creating and starting AioCompletions
authorJason Dillaman <dillaman@redhat.com>
Mon, 25 Jul 2016 16:42:26 +0000 (12:42 -0400)
committerMykola Golub <mgolub@mirantis.com>
Fri, 19 Aug 2016 19:59:06 +0000 (22:59 +0300)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 3df7213c0a9f0186e3a37c9e4a10f1c8bc84446e)

src/librbd/AioCompletion.h

index 758b1d8a6693823632dea63615ff5701d7c679af..e259a484698a457b2e148403aa0038b2c2e143d2 100644 (file)
@@ -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 <typename T, void (T::*MF)(int) = &T::complete>
+    static AioCompletion *create_and_start(T *obj, ImageCtx *image_ctx,
+                                           aio_type_t type) {
+      AioCompletion *comp = create<T, MF>(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);