From 0ed296b1e3441f953b8c2163d841c55455062b2c Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Fri, 20 Feb 2015 12:50:26 -0500 Subject: [PATCH] rbd: disable RBD exclusive locking by default Utilize the existing rbd_default_features config option to control whether or not to enable RBD exclusive locking and object map features by default. Also added a new option to the rbd cli to specify the image features when creating images. Signed-off-by: Jason Dillaman --- doc/man/8/rbd.rst | 11 +++++++ src/common/config_opts.h | 3 +- src/rbd.cc | 59 ++++++++++++++++++++++--------------- src/test/cli/rbd/help.t | 19 +++++++----- src/test/pybind/test_rbd.py | 2 +- 5 files changed, 60 insertions(+), 34 deletions(-) diff --git a/doc/man/8/rbd.rst b/doc/man/8/rbd.rst index 15d9ce2f4c839..7c85f9d4f07ab 100644 --- a/doc/man/8/rbd.rst +++ b/doc/man/8/rbd.rst @@ -123,6 +123,17 @@ Parameters Map the image read-only. Equivalent to -o ro. +.. option:: --image-features features + + Specifies which RBD format 2 features are to be enabled when creating + an image. The numbers from the desired features below should be added + to compute the parameter value: + + +1: layering support + +2: striping v2 support + +4: exclusive locking support + +8: object map support + .. option:: --image-shared Specifies that the image will be used concurrently by multiple clients. diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 7994e3e8fb4d1..a964303184c13 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -863,7 +863,6 @@ OPTION(rbd_readahead_trigger_requests, OPT_INT, 10) // number of sequential requ OPTION(rbd_readahead_max_bytes, OPT_LONGLONG, 512 * 1024) // set to 0 to disable readahead OPTION(rbd_readahead_disable_after_bytes, OPT_LONGLONG, 50 * 1024 * 1024) // how many bytes are read in total before readahead is disabled OPTION(rbd_clone_copy_on_read, OPT_BOOL, false) -OPTION(rbd_object_map, OPT_BOOL, false) // whether to enable the RBD object map OPTION(rbd_blacklist_on_break_lock, OPT_BOOL, true) // whether to blacklist clients whose lock was broken OPTION(rbd_blacklist_expire_seconds, OPT_INT, 0) // number of seconds to blacklist - set to 0 for OSD default @@ -887,7 +886,7 @@ OPTION(rbd_default_format, OPT_INT, 1) OPTION(rbd_default_order, OPT_INT, 22) OPTION(rbd_default_stripe_count, OPT_U64, 0) // changing requires stripingv2 feature OPTION(rbd_default_stripe_unit, OPT_U64, 0) // changing to non-object size requires stripingv2 feature -OPTION(rbd_default_features, OPT_INT, 7) // only applies to format 2 images +OPTION(rbd_default_features, OPT_INT, 3) // only applies to format 2 images // +1 for layering, +2 for stripingv2, // +4 for exclusive lock, +8 for object map diff --git a/src/rbd.cc b/src/rbd.cc index 806b739287776..1c7470b6bb729 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -85,10 +85,10 @@ void usage() " (-l includes snapshots/clones)\n" " info show information about image size,\n" " striping, etc.\n" -" create [--order ] [--image-shared] --size \n" -" create an empty image\n" -" clone [--order ] [--image-shared] \n" -" clone a snapshot into a COW\n" +" create [--order ] [--image-features ] [--image-shared]\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" @@ -97,10 +97,10 @@ void usage() " rm delete an image\n" " export export image to file\n" " \"-\" for stdout\n" -" import [--image-shared] import image from file\n" -" (dest defaults\n" -" as the filename part of file)\n" -" \"-\" for stdin\n" +" import [--image-features ] [--image-shared]\n" +" import image from file (dest\n" +" defaults as the filename part\n" +" of file). \"-\" for stdin\n" " diff [--from-snap ] print extents that differ since\n" " a previous snap, or image creation\n" " export-diff [--from-snap ] \n" @@ -154,6 +154,9 @@ void usage() " --image-format format to use when creating an image\n" " format 1 is the original format (default)\n" " format 2 supports cloning\n" +" --image-features optional format 2 features to enable\n" +" +1 layering support, +2 striping v2,\n" +" +4 exclusive lock, +8 object map\n" " --image-shared image will be used concurrently (disables\n" " RBD exclusive lock and dependent features)\n" " --id rados user (without 'client.'prefix) to\n" @@ -474,15 +477,11 @@ static int do_create(librbd::RBD &rbd, librados::IoCtx& io_ctx, } r = rbd.create(io_ctx, imgname, size, order); } else { - if (features == 0) { - features = RBD_FEATURE_LAYERING | RBD_FEATURE_EXCLUSIVE_LOCK; - } - if (g_conf->rbd_object_map) { - features |= RBD_FEATURE_OBJECT_MAP; - } if ((stripe_unit || stripe_count) && (stripe_unit != (1ull << *order) && stripe_count != 1)) { features |= RBD_FEATURE_STRIPINGV2; + } else { + features &= ~RBD_FEATURE_STRIPINGV2; } r = rbd.create3(io_ctx, imgname, size, features, order, stripe_unit, stripe_count); @@ -497,15 +496,9 @@ static int do_clone(librbd::RBD &rbd, librados::IoCtx &p_ioctx, librados::IoCtx &c_ioctx, const char *c_name, uint64_t features, int *c_order) { - if (features == 0) { - features = (RBD_FEATURES_ALL & ~RBD_FEATURE_OBJECT_MAP); - } - else if ((features & RBD_FEATURE_LAYERING) != RBD_FEATURE_LAYERING) { + if ((features & RBD_FEATURE_LAYERING) != RBD_FEATURE_LAYERING) { return -EINVAL; } - if (g_conf->rbd_object_map) { - features |= RBD_FEATURE_OBJECT_MAP; - } return rbd.clone(p_ioctx, p_name, p_snapname, c_ioctx, c_name, features, c_order); @@ -2620,7 +2613,10 @@ int main(int argc, const char **argv) bool format_specified = false, output_format_specified = false; int format = 1; - uint64_t features = RBD_FEATURE_LAYERING | RBD_FEATURE_EXCLUSIVE_LOCK; + + uint64_t features = g_conf->rbd_default_features; + bool shared = false; + const char *imgname = NULL, *snapname = NULL, *destname = NULL, *dest_poolname = NULL, *dest_snapname = NULL, *path = NULL, *devpath = NULL, *lock_cookie = NULL, *lock_client = NULL, @@ -2723,8 +2719,15 @@ int main(int argc, const char **argv) progress = false; } else if (ceph_argparse_flag(args, i , "--allow-shrink", (char *)NULL)) { resize_allow_shrink = true; + } else if (ceph_argparse_flag(args, i, "--image-features", (char *)NULL)) { + features = strict_strtol(val.c_str(), 10, &parse_err); + if (!parse_err.empty()) { + cerr << "rbd: error parsing --image-features: " << parse_err + << std::endl; + return EXIT_FAILURE; + } } else if (ceph_argparse_flag(args, i, "--image-shared", (char *)NULL)) { - features &= ~(RBD_FEATURE_EXCLUSIVE_LOCK | RBD_FEATURE_OBJECT_MAP); + shared = true; } else if (ceph_argparse_witharg(args, i, &val, "--format", (char *) NULL)) { long long ret = strict_strtoll(val.c_str(), 10, &parse_err); if (parse_err.empty()) { @@ -2744,6 +2747,16 @@ int main(int argc, const char **argv) } } + if (shared) { + features &= ~(RBD_FEATURE_EXCLUSIVE_LOCK | RBD_FEATURE_OBJECT_MAP); + } + if (((features & RBD_FEATURE_EXCLUSIVE_LOCK) == 0) && + ((features & RBD_FEATURE_OBJECT_MAP) != 0)) { + cerr << "rbd: exclusive lock image feature must be enabled to use " + << "the object map" << std::endl; + return EXIT_FAILURE; + } + common_init_finish(g_ceph_context); i = args.begin(); diff --git a/src/test/cli/rbd/help.t b/src/test/cli/rbd/help.t index 8d572c599c460..d6ed206b8038a 100644 --- a/src/test/cli/rbd/help.t +++ b/src/test/cli/rbd/help.t @@ -5,10 +5,10 @@ (-l includes snapshots/clones) info show information about image size, striping, etc. - create [--order ] [--image-shared] --size - create an empty image - clone [--order ] [--image-shared] - clone a snapshot into a COW + create [--order ] [--image-features ] [--image-shared] + --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 @@ -17,10 +17,10 @@ rm delete an image export export image to file "-" for stdout - import [--image-shared] import image from file - (dest defaults - as the filename part of file) - "-" for stdin + import [--image-features ] [--image-shared] + import image from file (dest + defaults as the filename part + of file). "-" for stdin diff [--from-snap ] print extents that differ since a previous snap, or image creation export-diff [--from-snap ] @@ -74,6 +74,9 @@ --image-format format to use when creating an image format 1 is the original format (default) format 2 supports cloning + --image-features optional format 2 features to enable + +1 layering support, +2 striping v2, + +4 exclusive lock, +8 object map --image-shared image will be used concurrently (disables RBD exclusive lock and dependent features) --id rados user (without 'client.'prefix) to diff --git a/src/test/pybind/test_rbd.py b/src/test/pybind/test_rbd.py index 853b8b2723ec5..5d61d53223291 100644 --- a/src/test/pybind/test_rbd.py +++ b/src/test/pybind/test_rbd.py @@ -138,7 +138,7 @@ def check_default_params(format, order=None, features=None, stripe_count=None, expected_features = features if expected_features is None or format == 1: - expected_features = 0 if format == 1 else 7 + expected_features = 0 if format == 1 else 3 eq(expected_features, image.features()) expected_stripe_count = stripe_count -- 2.39.5