]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/rbd_support: disallow scheduling mirror snapshots
authorRamana Raja <rraja@redhat.com>
Thu, 12 Dec 2024 21:38:29 +0000 (16:38 -0500)
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>
Thu, 24 Apr 2025 15:56:28 +0000 (21:26 +0530)
... of images that are part of a group.

Creating a global, pool or namespace level mirror snapshot
schedule shouldn't schedule mirror snapshots of images that
are part of a group and reside in the pool or namespace.

Also disallow directly scheduling mirror image snapshots on
images that are part of a group.

Signed-off-by: Ramana Raja <rraja@redhat.com>
qa/workunits/rbd/cli_generic.sh
src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py

index 3f210d440fc4ea5b003a61d8564aa85b3c76526f..cb74dd5c0958a3f884529111656ff3249419c792 100755 (executable)
@@ -1403,6 +1403,7 @@ test_mirror_snapshot_schedule() {
     done
     rbd mirror snapshot schedule status | grep 'rbd2/ns1/test1'
 
+    # set a global level mirror image snapshot schedule
     rbd mirror snapshot schedule add 1h 00:15
     test "$(rbd mirror snapshot schedule ls)" = 'every 1h starting at 00:15:00'
     rbd mirror snapshot schedule ls -R | grep 'every 1h starting at 00:15:00'
@@ -1427,6 +1428,30 @@ test_mirror_snapshot_schedule() {
     test "$(rbd mirror snapshot schedule ls)" = 'every 1h starting at 00:15:00'
     test "$(rbd mirror snapshot schedule ls -p rbd2/ns1 --image test1)" = 'every 1m'
 
+    rbd create $RBD_CREATE_ARGS -s 1 rbd2/ns1/img1
+    rbd create $RBD_CREATE_ARGS -s 1 rbd2/ns1/img2
+    rbd group create rbd2/ns1/gp1
+    rbd group image add rbd2/ns1/gp1 rbd2/ns1/img1
+    # enabling snapshot on the group sets the snapshot mirror mode of the
+    # group's member image 'img1'
+    rbd mirror group enable rbd2/ns1/gp1 snapshot
+    rbd mirror image enable rbd2/ns1/img2 snapshot
+    # can't schedule mirror-snapshot on image 'img1' that is part of a group
+    expect_fail rbd mirror snapshot schedule add -p rbd2/ns1 --image img1 1m
+    # global level snapshot schedule does not create a schedule for the image
+    # 'img1' that is part of a group, but creates a schedule for the standalone
+    # image 'img2'
+    for i in `seq 12`; do
+        rbd mirror snapshot schedule status | grep 'rbd2/ns1/img1' || break
+        sleep 10
+    done
+    rbd mirror snapshot schedule status | expect_fail grep 'rbd2/ns1/img1'
+    for i in `seq 12`; do
+        rbd mirror snapshot schedule status | grep 'rbd2/ns1/img2' && break
+        sleep 10
+    done
+    rbd mirror snapshot schedule status | grep 'rbd2/ns1/img2'
+
     rbd rm rbd2/ns1/test1
     for i in `seq 12`; do
         rbd mirror snapshot schedule status | grep 'rbd2/ns1/test1' || break
index e5b19f36228d3a48f9bc221014c4c566f93e69a5..a54845ece6b4c1e75aef293d717656cd2012474e 100644 (file)
@@ -24,6 +24,9 @@ def image_validator(image: rbd.Image) -> None:
     if mode != rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT:
         raise rbd.InvalidArgument("Invalid mirror image mode")
 
+    if image.group()['pool'] != -1:
+        raise ValueError("image {} is part of a group".format(image.get_name()))
+
 
 class ImageSpec(NamedTuple):
     pool_id: str
@@ -451,6 +454,9 @@ class MirrorSnapshotScheduleHandler:
                     image_name = image_names.get(image_id)
                     if not image_name:
                         continue
+                    with rbd.Image(ioctx, image_name, read_only=True) as img:
+                        if img.group()['pool'] != -1:
+                            continue
                     if namespace:
                         name = "{}/{}/{}".format(pool_name, namespace,
                                                  image_name)