From 179a5b82d6d9f3ba7ccd5321894450061d90f112 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Sun, 10 Dec 2017 16:44:07 +0200 Subject: [PATCH] librbd: allow to remove already opened image Signed-off-by: Mykola Golub --- src/librbd/image/RemoveRequest.cc | 22 ++++++++++++++++++++-- src/librbd/image/RemoveRequest.h | 17 +++++++++++++++-- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/librbd/image/RemoveRequest.cc b/src/librbd/image/RemoveRequest.cc index 66330345e1161..09564cca81a64 100644 --- a/src/librbd/image/RemoveRequest.cc +++ b/src/librbd/image/RemoveRequest.cc @@ -56,9 +56,19 @@ RemoveRequest::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(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 +RemoveRequest::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 @@ -70,6 +80,14 @@ void RemoveRequest::send() { template void RemoveRequest::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; diff --git a/src/librbd/image/RemoveRequest.h b/src/librbd/image/RemoveRequest.h index d85e301cfd979..803bd440c2d24 100644 --- a/src/librbd/image/RemoveRequest.h +++ b/src/librbd/image/RemoveRequest.h @@ -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: * * | * 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; -- 2.39.5