]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: improve mirror image status and validation error messages 68015/head
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Thu, 26 Mar 2026 18:44:45 +0000 (00:14 +0530)
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Thu, 26 Mar 2026 18:59:50 +0000 (00:29 +0530)
When a mirror image is left in a transitional state such as DISABLING,
the current mirror image status command reports:

  $ rbd mirror image status test_pool/test_image1
  rbd: mirroring not enabled on the image

This is the same message shown when mirroring is disabled or not yet
enabled, which can give the impression that mirroring is already
disabled.

Improve the validation logic and error messages to distinguish between
the DISABLED state and other non-enabled states, and include the image
name and current state in the output.

Examples:

When the image is completely disabled:

  $ rbd mirror image status test_pool/test_image1
  rbd: mirroring disabled on image 'test_image1'

When the image is in a transitional state (ex: DISABLING):

  $ rbd mirror image status test_pool/test_image1
  rbd: mirroring not enabled on image 'test_image1' (state: disabling)

Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
src/tools/rbd/action/MirrorImage.cc

index ca6211adc13f30285a8d9ae72d944f3fd08c5e2e..dcea5e592bcc6d6278d4cc354addfaa14dda996c 100644 (file)
@@ -35,16 +35,26 @@ namespace po = boost::program_options;
 namespace {
 
 int validate_mirroring_enabled(librbd::Image &image, bool snapshot = false) {
+  std::string image_name;
+  int r = image.get_name(&image_name);
+  ceph_assert(r == 0);
+
   librbd::mirror_image_info_t mirror_image;
-  int r = image.mirror_image_get_info(&mirror_image, sizeof(mirror_image));
+  r = image.mirror_image_get_info(&mirror_image, sizeof(mirror_image));
   if (r < 0) {
-    std::cerr << "rbd: failed to retrieve mirror info: "
-              << cpp_strerror(r) << std::endl;
+    std::cerr << "rbd: failed to get mirror info for image '" << image_name
+              << "': " << cpp_strerror(r) << std::endl;
     return r;
   }
 
-  if (mirror_image.state != RBD_MIRROR_IMAGE_ENABLED) {
-    std::cerr << "rbd: mirroring not enabled on the image" << std::endl;
+  if (mirror_image.state == RBD_MIRROR_IMAGE_DISABLED) {
+    std::cerr << "rbd: mirroring disabled on image '" << image_name
+              << "'" << std::endl;
+    return -EINVAL;
+  } else if (mirror_image.state != RBD_MIRROR_IMAGE_ENABLED) {
+    std::cerr << "rbd: mirroring not enabled on image '" << image_name
+              << "' (state: " << utils::mirror_image_state(mirror_image.state)
+              << ")" << std::endl;
     return -EINVAL;
   }
 
@@ -52,13 +62,15 @@ int validate_mirroring_enabled(librbd::Image &image, bool snapshot = false) {
     librbd::mirror_image_mode_t mode;
     r = image.mirror_image_get_mode(&mode);
     if (r < 0) {
-      std::cerr << "rbd: failed to retrieve mirror mode: "
-                << cpp_strerror(r) << std::endl;
+      std::cerr << "rbd: failed to get mirror mode for image '"
+                << image_name << "': " << cpp_strerror(r) << std::endl;
       return r;
     }
 
     if (mode != RBD_MIRROR_IMAGE_MODE_SNAPSHOT) {
-      std::cerr << "rbd: snapshot based mirroring not enabled on the image"
+      std::cerr << "rbd: snapshot based mirroring not enabled on image '"
+                << image_name << "' (mirroring mode: "
+                << utils::mirror_image_mode(mode) << ")"
                 << std::endl;
       return -EINVAL;
     }