From: Jason Dillaman Date: Mon, 27 Jan 2020 19:03:07 +0000 (-0500) Subject: rbd-mirror: store remote image ctx in state builder X-Git-Tag: v15.1.1~472^2~25 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=07c628876be03d900cb430892c50fbaf71d7e27b;p=ceph-ci.git rbd-mirror: store remote image ctx in state builder The snapshot-based mirroring logic will need access to the remote image during replay. Signed-off-by: Jason Dillaman --- diff --git a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc index 24822f6e493..a765c460672 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc @@ -240,6 +240,7 @@ struct StateBuilder { MockBaseRequest mock_base_request; librbd::MockTestImageCtx* local_image_ctx = nullptr; + librbd::MockTestImageCtx* remote_image_ctx = nullptr; std::string local_image_id; std::string remote_mirror_uuid; std::string remote_image_id; @@ -261,10 +262,9 @@ struct StateBuilder { MOCK_CONST_METHOD0(is_local_primary, bool()); MOCK_CONST_METHOD0(is_linked, bool()); - MOCK_METHOD6(create_local_image_request, + MOCK_METHOD5(create_local_image_request, BaseRequest*(Threads*, librados::IoCtx&, - librbd::MockTestImageCtx*, const std::string&, ProgressContext*, Context*)); @@ -428,8 +428,8 @@ public: void expect_create_local_image(MockStateBuilder& mock_state_builder, const std::string& local_image_id, int r) { EXPECT_CALL(mock_state_builder, - create_local_image_request(_, _, _, _, _, _)) - .WillOnce(WithArg<5>( + create_local_image_request(_, _, _, _, _)) + .WillOnce(WithArg<4>( Invoke([this, &mock_state_builder, local_image_id, r](Context* ctx) { if (r >= 0) { mock_state_builder.local_image_id = local_image_id; diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc index bfa252275c7..739a5599f1b 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc @@ -78,11 +78,6 @@ BootstrapRequest::BootstrapRequest( dout(10) << dendl; } -template -BootstrapRequest::~BootstrapRequest() { - ceph_assert(m_remote_image_ctx == nullptr); -} - template bool BootstrapRequest::is_syncing() const { std::lock_guard locker{m_lock}; @@ -215,12 +210,13 @@ void BootstrapRequest::open_remote_image() { update_progress("OPEN_REMOTE_IMAGE"); - Context *ctx = create_context_callback< - BootstrapRequest, &BootstrapRequest::handle_open_remote_image>( - this); + auto ctx = create_context_callback< + BootstrapRequest, + &BootstrapRequest::handle_open_remote_image>(this); + ceph_assert(*m_state_builder != nullptr); OpenImageRequest *request = OpenImageRequest::create( - m_remote_io_ctx, &m_remote_image_ctx, remote_image_id, false, - ctx); + m_remote_io_ctx, &(*m_state_builder)->remote_image_ctx, remote_image_id, + false, ctx); request->send(); } @@ -228,14 +224,14 @@ template void BootstrapRequest::handle_open_remote_image(int r) { dout(15) << "r=" << r << dendl; + ceph_assert(*m_state_builder != nullptr); if (r < 0) { derr << "failed to open remote image: " << cpp_strerror(r) << dendl; - ceph_assert(m_remote_image_ctx == nullptr); + ceph_assert((*m_state_builder)->remote_image_ctx == nullptr); finish(r); return; } - ceph_assert(*m_state_builder != nullptr); if ((*m_state_builder)->local_image_id.empty()) { create_local_image(); return; @@ -343,8 +339,7 @@ void BootstrapRequest::create_local_image() { BootstrapRequest, &BootstrapRequest::handle_create_local_image>(this); auto request = (*m_state_builder)->create_local_image_request( - m_threads, m_local_io_ctx, m_remote_image_ctx, m_global_image_id, - m_progress_ctx, ctx); + m_threads, m_local_io_ctx, m_global_image_id, m_progress_ctx, ctx); request->send(); } @@ -387,7 +382,7 @@ void BootstrapRequest::image_sync() { Context *ctx = create_context_callback< BootstrapRequest, &BootstrapRequest::handle_image_sync>(this); m_image_sync = ImageSync::create( - m_threads, state_builder->local_image_ctx, m_remote_image_ctx, + m_threads, state_builder->local_image_ctx, state_builder->remote_image_ctx, m_local_mirror_uuid, sync_point_handler, m_instance_watcher, m_progress_ctx, ctx); m_image_sync->get(); @@ -427,11 +422,12 @@ void BootstrapRequest::close_remote_image() { update_progress("CLOSE_REMOTE_IMAGE"); - Context *ctx = create_context_callback< - BootstrapRequest, &BootstrapRequest::handle_close_remote_image>( - this); - CloseImageRequest *request = CloseImageRequest::create( - &m_remote_image_ctx, ctx); + auto ctx = create_context_callback< + BootstrapRequest, + &BootstrapRequest::handle_close_remote_image>(this); + ceph_assert(*m_state_builder != nullptr); + auto request = CloseImageRequest::create( + &(*m_state_builder)->remote_image_ctx, ctx); request->send(); } diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h index 7d94d847c0d..cc15a91334b 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h @@ -73,7 +73,6 @@ public: StateBuilder** state_builder, bool* do_resync, Context* on_finish); - ~BootstrapRequest() override; bool is_syncing() const; @@ -139,7 +138,6 @@ private: mutable ceph::mutex m_lock; bool m_canceled = false; - ImageCtxT *m_remote_image_ctx = nullptr; int m_ret_val = 0; std::string m_local_image_name; diff --git a/src/tools/rbd_mirror/image_replayer/StateBuilder.cc b/src/tools/rbd_mirror/image_replayer/StateBuilder.cc index 4c543b7880a..1e8420bbbc8 100644 --- a/src/tools/rbd_mirror/image_replayer/StateBuilder.cc +++ b/src/tools/rbd_mirror/image_replayer/StateBuilder.cc @@ -31,6 +31,7 @@ StateBuilder::StateBuilder(const std::string& global_image_id) template StateBuilder::~StateBuilder() { ceph_assert(local_image_ctx == nullptr); + ceph_assert(remote_image_ctx == nullptr); ceph_assert(m_sync_point_handler == nullptr); } diff --git a/src/tools/rbd_mirror/image_replayer/StateBuilder.h b/src/tools/rbd_mirror/image_replayer/StateBuilder.h index 192ffca44e8..c6bf3ea8fd0 100644 --- a/src/tools/rbd_mirror/image_replayer/StateBuilder.h +++ b/src/tools/rbd_mirror/image_replayer/StateBuilder.h @@ -52,7 +52,6 @@ public: virtual BaseRequest* create_local_image_request( Threads* threads, librados::IoCtx& local_io_ctx, - ImageCtxT* remote_image_ctx, const std::string& global_image_id, ProgressContext* progress_ctx, Context* on_finish) = 0; @@ -81,6 +80,7 @@ public: std::string remote_image_id; librbd::mirror::PromotionState remote_promotion_state = librbd::mirror::PROMOTION_STATE_NON_PRIMARY; + ImageCtxT* remote_image_ctx = nullptr; protected: image_sync::SyncPointHandler* m_sync_point_handler = nullptr; diff --git a/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.cc b/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.cc index 7372475d870..01d51e7d569 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.cc +++ b/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.cc @@ -71,12 +71,11 @@ template BaseRequest* StateBuilder::create_local_image_request( Threads* threads, librados::IoCtx& local_io_ctx, - I* remote_image_ctx, const std::string& global_image_id, ProgressContext* progress_ctx, Context* on_finish) { return CreateLocalImageRequest::create( - threads, local_io_ctx, remote_image_ctx, this->global_image_id, + threads, local_io_ctx, this->remote_image_ctx, this->global_image_id, progress_ctx, this, on_finish); } diff --git a/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.h b/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.h index 868260699f2..ee0743d3b90 100644 --- a/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.h +++ b/src/tools/rbd_mirror/image_replayer/journal/StateBuilder.h @@ -45,7 +45,6 @@ public: BaseRequest* create_local_image_request( Threads* threads, librados::IoCtx& local_io_ctx, - ImageCtxT* remote_image_ctx, const std::string& global_image_id, ProgressContext* progress_ctx, Context* on_finish) override; diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc b/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc index 018574dec72..471a8a7a638 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc +++ b/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc @@ -59,7 +59,6 @@ template BaseRequest* StateBuilder::create_local_image_request( Threads* threads, librados::IoCtx& local_io_ctx, - I* remote_image_ctx, const std::string& global_image_id, ProgressContext* progress_ctx, Context* on_finish) { diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h b/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h index 105e3a01348..49e2f66d853 100644 --- a/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h +++ b/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.h @@ -39,7 +39,6 @@ public: BaseRequest* create_local_image_request( Threads* threads, librados::IoCtx& local_io_ctx, - ImageCtxT* remote_image_ctx, const std::string& global_image_id, ProgressContext* progress_ctx, Context* on_finish) override;