]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
[rbd] support G/T units in rbd create/resize 4948/head
authorVikhyat Umrao <vumrao@redhat.com>
Sat, 13 Jun 2015 04:55:45 +0000 (10:25 +0530)
committerVikhyat Umrao <vumrao@redhat.com>
Tue, 16 Jun 2015 17:57:52 +0000 (23:27 +0530)
Signed-off-by: Vikhyat Umrao <vumrao@redhat.com>
doc/man/8/rbd.rst
src/rbd.cc
src/test/cli-integration/rbd/defaults.t
src/test/cli-integration/rbd/formatted-output.t
src/test/cli/rbd/help.t

index ba09131c57de3dbed9c8650c4b85b8aebb4fc313..2d6108cfc71fc243d703b9d45af56f067bdc7d3e 100644 (file)
@@ -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
 
index 4355c4f0847871722af875e7709613baed675e9b..2808f9b8ce4e40f18ab082dd2595fe418ed49c0a 100644 (file)
@@ -98,14 +98,14 @@ void usage()
 "  info <image-name>                           show information about image size,\n"
 "                                              striping, etc.\n"
 "  create [--order <bits>] [--image-features <features>] [--image-shared]\n"
-"         --size <MB> <name>                   create an empty image\n"
+"         --size <M/G/T> <image-name>          create an empty image\n"
 "  clone [--order <bits>] [--image-features <features>] [--image-shared]\n"
 "        <parentsnap> <clonename>              clone a snapshot into a COW\n"
 "                                              child image\n"
 "  children <snap-name>                        display children of snapshot\n"
 "  flatten <image-name>                        fill clone with parent data\n"
 "                                              (make it independent)\n"
-"  resize --size <MB> <image-name>             resize (expand or contract) image\n"
+"  resize --size <M/G/T> <image-name>          resize (expand or contract) image\n"
 "  rm <image-name>                             delete an image\n"
 "  export <image-name> <path>                  export image to file\n"
 "                                              \"-\" for stdout\n"
@@ -168,7 +168,7 @@ void usage()
 "  --snap <snap-name>                 snapshot name\n"
 "  --dest-pool <name>                 destination pool name\n"
 "  --path <path-name>                 path name for import/export\n"
-"  --size <size in MB>                size of image for create and resize\n"
+"  -s, --size <size in M/G/T>         size of image for create and resize\n"
 "  --order <bits>                     the object size in bits; object size will be\n"
 "                                     (1 << order) bytes. Default is 22 (4 MB).\n"
 "  --image-format <format-number>     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<const char*>::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 <MB>" << std::endl;
+      cerr << "rbd: must specify --size <M/G/T>" << std::endl;
       return EINVAL;
     }
   }
index eec77ed7654b3498f14e89042ef8e1c4d810c918..85eefbcf374180b49eed90b27e812162d476e2ec 100644 (file)
@@ -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/,$/, /'
   {
index 846760b0a36ac4033bafefdff27719f4b55fb65f..4d407b9da4299400cb9d9ec8142b48bf9a0ea238 100644 (file)
@@ -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
index 80806ed7f00d5a8f686c450da9d246ae0e4b77af..19b4879fb5f4363b3ad6c48216e44142425f5248 100644 (file)
@@ -8,14 +8,14 @@
     info <image-name>                           show information about image size,
                                                 striping, etc.
     create [--order <bits>] [--image-features <features>] [--image-shared]
-           --size <MB> <name>                   create an empty image
+           --size <M/G/T> <image-name>          create an empty image
     clone [--order <bits>] [--image-features <features>] [--image-shared]
           <parentsnap> <clonename>              clone a snapshot into a COW
                                                 child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
-    resize --size <MB> <image-name>             resize (expand or contract) image
+    resize --size <M/G/T> <image-name>          resize (expand or contract) image
     rm <image-name>                             delete an image
     export <image-name> <path>                  export image to file
                                                 "-" for stdout
@@ -78,7 +78,7 @@
     --snap <snap-name>                 snapshot name
     --dest-pool <name>                 destination pool name
     --path <path-name>                 path name for import/export
-    --size <size in MB>                size of image for create and resize
+    -s, --size <size in M/G/T>         size of image for create and resize
     --order <bits>                     the object size in bits; object size will be
                                        (1 << order) bytes. Default is 22 (4 MB).
     --image-format <format-number>     format to use when creating an image