Skip to content

Commit 4c992e6

Browse files
committed
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 <[email protected]>
1 parent eb19563 commit 4c992e6

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

PendingReleaseNotes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@
165165
C `rbd_mirror_image_promote()`, and Python `Image.mirror_image_promote()` --
166166
will return EINVAL instead of ENOENT when mirroring is not enabled.
167167

168+
* RBD: Requesting a resync on an image is invalid if the image is not enabled
169+
for mirroring. The public APIs -- C++ `mirror_image_resync()`,
170+
C `rbd_mirror_image_resync()`, and Python `Image.mirror_image_resync()` --
171+
will return EINVAL instead of ENOENT when mirroring is not enabled.
172+
168173
>=19.2.1
169174

170175
* CephFS: Command `fs subvolume create` now allows tagging subvolumes through option

src/librbd/api/Mirror.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,14 @@ int Mirror<I>::image_resync(I *ictx) {
815815
req->send();
816816

817817
r = get_info_ctx.wait();
818-
if (r < 0) {
818+
if (r < 0 && r != -ENOENT) {
819+
lderr(cct) << "failed to retrieve mirroring state, cannot resync: "
820+
<< cpp_strerror(r) << dendl;
819821
return r;
820-
}
821-
822-
if (promotion_state == mirror::PROMOTION_STATE_PRIMARY) {
822+
} else if (mirror_image.state != cls::rbd::MIRROR_IMAGE_STATE_ENABLED) {
823+
lderr(cct) << "mirroring is not enabled, cannot resync" << dendl;
824+
return -EINVAL;
825+
} else if (promotion_state == mirror::PROMOTION_STATE_PRIMARY) {
823826
lderr(cct) << "image is primary, cannot resync to itself" << dendl;
824827
return -EINVAL;
825828
}

src/test/pybind/test_rbd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,6 +2682,7 @@ def test_mirror_image(self):
26822682
assert_raises(InvalidArgument, self.image.mirror_image_promote, False)
26832683
assert_raises(InvalidArgument, self.image.mirror_image_promote, True)
26842684
assert_raises(InvalidArgument, self.image.mirror_image_demote)
2685+
assert_raises(InvalidArgument, self.image.mirror_image_resync)
26852686

26862687
self.image.mirror_image_enable()
26872688
info = self.image.mirror_image_get_info()

0 commit comments

Comments
 (0)