From 91fe3c134438abc82d8b7b4651ef423fe75aba07 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 26 Feb 2020 20:11:28 -0500 Subject: [PATCH] librbd: don't create journal tag with non-primary mirror uuid If snapshot-based mirror is enabled we don't use the journal to keep state. Also clean-up the use of the API-level variables and use the RBD-internal types. Signed-off-by: Jason Dillaman --- src/librbd/image/CreateRequest.cc | 38 ++++++++++++------------------- src/librbd/image/CreateRequest.h | 2 +- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/src/librbd/image/CreateRequest.cc b/src/librbd/image/CreateRequest.cc index a2fbb89dd5c..ca4f141652e 100644 --- a/src/librbd/image/CreateRequest.cc +++ b/src/librbd/image/CreateRequest.cc @@ -575,10 +575,10 @@ void CreateRequest::handle_fetch_mirror_mode(int r) { return; } - cls::rbd::MirrorMode mirror_mode_internal = cls::rbd::MIRROR_MODE_DISABLED; + m_mirror_mode = cls::rbd::MIRROR_MODE_DISABLED; if (r == 0) { auto it = m_outbl.cbegin(); - r = cls_client::mirror_mode_get_finish(&it, &mirror_mode_internal); + r = cls_client::mirror_mode_get_finish(&it, &m_mirror_mode); if (r < 0) { lderr(m_cct) << "Failed to retrieve mirror mode" << dendl; @@ -588,21 +588,6 @@ void CreateRequest::handle_fetch_mirror_mode(int r) { } } - // TODO: remove redundant code... - switch (mirror_mode_internal) { - case cls::rbd::MIRROR_MODE_DISABLED: - case cls::rbd::MIRROR_MODE_IMAGE: - case cls::rbd::MIRROR_MODE_POOL: - m_mirror_mode = static_cast(mirror_mode_internal); - break; - default: - lderr(m_cct) << "Unknown mirror mode (" - << static_cast(mirror_mode_internal) << ")" << dendl; - r = -EINVAL; - remove_object_map(); - return; - } - journal_create(); } @@ -614,15 +599,20 @@ void CreateRequest::journal_create() { Context *ctx = create_context_callback( this); + // only link to remote primary mirror uuid if in journal-based + // mirroring mode + bool use_primary_mirror_uuid = ( + m_force_non_primary && + m_mirror_image_mode == cls::rbd::MIRROR_IMAGE_MODE_JOURNAL); + librbd::journal::TagData tag_data; - tag_data.mirror_uuid = (m_force_non_primary ? m_primary_mirror_uuid : + tag_data.mirror_uuid = (use_primary_mirror_uuid ? m_primary_mirror_uuid : librbd::Journal::LOCAL_MIRROR_UUID); - librbd::journal::CreateRequest *req = - librbd::journal::CreateRequest::create( - m_io_ctx, m_image_id, m_journal_order, m_journal_splay_width, - m_journal_pool, cls::journal::Tag::TAG_CLASS_NEW, tag_data, - librbd::Journal::IMAGE_CLIENT_ID, m_op_work_queue, ctx); + auto req = librbd::journal::CreateRequest::create( + m_io_ctx, m_image_id, m_journal_order, m_journal_splay_width, + m_journal_pool, cls::journal::Tag::TAG_CLASS_NEW, tag_data, + librbd::Journal::IMAGE_CLIENT_ID, m_op_work_queue, ctx); req->send(); } @@ -644,7 +634,7 @@ void CreateRequest::handle_journal_create(int r) { template void CreateRequest::mirror_image_enable() { - if (((m_mirror_mode != RBD_MIRROR_MODE_POOL) && !m_force_non_primary) || + if (((m_mirror_mode != cls::rbd::MIRROR_MODE_POOL) && !m_force_non_primary) || m_skip_mirror_enable) { complete(0); return; diff --git a/src/librbd/image/CreateRequest.h b/src/librbd/image/CreateRequest.h index 688e5c632a2..e5a870433a8 100644 --- a/src/librbd/image/CreateRequest.h +++ b/src/librbd/image/CreateRequest.h @@ -128,7 +128,7 @@ private: std::string m_id_obj, m_header_obj, m_objmap_name; bufferlist m_outbl; - rbd_mirror_mode_t m_mirror_mode = RBD_MIRROR_MODE_DISABLED; + cls::rbd::MirrorMode m_mirror_mode = cls::rbd::MIRROR_MODE_DISABLED; cls::rbd::MirrorImage m_mirror_image_internal; void validate_data_pool(); -- 2.47.3