From c16bdd3ef1844e7f72fba4af7163d3a1ab741336 Mon Sep 17 00:00:00 2001 From: Ramana Raja Date: Tue, 6 May 2025 16:19:09 -0400 Subject: [PATCH] librbd/api/Mirror: return EINVAL from image_resync() ... when mirroring is not enabled for the image. Mirror::image_resync() returns ENOENT when mirroring is disabled for the image. Instead, make it return EINVAL indicating that the call is invalid when mirroring is not enabled for the image. This also causes the public facing C, C++, and Python APIs that resync an image to return EINVAL or raise an equivalent exception when mirroring is not enabled for the image. Signed-off-by: Ramana Raja (cherry picked from commit 4c992e6c8555ba370717c11d9d8ead1a52f97968) --- PendingReleaseNotes | 5 +++++ src/librbd/api/Mirror.cc | 11 +++++++---- src/test/pybind/test_rbd.py | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/PendingReleaseNotes b/PendingReleaseNotes index 119284081d7e3..7c22516d07abc 100644 --- a/PendingReleaseNotes +++ b/PendingReleaseNotes @@ -165,6 +165,11 @@ C `rbd_mirror_image_promote()`, and Python `Image.mirror_image_promote()` -- will return EINVAL instead of ENOENT when mirroring is not enabled. +* RBD: Requesting a resync on an image is invalid if the image is not enabled + for mirroring. The public APIs -- C++ `mirror_image_resync()`, + C `rbd_mirror_image_resync()`, and Python `Image.mirror_image_resync()` -- + will return EINVAL instead of ENOENT when mirroring is not enabled. + >=19.2.1 * CephFS: Command `fs subvolume create` now allows tagging subvolumes through option diff --git a/src/librbd/api/Mirror.cc b/src/librbd/api/Mirror.cc index 934d38e30caef..334a16c56f8e4 100644 --- a/src/librbd/api/Mirror.cc +++ b/src/librbd/api/Mirror.cc @@ -815,11 +815,14 @@ int Mirror::image_resync(I *ictx) { req->send(); r = get_info_ctx.wait(); - if (r < 0) { + if (r < 0 && r != -ENOENT) { + lderr(cct) << "failed to retrieve mirroring state, cannot resync: " + << cpp_strerror(r) << dendl; return r; - } - - if (promotion_state == mirror::PROMOTION_STATE_PRIMARY) { + } else if (mirror_image.state != cls::rbd::MIRROR_IMAGE_STATE_ENABLED) { + lderr(cct) << "mirroring is not enabled, cannot resync" << dendl; + return -EINVAL; + } else if (promotion_state == mirror::PROMOTION_STATE_PRIMARY) { lderr(cct) << "image is primary, cannot resync to itself" << dendl; return -EINVAL; } diff --git a/src/test/pybind/test_rbd.py b/src/test/pybind/test_rbd.py index 817f40d236a46..9e3995687fbad 100644 --- a/src/test/pybind/test_rbd.py +++ b/src/test/pybind/test_rbd.py @@ -2682,6 +2682,7 @@ class TestMirroring(object): assert_raises(InvalidArgument, self.image.mirror_image_promote, False) assert_raises(InvalidArgument, self.image.mirror_image_promote, True) assert_raises(InvalidArgument, self.image.mirror_image_demote) + assert_raises(InvalidArgument, self.image.mirror_image_resync) self.image.mirror_image_enable() info = self.image.mirror_image_get_info() -- 2.39.5