Skip to content

Commit

Permalink
librbd: prevent creation of clone from non-primary mirrored image
Browse files Browse the repository at this point in the history
Fixes: http://tracker.ceph.com/issues/16449
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
(cherry picked from commit ba849e3)
  • Loading branch information
Mykola Golub authored and ldachary committed Aug 10, 2016
1 parent aacb793 commit 2b27212
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions qa/workunits/rbd/rbd_mirror.sh
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions qa/workunits/rbd/rbd_mirror_helpers.sh
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions src/librbd/internal.cc
Expand Up @@ -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);
}
Expand Down

0 comments on commit 2b27212

Please sign in to comment.