]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/mirror: cleanup EnableRequest::handle_get_mirror_image() 64545/head
authorRamana Raja <rraja@redhat.com>
Wed, 16 Jul 2025 17:43:18 +0000 (13:43 -0400)
committerRamana Raja <rraja@redhat.com>
Thu, 24 Jul 2025 15:23:40 +0000 (11:23 -0400)
In the EnableRequest state machine, clean up the handling of the async
request to fetch the mirror image, particularly when a non-primary image
is being created by the rbd-mirror daemon.

Signed-off-by: Ramana Raja <rraja@redhat.com>
src/librbd/mirror/EnableRequest.cc

index fd74a25ba65515d91076b8e99edb9916f9e7a787..5fc1dffb149aadf94a409a5823635e6246daa601 100644 (file)
@@ -68,41 +68,49 @@ void EnableRequest<I>::handle_get_mirror_image(int r) {
     r = cls_client::mirror_image_get_finish(&iter, &m_mirror_image);
   }
 
-  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
-    ldout(m_cct, 10) << "enabling mirroring on in-progress image replication"
-                     << dendl;
-  } else if (r == 0) {
+  if (r == 0) {
     if (m_mirror_image.mode != m_mode) {
       lderr(m_cct) << "invalid current image mirror mode" << dendl;
-      r = -EINVAL;
+      finish(-EINVAL);
+      return;
     } else if (m_mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_ENABLED) {
       ldout(m_cct, 10) << "mirroring is already enabled" << dendl;
-    } else {
+      finish(0);
+      return;
+    } else if (
+        m_mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_CREATING &&
+        m_mirror_image.global_image_id == m_non_primary_global_image_id) {
+      // special case where rbd-mirror injects a quasi-enabled mirror image
+      // entry to record the local image id prior to creating the image
+      ceph_assert(!m_mirror_image.global_image_id.empty());
+      ldout(m_cct, 10) << "enabling mirroring on in-progress image replication"
+                       << dendl;
+    } else if (
+       m_mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_DISABLING) {
       lderr(m_cct) << "currently disabling" << dendl;
-      r = -EINVAL;
+      finish(-EINVAL);
+      return;
+    } else {
+      lderr(m_cct) << "unexpected mirror image state" << dendl;
+      finish(-EINVAL);
+      return;
     }
-    finish(r);
-    return;
-  } else if (r != -ENOENT) {
+  } else if (r == -ENOENT) {
+    m_mirror_image.mode = m_mode;
+    if (m_non_primary_global_image_id.empty()) {
+      uuid_d uuid_gen;
+      uuid_gen.generate_random();
+      m_mirror_image.global_image_id = uuid_gen.to_string();
+    } else {
+      m_mirror_image.global_image_id = m_non_primary_global_image_id;
+    }
+  } else {
     lderr(m_cct) << "failed to retrieve mirror image: " << cpp_strerror(r)
                  << dendl;
     finish(r);
     return;
   }
 
-  r = 0;
-  m_mirror_image.mode = m_mode;
-  if (m_non_primary_global_image_id.empty()) {
-    uuid_d uuid_gen;
-    uuid_gen.generate_random();
-    m_mirror_image.global_image_id = uuid_gen.to_string();
-  } else {
-    m_mirror_image.global_image_id = m_non_primary_global_image_id;
-  }
-
   get_tag_owner();
 }