From 8e56a5b5c4fc1eeafb51459079591620961a146b Mon Sep 17 00:00:00 2001 From: Vikhyat Umrao Date: Sat, 13 Jun 2015 10:25:45 +0530 Subject: [PATCH] [rbd] support G/T units in rbd create/resize Signed-off-by: Vikhyat Umrao --- doc/man/8/rbd.rst | 4 +-- src/rbd.cc | 30 +++++++++++-------- src/test/cli-integration/rbd/defaults.t | 17 +++++++++++ .../cli-integration/rbd/formatted-output.t | 5 ++++ src/test/cli/rbd/help.t | 6 ++-- 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/doc/man/8/rbd.rst b/doc/man/8/rbd.rst index ba09131c57de3..2d6108cfc71fc 100644 --- a/doc/man/8/rbd.rst +++ b/doc/man/8/rbd.rst @@ -61,9 +61,9 @@ Parameters support for cloning and is more easily extensible to allow more features in the future. -.. option:: --size size-in-mb +.. option:: --size size-in-M/G/T - Specifies the size (in megabytes) of the new rbd image. + Specifies the size (in M/G/T) of the new rbd image. .. option:: --order bits diff --git a/src/rbd.cc b/src/rbd.cc index 4355c4f084787..2808f9b8ce4e4 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -98,14 +98,14 @@ void usage() " info show information about image size,\n" " striping, etc.\n" " create [--order ] [--image-features ] [--image-shared]\n" -" --size create an empty image\n" +" --size create an empty image\n" " clone [--order ] [--image-features ] [--image-shared]\n" " clone a snapshot into a COW\n" " child image\n" " children display children of snapshot\n" " flatten fill clone with parent data\n" " (make it independent)\n" -" resize --size resize (expand or contract) image\n" +" resize --size resize (expand or contract) image\n" " rm delete an image\n" " export export image to file\n" " \"-\" for stdout\n" @@ -168,7 +168,7 @@ void usage() " --snap snapshot name\n" " --dest-pool destination pool name\n" " --path path name for import/export\n" -" --size size of image for create and resize\n" +" -s, --size size of image for create and resize\n" " --order the object size in bits; object size will be\n" " (1 << order) bytes. Default is 22 (4 MB).\n" " --image-format format to use when creating an image\n" @@ -2975,7 +2975,7 @@ int main(int argc, const char **argv) std::string val, parse_err; std::ostringstream err; - long long sizell = 0; + uint64_t sizell = 0; std::vector::iterator i; for (i = args.begin(); i != args.end(); ) { if (ceph_argparse_double_dash(args, i)) { @@ -3009,16 +3009,22 @@ int main(int argc, const char **argv) fromsnapname = strdup(val.c_str()); } else if (ceph_argparse_witharg(args, i, &val, "-i", "--image", (char*)NULL)) { imgname = strdup(val.c_str()); - } else if (ceph_argparse_witharg(args, i, &sizell, err, "-s", "--size", (char*)NULL)) { + } else if (ceph_argparse_witharg(args, i, &val, err, "-s", "--size", (char*)NULL)) { if (!err.str().empty()) { - cerr << "rbd: " << err.str() << std::endl; - return EXIT_FAILURE; + cerr << "rbd: " << err.str() << std::endl; + return EXIT_FAILURE; } - if (sizell < 0) { - cerr << "rbd: size must be >= 0" << std::endl; - return EXIT_FAILURE; + const char *sizeval = val.c_str(); + size = strict_sistrtoll(sizeval, &parse_err); + if (!parse_err.empty()) { + cerr << "rbd: error parsing --size " << parse_err << std::endl; + return EXIT_FAILURE; } - size = sizell << 20; // bytes to MB + //NOTE: We can remove below given three lines of code once all applications, + //which use this CLI will adopt B/K/M/G/T/P/E with size value + sizell = atoll(sizeval); + if (size == sizell) + size = size << 20; // Default MB to Bytes size_set = true; } else if (ceph_argparse_flag(args, i, "-l", "--long", (char*)NULL)) { lflag = true; @@ -3540,7 +3546,7 @@ 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 " << std::endl; + cerr << "rbd: must specify --size " << std::endl; return EINVAL; } } diff --git a/src/test/cli-integration/rbd/defaults.t b/src/test/cli-integration/rbd/defaults.t index eec77ed7654b3..85eefbcf37418 100644 --- a/src/test/cli-integration/rbd/defaults.t +++ b/src/test/cli-integration/rbd/defaults.t @@ -41,6 +41,23 @@ Plain create with various options specified via usual cli arguments "size": 1048576 } $ rbd rm test --no-progress + $ rbd create -s 1G test --image-format 2 + $ rbd info test --format json | python -mjson.tool | sed 's/,$/, /' + { + "block_name_prefix": "rbd_data.*", (glob) + "features": [ + "layering", + "striping", + "exclusive" + ], + "format": 2, + "name": "test", + "object_size": 4194304, + "objects": 256, + "order": 22, + "size": 1073741824 + } + $ rbd rm test --no-progress $ rbd create -s 1 test --image-format 2 --order 20 $ rbd info test --format json | python -mjson.tool | sed 's/,$/, /' { diff --git a/src/test/cli-integration/rbd/formatted-output.t b/src/test/cli-integration/rbd/formatted-output.t index 846760b0a36ac..4d407b9da4299 100644 --- a/src/test/cli-integration/rbd/formatted-output.t +++ b/src/test/cli-integration/rbd/formatted-output.t @@ -15,12 +15,16 @@ create $ rbd create -s 512 --image-format 2 bar $ rbd create -s 2048 --image-format 2 baz $ rbd create -s 1 --image-format 1 quux + $ rbd create -s 1G --image-format 2 quuy snapshot ======== $ rbd snap create bar@snap $ rbd resize -s 1024 bar + Resizing image: 100% complete...done. + $ rbd resize -s 2G quuy + Resizing image: 100% complete...done. $ rbd snap create bar@snap2 $ rbd snap create foo@snap @@ -731,6 +735,7 @@ whenever it is run. grep -v to ignore it, but still work on other distros. $ rbd rm foo 2> /dev/null $ rbd rm bar 2> /dev/null $ rbd rm quux 2> /dev/null + $ rbd rm quuy 2> /dev/null $ rbd rm baz 2> /dev/null $ ceph osd pool delete rbd_other rbd_other --yes-i-really-really-mean-it pool 'rbd_other' removed diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 80806ed7f00d5..19b4879fb5f43 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -8,14 +8,14 @@ info show information about image size, striping, etc. create [--order ] [--image-features ] [--image-shared] - --size create an empty image + --size create an empty image clone [--order ] [--image-features ] [--image-shared] clone a snapshot into a COW child image children display children of snapshot flatten fill clone with parent data (make it independent) - resize --size resize (expand or contract) image + resize --size resize (expand or contract) image rm delete an image export export image to file "-" for stdout @@ -78,7 +78,7 @@ --snap snapshot name --dest-pool destination pool name --path path name for import/export - --size size of image for create and resize + -s, --size size of image for create and resize --order the object size in bits; object size will be (1 << order) bytes. Default is 22 (4 MB). --image-format format to use when creating an image -- 2.47.3