From 09d2f2265fb72ad4284d48e913eef9a09d1a8496 Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Fri, 25 May 2018 16:36:13 +0300 Subject: [PATCH] librbd: use 'open snap by id' in deep copy image copy request Signed-off-by: Mykola Golub --- src/librbd/deep_copy/ImageCopyRequest.cc | 46 ++++--------------- src/librbd/deep_copy/ImageCopyRequest.h | 7 --- .../deep_copy/test_mock_ImageCopyRequest.cc | 23 +--------- 3 files changed, 11 insertions(+), 65 deletions(-) diff --git a/src/librbd/deep_copy/ImageCopyRequest.cc b/src/librbd/deep_copy/ImageCopyRequest.cc index e537ce13ce4da..651937fcd36ff 100644 --- a/src/librbd/deep_copy/ImageCopyRequest.cc +++ b/src/librbd/deep_copy/ImageCopyRequest.cc @@ -8,7 +8,6 @@ #include "librbd/deep_copy/Utils.h" #include "librbd/image/CloseRequest.h" #include "librbd/image/OpenRequest.h" -#include "librbd/image/SetSnapRequest.h" #include "osdc/Striper.h" #define dout_subsys ceph_subsys_rbd @@ -62,6 +61,7 @@ void ImageCopyRequest::cancel() { template void ImageCopyRequest::send_open_parent() { + ParentSpec parent_spec; { RWLock::RLocker snap_locker(m_src_image_ctx->snap_lock); RWLock::RLocker parent_locker(m_src_image_ctx->parent_lock); @@ -72,24 +72,24 @@ void ImageCopyRequest::send_open_parent() { ldout(m_cct, 20) << "could not find parent info for snap id " << snap_id << dendl; } else { - m_parent_spec = parent_info->spec; + parent_spec = parent_info->spec; } } - if (m_parent_spec.pool_id == -1) { + if (parent_spec.pool_id == -1) { send_object_copies(); return; } - ldout(m_cct, 20) << "pool_id=" << m_parent_spec.pool_id << ", image_id=" - << m_parent_spec.image_id << ", snap_id=" - << m_parent_spec.snap_id << dendl; + ldout(m_cct, 20) << "pool_id=" << parent_spec.pool_id << ", image_id=" + << parent_spec.image_id << ", snap_id=" + << parent_spec.snap_id << dendl; librados::Rados rados(m_src_image_ctx->md_ctx); librados::IoCtx parent_io_ctx; - int r = rados.ioctx_create2(m_parent_spec.pool_id, parent_io_ctx); + int r = rados.ioctx_create2(parent_spec.pool_id, parent_io_ctx); if (r < 0) { - lderr(m_cct) << "failed to access parent pool (id=" << m_parent_spec.pool_id + lderr(m_cct) << "failed to access parent pool (id=" << parent_spec.pool_id << "): " << cpp_strerror(r) << dendl; finish(r); return; @@ -98,9 +98,8 @@ void ImageCopyRequest::send_open_parent() { // TODO support clone v2 parent namespaces parent_io_ctx.set_namespace(m_src_image_ctx->md_ctx.get_namespace()); - m_src_parent_image_ctx = I::create("", m_parent_spec.image_id, nullptr, - parent_io_ctx, true); - + m_src_parent_image_ctx = I::create("", parent_spec.image_id, + parent_spec.snap_id, parent_io_ctx, true); auto ctx = create_context_callback< ImageCopyRequest, &ImageCopyRequest::handle_open_parent>(this); @@ -120,31 +119,6 @@ void ImageCopyRequest::handle_open_parent(int r) { return; } - send_set_parent_snap(); -} - -template -void ImageCopyRequest::send_set_parent_snap() { - ldout(m_cct, 20) << dendl; - - auto ctx = create_context_callback< - ImageCopyRequest, &ImageCopyRequest::handle_set_parent_snap>(this); - auto req = image::SetSnapRequest::create(*m_src_parent_image_ctx, - m_parent_spec.snap_id, ctx); - req->send(); -} - -template -void ImageCopyRequest::handle_set_parent_snap(int r) { - ldout(m_cct, 20) << "r=" << r << dendl; - - if (r < 0) { - lderr(m_cct) << "failed to set parent snap: " << cpp_strerror(r) << dendl; - m_ret_val = r; - send_close_parent(); - return; - } - send_object_copies(); } diff --git a/src/librbd/deep_copy/ImageCopyRequest.h b/src/librbd/deep_copy/ImageCopyRequest.h index c8fc08169f349..c7d020785673a 100644 --- a/src/librbd/deep_copy/ImageCopyRequest.h +++ b/src/librbd/deep_copy/ImageCopyRequest.h @@ -59,9 +59,6 @@ private: * v * OPEN_PARENT (skip if not needed) * | - * v - * SET_PARENT_SNAP (skip if not needed) - * | * | . . . . . * | . . (parallel execution of * v v . multiple objects at once) @@ -98,15 +95,11 @@ private: bool m_updating_progress = false; SnapMap m_snap_map; int m_ret_val = 0; - ParentSpec m_parent_spec; ImageCtxT *m_src_parent_image_ctx = nullptr; void send_open_parent(); void handle_open_parent(int r); - void send_set_parent_snap(); - void handle_set_parent_snap(int r); - void send_object_copies(); void send_next_object_copy(); void handle_object_copy(uint64_t object_no, int r); diff --git a/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc b/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc index 602a12f04756b..04d93f4e025b0 100644 --- a/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc +++ b/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc @@ -10,7 +10,6 @@ #include "librbd/deep_copy/ObjectCopyRequest.h" #include "librbd/image/CloseRequest.h" #include "librbd/image/OpenRequest.h" -#include "librbd/image/SetSnapRequest.h" #include "librbd/internal.h" #include "test/librados_test_stub/MockTestMemIoCtxImpl.h" #include "test/librbd/mock/MockImageCtx.h" @@ -25,7 +24,7 @@ struct MockTestImageCtx : public librbd::MockImageCtx { static MockTestImageCtx* s_instance; static MockTestImageCtx* create(const std::string &image_name, const std::string &image_id, - const char *snap, librados::IoCtx& p, + librados::snap_t snap_id, librados::IoCtx& p, bool read_only) { assert(s_instance != nullptr); return s_instance; @@ -119,26 +118,6 @@ struct OpenRequest { OpenRequest* OpenRequest::s_instance = nullptr; -template <> -struct SetSnapRequest { - Context* on_finish = nullptr; - static SetSnapRequest* s_instance; - static SetSnapRequest* create(MockTestImageCtx &image_ctx, uint64_t snap_id, - Context *on_finish) { - assert(s_instance != nullptr); - s_instance->on_finish = on_finish; - return s_instance; - } - - MOCK_METHOD0(send, void()); - - SetSnapRequest() { - s_instance = this; - } -}; - -SetSnapRequest* SetSnapRequest::s_instance = nullptr; - } // namespace image } // namespace librbd -- 2.39.5