]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: respect rbd_default_* parameters 2112/head
authorJosh Durgin <josh.durgin@inktank.com>
Wed, 16 Jul 2014 21:13:47 +0000 (14:13 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Wed, 16 Jul 2014 21:34:15 +0000 (14:34 -0700)
Treat rbd_default_{format,order,stripe_unit,stripe_count} as defaults for
the usual arguments for specifying those properties.

librbd::create() is affected by rbd_default_format, so we need to
explicitly override it if --image-format is set. The rest of the
parameters are passed explicitly when they are used, so their rbd_default
equivalents don't matter.

Fixes: #8821
Signed-off-by: Josh Durgin <josh.durgin@inktank.com>
src/rbd.cc
src/test/cli-integration/rbd/defaults.t [new file with mode: 0644]

index 5e46474ae6c75733594ff0140d1126e83964cc17..9a411ec7a73050519a5e8cd72fd43c501612a5c8 100644 (file)
@@ -1970,7 +1970,8 @@ int main(int argc, const char **argv)
   const char *poolname = NULL;
   uint64_t size = 0;  // in bytes
   int order = 0;
-  bool format_specified = false, output_format_specified = false;
+  bool format_specified = false,
+    output_format_specified = false;
   int format = 1;
   uint64_t features = RBD_FEATURE_LAYERING;
   const char *imgname = NULL, *snapname = NULL, *destname = NULL,
@@ -1984,7 +1985,7 @@ int main(int argc, const char **argv)
   long long bench_io_size = 4096, bench_io_threads = 16, bench_bytes = 1 << 30;
   string bench_pattern = "seq";
 
-  std::string val;
+  std::string val, parse_err;
   std::ostringstream err;
   long long sizell = 0;
   std::vector<const char*>::iterator i;
@@ -2000,13 +2001,15 @@ int main(int argc, const char **argv)
     } else if (ceph_argparse_flag(args, i, "--new-format", (char*)NULL)) {
       format = 2;
       format_specified = true;
-    } else if (ceph_argparse_withint(args, i, &format, &err, "--image-format",
+    } else if (ceph_argparse_witharg(args, i, &val, "--image-format",
                                     (char*)NULL)) {
-      if (!err.str().empty()) {
-       cerr << "rbd: " << err.str() << std::endl;
+      format = strict_strtol(val.c_str(), 10, &parse_err);
+      if (!parse_err.empty()) {
+       cerr << "rbd: error parsing --image-format: " << parse_err << std::endl;
        return EXIT_FAILURE;
       }
       format_specified = true;
+      g_conf->set_val_or_die("rbd_default_format", val.c_str());
     } 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)) {
@@ -2073,9 +2076,9 @@ int main(int argc, const char **argv)
     } else if (ceph_argparse_flag(args, i , "--allow-shrink", (char *)NULL)) {
       resize_allow_shrink = true;
     } else if (ceph_argparse_witharg(args, i, &val, "--format", (char *) NULL)) {
-      std::string err;
-      long long ret = strict_strtoll(val.c_str(), 10, &err);
-      if (err.empty()) {
+      long long ret = strict_strtoll(val.c_str(), 10, &parse_err);
+      if (parse_err.empty()) {
+       g_conf->set_val_or_die("rbd_default_format", val.c_str());
        format = ret;
        format_specified = true;
        cerr << "rbd: using --format for specifying the rbd image format is"
@@ -2189,6 +2192,17 @@ if (!set_conf_param(v, p1, p2, p3)) { \
     }
   }
 
+  /* get defaults from rbd_default_* options to keep behavior consistent with
+     manual short-form options */
+  if (!format_specified)
+    format = g_conf->rbd_default_format;
+  if (!order)
+    order = g_conf->rbd_default_order;
+  if (!stripe_unit)
+    stripe_unit = g_conf->rbd_default_stripe_unit;
+  if (!stripe_count)
+    stripe_count = g_conf->rbd_default_stripe_count;
+
   if (format_specified && opt_cmd != OPT_IMPORT && opt_cmd != OPT_CREATE) {
     cerr << "rbd: image format can only be set when "
         << "creating or importing an image" << std::endl;
diff --git a/src/test/cli-integration/rbd/defaults.t b/src/test/cli-integration/rbd/defaults.t
new file mode 100644 (file)
index 0000000..c2a33e4
--- /dev/null
@@ -0,0 +1,214 @@
+Plain create with various options specified via usual cli arguments
+===================================================================
+  $ rbd create -s 1 test
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rb.0.*",  (glob)
+      "format": 1, 
+      "name": "test", 
+      "object_size": 4194304, 
+      "objects": 1, 
+      "order": 22, 
+      "size": 1048576
+  }
+  $ rbd rm test --no-progress
+  $ rbd create -s 1 --order 20 test
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rb.0.*",  (glob)
+      "format": 1, 
+      "name": "test", 
+      "object_size": 1048576, 
+      "objects": 1, 
+      "order": 20, 
+      "size": 1048576
+  }
+  $ rbd rm test --no-progress
+  $ rbd create -s 1 test --image-format 2
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rbd_data.*",  (glob)
+      "features": [
+          "layering", 
+          "striping"
+      ], 
+      "format": 2, 
+      "name": "test", 
+      "object_size": 4194304, 
+      "objects": 1, 
+      "order": 22, 
+      "size": 1048576
+  }
+  $ rbd rm test --no-progress
+  $ rbd create -s 1 test --image-format 2 --order 20
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rbd_data.*",  (glob)
+      "features": [
+          "layering", 
+          "striping"
+      ], 
+      "format": 2, 
+      "name": "test", 
+      "object_size": 1048576, 
+      "objects": 1, 
+      "order": 20, 
+      "size": 1048576
+  }
+  $ rbd rm test --no-progress
+  $ rbd create -s 1 test --image-format 2 --stripe-unit 1048576 --stripe-count 8
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rbd_data.*",  (glob)
+      "features": [
+          "layering", 
+          "striping"
+      ], 
+      "format": 2, 
+      "name": "test", 
+      "object_size": 4194304, 
+      "objects": 1, 
+      "order": 22, 
+      "size": 1048576, 
+      "stripe_count": 8, 
+      "stripe_unit": 1048576
+  }
+  $ rbd rm test --no-progress
+
+Format 2 Usual arguments with custom rbd_default_* params
+=========================================================
+  $ rbd create -s 1 test --image-format 2 --stripe-unit 1048576 --stripe-count 8 --rbd-default-order 21
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rbd_data.*",  (glob)
+      "features": [
+          "layering", 
+          "striping"
+      ], 
+      "format": 2, 
+      "name": "test", 
+      "object_size": 2097152, 
+      "objects": 1, 
+      "order": 21, 
+      "size": 1048576, 
+      "stripe_count": 8, 
+      "stripe_unit": 1048576
+  }
+  $ rbd rm test --no-progress
+  $ rbd create -s 1 test --image-format 2 --stripe-unit 1048576 --stripe-count 8 --order 23 --rbd-default-order 20
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rbd_data.*",  (glob)
+      "features": [
+          "layering", 
+          "striping"
+      ], 
+      "format": 2, 
+      "name": "test", 
+      "object_size": 8388608, 
+      "objects": 1, 
+      "order": 23, 
+      "size": 1048576, 
+      "stripe_count": 8, 
+      "stripe_unit": 1048576
+  }
+  $ rbd rm test --no-progress
+  $ rbd create -s 1 test --image-format 2 --rbd-default-stripe-unit 1048576 --rbd-default-stripe-count 8
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rbd_data.*",  (glob)
+      "features": [
+          "layering", 
+          "striping"
+      ], 
+      "format": 2, 
+      "name": "test", 
+      "object_size": 4194304, 
+      "objects": 1, 
+      "order": 22, 
+      "size": 1048576, 
+      "stripe_count": 8, 
+      "stripe_unit": 1048576
+  }
+  $ rbd rm test --no-progress
+
+Format 1 Usual arguments with custom rbd_default_* params
+=========================================================
+  $ rbd create -s 1 test --rbd-default-order 20
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rb.0.*",  (glob)
+      "format": 1, 
+      "name": "test", 
+      "object_size": 1048576, 
+      "objects": 1, 
+      "order": 20, 
+      "size": 1048576
+  }
+  $ rbd rm test --no-progress
+  $ rbd create -s 1 test --rbd-default-format 2
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rbd_data.*",  (glob)
+      "features": [
+          "layering", 
+          "striping"
+      ], 
+      "format": 2, 
+      "name": "test", 
+      "object_size": 4194304, 
+      "objects": 1, 
+      "order": 22, 
+      "size": 1048576
+  }
+  $ rbd rm test --no-progress
+  $ rbd create -s 1 test --rbd-default-format 2 --rbd-default-order 20
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rbd_data.*",  (glob)
+      "features": [
+          "layering", 
+          "striping"
+      ], 
+      "format": 2, 
+      "name": "test", 
+      "object_size": 1048576, 
+      "objects": 1, 
+      "order": 20, 
+      "size": 1048576
+  }
+  $ rbd rm test --no-progress
+  $ rbd create -s 1 test --rbd-default-format 2 --rbd-default-order 20 --rbd-default-features 1
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rbd_data.*",  (glob)
+      "features": [
+          "layering", 
+          "striping"
+      ], 
+      "format": 2, 
+      "name": "test", 
+      "object_size": 1048576, 
+      "objects": 1, 
+      "order": 20, 
+      "size": 1048576
+  }
+  $ rbd rm test --no-progress
+  $ rbd create -s 1 test --rbd-default-format 2 --stripe-unit 1048576 --stripe-count 8
+  $ rbd info test --format json | python -mjson.tool
+  {
+      "block_name_prefix": "rbd_data.*",  (glob)
+      "features": [
+          "layering", 
+          "striping"
+      ], 
+      "format": 2, 
+      "name": "test", 
+      "object_size": 4194304, 
+      "objects": 1, 
+      "order": 22, 
+      "size": 1048576, 
+      "stripe_count": 8, 
+      "stripe_unit": 1048576
+  }
+  $ rbd rm test --no-progress