]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: evaluate --show-config* after CEPH_ARGS 1019/head
authorLoic Dachary <loic@dachary.org>
Mon, 30 Dec 2013 09:30:51 +0000 (10:30 +0100)
committerLoic Dachary <loic@dachary.org>
Mon, 30 Dec 2013 10:12:41 +0000 (11:12 +0100)
The content of CEPH_ARGS is appended to the list of arguments. When
--show-config or --show-config-value is also set, it should be evaluated
after all arguments are parsed to accurately reflect the value that
would be visible to the program.

It failed to do so because the action for --show-config* was carried out
immediately. It is postponed until all options are parsed instead.

Signed-off-by: Loic Dachary <loic@dachary.org>
src/common/config.cc
src/test/cli/ceph-conf/show-config-value.t
src/test/cli/ceph-conf/show-config.t [new file with mode: 0644]

index 5c64f4ec1517c242bf3bf9a1d303f06fe94890e2..50923956cc14f1a1f87fbe562f4879076dbd6c6a 100644 (file)
@@ -357,6 +357,10 @@ 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.
@@ -373,24 +377,11 @@ int md_config_t::parse_argv(std::vector<const char*>& args)
       _exit(0);
     }
     else if (ceph_argparse_flag(args, i, "--show_config", (char*)NULL)) {
-      expand_all_meta();
-      _show_config(&cout, NULL);
-      _exit(0);
+      show_config = true;
     }
     else if (ceph_argparse_witharg(args, i, &val, "--show_config_value", (char*)NULL)) {
-      char *buf = 0;
-      int r = _get_val(val.c_str(), &buf, -1);
-      if (r < 0) {
-       if (r == -ENOENT)
-         std::cerr << "failed to get config option '" << val << "': option not found" << std::endl;
-       else
-         std::cerr << "failed to get config option '" << val << "': " << strerror(-r) << std::endl;
-       _exit(1);
-      }
-      string s = buf;
-      expand_meta(s);
-      std::cout << s << std::endl;
-      _exit(0);
+      show_config_value = true;
+      show_config_value_arg = val;
     }
     else if (ceph_argparse_flag(args, i, "--foreground", "-f", (char*)NULL)) {
       set_val_or_die("daemonize", "false");
@@ -429,6 +420,31 @@ int md_config_t::parse_argv(std::vector<const char*>& args)
       parse_option(args, i, NULL);
     }
   }
+
+  if (show_config) {
+    expand_all_meta();
+    _show_config(&cout, NULL);
+    _exit(0);
+  }
+
+  if (show_config_value) {
+    char *buf = 0;
+    int r = _get_val(show_config_value_arg.c_str(), &buf, -1);
+    if (r < 0) {
+      if (r == -ENOENT)
+       std::cerr << "failed to get config option '" <<
+         show_config_value_arg << "': option not found" << std::endl;
+      else
+       std::cerr << "failed to get config option '" <<
+         show_config_value_arg << "': " << strerror(-r) << std::endl;
+      _exit(1);
+    }
+    string s = buf;
+    expand_meta(s);
+    std::cout << s << std::endl;
+    _exit(0);
+  }
+
   return 0;
 }
 
index 03d7ed8e0863e1884125b05ce368bde697a8c286..3d7d319416ce9219233cd973e2304c90a4fc378f 100644 (file)
@@ -3,3 +3,8 @@
 
   $ ceph-conf -n osd.0 --show-config-value log_file -c /dev/null
   /var/log/ceph/ceph-osd.0.log
+  $ CEPH_ARGS="--fsid 96a3abe6-7552-4635-a79b-f3c096ff8b95" ceph-conf -n osd.0 --show-config-value fsid -c /dev/null
+  96a3abe6-7552-4635-a79b-f3c096ff8b95
+  $ ceph-conf -n osd.0 --show-config-value INVALID -c /dev/null
+  failed to get config option 'INVALID': option not found
+  [1]
diff --git a/src/test/cli/ceph-conf/show-config.t b/src/test/cli/ceph-conf/show-config.t
new file mode 100644 (file)
index 0000000..cfd7239
--- /dev/null
@@ -0,0 +1,6 @@
+  $ ceph-conf -n osd.0 --show-config -c /dev/null | grep ceph-osd
+  admin_socket = /var/run/ceph/ceph-osd.0.asok
+  log_file = /var/log/ceph/ceph-osd.0.log
+  mon_debug_dump_location = /var/log/ceph/ceph-osd.0.tdump
+  $ CEPH_ARGS="--fsid 96a3abe6-7552-4635-a79b-f3c096ff8b95" ceph-conf -n osd.0 --show-config -c /dev/null | grep fsid
+  fsid = 96a3abe6-7552-4635-a79b-f3c096ff8b95