]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
config: allow {get,set}_val on subsystem debug levels
authorSage Weil <sage.weil@dreamhost.com>
Fri, 27 Apr 2012 04:51:23 +0000 (21:51 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Fri, 27 Apr 2012 04:52:23 +0000 (21:52 -0700)
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>
src/common/config.cc
src/log/SubsystemMap.h

index b904a8973e2350163491893a2c2af17b0bdf605e..870b8bf977cfe7ef5e3ba0d744b074b25efd3a6f 100644 (file)
@@ -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;
 }
index af1430dca0c7dc2f185c006f0324706f0e2e61b5..31233e0e1c622b4b2ff79c1e764f82ec3cf70710 100644 (file)
@@ -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;