From a47c933e0cb43d5cc0ebf61cb7002472db10c025 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Sat, 1 Mar 2025 01:14:17 +0530 Subject: [PATCH] librbd: defend for primary as part of disable request Other wise we will procceed with disable in below case and end-up not able to promote the same later: [root@dhcp53-181 build]# ./bin/rbd --cluster site-a mirror group demote test_pool/test_group --debug-rbd=0 Group demoted to non-primary [root@dhcp53-181 build]# ./bin/rbd --cluster site-a mirror group disable test_pool/test_group --debug-rbd=0 2025-03-01T00:46:55.214+0530 7f1cdd71a6c0 -1 librbd::mirror::DisableRequest: 0x56213d4b8f10 handle_get_mirror_info: mirrored image is not primary, add force option to disable mirroring 2025-03-01T00:46:55.215+0530 7f1ce4c39b80 -1 librbd::api::Mirror: image_disable: cannot disable mirroring: (22) Invalid argument 2025-03-01T00:46:55.218+0530 7f1ce4c39b80 -1 librbd::api::Mirror: group_disable: failed to disable mirroring on image: test_image1(22) Invalid argument 2025-03-01T00:46:55.238+0530 7f1cddf1b6c0 -1 librbd::mirror::DisableRequest: 0x56213d17d790 handle_get_mirror_info: mirrored image is not primary, add force option to disable mirroring 2025-03-01T00:46:55.238+0530 7f1ce4c39b80 -1 librbd::api::Mirror: image_disable: cannot disable mirroring: (22) Invalid argument 2025-03-01T00:46:55.241+0530 7f1ce4c39b80 -1 librbd::api::Mirror: group_disable: failed to disable mirroring on image: test_image2(22) Invalid argument 2025-03-01T00:46:55.265+0530 7f1cdd71a6c0 -1 librbd::mirror::DisableRequest: 0x56213d52f290 handle_get_mirror_info: mirrored image is not primary, add force option to disable mirroring 2025-03-01T00:46:55.265+0530 7f1ce4c39b80 -1 librbd::api::Mirror: image_disable: cannot disable mirroring: (22) Invalid argument 2025-03-01T00:46:55.269+0530 7f1ce4c39b80 -1 librbd::api::Mirror: group_disable: failed to disable mirroring on image: test_image3(22) Invalid argument 2025-03-01T00:46:55.293+0530 7f1cddf1b6c0 -1 librbd::mirror::DisableRequest: 0x56213d544620 handle_get_mirror_info: mirrored image is not primary, add force option to disable mirroring 2025-03-01T00:46:55.293+0530 7f1ce4c39b80 -1 librbd::api::Mirror: image_disable: cannot disable mirroring: (22) Invalid argument 2025-03-01T00:46:55.297+0530 7f1ce4c39b80 -1 librbd::api::Mirror: group_disable: failed to disable mirroring on image: test_image4(22) Invalid argument 2025-03-01T00:46:55.316+0530 7f1ce4c39b80 -1 librbd::api::Mirror: group_disable: failed to disable one or more images: (22) Invalid argument [root@dhcp53-181 build]# ./bin/rbd --cluster site-a mirror group promote test_pool/test_group --debug-rbd=0 rbd: mirroring not enabled on the group Signed-off-by: Prasanna Kumar Kalever --- src/librbd/api/Mirror.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librbd/api/Mirror.cc b/src/librbd/api/Mirror.cc index a6a7450c6149d..0b2aa379ff9a2 100644 --- a/src/librbd/api/Mirror.cc +++ b/src/librbd/api/Mirror.cc @@ -2949,9 +2949,9 @@ int Mirror::group_disable(IoCtx& group_ioctx, const char *group_name, return r; } - if (state == cls::rbd::MIRROR_SNAPSHOT_STATE_NON_PRIMARY && !force) { + if (state != cls::rbd::MIRROR_SNAPSHOT_STATE_PRIMARY && !force) { lderr(cct) << "group " << group_name - << " is non-primary, ideally disable it from primary cluster " + << " is not primary, disable is allowed when cluster is primary" << " or if you know what you are doing, add a force flag" << dendl; return -EINVAL; -- 2.39.5