summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage.weil@dreamhost.com>2012-04-26 21:51:23 -0700
committerSage Weil <sage.weil@dreamhost.com>2012-04-26 21:52:23 -0700
commit4e2e87941b5f078eadf90a2c58a12765375ac66b (patch)
tree70db8df2266c5cfd482a777d01ab0eae07a73aa3
parent8f4dba62f8c725a5b07ed98b735b47dc8b7d0026 (diff)
downloadceph-4e2e87941b5f078eadf90a2c58a12765375ac66b.tar.gz
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 <sage.weil@dreamhost.com>
-rw-r--r--src/common/config.cc34
-rw-r--r--src/log/SubsystemMap.h6
2 files changed, 37 insertions, 3 deletions
diff --git a/src/common/config.cc b/src/common/config.cc
index b904a8973e2..870b8bf977c 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 af1430dca0c..31233e0e1c6 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;