]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd/api/Mirror: return EINVAL from image_resync()
authorRamana Raja <rraja@redhat.com>
Tue, 6 May 2025 20:19:09 +0000 (16:19 -0400)
committerRamana Raja <rraja@redhat.com>
Mon, 16 Jun 2025 17:44:06 +0000 (13:44 -0400)
... 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 <rraja@redhat.com>
PendingReleaseNotes
src/librbd/api/Mirror.cc
src/test/pybind/test_rbd.py

index 119284081d7e31531477746504764ec4236e584d..7c22516d07abcd4dc0cb728eab5fde0a89034022 100644 (file)
   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
index 934d38e30caefafe3704e5d72af9a0af9b429831..334a16c56f8e4f8ee1b2c1039eb33298763ef7ff 100644 (file)
@@ -815,11 +815,14 @@ int Mirror<I>::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;
   }
index 817f40d236a4636469b43809c306ccb6f7ba3eca..9e3995687fbad8bae18559e44372abf73a8802e9 100644 (file)
@@ -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()