diff options
author | Josh Durgin <josh.durgin@inktank.com> | 2012-08-29 19:58:30 +0200 |
---|---|---|
committer | Josh Durgin <josh.durgin@inktank.com> | 2012-08-30 23:34:49 +0200 |
commit | dcbb87cc0cc412929827794be73cb1d4be8d42fd (patch) | |
tree | 45419ff7782e3beddb47880ae9f022b7122ae64b | |
parent | librbd: prevent racing clone and snap unprotect (diff) | |
download | ceph-dcbb87cc0cc412929827794be73cb1d4be8d42fd.tar.xz ceph-dcbb87cc0cc412929827794be73cb1d4be8d42fd.zip |
rbd: add --format option
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>
-rw-r--r-- | doc/man/8/rbd.rst | 13 | ||||
-rw-r--r-- | src/rbd.cc | 55 | ||||
-rw-r--r-- | src/test/cli/rbd/help.t | 7 | ||||
-rw-r--r-- | src/test/cli/rbd/invalid-snap-usage.t | 63 |
4 files changed, 94 insertions, 44 deletions
diff --git a/doc/man/8/rbd.rst b/doc/man/8/rbd.rst index 5ccfefbfa9f..dfe497504ea 100644 --- a/doc/man/8/rbd.rst +++ b/doc/man/8/rbd.rst @@ -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. diff --git a/src/rbd.cc b/src/rbd.cc index 9c56c5959c8..35b85842d49 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -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; diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 55217fb677c..e70bd10aaa9 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -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 diff --git a/src/test/cli/rbd/invalid-snap-usage.t b/src/test/cli/rbd/invalid-snap-usage.t index e6ae9671d32..aca9eafb013 100644 --- a/src/test/cli/rbd/invalid-snap-usage.t +++ b/src/test/cli/rbd/invalid-snap-usage.t @@ -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) @@ -103,8 +104,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] @@ -118,7 +120,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) @@ -158,8 +160,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] @@ -173,7 +176,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) @@ -213,8 +216,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] @@ -228,7 +232,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) @@ -268,8 +272,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] @@ -283,7 +288,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) @@ -323,8 +328,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] @@ -338,7 +344,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) @@ -378,8 +384,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] @@ -393,7 +400,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) @@ -433,8 +440,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] @@ -448,7 +456,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) @@ -488,8 +496,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] |