From: Mykola Golub Date: Mon, 24 Apr 2017 18:29:36 +0000 (+0200) Subject: rbd: import needs to sanity check auto-generated image name X-Git-Tag: v12.0.3~196^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=40de8f1183b054c53396651e689bacbc014e2071;p=ceph.git rbd: import needs to sanity check auto-generated image name Fixes: http://tracker.ceph.com/issues/19128 Signed-off-by: Mykola Golub --- diff --git a/qa/workunits/rbd/cli_generic.sh b/qa/workunits/rbd/cli_generic.sh index e85ae619becfd..bbf86b66140bb 100755 --- a/qa/workunits/rbd/cli_generic.sh +++ b/qa/workunits/rbd/cli_generic.sh @@ -290,7 +290,7 @@ test_pool_image_args() { ceph osd pool delete test test --yes-i-really-really-mean-it || true ceph osd pool create test 100 - truncate -s 1 /tmp/empty + truncate -s 1 /tmp/empty /tmp/empty@snap rbd ls | wc -l | grep 0 rbd create -s 1 test1 @@ -302,6 +302,12 @@ test_pool_image_args() { rbd import /tmp/empty foo rbd ls | grep -q foo + # should fail due to "destination snapname specified" + rbd import --dest test/empty@snap /tmp/empty && exit 1 || true + rbd import /tmp/empty test/empty@snap && exit 1 || true + rbd import --image test/empty@snap /tmp/empty && exit 1 || true + rbd import /tmp/empty@snap && exit 1 || true + rbd ls test | wc -l | grep 0 rbd import /tmp/empty test/test1 rbd ls test | grep -q test1 @@ -336,7 +342,7 @@ test_pool_image_args() { rbd ls | grep test12 rbd ls test | grep -qv test12 - rm -f /tmp/empty + rm -f /tmp/empty /tmp/empty@snap ceph osd pool delete test test --yes-i-really-really-mean-it for f in foo test1 test10 test12 test2 test3 ; do diff --git a/src/tools/rbd/action/Import.cc b/src/tools/rbd/action/Import.cc index 348915dbcced2..5bea7805da738 100644 --- a/src/tools/rbd/action/Import.cc +++ b/src/tools/rbd/action/Import.cc @@ -871,15 +871,21 @@ int execute(const po::variables_map &vm) { std::string deprecated_image_name; if (vm.count(at::IMAGE_NAME)) { - utils::extract_spec(vm[at::IMAGE_NAME].as(), - &deprecated_pool_name, &deprecated_image_name, nullptr, - utils::SPEC_VALIDATION_FULL); + deprecated_image_name = vm[at::IMAGE_NAME].as(); std::cerr << "rbd: --image is deprecated for import, use --dest" << std::endl; } else { deprecated_image_name = path.substr(path.find_last_of("/") + 1); } + std::string deprecated_snap_name; + r = utils::extract_spec(deprecated_image_name, &deprecated_pool_name, + &deprecated_image_name, &deprecated_snap_name, + utils::SPEC_VALIDATION_FULL); + if (r < 0) { + return r; + } + size_t sparse_size = utils::RBD_DEFAULT_SPARSE_SIZE; if (vm.count(at::IMAGE_SPARSE_SIZE)) { sparse_size = vm[at::IMAGE_SPARSE_SIZE].as(); @@ -888,7 +894,7 @@ int execute(const po::variables_map &vm) { size_t arg_index = 1; std::string pool_name = deprecated_pool_name; std::string image_name; - std::string snap_name; + std::string snap_name = deprecated_snap_name; r = utils::get_pool_image_snapshot_names( vm, at::ARGUMENT_MODIFIER_DEST, &arg_index, &pool_name, &image_name, &snap_name, utils::SNAPSHOT_PRESENCE_NONE, utils::SPEC_VALIDATION_FULL,