diff options
author | Dan Mick <dan.mick@inktank.com> | 2012-11-26 22:03:49 -0800 |
---|---|---|
committer | Dan Mick <dan.mick@inktank.com> | 2012-11-26 22:03:49 -0800 |
commit | 9c76ed6244107a083c454e98a4a0b90d195e6dd1 (patch) | |
tree | eac63b0ba02317f470023d946e181a186be97a1d | |
parent | 3e988d45c07b9061d5834567bfafc86ec286089a (diff) | |
parent | ece11b0ed97ac6207980b412e3b2afe869065fff (diff) | |
download | ceph-9c76ed6244107a083c454e98a4a0b90d195e6dd1.tar.gz |
Merge branch 'wip-rbd-cmdparse'
Signed-off-by: Dan Mick <dan.mick@inktank.com>
Reviewed-by: Josh Durgin <josh.durgin@inktank.com>
-rwxr-xr-x | qa/workunits/rbd/copy.sh | 53 | ||||
-rw-r--r-- | src/rbd.cc | 37 |
2 files changed, 78 insertions, 12 deletions
diff --git a/qa/workunits/rbd/copy.sh b/qa/workunits/rbd/copy.sh index 7571f50471d..94f2c7f73c3 100755 --- a/qa/workunits/rbd/copy.sh +++ b/qa/workunits/rbd/copy.sh @@ -5,8 +5,8 @@ IMGS="testimg1 testimg2 testimg3 foo foo2 bar bar2 test1 test2 test3" remove_images() { for img in $IMGS do - rbd snap purge $img || true - rbd rm $img || true + (rbd snap purge $img || true) >/dev/null 2>&1 + (rbd rm $img || true) >/dev/null 2>&1 done } @@ -76,6 +76,16 @@ test_rename() { rbd rename bar bar2 rbd rename bar2 foo2 2>&1 | grep exists + rados mkpool rbd2 + rbd create -p rbd2 -s 1 foo + rbd rename rbd2/foo rbd2/bar + rbd -p rbd2 ls | grep bar + ! rbd rename rbd2/bar foo + ! rbd rename rbd2/bar --dest-pool rbd foo + rbd rename --pool rbd2 bar --dest-pool rbd2 foo + rbd -p rbd2 ls | grep foo + rados rmpool rbd2 + remove_images } @@ -254,8 +264,46 @@ test_pool_image_args() { rbd import --pool test /tmp/empty rbd ls test | grep -q empty + # copy with no explicit pool goes to pool rbd + rbd copy test/test9 test10 + rbd ls test | grep -qv test10 + rbd ls | grep -q test10 + rbd copy test/test9 test/test10 + rbd ls test | grep -q test10 + rbd copy --pool test test10 --dest-pool test test11 + rbd ls test | grep -q test11 + rbd copy --dest-pool rbd --pool test test11 test12 + rbd ls | grep test12 + rbd ls test | grep -qv test12 + rm -f /tmp/empty ceph osd pool delete test + ceph osd pool delete rbd + ceph osd pool create rbd 100 +} + +test_clone() { + remove_images + rbd create test1 $RBD_CREATE_ARGS -s 1 + rbd snap create test1@s1 + rbd snap protect test1@s1 + + rados mkpool rbd2 + rbd clone test1@s1 rbd2/clone + rbd -p rbd2 ls | grep clone + rbd -p rbd2 ls -l | grep clone | grep test1@s1 + rbd ls | grep -v clone + rbd flatten rbd2/clone + rbd snap create rbd2/clone@s1 + rbd snap protect rbd2/clone@s1 + rbd clone rbd2/clone@s1 clone2 + rbd ls | grep clone2 + rbd ls -l | grep clone2 | grep rbd2/clone@s1 + rbd -p rbd2 ls | grep -v clone2 + + rados rmpool rbd2 + rados rmpool rbd + rados mkpool rbd } test_pool_image_args @@ -268,5 +316,6 @@ test_locking RBD_CREATE_ARGS="--format 2" test_others test_locking +test_clone echo OK diff --git a/src/rbd.cc b/src/rbd.cc index 09d506f1ef7..ecdcfbe2ad0 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -754,9 +754,6 @@ static void set_pool_image_name(const char *orig_pool, const char *orig_img, { const char *sep; - if (orig_pool) - return; - if (!orig_img) return; @@ -1389,6 +1386,8 @@ static bool set_conf_param(const char *param, const char **var1, return true; } +bool size_set; + int main(int argc, const char **argv) { librados::Rados rados; @@ -1455,10 +1454,11 @@ int main(int argc, const char **argv) return EXIT_FAILURE; } if (sizell < 0) { - cerr << "rbd: size must be > 0" << std::endl; + cerr << "rbd: size must be >= 0" << std::endl; return EXIT_FAILURE; } size = sizell << 20; // bytes to MB + size_set = true; } else if (ceph_argparse_flag(args, i, "-l", "--long", (char*)NULL)) { lflag = true; } else if (ceph_argparse_withlonglong(args, i, &stripe_unit, &err, "--stripe-unit", (char*)NULL)) { @@ -1607,6 +1607,7 @@ if (!set_conf_param(v, p1, p2, p3)) { \ destname = imgname; if (!destname) destname = imgname_from_path(path); + imgname = NULL; } if (opt_cmd != OPT_LOCK_ADD && lock_tag) { @@ -1656,10 +1657,24 @@ if (!set_conf_param(v, p1, p2, p3)) { \ set_pool_image_name(dest_poolname, destname, (char **)&dest_poolname, (char **)&destname, (char **)&dest_snapname); + if (opt_cmd == OPT_IMPORT) { + if (poolname && dest_poolname) { + cerr << "rbd: source and destination pool both specified" << std::endl; + return EXIT_FAILURE; + } + if (imgname && destname) { + cerr << "rbd: source and destination image both specified" << std::endl; + return EXIT_FAILURE; + } + if (poolname) + dest_poolname = poolname; + } + if (!poolname) poolname = "rbd"; + if (!dest_poolname) - dest_poolname = poolname; + dest_poolname = "rbd"; if (opt_cmd == OPT_EXPORT && !path) path = imgname; @@ -1748,6 +1763,13 @@ if (!set_conf_param(v, p1, p2, p3)) { \ } } + if (opt_cmd == OPT_CREATE || opt_cmd == OPT_RESIZE) { + if (!size_set) { + cerr << "rbd: must specify --size <MB>" << std::endl; + return EXIT_FAILURE; + } + } + switch (opt_cmd) { case OPT_LIST: r = do_list(rbd, io_ctx, lflag); @@ -1765,11 +1787,6 @@ if (!set_conf_param(v, p1, p2, p3)) { \ break; case OPT_CREATE: - if (!size) { - cerr << "rbd: must specify size in MB to create an rbd image" - << std::endl; - return EXIT_FAILURE; - } if (order && (order < 12 || order > 25)) { cerr << "rbd: order must be between 12 (4 KB) and 25 (32 MB)" << std::endl; |