From 846f1041dbbda75375f56af61abcc86615c4af15 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 6 Jan 2018 11:25:47 -0600 Subject: [PATCH] global/global_init: make --show-config and --show-config-val reflect mon configs Pull down all configs, including both argv and mon, before we do the --show-config[-val] step. Signed-off-by: Sage Weil --- src/common/config.cc | 27 +++++++++++++-------------- src/common/config.h | 6 ++++++ src/global/global_init.cc | 3 +++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/common/config.cc b/src/common/config.cc index f31b3631ba924..6d770ccb69165 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -521,10 +521,6 @@ int md_config_t::parse_argv(std::vector& args) return -ENOSYS; } - bool show_config = false; - bool show_config_value = false; - string show_config_value_arg; - // In this function, don't change any parts of the configuration directly. // Instead, use set_val to set them. This will allow us to send the proper // observer notifications later. @@ -541,11 +537,10 @@ int md_config_t::parse_argv(std::vector& args) _exit(0); } else if (ceph_argparse_flag(args, i, "--show_config", (char*)NULL)) { - show_config = true; + do_show_config = true; } else if (ceph_argparse_witharg(args, i, &val, "--show_config_value", (char*)NULL)) { - show_config_value = true; - show_config_value_arg = val; + do_show_config_value = val; } else if (ceph_argparse_flag(args, i, "--foreground", "-f", (char*)NULL)) { set_val_or_die("daemonize", "false"); @@ -585,30 +580,34 @@ int md_config_t::parse_argv(std::vector& args) } } } + return 0; +} + +void md_config_t::do_argv_commands() +{ + Mutex::Locker l(lock); - if (show_config) { + if (do_show_config) { _show_config(&cout, NULL); _exit(0); } - if (show_config_value) { + if (do_show_config_value.size()) { string val; - int r = conf_stringify(_get_val(show_config_value_arg), &val); + int r = conf_stringify(_get_val(do_show_config_value), &val); if (r < 0) { if (r == -ENOENT) std::cerr << "failed to get config option '" - << show_config_value_arg << "': option not found" << std::endl; + << do_show_config_value << "': option not found" << std::endl; else std::cerr << "failed to get config option '" - << show_config_value_arg << "': " << cpp_strerror(r) + << do_show_config_value << "': " << cpp_strerror(r) << std::endl; _exit(1); } std::cout << val << std::endl; _exit(0); } - - return 0; } int md_config_t::parse_option(std::vector& args, diff --git a/src/common/config.h b/src/common/config.h index b9eba5cde40fa..201b3600f904b 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -145,6 +145,9 @@ public: // Absorb config settings from argv int parse_argv(std::vector& args); + // do any commands we got from argv (--show-config, --show-config-val) + void do_argv_commands(); + // Expand all metavariables. Make any pending observer callbacks. void apply_changes(std::ostream *oss); void _apply_changes(std::ostream *oss); @@ -301,6 +304,9 @@ private: // Once it is true, it will never change. bool safe_to_start_threads = false; + bool do_show_config = false; + string do_show_config_value; + obs_map_t observers; changed_set_t changed; diff --git a/src/global/global_init.cc b/src/global/global_init.cc index 716104c71f80d..ea454b11f1be5 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -147,6 +147,9 @@ void global_pre_init( } } + // do the --show-config[-val], if present in argv + conf->do_argv_commands(); + // Now we're ready to complain about config file parse errors g_conf->complain_about_parse_errors(g_ceph_context); } -- 2.39.5