From c047175b095c2d5b39c309aac0ff2a01c76dc9ba Mon Sep 17 00:00:00 2001 From: oliveiradan Date: Thu, 10 Nov 2016 15:14:24 -0700 Subject: [PATCH] common/ceph_context: config diff get option refactored Signed-off-by: Daniel Oliveira --- src/common/ceph_context.cc | 3 +- src/common/config.cc | 72 ++++++++++++++++---------------------- src/common/config.h | 15 +++++--- 3 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 43b88d8f1b85..05842ee6b78f 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -510,7 +510,8 @@ void CephContext::do_command(std::string command, cmdmap_t& cmdmap, def_conf.apply_changes(NULL); map> diff; - def_conf.diff_setting(_conf, &diff, ceph_setting, true); + set unknown; + def_conf.diff(_conf, &diff, &unknown, ceph_setting); f->open_object_section("diff"); f->open_object_section("current"); diff --git a/src/common/config.cc b/src/common/config.cc index 1f3c8630c76b..2a91e0d947dc 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -1342,21 +1342,45 @@ bool md_config_t::expand_meta(std::string &origval, } void md_config_t::diff( + const md_config_t *other, + map > *diff, + set *unknown) +{ + diff_helper(other, diff, unknown, ""); +} +void md_config_t::diff( + const md_config_t *other, + map > *diff, + set *unknown, const string& ceph_setting = string("")) +{ + diff_helper(other, diff, unknown, ceph_setting); +} + +void md_config_t::diff_helper( const md_config_t *other, map > *diff, - set *unknown) + set *unknown, const string& ceph_setting=string("")) { Mutex::Locker l(lock); + bool ceph_param_search = !ceph_setting.empty(); char local_buf[4096]; char other_buf[4096]; for (auto& opt: *config_options) { + if (ceph_param_search) { + if (ceph_setting != opt.name) { + continue; + } + } 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 (ceph_param_search) { + continue; + } if (err == -ENOENT) { unknown->insert(opt.name); } @@ -1370,48 +1394,14 @@ void md_config_t::diff( if (strcmp(local_val, other_val)) diff->insert(make_pair(opt.name, make_pair(local_val, other_val))); - } -} - -void md_config_t::diff_setting(const md_config_t *other, - map> *diff, - const string& ceph_setting, bool show_unchanged) -{ - 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]; - std::string ceph_setting_name(opt->name); - if (ceph_setting != opt->name) { - continue; - } - 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) { - 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(ceph_setting, make_pair(local_val, other_val))); - } else { - if (show_unchanged) { - diff->insert(make_pair(ceph_setting, make_pair(local_val, other_val))); + if (ceph_param_search) { + diff->insert(make_pair(opt.name, make_pair(local_val, other_val))); + break; } - } - break; - } -} + } + } +} void md_config_t::complain_about_parse_errors(CephContext *cct) { diff --git a/src/common/config.h b/src/common/config.h index ea4ce47b3052..2590c47c80c4 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -235,15 +235,15 @@ 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 + /// obtain a diff between our config values and another md_config_t values void diff(const md_config_t *other, map > *diff, set *unknown); - /// obtain a diff between config values and another md_config_t + /// obtain a diff between config values and another md_config_t /// values for a specific setting. - void diff_setting(const md_config_t*, - std::map>*, - const std::string&, bool show_unchanged = false); + void diff(const md_config_t *other, + map> *diff, set *unknown, + const string& ceph_setting); /// print/log warnings/errors from parsing the config void complain_about_parse_errors(CephContext *cct); @@ -276,6 +276,11 @@ private: bool expand_meta(std::string &val, std::ostream *oss) const; + + void diff_helper(const md_config_t *other, + map> *diff, + set *unknown, const string &ceph_setting); + public: // for global_init bool early_expand_meta(std::string &val, std::ostream *oss) const { -- 2.47.3