From 5363ad5c74da4f541eb345ee883602b5a400a7ac Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 20 Apr 2017 21:00:34 -0400 Subject: [PATCH] rbd-mirror: eliminate use of image name during bootstrap Signed-off-by: Jason Dillaman --- .../test_mock_BootstrapRequest.cc | 4 +--- src/tools/rbd_mirror/ImageReplayer.cc | 6 ++---- src/tools/rbd_mirror/ImageReplayer.h | 5 ----- .../image_replayer/BootstrapRequest.cc | 20 +++++++++---------- .../image_replayer/BootstrapRequest.h | 7 +++---- .../image_replayer/OpenLocalImageRequest.cc | 7 +++---- .../image_replayer/OpenLocalImageRequest.h | 6 +----- 7 files changed, 19 insertions(+), 36 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 197166b8c8ee..4da8665799b4 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc @@ -214,7 +214,6 @@ struct OpenLocalImageRequest { static OpenLocalImageRequest* create(librados::IoCtx &local_io_ctx, librbd::MockTestImageCtx **local_image_ctx, - const std::string &local_image_name, const std::string &local_image_id, ContextWQ *work_queue, Context *on_finish) { @@ -429,8 +428,7 @@ public: return new MockBootstrapRequest(m_local_io_ctx, m_remote_io_ctx, mock_image_sync_throttler, - &m_local_test_image_ctx, - "local image name", + &m_local_test_image_ctx, "", remote_image_id, global_image_id, m_threads->work_queue, diff --git a/src/tools/rbd_mirror/ImageReplayer.cc b/src/tools/rbd_mirror/ImageReplayer.cc index 0a58a6b72c6b..fa4cb470b1f4 100644 --- a/src/tools/rbd_mirror/ImageReplayer.cc +++ b/src/tools/rbd_mirror/ImageReplayer.cc @@ -421,15 +421,14 @@ void ImageReplayer::start(Context *on_finish, bool manual) template void ImageReplayer::bootstrap() { - dout(20) << "bootstrap params: " - << "local_image_name=" << m_local_image_name << dendl; + dout(20) << dendl; Context *ctx = create_context_callback< ImageReplayer, &ImageReplayer::handle_bootstrap>(this); BootstrapRequest *request = BootstrapRequest::create( m_local_ioctx, m_remote_image.io_ctx, m_image_sync_throttler, - &m_local_image_ctx, m_local_image_name, m_remote_image.image_id, + &m_local_image_ctx, m_local_image_id, m_remote_image.image_id, m_global_image_id, m_threads->work_queue, m_threads->timer, &m_threads->timer_lock, m_local_mirror_uuid, m_remote_image.mirror_uuid, m_remote_journaler, &m_client_meta, ctx, &m_do_resync, &m_progress_cxt); @@ -455,7 +454,6 @@ void ImageReplayer::handle_bootstrap(int r) { m_bootstrap_request = nullptr; if (m_local_image_ctx) { m_local_image_id = m_local_image_ctx->id; - m_local_image_name = m_local_image_ctx->name; } } diff --git a/src/tools/rbd_mirror/ImageReplayer.h b/src/tools/rbd_mirror/ImageReplayer.h index 87902dae9fb5..79a744d9842a 100644 --- a/src/tools/rbd_mirror/ImageReplayer.h +++ b/src/tools/rbd_mirror/ImageReplayer.h @@ -122,10 +122,6 @@ public: Mutex::Locker locker(m_lock); return m_local_image_id; } - inline std::string get_local_image_name() { - Mutex::Locker locker(m_lock); - return m_local_image_name; - } void start(Context *on_finish = nullptr, bool manual = false); void stop(Context *on_finish = nullptr, bool manual = false, @@ -296,7 +292,6 @@ private: int64_t m_local_pool_id; std::string m_local_image_id; std::string m_global_image_id; - std::string m_local_image_name; std::string m_name; mutable Mutex m_lock; State m_state = STATE_STOPPED; diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc index 3191daa672a9..7d7d5ed1a6c3 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc @@ -44,7 +44,7 @@ BootstrapRequest::BootstrapRequest( librados::IoCtx &remote_io_ctx, std::shared_ptr> image_sync_throttler, I **local_image_ctx, - const std::string &local_image_name, + const std::string &local_image_id, const std::string &remote_image_id, const std::string &global_image_id, ContextWQ *work_queue, SafeTimer *timer, @@ -60,7 +60,7 @@ BootstrapRequest::BootstrapRequest( reinterpret_cast(local_io_ctx.cct()), on_finish), m_local_io_ctx(local_io_ctx), m_remote_io_ctx(remote_io_ctx), m_image_sync_throttler(image_sync_throttler), - m_local_image_ctx(local_image_ctx), m_local_image_name(local_image_name), + m_local_image_ctx(local_image_ctx), m_local_image_id(local_image_id), m_remote_image_id(remote_image_id), m_global_image_id(global_image_id), m_work_queue(work_queue), m_timer(timer), m_timer_lock(timer_lock), m_local_mirror_uuid(local_mirror_uuid), @@ -305,11 +305,6 @@ void BootstrapRequest::handle_is_primary(int r) { return; } - // default local image name to the remote image name if not provided - if (m_local_image_name.empty()) { - m_local_image_name = m_remote_image_ctx->name; - } - if (m_local_image_id.empty()) { create_local_image(); return; @@ -364,9 +359,8 @@ void BootstrapRequest::open_local_image() { BootstrapRequest, &BootstrapRequest::handle_open_local_image>( this); OpenLocalImageRequest *request = OpenLocalImageRequest::create( - m_local_io_ctx, m_local_image_ctx, - (!m_local_image_id.empty() ? std::string() : m_local_image_name), - m_local_image_id, m_work_queue, ctx); + m_local_io_ctx, m_local_image_ctx, m_local_image_id, m_work_queue, + ctx); request->send(); } @@ -435,12 +429,16 @@ void BootstrapRequest::create_local_image() { m_local_image_id = ""; update_progress("CREATE_LOCAL_IMAGE"); + m_remote_image_ctx->snap_lock.get_read(); + std::string image_name = m_remote_image_ctx->name; + m_remote_image_ctx->snap_lock.put_read(); + Context *ctx = create_context_callback< BootstrapRequest, &BootstrapRequest::handle_create_local_image>( this); CreateImageRequest *request = CreateImageRequest::create( m_local_io_ctx, m_work_queue, m_global_image_id, m_remote_mirror_uuid, - m_local_image_name, m_remote_image_ctx, &m_local_image_id, ctx); + image_name, m_remote_image_ctx, &m_local_image_id, ctx); request->send(); } diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h index 0d7017e70535..e367b2ae4826 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h @@ -42,7 +42,7 @@ public: librados::IoCtx &remote_io_ctx, ImageSyncThrottlerRef image_sync_throttler, ImageCtxT **local_image_ctx, - const std::string &local_image_name, + const std::string &local_image_id, const std::string &remote_image_id, const std::string &global_image_id, ContextWQ *work_queue, SafeTimer *timer, @@ -56,7 +56,7 @@ public: ProgressContext *progress_ctx = nullptr) { return new BootstrapRequest(local_io_ctx, remote_io_ctx, image_sync_throttler, local_image_ctx, - local_image_name, remote_image_id, + local_image_id, remote_image_id, global_image_id, work_queue, timer, timer_lock, local_mirror_uuid, remote_mirror_uuid, journaler, client_meta, on_finish, do_resync, @@ -67,7 +67,7 @@ public: librados::IoCtx &remote_io_ctx, ImageSyncThrottlerRef image_sync_throttler, ImageCtxT **local_image_ctx, - const std::string &local_image_name, + const std::string &local_image_id, const std::string &remote_image_id, const std::string &global_image_id, ContextWQ *work_queue, SafeTimer *timer, Mutex *timer_lock, @@ -150,7 +150,6 @@ private: librados::IoCtx &m_remote_io_ctx; ImageSyncThrottlerRef m_image_sync_throttler; ImageCtxT **m_local_image_ctx; - std::string m_local_image_name; std::string m_local_image_id; std::string m_remote_image_id; std::string m_global_image_id; diff --git a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc index 5f67c41cfa43..2d7b8d125040 100644 --- a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc @@ -70,13 +70,12 @@ struct MirrorJournalPolicy : public librbd::journal::Policy { template OpenLocalImageRequest::OpenLocalImageRequest(librados::IoCtx &local_io_ctx, I **local_image_ctx, - const std::string &local_image_name, const std::string &local_image_id, ContextWQ *work_queue, Context *on_finish) : m_local_io_ctx(local_io_ctx), m_local_image_ctx(local_image_ctx), - m_local_image_name(local_image_name), m_local_image_id(local_image_id), - m_work_queue(work_queue), m_on_finish(on_finish) { + m_local_image_id(local_image_id), m_work_queue(work_queue), + m_on_finish(on_finish) { } template @@ -88,7 +87,7 @@ template void OpenLocalImageRequest::send_open_image() { dout(20) << dendl; - *m_local_image_ctx = I::create(m_local_image_name, m_local_image_id, nullptr, + *m_local_image_ctx = I::create("", m_local_image_id, nullptr, m_local_io_ctx, false); { RWLock::WLocker owner_locker((*m_local_image_ctx)->owner_lock); diff --git a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h index 570728dd762b..58de545fb3a2 100644 --- a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h +++ b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h @@ -21,18 +21,15 @@ class OpenLocalImageRequest { public: static OpenLocalImageRequest* create(librados::IoCtx &local_io_ctx, ImageCtxT **local_image_ctx, - const std::string &local_image_name, const std::string &local_image_id, ContextWQ *work_queue, Context *on_finish) { return new OpenLocalImageRequest(local_io_ctx, local_image_ctx, - local_image_name, local_image_id, - work_queue, on_finish); + local_image_id, work_queue, on_finish); } OpenLocalImageRequest(librados::IoCtx &local_io_ctx, ImageCtxT **local_image_ctx, - const std::string &local_image_name, const std::string &local_image_id, ContextWQ *m_work_queue, Context *on_finish); @@ -61,7 +58,6 @@ private: */ librados::IoCtx &m_local_io_ctx; ImageCtxT **m_local_image_ctx; - std::string m_local_image_name; std::string m_local_image_id; ContextWQ *m_work_queue; Context *m_on_finish; -- 2.47.3