]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: add rbd default map options config option
authorIlya Dryomov <idryomov@gmail.com>
Thu, 12 Mar 2015 11:27:32 +0000 (14:27 +0300)
committerIlya Dryomov <idryomov@gmail.com>
Thu, 12 Mar 2015 11:27:32 +0000 (14:27 +0300)
Allow supplying rbd map -o / --options through 'rbd default map
options' config option.  Options specified on the command line take
precedence on a per-option basis, i.e. default and cli options are
merged with a preference for the latter.  For example:

    # grep 'rbd default map options' ceph.conf
            rbd default map options = "ro,nocrc"
    # ./rbd map -o noshare,rw foo
    /dev/rbd0

results in a rw mapping with nocrc,noshare.

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
src/common/config_opts.h
src/rbd.cc

index 29af1bd6b48a6c9ee3b950a7af13deaec829b159..83cb85db526d28638a2a58e269e1055d7be3f2d7 100644 (file)
@@ -900,6 +900,8 @@ 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
 
+OPTION(rbd_default_map_options, OPT_STR, "") // default rbd map -o / --options
+
 OPTION(nss_db_path, OPT_STR, "") // path to nss db
 
 
index a53e8f4f2aa0d0cb3b3120c8bcccafa45091a792..553255b6563b7418fbd2b3fd6bc4792edcae65ce 100644 (file)
@@ -2590,6 +2590,7 @@ int main(int argc, const char **argv)
     *lock_tag = NULL, *output_format = "plain",
     *fromsnapname = NULL,
     *first_diff = NULL, *second_diff = NULL;
+  char *cli_map_options = NULL;
   bool lflag = false;
   int pretty_format = 0;
   long long stripe_unit = 0, stripe_count = 0;
@@ -2674,11 +2675,7 @@ int main(int argc, const char **argv)
     } else if (ceph_argparse_flag(args, i, "--no-settle", (char *)NULL)) {
       cerr << "rbd: --no-settle is deprecated" << std::endl;
     } else if (ceph_argparse_witharg(args, i, &val, "-o", "--options", (char*)NULL)) {
-      char *map_options = strdup(val.c_str());
-      if (parse_map_options(map_options)) {
-        cerr << "rbd: couldn't parse map options" << std::endl;
-        return EXIT_FAILURE;
-      }
+      cli_map_options = strdup(val.c_str());
     } else if (ceph_argparse_flag(args, i, "--read-only", (char *)NULL)) {
       // --read-only is equivalent to -o ro
       put_map_option("rw", "ro");
@@ -2910,6 +2907,20 @@ if (!set_conf_param(v, p1, p2, p3)) { \
     return EXIT_FAILURE;
   }
 
+  if (opt_cmd == OPT_MAP) {
+    char *default_map_options = strdup(g_conf->rbd_default_map_options.c_str());
+
+    // parse default options first so they can be overwritten by cli options
+    if (parse_map_options(default_map_options)) {
+      cerr << "rbd: couldn't parse default map options" << std::endl;
+      return EXIT_FAILURE;
+    }
+    if (cli_map_options && parse_map_options(cli_map_options)) {
+      cerr << "rbd: couldn't parse map options" << std::endl;
+      return EXIT_FAILURE;
+    }
+  }
+
   if (opt_cmd == OPT_UNMAP && !devpath) {
     cerr << "rbd: device path was not specified" << std::endl;
     return EXIT_FAILURE;