From d90f5aed33b7621511d7c0ce778be2228de0b2da Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 1 Dec 2020 19:48:41 -0500 Subject: [PATCH] librbd/migration: tweak open source image state machine Remove the need for the child (destination) image to be opened for the state machine to function. Signed-off-by: Jason Dillaman --- src/librbd/image/RefreshParentRequest.cc | 4 +-- .../migration/OpenSourceImageRequest.cc | 32 ++++++++----------- src/librbd/migration/OpenSourceImageRequest.h | 15 ++++++--- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/librbd/image/RefreshParentRequest.cc b/src/librbd/image/RefreshParentRequest.cc index 27cc99f529e..348226c392b 100644 --- a/src/librbd/image/RefreshParentRequest.cc +++ b/src/librbd/image/RefreshParentRequest.cc @@ -119,8 +119,8 @@ void RefreshParentRequest::send_open_parent() { RefreshParentRequest, &RefreshParentRequest::handle_open_parent, false>(this)); auto req = migration::OpenSourceImageRequest::create( - &m_child_image_ctx, m_parent_md.spec.snap_id, m_migration_info, - &m_parent_image_ctx, ctx); + m_child_image_ctx.md_ctx, &m_child_image_ctx, m_parent_md.spec.snap_id, + m_migration_info, &m_parent_image_ctx, ctx); req->send(); return; } diff --git a/src/librbd/migration/OpenSourceImageRequest.cc b/src/librbd/migration/OpenSourceImageRequest.cc index fc574ef7498..8dd3a6fc016 100644 --- a/src/librbd/migration/OpenSourceImageRequest.cc +++ b/src/librbd/migration/OpenSourceImageRequest.cc @@ -22,13 +22,13 @@ namespace migration { template OpenSourceImageRequest::OpenSourceImageRequest( - I* dst_image_ctx, uint64_t src_snap_id, + librados::IoCtx& io_ctx, I* dst_image_ctx, uint64_t src_snap_id, const MigrationInfo &migration_info, I** src_image_ctx, Context* on_finish) - : m_dst_image_ctx(dst_image_ctx), m_src_snap_id(src_snap_id), + : m_cct(reinterpret_cast(io_ctx.cct())), m_io_ctx(io_ctx), + m_dst_image_ctx(dst_image_ctx), m_src_snap_id(src_snap_id), m_migration_info(migration_info), m_src_image_ctx(src_image_ctx), m_on_finish(on_finish) { - auto cct = m_dst_image_ctx->cct; - ldout(cct, 10) << dendl; + ldout(m_cct, 10) << dendl; } template @@ -38,12 +38,10 @@ void OpenSourceImageRequest::send() { template void OpenSourceImageRequest::open_source() { - auto cct = m_dst_image_ctx->cct; - ldout(cct, 10) << dendl; + ldout(m_cct, 10) << dendl; // note that all source image ctx properties are placeholders - *m_src_image_ctx = I::create("", "", m_src_snap_id, m_dst_image_ctx->md_ctx, - true); + *m_src_image_ctx = I::create("", "", m_src_snap_id, m_io_ctx, true); auto src_image_ctx = *m_src_image_ctx; src_image_ctx->child = m_dst_image_ctx; @@ -70,8 +68,8 @@ void OpenSourceImageRequest::open_source() { int r = source_spec_builder.parse_source_spec(source_spec, &source_spec_object); if (r < 0) { - lderr(cct) << "failed to parse migration source-spec:" << cpp_strerror(r) - << dendl; + lderr(m_cct) << "failed to parse migration source-spec:" << cpp_strerror(r) + << dendl; (*m_src_image_ctx)->state->close(); finish(r); return; @@ -80,8 +78,8 @@ void OpenSourceImageRequest::open_source() { r = source_spec_builder.build_format(source_spec_object, import_only, &m_format); if (r < 0) { - lderr(cct) << "failed to build migration format handler: " - << cpp_strerror(r) << dendl; + lderr(m_cct) << "failed to build migration format handler: " + << cpp_strerror(r) << dendl; (*m_src_image_ctx)->state->close(); finish(r); return; @@ -95,12 +93,11 @@ void OpenSourceImageRequest::open_source() { template void OpenSourceImageRequest::handle_open_source(int r) { - auto cct = m_dst_image_ctx->cct; - ldout(cct, 10) << "r=" << r << dendl; + ldout(m_cct, 10) << "r=" << r << dendl; if (r < 0) { - lderr(cct) << "failed to open migration source: " << cpp_strerror(r) - << dendl; + lderr(m_cct) << "failed to open migration source: " << cpp_strerror(r) + << dendl; finish(r); return; } @@ -115,8 +112,7 @@ void OpenSourceImageRequest::handle_open_source(int r) { template void OpenSourceImageRequest::finish(int r) { - auto cct = m_dst_image_ctx->cct; - ldout(cct, 10) << "r=" << r << dendl; + ldout(m_cct, 10) << "r=" << r << dendl; if (r < 0) { *m_src_image_ctx = nullptr; diff --git a/src/librbd/migration/OpenSourceImageRequest.h b/src/librbd/migration/OpenSourceImageRequest.h index 1ad247686a1..a9099452d60 100644 --- a/src/librbd/migration/OpenSourceImageRequest.h +++ b/src/librbd/migration/OpenSourceImageRequest.h @@ -4,6 +4,7 @@ #ifndef CEPH_LIBRBD_MIGRATION_OPEN_SOURCE_IMAGE_REQUEST_H #define CEPH_LIBRBD_MIGRATION_OPEN_SOURCE_IMAGE_REQUEST_H +#include "include/rados/librados_fwd.hpp" #include "librbd/Types.h" #include @@ -20,17 +21,19 @@ struct FormatInterface; template class OpenSourceImageRequest { public: - static OpenSourceImageRequest* create(ImageCtxT* destination_image_ctx, + static OpenSourceImageRequest* create(librados::IoCtx& io_ctx, + ImageCtxT* destination_image_ctx, uint64_t src_snap_id, const MigrationInfo &migration_info, ImageCtxT** source_image_ctx, Context* on_finish) { - return new OpenSourceImageRequest(destination_image_ctx, src_snap_id, - migration_info, source_image_ctx, - on_finish); + return new OpenSourceImageRequest(io_ctx, destination_image_ctx, + src_snap_id, migration_info, + source_image_ctx, on_finish); } - OpenSourceImageRequest(ImageCtxT* destination_image_ctx, + OpenSourceImageRequest(librados::IoCtx& io_ctx, + ImageCtxT* destination_image_ctx, uint64_t src_snap_id, const MigrationInfo &migration_info, ImageCtxT** source_image_ctx, @@ -53,6 +56,8 @@ private: * @endverbatim */ + CephContext* m_cct; + librados::IoCtx& m_io_ctx; ImageCtxT* m_dst_image_ctx; uint64_t m_src_snap_id; MigrationInfo m_migration_info; -- 2.39.5