]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: prevent creation of clone from non-primary mirrored image 10650/head
authorMykola Golub <mgolub@mirantis.com>
Mon, 4 Jul 2016 10:54:32 +0000 (13:54 +0300)
committerLoic Dachary <ldachary@redhat.com>
Wed, 10 Aug 2016 08:25:09 +0000 (10:25 +0200)
Fixes: http://tracker.ceph.com/issues/16449
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
(cherry picked from commit ba849e3b04a5c513849d40a7fe4151375265302a)

qa/workunits/rbd/rbd_mirror.sh
qa/workunits/rbd/rbd_mirror_helpers.sh
src/librbd/internal.cc

index 8c2c5873ad22ca845b4047ce6f5e8d0d314d3801..8e69f2d0ee526d7fddf604d5fa266b58439937a8 100755 (executable)
@@ -141,6 +141,9 @@ wait_for_replay_complete ${CLUSTER1} ${CLUSTER2} ${POOL} ${clone_image}
 test_status_in_pool_dir ${CLUSTER1} ${POOL} ${clone_image} 'up+replaying' 'master_position'
 compare_images ${POOL} ${clone_image}
 
+expect_failure "is non-primary" clone_image ${CLUSTER1} ${PARENT_POOL} \
+    ${parent_image} ${parent_snap} ${POOL} ${clone_image}1
+
 testlog "TEST: disable mirroring / delete non-primary image"
 image2=test2
 image3=test3
index 8094bd8de427eb4cb77d47f962a2dc7ce82c7ba0..4799898072a99f107cf8e4cb0500dd570aab77e5 100755 (executable)
@@ -108,6 +108,28 @@ testlog()
     echo $(date '+%F %T') $@ | tee -a "${TEMPDIR}/rbd-mirror.test.log"
 }
 
+expect_failure()
+{
+    local expected="$1" ; shift
+    local out=${TEMPDIR}/expect_failure.out
+
+    if "$@" > ${out} 2>&1 ; then
+        cat ${out} >&2
+        return 1
+    fi
+
+    if [ -z "${expected}" ]; then
+       return 0
+    fi
+
+    if ! grep -q "${expected}" ${out} ; then
+        cat ${out} >&2
+        return 1
+    fi
+
+    return 0
+}
+
 setup()
 {
     local c
index d3f1cd3fb714f67a79843cadd9fbbbfd1a358729..f4da923ca87ce5fd7a0932bf8bdec9bbb8956a52 100644 (file)
@@ -1484,6 +1484,21 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force,
       return -EINVAL;
     }
 
+    if ((p_features & RBD_FEATURE_JOURNALING) != 0) {
+      bool force_non_primary = !non_primary_global_image_id.empty();
+      bool is_primary;
+      int r = Journal<>::is_tag_owner(p_imctx, &is_primary);
+      if (r < 0) {
+       lderr(cct) << "failed to determine tag ownership: " << cpp_strerror(r)
+                  << dendl;
+       return r;
+      }
+      if (!is_primary && !force_non_primary) {
+       lderr(cct) << "parent is non-primary mirrored image" << dendl;
+       return -EINVAL;
+      }
+    }
+
     if (use_p_features) {
       c_opts.set(RBD_IMAGE_OPTION_FEATURES, p_features);
     }