From 5466e6820197c910859f9982f5d26d9a91f6c7d7 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Wed, 26 Feb 2020 20:12:38 -0500 Subject: [PATCH] librbd: ignore unexpected state when mirror image flagged as creating When retrieving the mirror info we should just flag the promotion state as unknown if we are in the creating state and the image doesn't exist. When enabling mirroring, ignore the fact that a mirror image record will already exist. Signed-off-by: Jason Dillaman --- src/librbd/mirror/EnableRequest.cc | 11 +++++++---- src/librbd/mirror/GetInfoRequest.cc | 12 +++++++++++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/librbd/mirror/EnableRequest.cc b/src/librbd/mirror/EnableRequest.cc index 50f2afb7a48..5071763a5c7 100644 --- a/src/librbd/mirror/EnableRequest.cc +++ b/src/librbd/mirror/EnableRequest.cc @@ -65,7 +65,12 @@ void EnableRequest::handle_get_mirror_image(int r) { r = cls_client::mirror_image_get_finish(&iter, &m_mirror_image); } - if (r == 0) { + if (r == 0 && m_mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_CREATING && + !m_non_primary_global_image_id.empty()) { + // special case where rbd-mirror injects a disabled record to record the + // local image id prior to creating ther image + r = -ENOENT; + } else if (r == 0) { if (m_mirror_image.mode != m_mode) { lderr(m_cct) << "invalid current image mirror mode" << dendl; r = -EINVAL; @@ -77,9 +82,7 @@ void EnableRequest::handle_get_mirror_image(int r) { } finish(r); return; - } - - if (r != -ENOENT) { + } else if (r != -ENOENT) { lderr(m_cct) << "failed to retrieve mirror image: " << cpp_strerror(r) << dendl; finish(r); diff --git a/src/librbd/mirror/GetInfoRequest.cc b/src/librbd/mirror/GetInfoRequest.cc index c264dec03a8..0f6981fc743 100644 --- a/src/librbd/mirror/GetInfoRequest.cc +++ b/src/librbd/mirror/GetInfoRequest.cc @@ -168,7 +168,16 @@ void GetInfoRequest::handle_get_snapcontext(int r) { r = cls_client::get_snapcontext_finish(&it, &m_snapc); } - if (r < 0) { + if (r == -ENOENT && + m_mirror_image->state == cls::rbd::MIRROR_IMAGE_STATE_CREATING) { + // image doesn't exist but we have a mirror image record for it + ldout(m_cct, 10) << "image does not exist for mirror image id " + << m_image_id << dendl; + *m_promotion_state = PROMOTION_STATE_UNKNOWN; + *m_primary_mirror_uuid = ""; + finish(0); + return; + } else if (r < 0) { lderr(m_cct) << "failed to get snapcontext: " << cpp_strerror(r) << dendl; finish(r); @@ -252,6 +261,7 @@ void GetInfoRequest::calc_promotion_state( for (auto it = snap_info.rbegin(); it != snap_info.rend(); it++) { auto mirror_ns = boost::get( &it->second.snap_namespace); + if (mirror_ns != nullptr) { switch (mirror_ns->state) { case cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY: -- 2.39.5