]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: improve log msgs when failing to enable mirroring on image 50343/head
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Thu, 2 Mar 2023 10:29:19 +0000 (15:59 +0530)
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Mon, 13 Mar 2023 12:48:51 +0000 (18:18 +0530)
Attempting to enable mirroring on an an image within a namespace bails
out without any useful msg.

$ rbd mirror image enable mi_pool/ns_0/big snapshot
2021-11-17T08:33:21.321+0000 7f4b36f9c2c0 -1 librbd::api::Mirror:
  image_enable: cannot enable mirroring in the current pool mirroring mode

Fixes: https://tracker.ceph.com/issues/58895
Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
src/librbd/api/Mirror.cc

index ef290e46b79171bf8e86f98af3e2ba2cbb8172a7..ee5897eddfc30e8991bf38c7ec76361bce452f96 100644 (file)
@@ -299,6 +299,15 @@ int list_mirror_images(librados::IoCtx& io_ctx,
   return 0;
 }
 
+template <typename I>
+const char *pool_or_namespace(I *ictx) {
+  if (!ictx->md_ctx.get_namespace().empty()) {
+    return "namespace";
+  } else {
+    return "pool";
+  }
+}
+
 struct C_ImageGetInfo : public Context {
   mirror_image_info_t *mirror_image_info;
   mirror_image_mode_t *mirror_image_mode;
@@ -434,9 +443,15 @@ int Mirror<I>::image_enable(I *ictx, mirror_image_mode_t mode,
     return r;
   }
 
+  if (mirror_mode == cls::rbd::MIRROR_MODE_DISABLED) {
+    lderr(cct) << "cannot enable mirroring: mirroring is not enabled on a "
+               << pool_or_namespace(ictx) << dendl;
+    return -EINVAL;
+  }
+
   if (mirror_mode != cls::rbd::MIRROR_MODE_IMAGE) {
-    lderr(cct) << "cannot enable mirroring in the current pool mirroring mode"
-               << dendl;
+    lderr(cct) << "cannot enable mirroring: " << pool_or_namespace(ictx)
+               << " is not in image mirror mode" << dendl;
     return -EINVAL;
   }