]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: add flags to open request
authorMykola Golub <to.my.trociny@gmail.com>
Sun, 10 Dec 2017 19:16:37 +0000 (21:16 +0200)
committerJason Dillaman <dillaman@redhat.com>
Tue, 14 Aug 2018 22:29:44 +0000 (18:29 -0400)
Signed-off-by: Mykola Golub <mgolub@suse.com>
13 files changed:
src/librbd/ImageState.cc
src/librbd/ImageState.h
src/librbd/Types.h
src/librbd/api/Mirror.cc
src/librbd/image/CloneRequest.cc
src/librbd/image/OpenRequest.cc
src/librbd/image/OpenRequest.h
src/librbd/image/RefreshParentRequest.cc
src/librbd/internal.cc
src/librbd/librbd.cc
src/tools/rbd_mirror/image_deleter/SnapshotPurgeRequest.cc
src/tools/rbd_mirror/image_replayer/OpenImageRequest.cc
src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc

index c290e6b988d92a48179e03ba6fc0847f9298cfce..12f7700bae0c36e6e3b2a4e0d0f5d0f735aea1a4 100644 (file)
@@ -234,8 +234,7 @@ ImageState<I>::ImageState(I *image_ctx)
   : m_image_ctx(image_ctx), m_state(STATE_UNINITIALIZED),
     m_lock(util::unique_lock_name("librbd::ImageState::m_lock", this)),
     m_last_refresh(0), m_refresh_seq(0),
-    m_update_watchers(new ImageUpdateWatchers(image_ctx->cct)),
-    m_skip_open_parent_image(false) {
+    m_update_watchers(new ImageUpdateWatchers(image_ctx->cct)) {
 }
 
 template <typename I>
@@ -245,9 +244,9 @@ ImageState<I>::~ImageState() {
 }
 
 template <typename I>
-int ImageState<I>::open(bool skip_open_parent) {
+int ImageState<I>::open(uint64_t flags) {
   C_SaferCond ctx;
-  open(skip_open_parent, &ctx);
+  open(flags, &ctx);
 
   int r = ctx.wait();
   if (r < 0) {
@@ -257,13 +256,13 @@ int ImageState<I>::open(bool skip_open_parent) {
 }
 
 template <typename I>
-void ImageState<I>::open(bool skip_open_parent, Context *on_finish) {
+void ImageState<I>::open(uint64_t flags, Context *on_finish) {
   CephContext *cct = m_image_ctx->cct;
   ldout(cct, 20) << __func__ << dendl;
 
   m_lock.Lock();
   assert(m_state == STATE_UNINITIALIZED);
-  m_skip_open_parent_image = skip_open_parent;
+  m_open_flags = flags;
 
   Action action(ACTION_TYPE_OPEN);
   action.refresh_seq = m_refresh_seq;
@@ -583,7 +582,7 @@ void ImageState<I>::send_open_unlock() {
     *m_image_ctx, create_context_callback<
       ImageState<I>, &ImageState<I>::handle_open>(this));
   image::OpenRequest<I> *req = image::OpenRequest<I>::create(
-    m_image_ctx, m_skip_open_parent_image, ctx);
+    m_image_ctx, m_open_flags, ctx);
 
   m_lock.Unlock();
   req->send();
index d577f290d92028fbb391dde9cd6336ed68411b6d..7f28d1eec712e2e4c0df6d220d5abefc3b788274 100644 (file)
@@ -26,8 +26,8 @@ public:
   ImageState(ImageCtxT *image_ctx);
   ~ImageState();
 
-  int open(bool skip_open_parent);
-  void open(bool skip_open_parent, Context *on_finish);
+  int open(uint64_t flags);
+  void open(uint64_t flags, Context *on_finish);
 
   int close();
   void close(Context *on_finish);
@@ -110,7 +110,7 @@ private:
 
   ImageUpdateWatchers *m_update_watchers;
 
-  bool m_skip_open_parent_image;
+  uint64_t m_open_flags;
 
   bool is_transition_state() const;
   bool is_closed() const;
index 809311adec26813e36af393438f1efb006b650b0..9597b71880b67a290c8c99c374a938fc1f47a207 100644 (file)
@@ -114,6 +114,10 @@ struct SnapInfo {
   }
 };
 
+enum {
+  OPEN_FLAG_SKIP_OPEN_PARENT = 1 << 0,
+};
+
 } // namespace librbd
 
 #endif // LIBRBD_TYPES_H
index c1e545a39eac1fa0ace0bcd18f2b4995730f8f27..3a2dff18cf6129f62a2f743e7656d481827b9656 100644 (file)
@@ -596,7 +596,7 @@ int Mirror<I>::mode_set(librados::IoCtx& io_ctx,
 
       if ((features & RBD_FEATURE_JOURNALING) != 0) {
         I *img_ctx = I::create("", img_pair.second, nullptr, io_ctx, false);
-        r = img_ctx->state->open(false);
+        r = img_ctx->state->open(0);
         if (r < 0) {
           lderr(cct) << "error opening image "<< img_pair.first << ": "
                      << cpp_strerror(r) << dendl;
@@ -640,7 +640,7 @@ int Mirror<I>::mode_set(librados::IoCtx& io_ctx,
         }
       } else {
         I *img_ctx = I::create("", img_id, nullptr, io_ctx, false);
-        r = img_ctx->state->open(false);
+        r = img_ctx->state->open(0);
         if (r < 0) {
           lderr(cct) << "error opening image id "<< img_id << ": "
                      << cpp_strerror(r) << dendl;
index 44f3ac7d8aaf4a003ee21c67aeac206fcbe675af..b784b9ab0c362a20e7fe9886c60858ade73c85c4 100644 (file)
@@ -238,7 +238,7 @@ void CloneRequest<I>::send_open() {
   using klass = CloneRequest<I>;
   Context *ctx = create_context_callback<klass, &klass::handle_open>(this);
 
-  m_imctx->state->open(true, ctx);
+  m_imctx->state->open(OPEN_FLAG_SKIP_OPEN_PARENT, ctx);
 }
 
 template <typename I>
index ae187395eaaef078d3a5066a404517109d0234be..33fa0335768a21842ae40bae1189c1f8ba05da31 100644 (file)
@@ -25,9 +25,10 @@ using util::create_context_callback;
 using util::create_rados_callback;
 
 template <typename I>
-OpenRequest<I>::OpenRequest(I *image_ctx, bool skip_open_parent,
+OpenRequest<I>::OpenRequest(I *image_ctx, uint64_t flags,
                             Context *on_finish)
-  : m_image_ctx(image_ctx), m_skip_open_parent_image(skip_open_parent),
+  : m_image_ctx(image_ctx),
+    m_skip_open_parent_image(flags & OPEN_FLAG_SKIP_OPEN_PARENT),
     m_on_finish(on_finish), m_error_result(0) {
 }
 
index 3b65f5455be54227aca80413833748468525c957..b3bc26a8d47c070106745cfdee0a785cb642258d 100644 (file)
@@ -19,9 +19,9 @@ namespace image {
 template <typename ImageCtxT = ImageCtx>
 class OpenRequest {
 public:
-  static OpenRequest *create(ImageCtxT *image_ctx, bool skip_open_parent,
+  static OpenRequest *create(ImageCtxT *image_ctx, uint64_t flags,
                              Context *on_finish) {
-    return new OpenRequest(image_ctx, skip_open_parent, on_finish);
+    return new OpenRequest(image_ctx, flags, on_finish);
   }
 
   void send();
@@ -75,7 +75,7 @@ private:
    * @endverbatim
    */
 
-  OpenRequest(ImageCtxT *image_ctx, bool skip_open_parent, Context *on_finish);
+  OpenRequest(ImageCtxT *image_ctx, uint64_t flags, Context *on_finish);
 
   ImageCtxT *m_image_ctx;
   bool m_skip_open_parent_image;
index bc5409131442e269539624b165516f01ea8754e5..37bfc3c10177d0d36c86ed6db621239a6e7ee62b 100644 (file)
@@ -125,7 +125,7 @@ void RefreshParentRequest<I>::send_open_parent() {
   Context *ctx = create_async_context_callback(
     m_child_image_ctx, create_context_callback<
       klass, &klass::handle_open_parent, false>(this));
-  OpenRequest<I> *req = OpenRequest<I>::create(m_parent_image_ctx, false, ctx);
+  OpenRequest<I> *req = OpenRequest<I>::create(m_parent_image_ctx, 0, ctx);
   req->send();
 }
 
index f7ca1e2478db176f40f09ad53a74a4c4567a3c55..cb7cf88f2fb2c5d281c1a04e7b69478c90b8c2f1 100644 (file)
@@ -597,7 +597,7 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2)
 
       for (auto &id_it : info.second) {
        ImageCtx *imctx = new ImageCtx("", id_it, NULL, ioctx, false);
-       int r = imctx->state->open(false);
+       int r = imctx->state->open(0);
        if (r < 0) {
          lderr(cct) << "error opening image: "
                     << cpp_strerror(r) << dendl;
@@ -958,7 +958,7 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2)
 
     // make sure parent snapshot exists
     ImageCtx *p_imctx = new ImageCtx(p_name, "", p_snap_name, p_ioctx, true);
-    int r = p_imctx->state->open(false);
+    int r = p_imctx->state->open(0);
     if (r < 0) {
       lderr(cct) << "error opening parent image: "
                 << cpp_strerror(r) << dendl;
@@ -1014,7 +1014,7 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2)
                   << dstname << dendl;
 
     ImageCtx *ictx = new ImageCtx(srcname, "", "", io_ctx, false);
-    int r = ictx->state->open(false);
+    int r = ictx->state->open(0);
     if (r < 0) {
       lderr(cct) << "error opening source image: " << cpp_strerror(r) << dendl;
       return r;
@@ -1392,7 +1392,7 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2)
 
     ImageCtx *ictx = new ImageCtx((image_id.empty() ? image_name : ""),
                                   image_id, nullptr, io_ctx, false);
-    r = ictx->state->open(true);
+    r = ictx->state->open(OPEN_FLAG_SKIP_OPEN_PARENT);
     if (r == -ENOENT) {
       return r;
     } else if (r < 0) {
@@ -1801,7 +1801,7 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2)
 
     ImageCtx *dest = new librbd::ImageCtx(destname, "", NULL,
                                          dest_md_ctx, false);
-    r = dest->state->open(false);
+    r = dest->state->open(0);
     if (r < 0) {
       lderr(cct) << "failed to read newly created header" << dendl;
       return r;
index b46ceb5002f610c9c540360624f5d3f8c9c12c4d..fee8f1d8f005c61d0356ea7559207c19dffe1357 100644 (file)
@@ -138,7 +138,7 @@ struct C_OpenAfterCloseComplete : public Context {
     delete reinterpret_cast<librbd::ImageCtx*>(*ictxp);
     *ictxp = nullptr;
 
-    ictx->state->open(false, new C_OpenComplete(ictx, comp, ictxp));
+    ictx->state->open(0, new C_OpenComplete(ictx, comp, ictxp));
   }
 };
 
@@ -305,7 +305,7 @@ namespace librbd {
       image.ctx = NULL;
     }
 
-    int r = ictx->state->open(false);
+    int r = ictx->state->open(0);
     if (r < 0) {
       tracepoint(librbd, open_image_exit, r);
       return r;
@@ -329,7 +329,7 @@ namespace librbd {
       image.ctx = nullptr;
     }
 
-    int r = ictx->state->open(false);
+    int r = ictx->state->open(0);
     if (r < 0) {
       tracepoint(librbd, open_image_by_id_exit, r);
       return r;
@@ -351,8 +351,8 @@ namespace librbd {
       reinterpret_cast<ImageCtx*>(image.ctx)->state->close(
        new C_OpenAfterCloseComplete(ictx, get_aio_completion(c), &image.ctx));
     } else {
-      ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(c),
-                                          &image.ctx));
+      ictx->state->open(0, new C_OpenComplete(ictx, get_aio_completion(c),
+                                              &image.ctx));
     }
     tracepoint(librbd, aio_open_image_exit, 0);
     return 0;
@@ -370,8 +370,8 @@ namespace librbd {
       reinterpret_cast<ImageCtx*>(image.ctx)->state->close(
        new C_OpenAfterCloseComplete(ictx, get_aio_completion(c), &image.ctx));
     } else {
-      ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(c),
-                                                  &image.ctx));
+      ictx->state->open(0, new C_OpenComplete(ictx, get_aio_completion(c),
+                                              &image.ctx));
     }
     tracepoint(librbd, aio_open_image_by_id_exit, 0);
     return 0;
@@ -389,7 +389,7 @@ namespace librbd {
       image.ctx = NULL;
     }
 
-    int r = ictx->state->open(false);
+    int r = ictx->state->open(0);
     if (r < 0) {
       tracepoint(librbd, open_image_exit, r);
       return r;
@@ -413,7 +413,7 @@ namespace librbd {
       image.ctx = nullptr;
     }
 
-    int r = ictx->state->open(false);
+    int r = ictx->state->open(0);
     if (r < 0) {
       tracepoint(librbd, open_image_by_id_exit, r);
       return r;
@@ -435,8 +435,8 @@ namespace librbd {
       reinterpret_cast<ImageCtx*>(image.ctx)->state->close(
        new C_OpenAfterCloseComplete(ictx, get_aio_completion(c), &image.ctx));
     } else {
-      ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(c),
-                                          &image.ctx));
+      ictx->state->open(0, new C_OpenComplete(ictx, get_aio_completion(c),
+                                              &image.ctx));
     }
     tracepoint(librbd, aio_open_image_exit, 0);
     return 0;
@@ -454,8 +454,8 @@ namespace librbd {
       reinterpret_cast<ImageCtx*>(image.ctx)->state->close(
        new C_OpenAfterCloseComplete(ictx, get_aio_completion(c), &image.ctx));
     } else {
-      ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(c),
-                                                  &image.ctx));
+      ictx->state->open(0, new C_OpenComplete(ictx, get_aio_completion(c),
+                                              &image.ctx));
     }
     tracepoint(librbd, aio_open_image_by_id_exit, 0);
     return 0;
@@ -2953,7 +2953,7 @@ extern "C" int rbd_open(rados_ioctx_t p, const char *name, rbd_image_t *image,
                                                false);
   tracepoint(librbd, open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only);
 
-  int r = ictx->state->open(false);
+  int r = ictx->state->open(0);
   if (r >= 0) {
     *image = (rbd_image_t)ictx;
   }
@@ -2972,7 +2972,7 @@ extern "C" int rbd_open_by_id(rados_ioctx_t p, const char *id,
   tracepoint(librbd, open_image_enter, ictx, ictx->name.c_str(),
              ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only);
 
-  int r = ictx->state->open(false);
+  int r = ictx->state->open(0);
   if (r < 0) {
     delete ictx;
   } else {
@@ -2993,7 +2993,8 @@ extern "C" int rbd_aio_open(rados_ioctx_t p, const char *name,
                                                false);
   librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c;
   tracepoint(librbd, aio_open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only, comp->pc);
-  ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(comp), image));
+  ictx->state->open(0, new C_OpenComplete(ictx, get_aio_completion(comp),
+                                          image));
   tracepoint(librbd, aio_open_image_exit, 0);
   return 0;
 }
@@ -3011,7 +3012,8 @@ extern "C" int rbd_aio_open_by_id(rados_ioctx_t p, const char *id,
   tracepoint(librbd, aio_open_image_enter, ictx, ictx->name.c_str(),
              ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only,
              comp->pc);
-  ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(comp), image));
+  ictx->state->open(0, new C_OpenComplete(ictx, get_aio_completion(comp),
+                                          image));
   tracepoint(librbd, aio_open_image_exit, 0);
   return 0;
 }
@@ -3026,7 +3028,7 @@ extern "C" int rbd_open_read_only(rados_ioctx_t p, const char *name,
                                                true);
   tracepoint(librbd, open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only);
 
-  int r = ictx->state->open(false);
+  int r = ictx->state->open(0);
   if (r >= 0) {
     *image = (rbd_image_t)ictx;
   }
@@ -3045,7 +3047,7 @@ extern "C" int rbd_open_by_id_read_only(rados_ioctx_t p, const char *id,
   tracepoint(librbd, open_image_enter, ictx, ictx->name.c_str(),
              ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only);
 
-  int r = ictx->state->open(false);
+  int r = ictx->state->open(0);
   if (r < 0) {
     delete ictx;
   } else {
@@ -3066,8 +3068,8 @@ extern "C" int rbd_aio_open_read_only(rados_ioctx_t p, const char *name,
                                                true);
   librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c;
   tracepoint(librbd, aio_open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only, comp->pc);
-  ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(comp),
-                                              image));
+  ictx->state->open(0, new C_OpenComplete(ictx, get_aio_completion(comp),
+                                          image));
   tracepoint(librbd, aio_open_image_exit, 0);
   return 0;
 }
@@ -3085,8 +3087,8 @@ extern "C" int rbd_aio_open_by_id_read_only(rados_ioctx_t p, const char *id,
   librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c;
   tracepoint(librbd, aio_open_image_enter, ictx, ictx->name.c_str(),
              ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only, comp->pc);
-  ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(comp),
-                                              image));
+  ictx->state->open(0, new C_OpenComplete(ictx, get_aio_completion(comp),
+                                          image));
   tracepoint(librbd, aio_open_image_exit, 0);
   return 0;
 }
index d6aebeb56b30c8dec2c4783ec57d4f790eabed26..4d1c3737d61a4ed96cf66287ddbe17ff62347555 100644 (file)
@@ -42,7 +42,7 @@ void SnapshotPurgeRequest<I>::open_image() {
   Context *ctx = create_context_callback<
     SnapshotPurgeRequest<I>, &SnapshotPurgeRequest<I>::handle_open_image>(
       this);
-  m_image_ctx->state->open(true, ctx);
+  m_image_ctx->state->open(librbd::OPEN_FLAG_SKIP_OPEN_PARENT, ctx);
 }
 
 template <typename I>
index 54b95587f40b8ac26d5e68dd39371d396a2984fa..7f55745e1247a77f040ed9d940b01c7d0cc6edab 100644 (file)
@@ -43,7 +43,7 @@ void OpenImageRequest<I>::send_open_image() {
   Context *ctx = create_context_callback<
     OpenImageRequest<I>, &OpenImageRequest<I>::handle_open_image>(
       this);
-  (*m_image_ctx)->state->open(false, ctx);
+  (*m_image_ctx)->state->open(0, ctx);
 }
 
 template <typename I>
index aca3f04b8757dfc18c3404d866b1a9900dc6b1f6..eabce81cb994d85f589abef47155c1855ee0a0b2 100644 (file)
@@ -118,7 +118,7 @@ void OpenLocalImageRequest<I>::send_open_image() {
   Context *ctx = create_context_callback<
     OpenLocalImageRequest<I>, &OpenLocalImageRequest<I>::handle_open_image>(
       this);
-  (*m_local_image_ctx)->state->open(false, ctx);
+  (*m_local_image_ctx)->state->open(0, ctx);
 }
 
 template <typename I>