]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: config: let us obtain a diff between current and default config
authorJoao Eduardo Luis <joao.luis@inktank.com>
Sun, 24 Aug 2014 16:20:53 +0000 (17:20 +0100)
committerJoao Eduardo Luis <joao.luis@inktank.com>
Tue, 26 Aug 2014 22:31:37 +0000 (23:31 +0100)
It's mildly annoying when trying to figure out what has been changed on
a running system's config options and having to rely on whatever is set
on ceph.conf and the admin's memory of what has been injected.

With this we can simply ask the daemon for the diff between what would be
its default and what is its current config.

Current form will output extraneous information that was not directly
supplied by the user though, such as 'host' 'fsid' and 'daemonize', as
well as defaults we may rewrite ourselves (leveldb tunables on the monitor
for instance).  Nonetheless, it's way better than the alternative and
considering it should be used solely for debug purposes I think we can
get away with it.

Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/common/config.cc
src/common/config.h

index dcb84b5f70fc617d7833ac7e324fe2ee99845652..068fe8349cd1a0c20670b075d9bf333b7216f2b8 100644 (file)
@@ -1100,6 +1100,39 @@ bool md_config_t::expand_meta(std::string &origval,
   return found_meta;
 }
 
+void md_config_t::diff(
+    const md_config_t *other,
+    map<string,pair<string,string> > *diff,
+    set<string> *unknown)
+{
+  Mutex::Locker l(lock);
+
+  char local_buf[4096];
+  char other_buf[4096];
+  for (int i = 0; i < NUM_CONFIG_OPTIONS; i++) {
+    config_option *opt = &config_optionsp[i];
+    memset(local_buf, 0, sizeof(local_buf));
+    memset(other_buf, 0, sizeof(other_buf));
+
+    char *other_val = other_buf;
+    int err = other->get_val(opt->name, &other_val, sizeof(other_buf));
+    if (err < 0) {
+      if (err == -ENOENT) {
+        unknown->insert(opt->name);
+      }
+      continue;
+    }
+
+    char *local_val = local_buf;
+    err = _get_val(opt->name, &local_val, sizeof(local_buf));
+    if (err != 0)
+      continue;
+
+    if (strcmp(local_val, other_val))
+      diff->insert(make_pair(opt->name, make_pair(local_val, other_val)));
+  }
+}
+
 md_config_obs_t::
 ~md_config_obs_t()
 {
index 99115430931c15442897b178ada1e48b4574f7ad..d4a84becca8684e4da7725be4e6a090d2220a240 100644 (file)
@@ -156,6 +156,10 @@ public:
   /// dump all config values to a formatter
   void show_config(Formatter *f);
 
+  /// obtain a diff between our config values and another md_config_t values
+  void diff(const md_config_t *other,
+            map<string,pair<string,string> > *diff, set<string> *unknown);
+
 private:
   void _show_config(std::ostream *out, Formatter *f);