From 50d24c95f3a49dc55d7fc1aa6a5a492f3cdb1331 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 11 Apr 2019 16:18:54 -0400 Subject: [PATCH] rbd-mirror: simplify image replayer IO / commit position flush path There is no current user of the callback context provided to the flush method and there are no longer any reason to have the flush support methods be virtual. Signed-off-by: Jason Dillaman --- src/tools/rbd_mirror/ImageReplayer.cc | 72 +++++++++++++-------------- src/tools/rbd_mirror/ImageReplayer.h | 13 ++--- 2 files changed, 41 insertions(+), 44 deletions(-) diff --git a/src/tools/rbd_mirror/ImageReplayer.cc b/src/tools/rbd_mirror/ImageReplayer.cc index 42cfec7ca54..48b78be01aa 100644 --- a/src/tools/rbd_mirror/ImageReplayer.cc +++ b/src/tools/rbd_mirror/ImageReplayer.cc @@ -853,80 +853,76 @@ void ImageReplayer::restart(Context *on_finish) } template -void ImageReplayer::flush(Context *on_finish) +void ImageReplayer::flush() { dout(10) << dendl; + C_SaferCond ctx; + flush_local_replay(&ctx); + ctx.wait(); - { - Mutex::Locker locker(m_lock); - if (m_state == STATE_REPLAYING) { - Context *ctx = new FunctionContext( - [on_finish](int r) { - if (on_finish != nullptr) { - on_finish->complete(r); - } - }); - on_flush_local_replay_flush_start(ctx); - return; - } - } - - if (on_finish) { - on_finish->complete(0); - } + update_mirror_image_status(false, boost::none); } template -void ImageReplayer::on_flush_local_replay_flush_start(Context *on_flush) +void ImageReplayer::flush_local_replay(Context* on_flush) { - dout(10) << dendl; - FunctionContext *ctx = new FunctionContext( + m_lock.Lock(); + if (m_state != STATE_REPLAYING) { + m_lock.Unlock(); + on_flush->complete(0); + return; + } + + dout(15) << dendl; + auto ctx = new FunctionContext( [this, on_flush](int r) { - on_flush_local_replay_flush_finish(on_flush, r); + handle_flush_local_replay(on_flush, r); }); - - ceph_assert(m_lock.is_locked()); - ceph_assert(m_state == STATE_REPLAYING); m_local_replay->flush(ctx); + m_lock.Unlock(); } template -void ImageReplayer::on_flush_local_replay_flush_finish(Context *on_flush, - int r) +void ImageReplayer::handle_flush_local_replay(Context* on_flush, int r) { - dout(10) << "r=" << r << dendl; + dout(15) << "r=" << r << dendl; if (r < 0) { derr << "error flushing local replay: " << cpp_strerror(r) << dendl; on_flush->complete(r); return; } - on_flush_flush_commit_position_start(on_flush); + flush_commit_position(on_flush); } template -void ImageReplayer::on_flush_flush_commit_position_start(Context *on_flush) +void ImageReplayer::flush_commit_position(Context* on_flush) { - FunctionContext *ctx = new FunctionContext( + m_lock.Lock(); + if (m_state != STATE_REPLAYING) { + m_lock.Unlock(); + on_flush->complete(0); + return; + } + + dout(15) << dendl; + auto ctx = new FunctionContext( [this, on_flush](int r) { - on_flush_flush_commit_position_finish(on_flush, r); + handle_flush_commit_position(on_flush, r); }); - m_remote_journaler->flush_commit_position(ctx); + m_lock.Unlock(); } template -void ImageReplayer::on_flush_flush_commit_position_finish(Context *on_flush, - int r) +void ImageReplayer::handle_flush_commit_position(Context* on_flush, int r) { + dout(15) << "r=" << r << dendl; if (r < 0) { derr << "error flushing remote journal commit position: " << cpp_strerror(r) << dendl; } - update_mirror_image_status(false, boost::none); - - dout(20) << "flush complete, r=" << r << dendl; on_flush->complete(r); } diff --git a/src/tools/rbd_mirror/ImageReplayer.h b/src/tools/rbd_mirror/ImageReplayer.h index 0852c44d11b..9af3e9611cd 100644 --- a/src/tools/rbd_mirror/ImageReplayer.h +++ b/src/tools/rbd_mirror/ImageReplayer.h @@ -117,7 +117,7 @@ public: void stop(Context *on_finish = nullptr, bool manual = false, int r = 0, const std::string& desc = ""); void restart(Context *on_finish = nullptr); - void flush(Context *on_finish = nullptr); + void flush(); void resync_image(Context *on_finish=nullptr); @@ -203,11 +203,6 @@ protected: virtual void on_stop_journal_replay(int r = 0, const std::string &desc = ""); - virtual void on_flush_local_replay_flush_start(Context *on_flush); - virtual void on_flush_local_replay_flush_finish(Context *on_flush, int r); - virtual void on_flush_flush_commit_position_start(Context *on_flush); - virtual void on_flush_flush_commit_position_finish(Context *on_flush, int r); - bool on_replay_interrupted(); private: @@ -379,6 +374,12 @@ private: m_state == STATE_REPLAY_FLUSHING); } + void flush_local_replay(Context* on_flush); + void handle_flush_local_replay(Context* on_flush, int r); + + void flush_commit_position(Context* on_flush); + void handle_flush_commit_position(Context* on_flush, int r); + bool update_mirror_image_status(bool force, const OptionalState &state); bool start_mirror_image_status_update(bool force, bool restarting); void finish_mirror_image_status_update(); -- 2.39.5