From 4e6e01c50c1ae6bd5bcd0cbe806360197de54a63 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Thu, 2 Mar 2023 15:59:19 +0530 Subject: [PATCH] rbd: improve log msgs when failing to enable mirroring on image 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 (cherry picked from commit 828a0dea2d40ba0c1aa0a9d4b211f0fabc854350) --- src/librbd/api/Mirror.cc | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/librbd/api/Mirror.cc b/src/librbd/api/Mirror.cc index bbaa4eff7bb17..a1b2a83d9f3dd 100644 --- a/src/librbd/api/Mirror.cc +++ b/src/librbd/api/Mirror.cc @@ -299,6 +299,15 @@ int list_mirror_images(librados::IoCtx& io_ctx, return 0; } +template +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::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; } -- 2.39.5