]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add --format option
authorJosh Durgin <josh.durgin@inktank.com>
Wed, 29 Aug 2012 17:58:30 +0000 (10:58 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Thu, 30 Aug 2012 21:34:49 +0000 (14:34 -0700)
This chooses whether to use the original (supported by krbd)
or the new (supports layering) format.

Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
doc/man/8/rbd.rst
src/rbd.cc
src/test/cli/rbd/help.t
src/test/cli/rbd/invalid-snap-usage.t

index 5ccfefbfa9fbce223e2b401539f59ce4e2ccd9da..dfe497504ea1cf2dde1a56e180b79a278ca6b52c 100644 (file)
@@ -41,6 +41,19 @@ Options
 Parameters
 ==========
 
+.. option:: --format format
+
+   Specifies which object layout to use. The default is 1.
+
+   * format 1 - Use the original format for a new rbd image. This format is
+     understood by all versions of librbd and the kernel rbd module, but
+     does not support newer features like cloning.
+
+   * format 2 - Use the second rbd format, which is supported by
+     librbd (but not the kernel rbd module) at this time. This adds
+     support for cloning and is more easily extensible to allow more
+     features in the future.
+
 .. option:: --size size-in-mb
 
    Specifies the size (in megabytes) of the new rbd image.
index 9c56c5959c8326bf0235aa6add1fed11257c2db2..35b85842d49f8cca3b88ccf3eac691cd0eb78cc5 100644 (file)
@@ -72,7 +72,7 @@ void usage()
 "  create [--order <bits>] --size <MB> <name>  create an empty image\n"
 "  clone [--order <bits>] <parentsnap> <clonename>\n"
 "                                              clone a snapshot into a COW\n"
-"                                               child image\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"
@@ -112,8 +112,9 @@ void usage()
 "  --size <size in MB>          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"
-"\n"
-"For the map command:\n"
+"  --format <format-number>     format to use when creating an image\n"
+"                               format 1 is the original format (default)\n"
+"                               format 2 supports cloning\n"
 "  --id <username>              rados user (without 'client.' prefix) to authenticate as\n"
 "  --keyfile <path>             file containing secret key for use with cephx\n";
 }
@@ -167,13 +168,13 @@ static int do_list(librbd::RBD &rbd, librados::IoCtx& io_ctx)
 
 static int do_create(librbd::RBD &rbd, librados::IoCtx& io_ctx,
                     const char *imgname, uint64_t size, int *order,
-                    bool old_format, uint64_t features)
+                    int format, uint64_t features)
 {
   int r;
   if (features == 0) 
     features = RBD_FEATURES_ALL;
 
-  if (old_format)
+  if (format == 1)
     r = rbd.create(io_ctx, imgname, size, order);
   else
     r = rbd.create2(io_ctx, imgname, size, features, order);
@@ -256,11 +257,13 @@ static int do_show_info(const char *imgname, librbd::Image& image,
        << std::endl
        << "\tblock_name_prefix: " << info.block_name_prefix
        << std::endl
-       << "\told format: " << (old_format ? "True" : "False")
-       << std::endl
-       << "\tfeatures: " << feature_str(features)
+       << "\tformat: " << (old_format ? "1" : "2")
        << std::endl;
 
+  if (!old_format) {
+    cout << "\tfeatures: " << feature_str(features) << std::endl;
+  }
+
   // snapshot info, if present
   if (snapname) {
     cout << "\tprotected: " << (snap_protected ? "True" : "False")
@@ -520,7 +523,7 @@ done_img:
 
 static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
                     const char *imgname, int *order, const char *path,
-                    bool old_format, uint64_t features, int64_t size)
+                    int format, uint64_t features, int64_t size)
 {
   int fd, r;
   struct stat stat_buf;
@@ -558,7 +561,7 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
 
   assert(imgname);
 
-  r = do_create(rbd, io_ctx, imgname, size, order, old_format, features);
+  r = do_create(rbd, io_ctx, imgname, size, order, format, features);
   if (r < 0) {
     cerr << "image creation failed" << std::endl;
     return r;
@@ -1093,7 +1096,8 @@ int main(int argc, const char **argv)
   const char *poolname = NULL;
   uint64_t size = 0;  // in bytes
   int order = 0;
-  bool old_format = true;
+  bool format_specified = false;
+  int format = 1;
   uint64_t features = RBD_FEATURE_LAYERING;
   const char *imgname = NULL, *snapname = NULL, *destname = NULL, *dest_poolname = NULL, *dest_snapname = NULL, *path = NULL, *devpath = NULL;
 
@@ -1111,7 +1115,15 @@ int main(int argc, const char **argv)
       usage();
       return 0;
     } else if (ceph_argparse_flag(args, i, "--new-format", (char*)NULL)) {
-      old_format = false;
+      format = 2;
+      format_specified = true;
+    } else if (ceph_argparse_withint(args, i, &format, &err, "--format",
+                                    (char*)NULL)) {
+      if (!err.str().empty()) {
+       cerr << err.str() << std::endl;
+       return EXIT_FAILURE;
+      }
+      format_specified = true;
     } else if (ceph_argparse_witharg(args, i, &val, "-p", "--pool", (char*)NULL)) {
       poolname = strdup(val.c_str());
     } else if (ceph_argparse_witharg(args, i, &val, "--dest-pool", (char*)NULL)) {
@@ -1222,6 +1234,21 @@ int main(int argc, const char **argv)
     }
   }
 
+  if (format_specified && opt_cmd != OPT_IMPORT && opt_cmd != OPT_CREATE) {
+    cerr << "error: format can only be set when "
+        << "creating or importing an image" << std::endl;
+    usage();
+    return EXIT_FAILURE;
+  }
+
+  if (format_specified) {
+    if (format < 1 || format > 2) {
+      cerr << "error: format must be 1 or 2" << std::endl;
+      usage();
+      return EXIT_FAILURE;
+    }
+  }
+
   if (opt_cmd == OPT_EXPORT && !imgname) {
     cerr << "error: image name was not specified" << std::endl;
     usage();
@@ -1383,7 +1410,7 @@ int main(int argc, const char **argv)
       usage();
       return EXIT_FAILURE;
     }
-    r = do_create(rbd, io_ctx, imgname, size, &order, old_format, features);
+    r = do_create(rbd, io_ctx, imgname, size, &order, format, features);
     if (r < 0) {
       cerr << "create error: " << cpp_strerror(-r) << std::endl;
       return EXIT_FAILURE;
@@ -1572,7 +1599,7 @@ int main(int argc, const char **argv)
       return EXIT_FAILURE;
     }
     r = do_import(rbd, dest_io_ctx, destname, &order, path,
-                 old_format, features, size);
+                 format, features, size);
     if (r < 0) {
       cerr << "import failed: " << cpp_strerror(-r) << std::endl;
       return EXIT_FAILURE;
index 55217fb677cf89b2f4adbfc7d7f371f380bcd3ec..e70bd10aaa9b67ecbf24fd3ad032916e693351b0 100644 (file)
@@ -7,7 +7,7 @@
     create [--order <bits>] --size <MB> <name>  create an empty image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
-                                                 child image
+                                                child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
@@ -47,7 +47,8 @@
     --size <size in MB>          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).
-  
-  For the map command:
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
index e6ae9671d3266ff0c13fdf010e14888775ccf473..aca9eafb0135ada643f2c43e716c706e0a917ce8 100644 (file)
@@ -8,7 +8,7 @@
     create [--order <bits>] --size <MB> <name>  create an empty image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
-                                                 child image
+                                                child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
@@ -48,8 +48,9 @@
     --size <size in MB>          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).
-  
-  For the map command:
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
   [1]
@@ -63,7 +64,7 @@
     create [--order <bits>] --size <MB> <name>  create an empty image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
-                                                 child image
+                                                child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     --size <size in MB>          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).
-  
-  For the map command:
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
   [1]
     create [--order <bits>] --size <MB> <name>  create an empty image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
-                                                 child image
+                                                child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     --size <size in MB>          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).
-  
-  For the map command:
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
   [1]
     create [--order <bits>] --size <MB> <name>  create an empty image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
-                                                 child image
+                                                child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     --size <size in MB>          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).
-  
-  For the map command:
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
   [1]
     create [--order <bits>] --size <MB> <name>  create an empty image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
-                                                 child image
+                                                child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     --size <size in MB>          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).
-  
-  For the map command:
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
   [1]
     create [--order <bits>] --size <MB> <name>  create an empty image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
-                                                 child image
+                                                child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     --size <size in MB>          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).
-  
-  For the map command:
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
   [1]
     create [--order <bits>] --size <MB> <name>  create an empty image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
-                                                 child image
+                                                child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     --size <size in MB>          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).
-  
-  For the map command:
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
   [1]
     create [--order <bits>] --size <MB> <name>  create an empty image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
-                                                 child image
+                                                child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     --size <size in MB>          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).
-  
-  For the map command:
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
   [1]
     create [--order <bits>] --size <MB> <name>  create an empty image
     clone [--order <bits>] <parentsnap> <clonename>
                                                 clone a snapshot into a COW
-                                                 child image
+                                                child image
     children <snap-name>                        display children of snapshot
     flatten <image-name>                        fill clone with parent data
                                                 (make it independent)
     --size <size in MB>          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).
-  
-  For the map command:
+    --format <format-number>     format to use when creating an image
+                                 format 1 is the original format (default)
+                                 format 2 supports cloning
     --id <username>              rados user (without 'client.' prefix) to authenticate as
     --keyfile <path>             file containing secret key for use with cephx
   [1]