]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: allow to remove already opened image
authorMykola Golub <to.my.trociny@gmail.com>
Sun, 10 Dec 2017 14:44:07 +0000 (16:44 +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>
src/librbd/image/RemoveRequest.cc
src/librbd/image/RemoveRequest.h

index 66330345e1161bf31f4e9ad518264f3aab2fdf6f..09564cca81a641589c65808ba36bf43a628101a7 100644 (file)
@@ -56,9 +56,19 @@ RemoveRequest<I>::RemoveRequest(IoCtx &ioctx, const std::string &image_name,
     m_prog_ctx(prog_ctx), m_op_work_queue(op_work_queue),
     m_on_finish(on_finish) {
   m_cct = reinterpret_cast<CephContext *>(m_ioctx.cct());
+}
 
-  m_image_ctx = I::create((m_image_id.empty() ? m_image_name : std::string()),
-                          m_image_id, nullptr, m_ioctx, false);
+template<typename I>
+RemoveRequest<I>::RemoveRequest(IoCtx &ioctx, I *image_ctx, bool force,
+                                bool from_trash_remove,
+                                ProgressContext &prog_ctx,
+                                ContextWQ *op_work_queue, Context *on_finish)
+  : m_ioctx(ioctx), m_image_name(image_ctx->name), m_image_id(image_ctx->id),
+    m_image_ctx(image_ctx), m_force(force),
+    m_from_trash_remove(from_trash_remove), m_prog_ctx(prog_ctx),
+    m_op_work_queue(op_work_queue), m_on_finish(on_finish),
+    m_cct(image_ctx->cct), m_header_oid(image_ctx->header_oid),
+    m_old_format(image_ctx->old_format), m_unknown_format(false) {
 }
 
 template<typename I>
@@ -70,6 +80,14 @@ void RemoveRequest<I>::send() {
 
 template<typename I>
 void RemoveRequest<I>::open_image() {
+  if (m_image_ctx != nullptr) {
+    check_exclusive_lock();
+    return;
+  }
+
+  m_image_ctx = I::create(m_image_id.empty() ? m_image_name : "", m_image_id,
+                          nullptr, m_ioctx, false);
+
   ldout(m_cct, 20) << dendl;
 
   using klass = RemoveRequest<I>;
index d85e301cfd979418d2a357d782364f6c0ad2db4c..803bd440c2d24c983e9d9ede4b1f1bf2cfb0cb09 100644 (file)
@@ -37,6 +37,15 @@ public:
                              on_finish);
   }
 
+  static RemoveRequest *create(librados::IoCtx &ioctx, ImageCtxT *image_ctx,
+                               bool force, bool from_trash_remove,
+                               ProgressContext &prog_ctx,
+                               ContextWQ *op_work_queue,
+                               Context *on_finish) {
+    return new RemoveRequest(ioctx, image_ctx, force, from_trash_remove,
+                             prog_ctx, op_work_queue, on_finish);
+  }
+
   void send();
 
 private:
@@ -46,7 +55,7 @@ private:
    *                                  <start>
    *                                     |
    *                                     v
-   *                                OPEN IMAGE------------------\
+   *       (skip if already opened) OPEN IMAGE------------------\
    *                                     |                      |
    *                                     v                      |
    *      error                   CHECK EXCLUSIVE LOCK---\     |
@@ -107,9 +116,14 @@ private:
                 ProgressContext &prog_ctx, ContextWQ *op_work_queue,
                 Context *on_finish);
 
+  RemoveRequest(librados::IoCtx &ioctx, ImageCtxT *image_ctx, bool force,
+                bool from_trash_remove, ProgressContext &prog_ctx,
+                ContextWQ *op_work_queue, Context *on_finish);
+
   librados::IoCtx &m_ioctx;
   std::string m_image_name;
   std::string m_image_id;
+  ImageCtxT *m_image_ctx = nullptr;
   bool m_force;
   bool m_from_trash_remove;
   ProgressContext &m_prog_ctx;
@@ -120,7 +134,6 @@ private:
   std::string m_header_oid;
   bool m_old_format = false;
   bool m_unknown_format = true;
-  ImageCtxT *m_image_ctx;
 
   librados::IoCtx m_parent_io_ctx;