]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/mirror/PromoteRequest: return EINVAL
authorRamana Raja <rraja@redhat.com>
Mon, 5 May 2025 23:37:42 +0000 (19:37 -0400)
committerRamana Raja <rraja@redhat.com>
Mon, 16 Jun 2025 17:09:08 +0000 (13:09 -0400)
... instead of ENOENT when mirroring is not enabled for the image.

The PromoteRequest async state machine returns ENOENT when mirroring is
not enabled for the image. Instead, make it return EINVAL similar to
DemoteRequest's behavior, which is more appropriate. This also causes
the public facing C, C++, and Python APIs that promote 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/mirror/PromoteRequest.cc
src/test/librbd/test_mirroring.cc
src/test/pybind/test_rbd.py

index 687f634345662ce94f17f249adff14e6199af675..119284081d7e31531477746504764ec4236e584d 100644 (file)
   C `rbd_mirror_image_get_mode()`, and Python `Image.mirror_image_get_mode()`
   -- will return EINVAL when mirroring is disabled.
 
+* RBD: Promoting an image is invalid if the image is not enabled for mirroring.
+  The public APIs -- C++ `mirror_image_promote()`,
+  C `rbd_mirror_image_promote()`, and Python `Image.mirror_image_promote()` --
+  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 b119e4edcd95b3d761ea738743d173d66602b018..62b528390a3aeb76f365da782d083ee5cd83ccb7 100644 (file)
@@ -45,7 +45,7 @@ void PromoteRequest<I>::handle_get_info(int r) {
   CephContext *cct = m_image_ctx.cct;
   ldout(cct, 20) << "r=" << r << dendl;
 
-  if (r < 0) {
+  if (r < 0 && r != -ENOENT) {
     lderr(cct) << "failed to retrieve mirroring state: " << cpp_strerror(r)
                << dendl;
     finish(r);
index 4d4b509c9a560fa2ce12702da99459628bd0e92f..400756813f3ab68f3dedc9436f7406b0330e86f4 100644 (file)
@@ -1477,6 +1477,10 @@ TEST_F(TestMirroring, SnapshotPromoteDemote)
   ASSERT_EQ(0, image.mirror_image_demote());
   ASSERT_EQ(0, image.mirror_image_promote(false));
 
+  ASSERT_EQ(0, image.mirror_image_disable(false));
+  ASSERT_EQ(-EINVAL, image.mirror_image_promote(false));
+  ASSERT_EQ(-EINVAL, image.mirror_image_demote());
+
   ASSERT_EQ(0, image.close());
   ASSERT_EQ(0, m_rbd.remove(m_ioctx, image_name.c_str()));
   ASSERT_EQ(0, m_rbd.mirror_peer_site_remove(m_ioctx, peer_uuid));
index 810bc7ee21548daf6acc46cb6b1c8507a3887a24..817f40d236a4636469b43809c306ccb6f7ba3eca 100644 (file)
@@ -2679,6 +2679,9 @@ class TestMirroring(object):
         info = self.image.mirror_image_get_info()
         self.check_info(info, '', RBD_MIRROR_IMAGE_DISABLED, False)
         assert_raises(InvalidArgument, self.image.mirror_image_get_mode)
+        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)
 
         self.image.mirror_image_enable()
         info = self.image.mirror_image_get_info()