From: Sage Weil Date: Fri, 27 Apr 2012 04:51:23 +0000 (-0700) Subject: config: allow {get,set}_val on subsystem debug levels X-Git-Tag: v0.46~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4e2e87941b5f078eadf90a2c58a12765375ac66b;p=ceph.git config: allow {get,set}_val on subsystem debug levels This mimics the allows you to get and set subsystem debug levels via the normal config access methods. Among other things, this allows librados users to set debug levels. Fixes: #2350 Signed-off-by: Sage Weil --- diff --git a/src/common/config.cc b/src/common/config.cc index b904a8973e23..870b8bf977cf 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -591,6 +591,26 @@ int md_config_t::set_val(const char *key, const char *val) string k(ConfFile::normalize_key_name(key)); + // subsystems? + if (strncmp(k.c_str(), "debug_", 6) == 0) { + for (int o = 0; o < subsys.get_num(); o++) { + std::string as_option = "debug_" + subsys.get_name(o); + if (k == as_option) { + int log, gather; + int r = sscanf(v.c_str(), "%d/%d", &log, &gather); + if (r >= 1) { + if (r < 2) + gather = log; + // cout << "subsys " << subsys.get_name(o) << " log " << log << " gather " << gather << std::endl; + subsys.set_log_level(o, log); + subsys.set_gather_level(o, gather); + return 0; + } + return -EINVAL; + } + } + } + for (int i = 0; i < NUM_CONFIG_OPTIONS; ++i) { config_option *opt = &config_optionsp[i]; if (strcmp(opt->name, k.c_str()) == 0) { @@ -681,6 +701,20 @@ int md_config_t::_get_val(const char *key, char **buf, int len) const snprintf(*buf, len, "%s", str.c_str()); return (l > len) ? -ENAMETOOLONG : 0; } + + // subsys? + for (int o = 0; o < subsys.get_num(); o++) { + std::string as_option = "debug_" + subsys.get_name(o); + if (k == as_option) { + if (len == -1) { + *buf = (char*)malloc(20); + len = 20; + } + int l = snprintf(*buf, len, "%d/%d", subsys.get_log_level(o), subsys.get_gather_level(o)); + return (l == len) ? -ENAMETOOLONG : 0; + } + } + // couldn't find a configuration option with key 'k' return -ENOENT; } diff --git a/src/log/SubsystemMap.h b/src/log/SubsystemMap.h index af1430dca0c7..31233e0e1c62 100644 --- a/src/log/SubsystemMap.h +++ b/src/log/SubsystemMap.h @@ -52,19 +52,19 @@ public: m_subsys[subsys].gather_level = gather; } - int get_log_level(unsigned subsys) { + int get_log_level(unsigned subsys) const { if (subsys >= m_subsys.size()) subsys = 0; return m_subsys[subsys].log_level; } - int get_gather_level(unsigned subsys) { + int get_gather_level(unsigned subsys) const { if (subsys >= m_subsys.size()) subsys = 0; return m_subsys[subsys].gather_level; } - const string& get_name(unsigned subsys) { + const string& get_name(unsigned subsys) const { if (subsys >= m_subsys.size()) subsys = 0; return m_subsys[subsys].name;