From 54efc8fc8d9ca301260d40c7adf67dfc665188a7 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 27 Jan 2020 10:15:46 -0500 Subject: [PATCH] librbd: retrieve primary mirror uuid as part of get info request This will be used for both journal and snapshot-based mirroring to link the image to proper primary. Signed-off-by: Jason Dillaman --- src/librbd/api/Mirror.cc | 7 +++++-- src/librbd/mirror/DemoteRequest.cc | 3 ++- src/librbd/mirror/DemoteRequest.h | 1 + src/librbd/mirror/DisableRequest.cc | 3 ++- src/librbd/mirror/DisableRequest.h | 1 + src/librbd/mirror/GetInfoRequest.cc | 16 +++++++++++++--- src/librbd/mirror/GetInfoRequest.h | 13 +++++++++---- src/librbd/mirror/GetStatusRequest.cc | 3 ++- src/librbd/mirror/GetStatusRequest.h | 1 + src/librbd/mirror/PromoteRequest.cc | 3 ++- src/librbd/mirror/PromoteRequest.h | 1 + .../librbd/mirror/test_mock_DisableRequest.cc | 1 + .../image_replayer/test_mock_BootstrapRequest.cc | 1 + .../image_replayer/BootstrapRequest.cc | 4 ++-- .../rbd_mirror/image_replayer/BootstrapRequest.h | 1 + .../image_replayer/OpenLocalImageRequest.cc | 3 ++- .../image_replayer/OpenLocalImageRequest.h | 1 + 17 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/librbd/api/Mirror.cc b/src/librbd/api/Mirror.cc index c2b4683fa7c1b..76be2138ffa9b 100644 --- a/src/librbd/api/Mirror.cc +++ b/src/librbd/api/Mirror.cc @@ -282,6 +282,7 @@ struct C_ImageGetInfo : public Context { cls::rbd::MirrorImage mirror_image; mirror::PromotionState promotion_state = mirror::PROMOTION_STATE_PRIMARY; + std::string primary_mirror_uuid; C_ImageGetInfo(mirror_image_info_t *mirror_image_info, mirror_image_mode_t *mirror_image_mode, Context *on_finish) @@ -658,6 +659,7 @@ void Mirror::image_get_info(I *ictx, mirror_image_info_t *mirror_image_info, auto ctx = new C_ImageGetInfo(mirror_image_info, nullptr, on_finish); auto req = mirror::GetInfoRequest::create(*ictx, &ctx->mirror_image, &ctx->promotion_state, + &ctx->primary_mirror_uuid, ctx); req->send(); }); @@ -694,7 +696,8 @@ void Mirror::image_get_info(librados::IoCtx& io_ctx, auto ctx = new C_ImageGetInfo(mirror_image_info, nullptr, on_finish); auto req = mirror::GetInfoRequest::create(io_ctx, op_work_queue, image_id, &ctx->mirror_image, - &ctx->promotion_state, ctx); + &ctx->promotion_state, + &ctx->primary_mirror_uuid, ctx); req->send(); } @@ -722,7 +725,7 @@ void Mirror::image_get_mode(I *ictx, mirror_image_mode_t *mode, auto ctx = new C_ImageGetInfo(nullptr, mode, on_finish); auto req = mirror::GetInfoRequest::create(*ictx, &ctx->mirror_image, &ctx->promotion_state, - ctx); + &ctx->primary_mirror_uuid, ctx); req->send(); } diff --git a/src/librbd/mirror/DemoteRequest.cc b/src/librbd/mirror/DemoteRequest.cc index 171b86b1f896e..f70c2020c2938 100644 --- a/src/librbd/mirror/DemoteRequest.cc +++ b/src/librbd/mirror/DemoteRequest.cc @@ -36,7 +36,8 @@ void DemoteRequest::get_info() { auto ctx = create_context_callback< DemoteRequest, &DemoteRequest::handle_get_info>(this); auto req = GetInfoRequest::create(m_image_ctx, &m_mirror_image, - &m_promotion_state, ctx); + &m_promotion_state, + &m_primary_mirror_uuid, ctx); req->send(); } diff --git a/src/librbd/mirror/DemoteRequest.h b/src/librbd/mirror/DemoteRequest.h index 7dc0585e056c5..ab92390684524 100644 --- a/src/librbd/mirror/DemoteRequest.h +++ b/src/librbd/mirror/DemoteRequest.h @@ -60,6 +60,7 @@ private: cls::rbd::MirrorImage m_mirror_image; PromotionState m_promotion_state = PROMOTION_STATE_PRIMARY; + std::string m_primary_mirror_uuid; void get_info(); void handle_get_info(int r); diff --git a/src/librbd/mirror/DisableRequest.cc b/src/librbd/mirror/DisableRequest.cc index bdbb28504f6f5..2c0f669b3586b 100644 --- a/src/librbd/mirror/DisableRequest.cc +++ b/src/librbd/mirror/DisableRequest.cc @@ -48,7 +48,8 @@ void DisableRequest::send_get_mirror_info() { klass, &klass::handle_get_mirror_info>(this); auto req = GetInfoRequest::create(*m_image_ctx, &m_mirror_image, - &m_promotion_state, ctx); + &m_promotion_state, + &m_primary_mirror_uuid, ctx); req->send(); } diff --git a/src/librbd/mirror/DisableRequest.h b/src/librbd/mirror/DisableRequest.h index 1434d3f3ee8ea..d753076243ad8 100644 --- a/src/librbd/mirror/DisableRequest.h +++ b/src/librbd/mirror/DisableRequest.h @@ -87,6 +87,7 @@ private: bool m_is_primary = false; cls::rbd::MirrorImage m_mirror_image; PromotionState m_promotion_state = PROMOTION_STATE_NON_PRIMARY; + std::string m_primary_mirror_uuid; std::set m_clients; std::map m_ret; std::map m_current_ops; diff --git a/src/librbd/mirror/GetInfoRequest.cc b/src/librbd/mirror/GetInfoRequest.cc index 7e50b06390c68..e8f2134ff907d 100644 --- a/src/librbd/mirror/GetInfoRequest.cc +++ b/src/librbd/mirror/GetInfoRequest.cc @@ -27,10 +27,11 @@ GetInfoRequest::GetInfoRequest(librados::IoCtx& io_ctx, const std::string &image_id, cls::rbd::MirrorImage *mirror_image, PromotionState *promotion_state, + std::string* primary_mirror_uuid, Context *on_finish) : m_io_ctx(io_ctx), m_op_work_queue(op_work_queue), m_image_id(image_id), m_mirror_image(mirror_image), m_promotion_state(promotion_state), - m_on_finish(on_finish), + m_primary_mirror_uuid(primary_mirror_uuid), m_on_finish(on_finish), m_cct(reinterpret_cast(io_ctx.cct())) { } @@ -38,11 +39,13 @@ template GetInfoRequest::GetInfoRequest(I &image_ctx, cls::rbd::MirrorImage *mirror_image, PromotionState *promotion_state, + std::string* primary_mirror_uuid, Context *on_finish) : m_image_ctx(&image_ctx), m_io_ctx(image_ctx.md_ctx), m_op_work_queue(image_ctx.op_work_queue), m_image_id(image_ctx.id), m_mirror_image(mirror_image), m_promotion_state(promotion_state), - m_on_finish(on_finish), m_cct(image_ctx.cct) { + m_primary_mirror_uuid(primary_mirror_uuid), m_on_finish(on_finish), + m_cct(image_ctx.cct) { } template @@ -120,8 +123,12 @@ void GetInfoRequest::handle_get_journal_tag_owner(int r) { if (m_mirror_uuid == Journal<>::LOCAL_MIRROR_UUID) { *m_promotion_state = PROMOTION_STATE_PRIMARY; + *m_primary_mirror_uuid = ""; } else if (m_mirror_uuid == Journal<>::ORPHAN_MIRROR_UUID) { *m_promotion_state = PROMOTION_STATE_ORPHAN; + *m_primary_mirror_uuid = ""; + } else { + *m_primary_mirror_uuid = m_mirror_uuid; } finish(0); @@ -240,6 +247,7 @@ template void GetInfoRequest::calc_promotion_state( const std::map &snap_info) { *m_promotion_state = PROMOTION_STATE_PRIMARY; + *m_primary_mirror_uuid = ""; for (auto it = snap_info.rbegin(); it != snap_info.rend(); it++) { auto primary = boost::get( @@ -258,12 +266,14 @@ void GetInfoRequest::calc_promotion_state( *m_promotion_state = PROMOTION_STATE_ORPHAN; } else { *m_promotion_state = PROMOTION_STATE_NON_PRIMARY; + *m_primary_mirror_uuid = non_primary->primary_mirror_uuid; } break; } } - ldout(m_cct, 20) << *m_promotion_state << dendl; + ldout(m_cct, 10) << "promotion_state=" << *m_promotion_state << ", " + << "primary_mirror_uuid=" << *m_promotion_state << dendl; } } // namespace mirror diff --git a/src/librbd/mirror/GetInfoRequest.h b/src/librbd/mirror/GetInfoRequest.h index 470c1b0be1069..28308ae954501 100644 --- a/src/librbd/mirror/GetInfoRequest.h +++ b/src/librbd/mirror/GetInfoRequest.h @@ -31,24 +31,28 @@ public: const std::string &image_id, cls::rbd::MirrorImage *mirror_image, PromotionState *promotion_state, + std::string* primary_mirror_uuid, Context *on_finish) { return new GetInfoRequest(io_ctx, op_work_queue, image_id, mirror_image, - promotion_state, on_finish); + promotion_state, primary_mirror_uuid, on_finish); } static GetInfoRequest *create(ImageCtxT &image_ctx, cls::rbd::MirrorImage *mirror_image, PromotionState *promotion_state, + std::string* primary_mirror_uuid, Context *on_finish) { return new GetInfoRequest(image_ctx, mirror_image, promotion_state, - on_finish); + primary_mirror_uuid, on_finish); } GetInfoRequest(librados::IoCtx& io_ctx, ContextWQ *op_work_queue, const std::string &image_id, cls::rbd::MirrorImage *mirror_image, - PromotionState *promotion_state, Context *on_finish); + PromotionState *promotion_state, + std::string* primary_mirror_uuid, Context *on_finish); GetInfoRequest(ImageCtxT &image_ctx, cls::rbd::MirrorImage *mirror_image, - PromotionState *promotion_state, Context *on_finish); + PromotionState *promotion_state, + std::string* primary_mirror_uuid, Context *on_finish); void send(); @@ -83,6 +87,7 @@ private: std::string m_image_id; cls::rbd::MirrorImage *m_mirror_image; PromotionState *m_promotion_state; + std::string* m_primary_mirror_uuid; Context *m_on_finish; CephContext *m_cct; diff --git a/src/librbd/mirror/GetStatusRequest.cc b/src/librbd/mirror/GetStatusRequest.cc index e6b7f81843649..e5afb4869058a 100644 --- a/src/librbd/mirror/GetStatusRequest.cc +++ b/src/librbd/mirror/GetStatusRequest.cc @@ -39,7 +39,8 @@ void GetStatusRequest::get_info() { auto ctx = create_context_callback< GetStatusRequest, &GetStatusRequest::handle_get_info>(this); auto req = GetInfoRequest::create(m_image_ctx, m_mirror_image, - m_promotion_state, ctx); + m_promotion_state, + &m_primary_mirror_uuid, ctx); req->send(); } diff --git a/src/librbd/mirror/GetStatusRequest.h b/src/librbd/mirror/GetStatusRequest.h index 4c1a81f08f024..581a0d6674987 100644 --- a/src/librbd/mirror/GetStatusRequest.h +++ b/src/librbd/mirror/GetStatusRequest.h @@ -65,6 +65,7 @@ private: Context *m_on_finish; bufferlist m_out_bl; + std::string m_primary_mirror_uuid; void get_info(); void handle_get_info(int r); diff --git a/src/librbd/mirror/PromoteRequest.cc b/src/librbd/mirror/PromoteRequest.cc index e2bc6bd0582fd..2b829fb8a2829 100644 --- a/src/librbd/mirror/PromoteRequest.cc +++ b/src/librbd/mirror/PromoteRequest.cc @@ -35,7 +35,8 @@ void PromoteRequest::get_info() { auto ctx = create_context_callback< PromoteRequest, &PromoteRequest::handle_get_info>(this); auto req = GetInfoRequest::create(m_image_ctx, &m_mirror_image, - &m_promotion_state, ctx); + &m_promotion_state, + &m_primary_mirror_uuid, ctx); req->send(); } diff --git a/src/librbd/mirror/PromoteRequest.h b/src/librbd/mirror/PromoteRequest.h index 17609c5ff8caf..c54f3bb76aca1 100644 --- a/src/librbd/mirror/PromoteRequest.h +++ b/src/librbd/mirror/PromoteRequest.h @@ -56,6 +56,7 @@ private: cls::rbd::MirrorImage m_mirror_image; PromotionState m_promotion_state = PROMOTION_STATE_PRIMARY; + std::string m_primary_mirror_uuid; void get_info(); void handle_get_info(int r); diff --git a/src/test/librbd/mirror/test_mock_DisableRequest.cc b/src/test/librbd/mirror/test_mock_DisableRequest.cc index 688bddb99dcc8..684c05d100df2 100644 --- a/src/test/librbd/mirror/test_mock_DisableRequest.cc +++ b/src/test/librbd/mirror/test_mock_DisableRequest.cc @@ -83,6 +83,7 @@ struct GetInfoRequest { static GetInfoRequest *create(librbd::MockTestImageCtx &, cls::rbd::MirrorImage *mirror_image, PromotionState *promotion_state, + std::string* primary_mirror_uuid, Context *on_finish) { ceph_assert(s_instance != nullptr); s_instance->mirror_image = mirror_image; 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 d63d596461add..6928b426f0c19 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc @@ -43,6 +43,7 @@ struct GetInfoRequest { static GetInfoRequest* create(librbd::MockTestImageCtx &image_ctx, cls::rbd::MirrorImage *mirror_image, PromotionState *promotion_state, + std::string* primary_mirror_uuid, Context *on_finish) { ceph_assert(s_instance != nullptr); s_instance->mirror_image = mirror_image; diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc index 442404c7cc228..334759ae19da2 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc @@ -239,7 +239,8 @@ void BootstrapRequest::get_remote_mirror_info() { BootstrapRequest, &BootstrapRequest::handle_get_remote_mirror_info>( this); auto request = librbd::mirror::GetInfoRequest::create( - *m_remote_image_ctx, &m_mirror_image, &m_promotion_state, ctx); + *m_remote_image_ctx, &m_mirror_image, &m_promotion_state, + &m_remote_primary_mirror_uuid, ctx); request->send(); } @@ -285,7 +286,6 @@ void BootstrapRequest::handle_get_remote_mirror_info(int r) { return; } - if ((*m_state_builder)->local_image_id.empty()) { create_local_image(); return; diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h index b5f14c816c44b..42010b6e91ae8 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h @@ -142,6 +142,7 @@ private: cls::rbd::MirrorImage m_mirror_image; librbd::mirror::PromotionState m_promotion_state = librbd::mirror::PROMOTION_STATE_NON_PRIMARY; + std::string m_remote_primary_mirror_uuid; int m_ret_val = 0; std::string m_local_image_name; diff --git a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc index a4969ef6ec122..a027152024479 100644 --- a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc @@ -158,7 +158,8 @@ void OpenLocalImageRequest::send_get_mirror_info() { &OpenLocalImageRequest::handle_get_mirror_info>( this); auto request = librbd::mirror::GetInfoRequest::create( - **m_local_image_ctx, &m_mirror_image, &m_promotion_state, ctx); + **m_local_image_ctx, &m_mirror_image, &m_promotion_state, + &m_primary_mirror_uuid, ctx); request->send(); } diff --git a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h index 7acf349046b63..31e7add957508 100644 --- a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h +++ b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.h @@ -67,6 +67,7 @@ private: cls::rbd::MirrorImage m_mirror_image; librbd::mirror::PromotionState m_promotion_state = librbd::mirror::PROMOTION_STATE_NON_PRIMARY; + std::string m_primary_mirror_uuid; int m_ret_val = 0; void send_open_image(); -- 2.39.5