From: Mykola Golub Date: Mon, 4 Jul 2016 10:54:32 +0000 (+0300) Subject: librbd: prevent creation of clone from non-primary mirrored image X-Git-Tag: v10.2.4~60^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2b272126de6ea6e75b9dcf4fedac5c216093e36d;p=ceph.git librbd: prevent creation of clone from non-primary mirrored image Fixes: http://tracker.ceph.com/issues/16449 Signed-off-by: Mykola Golub (cherry picked from commit ba849e3b04a5c513849d40a7fe4151375265302a) --- diff --git a/qa/workunits/rbd/rbd_mirror.sh b/qa/workunits/rbd/rbd_mirror.sh index 8c2c5873ad2..8e69f2d0ee5 100755 --- a/qa/workunits/rbd/rbd_mirror.sh +++ b/qa/workunits/rbd/rbd_mirror.sh @@ -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 diff --git a/qa/workunits/rbd/rbd_mirror_helpers.sh b/qa/workunits/rbd/rbd_mirror_helpers.sh index 8094bd8de42..4799898072a 100755 --- a/qa/workunits/rbd/rbd_mirror_helpers.sh +++ b/qa/workunits/rbd/rbd_mirror_helpers.sh @@ -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 diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index d3f1cd3fb71..f4da923ca87 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -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); }