]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: ignore unexpected state when mirror image flagged as creating
authorJason Dillaman <dillaman@redhat.com>
Thu, 27 Feb 2020 01:12:38 +0000 (20:12 -0500)
committerJason Dillaman <dillaman@redhat.com>
Thu, 27 Feb 2020 21:33:21 +0000 (16:33 -0500)
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 <dillaman@redhat.com>
src/librbd/mirror/EnableRequest.cc
src/librbd/mirror/GetInfoRequest.cc

index 50f2afb7a48428387f36a150ef8e074ac731c06f..5071763a5c7e9642d975e258306fd33b52e48b4b 100644 (file)
@@ -65,7 +65,12 @@ void EnableRequest<I>::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<I>::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);
index c264dec03a8591f68c0d3e010d49459cfc784092..0f6981fc743b63eb4e425894777c36ffbcea3f7f 100644 (file)
@@ -168,7 +168,16 @@ void GetInfoRequest<I>::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<I>::calc_promotion_state(
   for (auto it = snap_info.rbegin(); it != snap_info.rend(); it++) {
     auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>(
       &it->second.snap_namespace);
+
     if (mirror_ns != nullptr) {
       switch (mirror_ns->state) {
       case cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY: