From: Ilya Dryomov Date: Thu, 12 Mar 2015 11:27:32 +0000 (+0300) Subject: rbd: add rbd default map options config option X-Git-Tag: v9.0.0~182^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=84adff4c743690b4293df6e1b328244ecb2cf949;p=ceph.git rbd: add rbd default map options config option 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 --- diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 29af1bd6b48a..83cb85db526d 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -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 diff --git a/src/rbd.cc b/src/rbd.cc index a53e8f4f2aa0..553255b6563b 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -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;