From c7d6e762d19284a05b88daba6c27cbbdbdb210e9 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Fri, 3 Apr 2020 11:12:48 -0400 Subject: [PATCH] librbd: pass specialized handler interface to deep-copy The initial version mimics the existing ProgressContext callback interface. Later commits will add additional deep-copy unique methods. Signed-off-by: Jason Dillaman --- src/librbd/DeepCopyRequest.cc | 6 +-- src/librbd/DeepCopyRequest.h | 9 ++-- src/librbd/api/Image.cc | 8 ++-- src/librbd/deep_copy/Handler.h | 45 +++++++++++++++++++ src/librbd/deep_copy/ImageCopyRequest.cc | 7 +-- src/librbd/deep_copy/ImageCopyRequest.h | 11 ++--- .../deep_copy/test_mock_ImageCopyRequest.cc | 35 ++++++++------- src/test/librbd/test_mock_DeepCopyRequest.cc | 17 +++---- .../snapshot/test_mock_Replayer.cc | 2 +- src/test/rbd_mirror/test_mock_ImageSync.cc | 3 +- src/tools/rbd_mirror/ImageSync.cc | 16 ++++--- src/tools/rbd_mirror/ImageSync.h | 5 +-- .../image_replayer/snapshot/Replayer.cc | 15 ++++--- .../image_replayer/snapshot/Replayer.h | 4 +- 14 files changed, 118 insertions(+), 65 deletions(-) create mode 100644 src/librbd/deep_copy/Handler.h diff --git a/src/librbd/DeepCopyRequest.cc b/src/librbd/DeepCopyRequest.cc index 90fde47b71dbf..33f1b245befd2 100644 --- a/src/librbd/DeepCopyRequest.cc +++ b/src/librbd/DeepCopyRequest.cc @@ -33,13 +33,13 @@ DeepCopyRequest::DeepCopyRequest(I *src_image_ctx, I *dst_image_ctx, bool flatten, const ObjectNumber &object_number, ContextWQ *work_queue, SnapSeqs *snap_seqs, - ProgressContext *prog_ctx, + deep_copy::Handler *handler, Context *on_finish) : RefCountedObject(dst_image_ctx->cct), m_src_image_ctx(src_image_ctx), m_dst_image_ctx(dst_image_ctx), m_src_snap_id_start(src_snap_id_start), m_src_snap_id_end(src_snap_id_end), m_dst_snap_id_start(dst_snap_id_start), m_flatten(flatten), m_object_number(object_number), - m_work_queue(work_queue), m_snap_seqs(snap_seqs), m_prog_ctx(prog_ctx), + m_work_queue(work_queue), m_snap_seqs(snap_seqs), m_handler(handler), m_on_finish(on_finish), m_cct(dst_image_ctx->cct), m_lock(ceph::make_mutex(unique_lock_name("DeepCopyRequest::m_lock", this))) { } @@ -158,7 +158,7 @@ void DeepCopyRequest::send_copy_image() { DeepCopyRequest, &DeepCopyRequest::handle_copy_image>(this); m_image_copy_request = ImageCopyRequest::create( m_src_image_ctx, m_dst_image_ctx, m_src_snap_id_start, m_src_snap_id_end, - m_dst_snap_id_start, m_flatten, m_object_number, *m_snap_seqs, m_prog_ctx, + m_dst_snap_id_start, m_flatten, m_object_number, *m_snap_seqs, m_handler, ctx); m_image_copy_request->get(); m_lock.unlock(); diff --git a/src/librbd/DeepCopyRequest.h b/src/librbd/DeepCopyRequest.h index 0348246e72249..201c86f700fe1 100644 --- a/src/librbd/DeepCopyRequest.h +++ b/src/librbd/DeepCopyRequest.h @@ -24,6 +24,7 @@ namespace deep_copy { template class ImageCopyRequest; template class SnapshotCopyRequest; +struct Handler; } @@ -39,11 +40,11 @@ public: const deep_copy::ObjectNumber &object_number, ContextWQ *work_queue, SnapSeqs *snap_seqs, - ProgressContext *prog_ctx, + deep_copy::Handler *handler, Context *on_finish) { return new DeepCopyRequest(src_image_ctx, dst_image_ctx, src_snap_id_start, src_snap_id_end, dst_snap_id_start, flatten, - object_number, work_queue, snap_seqs, prog_ctx, + object_number, work_queue, snap_seqs, handler, on_finish); } @@ -53,7 +54,7 @@ public: librados::snap_t dst_snap_id_start, bool flatten, const deep_copy::ObjectNumber &object_number, ContextWQ *work_queue, SnapSeqs *snap_seqs, - ProgressContext *prog_ctx, Context *on_finish); + deep_copy::Handler *handler, Context *on_finish); ~DeepCopyRequest(); void send(); @@ -98,7 +99,7 @@ private: deep_copy::ObjectNumber m_object_number; ContextWQ *m_work_queue; SnapSeqs *m_snap_seqs; - ProgressContext *m_prog_ctx; + deep_copy::Handler *m_handler; Context *m_on_finish; CephContext *m_cct; diff --git a/src/librbd/api/Image.cc b/src/librbd/api/Image.cc index 7b7be14acf1c4..6b95ac696bcb9 100644 --- a/src/librbd/api/Image.cc +++ b/src/librbd/api/Image.cc @@ -16,6 +16,7 @@ #include "librbd/Utils.h" #include "librbd/api/Config.h" #include "librbd/api/Trash.h" +#include "librbd/deep_copy/Handler.h" #include "librbd/image/CloneRequest.h" #include "librbd/image/RemoveRequest.h" #include "librbd/image/PreRemoveRequest.h" @@ -679,9 +680,10 @@ int Image::deep_copy(I *src, I *dest, bool flatten, C_SaferCond cond; SnapSeqs snap_seqs; - auto req = DeepCopyRequest::create(src, dest, snap_id_start, snap_id_end, - 0U, flatten, boost::none, op_work_queue, - &snap_seqs, &prog_ctx, &cond); + deep_copy::ProgressHandler progress_handler{&prog_ctx}; + auto req = DeepCopyRequest::create( + src, dest, snap_id_start, snap_id_end, 0U, flatten, boost::none, op_work_queue, + &snap_seqs, &progress_handler, &cond); req->send(); int r = cond.wait(); if (r < 0) { diff --git a/src/librbd/deep_copy/Handler.h b/src/librbd/deep_copy/Handler.h new file mode 100644 index 0000000000000..cd4eb1db3eed3 --- /dev/null +++ b/src/librbd/deep_copy/Handler.h @@ -0,0 +1,45 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_LIBRBD_DEEP_COPY_HANDLER_H +#define CEPH_LIBRBD_DEEP_COPY_HANDLER_H + +#include "include/int_types.h" +#include "include/rbd/librbd.hpp" + +namespace librbd { +namespace deep_copy { + +struct Handler { + virtual ~Handler() {} + + virtual int update_progress(uint64_t object_number, + uint64_t object_count) = 0; +}; + +struct NoOpHandler : public Handler { + int update_progress(uint64_t object_number, + uint64_t object_count) override { + return 0; + } +}; + +class ProgressHandler : public NoOpHandler { +public: + ProgressHandler(ProgressContext* progress_ctx) + : m_progress_ctx(progress_ctx) { + } + + int update_progress(uint64_t object_number, + uint64_t object_count) override { + return m_progress_ctx->update_progress(object_number, object_count); + } + +private: + librbd::ProgressContext* m_progress_ctx; +}; + +} // namespace deep_copy +} // namespace librbd + +#endif // CEPH_LIBRBD_DEEP_COPY_HANDLER_H diff --git a/src/librbd/deep_copy/ImageCopyRequest.cc b/src/librbd/deep_copy/ImageCopyRequest.cc index 09d51169f1a3b..8b2b610300ff1 100644 --- a/src/librbd/deep_copy/ImageCopyRequest.cc +++ b/src/librbd/deep_copy/ImageCopyRequest.cc @@ -5,6 +5,7 @@ #include "ObjectCopyRequest.h" #include "common/errno.h" #include "librbd/Utils.h" +#include "librbd/deep_copy/Handler.h" #include "librbd/deep_copy/Utils.h" #include "librbd/image/CloseRequest.h" #include "librbd/image/OpenRequest.h" @@ -30,13 +31,13 @@ ImageCopyRequest::ImageCopyRequest(I *src_image_ctx, I *dst_image_ctx, bool flatten, const ObjectNumber &object_number, const SnapSeqs &snap_seqs, - ProgressContext *prog_ctx, + Handler *handler, Context *on_finish) : RefCountedObject(dst_image_ctx->cct), m_src_image_ctx(src_image_ctx), m_dst_image_ctx(dst_image_ctx), m_src_snap_id_start(src_snap_id_start), m_src_snap_id_end(src_snap_id_end), m_dst_snap_id_start(dst_snap_id_start), m_flatten(flatten), m_object_number(object_number), m_snap_seqs(snap_seqs), - m_prog_ctx(prog_ctx), m_on_finish(on_finish), m_cct(dst_image_ctx->cct), + m_handler(handler), m_on_finish(on_finish), m_cct(dst_image_ctx->cct), m_lock(ceph::make_mutex(unique_lock_name("ImageCopyRequest::m_lock", this))) { } @@ -193,7 +194,7 @@ void ImageCopyRequest::handle_object_copy(uint64_t object_no, int r) { uint64_t progress_object_no = *m_object_number + 1; m_updating_progress = true; m_lock.unlock(); - m_prog_ctx->update_progress(progress_object_no, m_end_object_no); + m_handler->update_progress(progress_object_no, m_end_object_no); m_lock.lock(); ceph_assert(m_updating_progress); m_updating_progress = false; diff --git a/src/librbd/deep_copy/ImageCopyRequest.h b/src/librbd/deep_copy/ImageCopyRequest.h index 45967fdaf2a54..63b4bf3daaf4e 100644 --- a/src/librbd/deep_copy/ImageCopyRequest.h +++ b/src/librbd/deep_copy/ImageCopyRequest.h @@ -22,10 +22,11 @@ class Context; namespace librbd { class ImageCtx; -class ProgressContext; namespace deep_copy { +class Handler; + template class ImageCopyRequest : public RefCountedObject { public: @@ -37,11 +38,11 @@ public: bool flatten, const ObjectNumber &object_number, const SnapSeqs &snap_seqs, - ProgressContext *prog_ctx, + Handler *handler, Context *on_finish) { return new ImageCopyRequest(src_image_ctx, dst_image_ctx, src_snap_id_start, src_snap_id_end, dst_snap_id_start, flatten, - object_number, snap_seqs, prog_ctx, on_finish); + object_number, snap_seqs, handler, on_finish); } ImageCopyRequest(ImageCtxT *src_image_ctx, ImageCtxT *dst_image_ctx, @@ -49,7 +50,7 @@ public: librados::snap_t src_snap_id_end, librados::snap_t dst_snap_id_start, bool flatten, const ObjectNumber &object_number, - const SnapSeqs &snap_seqs, ProgressContext *prog_ctx, + const SnapSeqs &snap_seqs, Handler *handler, Context *on_finish); void send(); @@ -83,7 +84,7 @@ private: bool m_flatten; ObjectNumber m_object_number; SnapSeqs m_snap_seqs; - ProgressContext *m_prog_ctx; + Handler *m_handler; Context *m_on_finish; CephContext *m_cct; diff --git a/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc b/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc index a0a0c18b47b60..95c157a10c2f0 100644 --- a/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc +++ b/src/test/librbd/deep_copy/test_mock_ImageCopyRequest.cc @@ -7,6 +7,7 @@ #include "librbd/ImageState.h" #include "librbd/internal.h" #include "librbd/Operations.h" +#include "librbd/deep_copy/Handler.h" #include "librbd/deep_copy/ImageCopyRequest.h" #include "librbd/deep_copy/ObjectCopyRequest.h" #include "librbd/image/CloseRequest.h" @@ -313,7 +314,7 @@ TEST_F(TestMockDeepCopyImageCopyRequest, SimpleImage) { expect_get_image_size(mock_src_image_ctx, 0); expect_object_copy_send(mock_object_copy_request); - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, @@ -343,7 +344,7 @@ TEST_F(TestMockDeepCopyImageCopyRequest, FastDiff) { expect_get_image_size(mock_src_image_ctx, 1 << m_src_image_ctx->order); expect_get_image_size(mock_src_image_ctx, 0); - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, @@ -380,12 +381,12 @@ TEST_F(TestMockDeepCopyImageCopyRequest, OutOfOrder) { EXPECT_CALL(mock_object_copy_request, send()).Times(object_count); - class ProgressContext : public librbd::ProgressContext { + class Handler : public librbd::deep_copy::NoOpHandler { public: uint64_t object_count; librbd::deep_copy::ObjectNumber expected_object_number; - ProgressContext(uint64_t object_count) + Handler(uint64_t object_count) : object_count(object_count) { } @@ -401,13 +402,13 @@ TEST_F(TestMockDeepCopyImageCopyRequest, OutOfOrder) { return 0; } - } prog_ctx(object_count); + } handler(object_count); C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, 0, snap_id_end, 0, false, boost::none, - m_snap_seqs, &prog_ctx, &ctx); + m_snap_seqs, &handler, &ctx); request->send(); std::map copy_contexts; @@ -449,7 +450,7 @@ TEST_F(TestMockDeepCopyImageCopyRequest, SnapshotSubset) { expect_get_image_size(mock_src_image_ctx, 0); expect_object_copy_send(mock_object_copy_request); - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, @@ -481,7 +482,7 @@ TEST_F(TestMockDeepCopyImageCopyRequest, RestartPartialSync) { expect_get_image_size(mock_src_image_ctx, 0); expect_object_copy_send(mock_object_copy_request); - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, @@ -517,7 +518,7 @@ TEST_F(TestMockDeepCopyImageCopyRequest, Cancel) { expect_get_image_size(mock_src_image_ctx, 0); expect_object_copy_send(mock_object_copy_request); - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, @@ -556,20 +557,20 @@ TEST_F(TestMockDeepCopyImageCopyRequest, Cancel_Inflight_Sync) { EXPECT_CALL(mock_object_copy_request, send()).Times(6); - struct ProgressContext : public librbd::ProgressContext { + struct Handler : public librbd::deep_copy::NoOpHandler { librbd::deep_copy::ObjectNumber object_number; int update_progress(uint64_t object_no, uint64_t end_object_no) override { object_number = object_number ? *object_number + 1 : 0; return 0; } - } prog_ctx; + } handler; C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, 0, snap_id_end, 0, false, boost::none, - m_snap_seqs, &prog_ctx, &ctx); + m_snap_seqs, &handler, &ctx); request->send(); ASSERT_EQ(m_snap_map, wait_for_snap_map(mock_object_copy_request)); @@ -587,14 +588,14 @@ TEST_F(TestMockDeepCopyImageCopyRequest, Cancel_Inflight_Sync) { cancel_ctx->complete(0); ASSERT_EQ(-ECANCELED, ctx.wait()); - ASSERT_EQ(5u, prog_ctx.object_number.get()); + ASSERT_EQ(5u, handler.object_number.get()); } TEST_F(TestMockDeepCopyImageCopyRequest, MissingSnap) { librbd::MockTestImageCtx mock_src_image_ctx(*m_src_image_ctx); librbd::MockTestImageCtx mock_dst_image_ctx(*m_dst_image_ctx); - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, @@ -611,7 +612,7 @@ TEST_F(TestMockDeepCopyImageCopyRequest, MissingFromSnap) { librbd::MockTestImageCtx mock_src_image_ctx(*m_src_image_ctx); librbd::MockTestImageCtx mock_dst_image_ctx(*m_dst_image_ctx); - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, @@ -631,7 +632,7 @@ TEST_F(TestMockDeepCopyImageCopyRequest, EmptySnapMap) { librbd::MockTestImageCtx mock_src_image_ctx(*m_src_image_ctx); librbd::MockTestImageCtx mock_dst_image_ctx(*m_dst_image_ctx); - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, @@ -650,7 +651,7 @@ TEST_F(TestMockDeepCopyImageCopyRequest, EmptySnapSeqs) { librbd::MockTestImageCtx mock_src_image_ctx(*m_src_image_ctx); librbd::MockTestImageCtx mock_dst_image_ctx(*m_dst_image_ctx); - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; C_SaferCond ctx; auto request = new MockImageCopyRequest(&mock_src_image_ctx, &mock_dst_image_ctx, diff --git a/src/test/librbd/test_mock_DeepCopyRequest.cc b/src/test/librbd/test_mock_DeepCopyRequest.cc index fa5f77e8f468e..340fe1e2a4d67 100644 --- a/src/test/librbd/test_mock_DeepCopyRequest.cc +++ b/src/test/librbd/test_mock_DeepCopyRequest.cc @@ -8,6 +8,7 @@ #include "librbd/Operations.h" #include "librbd/internal.h" #include "librbd/api/Image.h" +#include "librbd/deep_copy/Handler.h" #include "librbd/deep_copy/ImageCopyRequest.h" #include "librbd/deep_copy/MetadataCopyRequest.h" #include "librbd/deep_copy/SnapshotCopyRequest.h" @@ -46,7 +47,7 @@ public: librados::snap_t src_snap_id_end, librados::snap_t dst_snap_id_start, bool flatten, const ObjectNumber &object_number, - const SnapSeqs &snap_seqs, ProgressContext *prog_ctx, + const SnapSeqs &snap_seqs, Handler *handler, Context *on_finish) { ceph_assert(s_instance != nullptr); s_instance->on_finish = on_finish; @@ -266,7 +267,7 @@ TEST_F(TestMockDeepCopyRequest, SimpleCopy) { C_SaferCond ctx; librbd::SnapSeqs snap_seqs; - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; auto request = librbd::DeepCopyRequest::create( &mock_src_image_ctx, &mock_dst_image_ctx, 0, CEPH_NOSNAP, 0, false, boost::none, m_work_queue, &snap_seqs, &no_op, &ctx); @@ -284,7 +285,7 @@ TEST_F(TestMockDeepCopyRequest, ErrorOnCopySnapshots) { C_SaferCond ctx; librbd::SnapSeqs snap_seqs; - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; auto request = librbd::DeepCopyRequest::create( &mock_src_image_ctx, &mock_dst_image_ctx, 0, CEPH_NOSNAP, 0, false, boost::none, m_work_queue, &snap_seqs, &no_op, &ctx); @@ -317,7 +318,7 @@ TEST_F(TestMockDeepCopyRequest, ErrorOnRefreshObjectMap) { C_SaferCond ctx; librbd::SnapSeqs snap_seqs; - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; auto request = librbd::DeepCopyRequest::create( &mock_src_image_ctx, &mock_dst_image_ctx, 0, CEPH_NOSNAP, 0, false, boost::none, m_work_queue, &snap_seqs, &no_op, &ctx); @@ -337,7 +338,7 @@ TEST_F(TestMockDeepCopyRequest, ErrorOnCopyImage) { C_SaferCond ctx; librbd::SnapSeqs snap_seqs; - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; auto request = librbd::DeepCopyRequest::create( &mock_src_image_ctx, &mock_dst_image_ctx, 0, CEPH_NOSNAP, 0, false, boost::none, m_work_queue, &snap_seqs, &no_op, &ctx); @@ -374,7 +375,7 @@ TEST_F(TestMockDeepCopyRequest, ErrorOnCopyMetadata) { C_SaferCond ctx; librbd::SnapSeqs snap_seqs; - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; auto request = librbd::DeepCopyRequest::create( &mock_src_image_ctx, &mock_dst_image_ctx, 0, CEPH_NOSNAP, 0, false, boost::none, m_work_queue, &snap_seqs, &no_op, &ctx); @@ -415,7 +416,7 @@ TEST_F(TestMockDeepCopyRequest, Snap) { C_SaferCond ctx; librbd::SnapSeqs snap_seqs = {{m_src_image_ctx->snap_id, 123}}; - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; auto request = librbd::DeepCopyRequest::create( &mock_src_image_ctx, &mock_dst_image_ctx, 0, m_src_image_ctx->snap_id, 0, false, boost::none, m_work_queue, &snap_seqs, &no_op, &ctx); @@ -452,7 +453,7 @@ TEST_F(TestMockDeepCopyRequest, ErrorOnRollbackObjectMap) { C_SaferCond ctx; librbd::SnapSeqs snap_seqs = {{m_src_image_ctx->snap_id, 123}}; - librbd::NoOpProgressContext no_op; + librbd::deep_copy::NoOpHandler no_op; auto request = librbd::DeepCopyRequest::create( &mock_src_image_ctx, &mock_dst_image_ctx, 0, m_src_image_ctx->snap_id, 0, false, boost::none, m_work_queue, &snap_seqs, &no_op, &ctx); diff --git a/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc b/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc index b2e95bad097e1..cfbc675a6b228 100644 --- a/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc +++ b/src/test/rbd_mirror/image_replayer/snapshot/test_mock_Replayer.cc @@ -51,7 +51,7 @@ struct ImageCopyRequest { bool flatten, const ObjectNumber &object_number, const SnapSeqs &snap_seqs, - ProgressContext *prog_ctx, + Handler *handler, Context *on_finish) { ceph_assert(s_instance != nullptr); s_instance->src_snap_id_start = src_snap_id_start; diff --git a/src/test/rbd_mirror/test_mock_ImageSync.cc b/src/test/rbd_mirror/test_mock_ImageSync.cc index 743418325ced0..5b424718cb738 100644 --- a/src/test/rbd_mirror/test_mock_ImageSync.cc +++ b/src/test/rbd_mirror/test_mock_ImageSync.cc @@ -36,7 +36,7 @@ public: librados::snap_t src_snap_id_start, librados::snap_t src_snap_id_end, librados::snap_t dst_snap_id_start, bool flatten, const librbd::deep_copy::ObjectNumber &object_number, - ContextWQ *work_queue, SnapSeqs *snap_seqs, ProgressContext *prog_ctx, + ContextWQ *work_queue, SnapSeqs *snap_seqs, deep_copy::Handler *handler, Context *on_finish) { ceph_assert(s_instance != nullptr); s_instance->on_finish = on_finish; @@ -62,7 +62,6 @@ DeepCopyRequest* DeepCopyRequest; #include "tools/rbd_mirror/ImageSync.cc" namespace rbd { diff --git a/src/tools/rbd_mirror/ImageSync.cc b/src/tools/rbd_mirror/ImageSync.cc index 2765b66bf29db..a56723be2edad 100644 --- a/src/tools/rbd_mirror/ImageSync.cc +++ b/src/tools/rbd_mirror/ImageSync.cc @@ -12,6 +12,7 @@ #include "librbd/ImageState.h" #include "librbd/Utils.h" #include "librbd/internal.h" +#include "librbd/deep_copy/Handler.h" #include "tools/rbd_mirror/Threads.h" #include "tools/rbd_mirror/image_sync/SyncPointCreateRequest.h" #include "tools/rbd_mirror/image_sync/SyncPointPruneRequest.h" @@ -32,9 +33,10 @@ using librbd::util::create_context_callback; using librbd::util::unique_lock_name; template -class ImageSync::ImageCopyProgressContext : public librbd::ProgressContext { +class ImageSync::ImageCopyProgressHandler + : public librbd::deep_copy::NoOpHandler { public: - ImageCopyProgressContext(ImageSync *image_sync) : image_sync(image_sync) { + ImageCopyProgressHandler(ImageSync *image_sync) : image_sync(image_sync) { } int update_progress(uint64_t object_no, uint64_t object_count) override { @@ -73,7 +75,7 @@ ImageSync::ImageSync( template ImageSync::~ImageSync() { ceph_assert(m_image_copy_request == nullptr); - ceph_assert(m_image_copy_prog_ctx == nullptr); + ceph_assert(m_image_copy_prog_handler == nullptr); ceph_assert(m_update_sync_ctx == nullptr); } @@ -252,11 +254,11 @@ void ImageSync::send_copy_image() { Context *ctx = create_context_callback< ImageSync, &ImageSync::handle_copy_image>(this); - m_image_copy_prog_ctx = new ImageCopyProgressContext(this); + m_image_copy_prog_handler = new ImageCopyProgressHandler(this); m_image_copy_request = librbd::DeepCopyRequest::create( m_remote_image_ctx, m_local_image_ctx, snap_id_start, snap_id_end, 0, false, object_number, m_threads->work_queue, &m_snap_seqs_copy, - m_image_copy_prog_ctx, ctx); + m_image_copy_prog_handler, ctx); m_image_copy_request->get(); m_lock.unlock(); @@ -273,8 +275,8 @@ void ImageSync::handle_copy_image(int r) { std::scoped_lock locker{m_threads->timer_lock, m_lock}; m_image_copy_request->put(); m_image_copy_request = nullptr; - delete m_image_copy_prog_ctx; - m_image_copy_prog_ctx = nullptr; + delete m_image_copy_prog_handler; + m_image_copy_prog_handler = nullptr; if (r == 0 && m_canceled) { r = -ECANCELED; } diff --git a/src/tools/rbd_mirror/ImageSync.h b/src/tools/rbd_mirror/ImageSync.h index 0662732327068..b1d88b857e3bc 100644 --- a/src/tools/rbd_mirror/ImageSync.h +++ b/src/tools/rbd_mirror/ImageSync.h @@ -14,7 +14,6 @@ class Context; class ContextWQ; namespace journal { class Journaler; } -namespace librbd { class ProgressContext; } namespace librbd { template class DeepCopyRequest; } namespace rbd { @@ -90,7 +89,7 @@ private: * @endverbatim */ - class ImageCopyProgressContext; + class ImageCopyProgressHandler; Threads* m_threads; ImageCtxT *m_local_image_ctx; @@ -104,7 +103,7 @@ private: bool m_canceled = false; librbd::DeepCopyRequest *m_image_copy_request = nullptr; - librbd::ProgressContext *m_image_copy_prog_ctx = nullptr; + ImageCopyProgressHandler *m_image_copy_prog_handler = nullptr; bool m_updating_sync_point = false; Context *m_update_sync_ctx = nullptr; diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc index 69fb3d93af4d8..5656b16a01de3 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc +++ b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc @@ -11,6 +11,7 @@ #include "librbd/ImageCtx.h" #include "librbd/ImageState.h" #include "librbd/Utils.h" +#include "librbd/deep_copy/Handler.h" #include "librbd/deep_copy/ImageCopyRequest.h" #include "librbd/deep_copy/SnapshotCopyRequest.h" #include "librbd/mirror/snapshot/CreateNonPrimaryRequest.h" @@ -96,10 +97,10 @@ struct Replayer::C_TrackedOp : public Context { }; template -struct Replayer::ProgressContext : public librbd::ProgressContext { +struct Replayer::DeepCopyHandler : public librbd::deep_copy::Handler { Replayer *replayer; - ProgressContext(Replayer* replayer) : replayer(replayer) { + DeepCopyHandler(Replayer* replayer) : replayer(replayer) { } int update_progress(uint64_t object_number, uint64_t object_count) override { @@ -132,7 +133,7 @@ Replayer::~Replayer() { dout(10) << dendl; ceph_assert(m_state == STATE_COMPLETE); ceph_assert(m_update_watch_ctx == nullptr); - ceph_assert(m_progress_ctx == nullptr); + ceph_assert(m_deep_copy_handler == nullptr); } template @@ -791,7 +792,7 @@ void Replayer::copy_image() { << m_local_mirror_snap_ns.last_copied_object_number << ", " << "snap_seqs=" << m_local_mirror_snap_ns.snap_seqs << dendl; - m_progress_ctx = new ProgressContext(this); + m_deep_copy_handler = new DeepCopyHandler(this); auto ctx = create_context_callback< Replayer, &Replayer::handle_copy_image>(this); auto req = librbd::deep_copy::ImageCopyRequest::create( @@ -801,7 +802,7 @@ void Replayer::copy_image() { librbd::deep_copy::ObjectNumber{ m_local_mirror_snap_ns.last_copied_object_number} : librbd::deep_copy::ObjectNumber{}), - m_local_mirror_snap_ns.snap_seqs, m_progress_ctx, ctx); + m_local_mirror_snap_ns.snap_seqs, m_deep_copy_handler, ctx); req->send(); } @@ -809,8 +810,8 @@ template void Replayer::handle_copy_image(int r) { dout(10) << "r=" << r << dendl; - delete m_progress_ctx; - m_progress_ctx = nullptr; + delete m_deep_copy_handler; + m_deep_copy_handler = nullptr; if (r < 0) { derr << "failed to copy remote image to local image: " << cpp_strerror(r) diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.h b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.h index e7536f5a6fa26..ba49d7cd7991c 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.h +++ b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.h @@ -183,7 +183,7 @@ private: struct C_UpdateWatchCtx; struct C_TrackedOp; - struct ProgressContext; + struct DeepCopyHandler; Threads* m_threads; InstanceWatcher* m_instance_watcher; @@ -220,7 +220,7 @@ private: cls::rbd::MirrorSnapshotNamespace m_remote_mirror_snap_ns; librbd::mirror::snapshot::ImageState m_image_state; - ProgressContext* m_progress_ctx = nullptr; + DeepCopyHandler* m_deep_copy_handler = nullptr; bool m_remote_image_updated = false; bool m_updating_sync_point = false; -- 2.39.5