From 8a46155b6c8d07d5878b7c97b1fba5402b0b57fd Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Fri, 17 Apr 2020 10:20:44 -0400 Subject: [PATCH] rbd-mirror: switch to common C_TrackedOp context class Signed-off-by: Jason Dillaman (cherry picked from commit 64f8d9c30c53077f48107e83ba836897aa99e609) --- .../image_replayer/journal/Replayer.cc | 30 +++++-------------- .../image_replayer/journal/Replayer.h | 1 - .../image_replayer/snapshot/Replayer.cc | 21 ++----------- .../image_replayer/snapshot/Replayer.h | 1 - 4 files changed, 11 insertions(+), 42 deletions(-) diff --git a/src/tools/rbd_mirror/image_replayer/journal/Replayer.cc b/src/tools/rbd_mirror/image_replayer/journal/Replayer.cc index cd7a04926109e..f1552ac68ca59 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/Replayer.cc +++ b/src/tools/rbd_mirror/image_replayer/journal/Replayer.cc @@ -75,22 +75,6 @@ struct Replayer::C_ReplayCommitted : public Context { } }; -template -struct Replayer::C_TrackedOp : public Context { - Replayer *replayer; - Context* ctx; - - C_TrackedOp(Replayer* replayer, Context* ctx) - : replayer(replayer), ctx(ctx) { - replayer->m_in_flight_op_tracker.start_op(); - } - - void finish(int r) override { - ctx->complete(r); - replayer->m_in_flight_op_tracker.finish_op(); - } -}; - template struct Replayer::RemoteJournalerListener : public ::journal::JournalMetadataListener { @@ -99,9 +83,11 @@ struct Replayer::RemoteJournalerListener RemoteJournalerListener(Replayer* replayer) : replayer(replayer) {} void handle_update(::journal::JournalMetadata*) override { - auto ctx = new C_TrackedOp(replayer, new LambdaContext([this](int r) { - replayer->handle_remote_journal_metadata_updated(); - })); + auto ctx = new C_TrackedOp( + replayer->m_in_flight_op_tracker, + new LambdaContext([this](int r) { + replayer->handle_remote_journal_metadata_updated(); + })); replayer->m_threads->work_queue->queue(ctx, 0); } }; @@ -247,7 +233,7 @@ template void Replayer::flush(Context* on_finish) { dout(10) << dendl; - flush_local_replay(new C_TrackedOp(this, on_finish)); + flush_local_replay(new C_TrackedOp(m_in_flight_op_tracker, on_finish)); } template @@ -264,7 +250,7 @@ bool Replayer::get_replay_status(std::string* description, return false; } - on_finish = new C_TrackedOp(this, on_finish); + on_finish = new C_TrackedOp(m_in_flight_op_tracker, on_finish); return m_replay_status_formatter->get_or_send_update(description, on_finish); } @@ -1136,7 +1122,7 @@ void Replayer::notify_status_updated() { dout(10) << dendl; - auto ctx = new C_TrackedOp(this, new LambdaContext( + auto ctx = new C_TrackedOp(m_in_flight_op_tracker, new LambdaContext( [this](int) { m_replayer_listener->handle_notification(); })); diff --git a/src/tools/rbd_mirror/image_replayer/journal/Replayer.h b/src/tools/rbd_mirror/image_replayer/journal/Replayer.h index 90ef61022331e..f5d59a07f8a47 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/Replayer.h +++ b/src/tools/rbd_mirror/image_replayer/journal/Replayer.h @@ -174,7 +174,6 @@ private: }; struct C_ReplayCommitted; - struct C_TrackedOp; struct RemoteJournalerListener; struct RemoteReplayHandler; struct LocalJournalListener; diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc index 091a40d5b2c6d..18a56b3a8d4b3 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc +++ b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.cc @@ -87,22 +87,6 @@ struct Replayer::C_UpdateWatchCtx : public librbd::UpdateWatchCtx { } }; -template -struct Replayer::C_TrackedOp : public Context { - Replayer *replayer; - Context* ctx; - - C_TrackedOp(Replayer* replayer, Context* ctx) - : replayer(replayer), ctx(ctx) { - replayer->m_in_flight_op_tracker.start_op(); - } - - void finish(int r) override { - ctx->complete(r); - replayer->m_in_flight_op_tracker.finish_op(); - } -}; - template struct Replayer::DeepCopyHandler : public librbd::deep_copy::Handler { Replayer *replayer; @@ -1101,7 +1085,8 @@ void Replayer::update_non_primary_snapshot(bool complete) { &op, m_local_snap_id_end, m_local_mirror_snap_ns.complete, m_local_mirror_snap_ns.last_copied_object_number); - auto ctx = new C_TrackedOp(this, new LambdaContext([this, complete](int r) { + auto ctx = new C_TrackedOp( + m_in_flight_op_tracker, new LambdaContext([this, complete](int r) { handle_update_non_primary_snapshot(complete, r); })); auto aio_comp = create_rados_callback(ctx); @@ -1419,7 +1404,7 @@ void Replayer::notify_status_updated() { ceph_assert(ceph_mutex_is_locked_by_me(m_lock)); dout(10) << dendl; - auto ctx = new C_TrackedOp(this, new LambdaContext( + auto ctx = new C_TrackedOp(m_in_flight_op_tracker, new LambdaContext( [this](int) { m_replayer_listener->handle_notification(); })); diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.h b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.h index dda101b0c2a4e..3eab052a20d30 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.h +++ b/src/tools/rbd_mirror/image_replayer/snapshot/Replayer.h @@ -189,7 +189,6 @@ private: }; struct C_UpdateWatchCtx; - struct C_TrackedOp; struct DeepCopyHandler; Threads* m_threads; -- 2.39.5