]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: improve log msgs when failing to enable mirroring on image 50836/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, 3 Apr 2023 06:44:22 +0000 (12:14 +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>
(cherry picked from commit 828a0dea2d40ba0c1aa0a9d4b211f0fabc854350)

src/librbd/api/Mirror.cc

index bbaa4eff7bb17d258a0806d3bb5f30f8970f0eb6..a1b2a83d9f3dd997add1c0b34280ec126c96e5dd 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;
   }