From: Joao Eduardo Luis Date: Sun, 24 Aug 2014 16:20:53 +0000 (+0100) Subject: common: config: let us obtain a diff between current and default config X-Git-Tag: v0.86~205^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ef51160b4f54cfd101aa2ff4117588c0dac5a2c9;p=ceph.git common: config: let us obtain a diff between current and default config 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 --- diff --git a/src/common/config.cc b/src/common/config.cc index dcb84b5f70f..068fe8349cd 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -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 > *diff, + set *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() { diff --git a/src/common/config.h b/src/common/config.h index 99115430931..d4a84becca8 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -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 > *diff, set *unknown); + private: void _show_config(std::ostream *out, Formatter *f);