]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
global/global_init: make --show-config and --show-config-val reflect mon configs
authorSage Weil <sage@redhat.com>
Sat, 6 Jan 2018 17:25:47 +0000 (11:25 -0600)
committerSage Weil <sage@redhat.com>
Tue, 6 Mar 2018 20:44:49 +0000 (14:44 -0600)
Pull down all configs, including both argv and mon, before we do the
--show-config[-val] step.

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/config.cc
src/common/config.h
src/global/global_init.cc

index f31b3631ba924df93dfac8371e8cc46b00912009..6d770ccb69165e92f4866ef7452b1bf68091a8ab 100644 (file)
@@ -521,10 +521,6 @@ int md_config_t::parse_argv(std::vector<const char*>& 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<const char*>& 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<const char*>& 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<const char*>& args,
index b9eba5cde40fab7fde8e5c5f86abf1fabc0b2163..201b3600f904b489f4bfa6f4167d7c0a380242e5 100644 (file)
@@ -145,6 +145,9 @@ public:
   // Absorb config settings from argv
   int parse_argv(std::vector<const char*>& 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;
 
index 716104c71f80d9d7b06224f1abd30df39da744ea..ea454b11f1be562e30d0ac55a036cf50f6866e5a 100644 (file)
@@ -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);
 }