From 72e98b4a361345d63648d27ff79f42cc7bd328b4 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 6 Jan 2020 15:22:52 -0500 Subject: [PATCH] rbd-mirror: allow bootstrap to populate remote image id The remote image id is used as a sanity check and a test for permanently shutting down the replayer after the remote image is deleted. Recent refactor work broke this by passing the remote image id by value. Signed-off-by: Jason Dillaman --- .../test_mock_BootstrapRequest.cc | 56 +++++++++---------- .../rbd_mirror/test_mock_ImageReplayer.cc | 2 +- src/tools/rbd_mirror/ImageReplayer.cc | 8 +-- .../image_replayer/BootstrapRequest.cc | 12 ++-- .../image_replayer/BootstrapRequest.h | 12 ++-- 5 files changed, 45 insertions(+), 45 deletions(-) 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 1f7072edb82dd..1fd4192c2f37a 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc @@ -567,7 +567,6 @@ public: MockBootstrapRequest *create_request(MockThreads* mock_threads, MockInstanceWatcher *mock_instance_watcher, - const std::string &remote_image_id, const std::string &global_image_id, const std::string &local_mirror_uuid, Context *on_finish) { @@ -575,12 +574,12 @@ public: m_local_io_ctx, m_remote_io_ctx, mock_instance_watcher, - remote_image_id, global_image_id, local_mirror_uuid, nullptr, nullptr, &m_local_test_image_ctx, &m_local_image_id, + &m_remote_image_id, &m_remote_mirror_uuid, &m_mock_remote_journaler, &m_do_resync, on_finish); @@ -591,6 +590,7 @@ public: librbd::MockTestImageCtx *m_local_test_image_ctx = nullptr; std::string m_local_image_id; + std::string m_remote_image_id; std::string m_remote_mirror_uuid; ::journal::MockJournaler *m_mock_remote_journaler = nullptr; bool m_do_resync = false; @@ -648,8 +648,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, Success) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(0, ctx.wait()); } @@ -703,8 +703,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, OpenLocalImageError) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -771,8 +771,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, OpenLocalImageDNE) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(0, ctx.wait()); } @@ -826,8 +826,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, OpenLocalImagePrimary) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(-EREMOTEIO, ctx.wait()); } @@ -876,8 +876,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, CreateLocalImageError) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -937,8 +937,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, PrepareReplayError) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -995,8 +995,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, PrepareReplayResyncRequested) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(0, ctx.wait()); ASSERT_TRUE(m_do_resync); @@ -1058,8 +1058,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, PrepareReplaySyncing) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(0, ctx.wait()); } @@ -1116,8 +1116,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, PrepareReplayDisconnected) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(0, ctx.wait()); } @@ -1178,8 +1178,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, ImageSyncError) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(-EINVAL, ctx.wait()); } @@ -1236,8 +1236,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, ImageSyncCanceled) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->cancel(); request->send(); ASSERT_EQ(-ECANCELED, ctx.wait()); @@ -1298,8 +1298,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, CloseLocalImageError) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(-EREMOTEIO, ctx.wait()); } @@ -1355,8 +1355,8 @@ TEST_F(TestMockImageReplayerBootstrapRequest, CloseRemoteImageError) { MockThreads mock_threads(m_threads); MockInstanceWatcher mock_instance_watcher; MockBootstrapRequest *request = create_request( - &mock_threads, &mock_instance_watcher, mock_remote_image_ctx.id, - "global image id", "local mirror uuid", &ctx); + &mock_threads, &mock_instance_watcher, "global image id", + "local mirror uuid", &ctx); request->send(); ASSERT_EQ(0, ctx.wait()); } diff --git a/src/test/rbd_mirror/test_mock_ImageReplayer.cc b/src/test/rbd_mirror/test_mock_ImageReplayer.cc index 01bf2e499c25f..fb30f3b113b2a 100644 --- a/src/test/rbd_mirror/test_mock_ImageReplayer.cc +++ b/src/test/rbd_mirror/test_mock_ImageReplayer.cc @@ -113,13 +113,13 @@ struct BootstrapRequest { librados::IoCtx &local_io_ctx, librados::IoCtx &remote_io_ctx, rbd::mirror::InstanceWatcher *instance_watcher, - const std::string &remote_image_id, const std::string &global_image_id, const std::string &local_mirror_uuid, ::journal::CacheManagerHandler *cache_manager_handler, rbd::mirror::ProgressContext *progress_ctx, librbd::MockTestImageCtx **local_image_ctx, std::string* local_image_id, + std::string* remote_image_id, std::string* remote_mirror_uuid, ::journal::MockJournalerProxy** remote_journaler, bool *do_resync, Context *on_finish) { diff --git a/src/tools/rbd_mirror/ImageReplayer.cc b/src/tools/rbd_mirror/ImageReplayer.cc index e993e55507db7..766191c040e39 100644 --- a/src/tools/rbd_mirror/ImageReplayer.cc +++ b/src/tools/rbd_mirror/ImageReplayer.cc @@ -352,10 +352,10 @@ void ImageReplayer::bootstrap() { ImageReplayer, &ImageReplayer::handle_bootstrap>(this); auto request = image_replayer::BootstrapRequest::create( m_threads, m_local_io_ctx, m_remote_image.io_ctx, m_instance_watcher, - m_remote_image.image_id, m_global_image_id, m_local_mirror_uuid, - m_cache_manager_handler, &m_progress_cxt, &m_local_image_ctx, - &m_local_image_id, &m_remote_image.mirror_uuid, &m_remote_journaler, - &m_resync_requested, ctx); + m_global_image_id, m_local_mirror_uuid, m_cache_manager_handler, + &m_progress_cxt, &m_local_image_ctx, &m_local_image_id, + &m_remote_image.image_id, &m_remote_image.mirror_uuid, + &m_remote_journaler, &m_resync_requested, ctx); request->get(); m_bootstrap_request = request; diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc index cdc6a95aac673..379cb666c5167 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc @@ -49,13 +49,13 @@ BootstrapRequest::BootstrapRequest( librados::IoCtx& local_io_ctx, librados::IoCtx& remote_io_ctx, InstanceWatcher* instance_watcher, - const std::string& remote_image_id, const std::string& global_image_id, const std::string& local_mirror_uuid, ::journal::CacheManagerHandler* cache_manager_handler, ProgressContext* progress_ctx, I** local_image_ctx, std::string* local_image_id, + std::string* remote_image_id, std::string* remote_mirror_uuid, Journaler** remote_journaler, bool* do_resync, @@ -66,13 +66,13 @@ BootstrapRequest::BootstrapRequest( m_local_io_ctx(local_io_ctx), m_remote_io_ctx(remote_io_ctx), m_instance_watcher(instance_watcher), - m_remote_image_id(remote_image_id), m_global_image_id(global_image_id), m_local_mirror_uuid(local_mirror_uuid), m_cache_manager_handler(cache_manager_handler), m_progress_ctx(progress_ctx), m_local_image_ctx(local_image_ctx), m_local_image_id(local_image_id), + m_remote_image_id(remote_image_id), m_remote_mirror_uuid(remote_mirror_uuid), m_remote_journaler(remote_journaler), m_do_resync(do_resync), @@ -173,7 +173,7 @@ void BootstrapRequest::prepare_remote_image() { auto req = image_replayer::PrepareRemoteImageRequest::create( m_threads, m_remote_io_ctx, m_global_image_id, m_local_mirror_uuid, *m_local_image_id, journal_settings, m_cache_manager_handler, - m_remote_mirror_uuid, &m_remote_image_id, m_remote_journaler, + m_remote_mirror_uuid, m_remote_image_id, m_remote_journaler, &m_client_state, &m_client_meta, ctx); req->send(); } @@ -191,7 +191,7 @@ void BootstrapRequest::handle_prepare_remote_image(int r) { dout(10) << "remote image does not exist" << dendl; // TODO need to support multiple remote images - if (m_remote_image_id.empty() && !m_local_image_id->empty() && + if (m_remote_image_id->empty() && !m_local_image_id->empty() && m_local_image_tag_owner == *m_remote_mirror_uuid) { // local image exists and is non-primary and linked to the missing // remote image @@ -219,7 +219,7 @@ void BootstrapRequest::handle_prepare_remote_image(int r) { template void BootstrapRequest::open_remote_image() { - dout(15) << "remote_image_id=" << m_remote_image_id << dendl; + dout(15) << "remote_image_id=" << *m_remote_image_id << dendl; update_progress("OPEN_REMOTE_IMAGE"); @@ -227,7 +227,7 @@ void BootstrapRequest::open_remote_image() { BootstrapRequest, &BootstrapRequest::handle_open_remote_image>( this); OpenImageRequest *request = OpenImageRequest::create( - m_remote_io_ctx, &m_remote_image_ctx, m_remote_image_id, false, + m_remote_io_ctx, &m_remote_image_ctx, *m_remote_image_id, false, ctx); request->send(); } diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h index 33adc7bdee319..012bbbe2141b8 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h @@ -48,21 +48,21 @@ public: librados::IoCtx& local_io_ctx, librados::IoCtx& remote_io_ctx, InstanceWatcher* instance_watcher, - const std::string& remote_image_id, const std::string& global_image_id, const std::string& local_mirror_uuid, ::journal::CacheManagerHandler* cache_manager_handler, ProgressContext* progress_ctx, ImageCtxT** local_image_ctx, std::string* local_image_id, + std::string* remote_image_id, std::string* remote_mirror_uuid, Journaler** remote_journaler, bool* do_resync, Context* on_finish) { return new BootstrapRequest( - threads, local_io_ctx, remote_io_ctx, instance_watcher, remote_image_id, - global_image_id, local_mirror_uuid, cache_manager_handler, progress_ctx, - local_image_ctx, local_image_id, remote_mirror_uuid, remote_journaler, + threads, local_io_ctx, remote_io_ctx, instance_watcher, global_image_id, + local_mirror_uuid, cache_manager_handler, progress_ctx, local_image_ctx, + local_image_id, remote_image_id, remote_mirror_uuid, remote_journaler, do_resync, on_finish); } @@ -71,13 +71,13 @@ public: librados::IoCtx& local_io_ctx, librados::IoCtx& remote_io_ctx, InstanceWatcher* instance_watcher, - const std::string& remote_image_id, const std::string& global_image_id, const std::string& local_mirror_uuid, ::journal::CacheManagerHandler* cache_manager_handler, ProgressContext* progress_ctx, ImageCtxT** local_image_ctx, std::string* local_image_id, + std::string* remote_image_id, std::string* remote_mirror_uuid, Journaler** remote_journaler, bool* do_resync, @@ -144,13 +144,13 @@ private: librados::IoCtx &m_local_io_ctx; librados::IoCtx &m_remote_io_ctx; InstanceWatcher *m_instance_watcher; - std::string m_remote_image_id; std::string m_global_image_id; std::string m_local_mirror_uuid; ::journal::CacheManagerHandler *m_cache_manager_handler; ProgressContext *m_progress_ctx; ImageCtxT **m_local_image_ctx; std::string* m_local_image_id; + std::string* m_remote_image_id; std::string* m_remote_mirror_uuid; Journaler** m_remote_journaler; bool *m_do_resync; -- 2.39.5