]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: pass up error strings from set_val
authorJohn Spray <john.spray@redhat.com>
Wed, 12 Jul 2017 12:49:43 +0000 (08:49 -0400)
committerJohn Spray <john.spray@redhat.com>
Fri, 21 Jul 2017 10:27:26 +0000 (06:27 -0400)
This is so that we can use it as a replacment
for the ugly injectargs.

Signed-off-by: John Spray <john.spray@redhat.com>
src/common/config.cc
src/common/config.h

index 12f21ea7db6c18e87f6812f8dd5731a15440b91d..4b720f355bdf50f912699260e0731cc653c57878 100644 (file)
@@ -751,13 +751,17 @@ void md_config_t::set_val_or_die(const std::string &key, const char *val)
   assert(ret == 0);
 }
 
-int md_config_t::set_val(const std::string &key, const char *val, bool meta)
+int md_config_t::set_val(const std::string &key, const char *val,
+    bool meta, std::stringstream *err_ss)
 {
   Mutex::Locker l(lock);
-  if (key.empty())
+  if (key.empty()) {
+    if (err_ss) *err_ss << "No key specified";
     return -EINVAL;
-  if (!val)
+  }
+  if (!val) {
     return -EINVAL;
+  }
 
   std::string v(val);
   if (meta)
@@ -773,13 +777,17 @@ int md_config_t::set_val(const std::string &key, const char *val, bool meta)
        int log, gather;
        int r = sscanf(v.c_str(), "%d/%d", &log, &gather);
        if (r >= 1) {
-         if (r < 2)
+         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);
+          if (err_ss) *err_ss << "Set " << k << " to " << log << "/" << gather;
          return 0;
        }
+        if (err_ss) {
+          *err_ss << "Invalid debug level, should be <int> or <int>/<int>";
+        }
        return -EINVAL;
       }
     }  
@@ -793,15 +801,23 @@ int md_config_t::set_val(const std::string &key, const char *val, bool meta)
       if (observers.find(opt.name) == observers.end()) {
         // And there is no observer to safely change it...
         // You lose.
+        if (err_ss) *err_ss << "Configuration option '" << key << "' may "
+                    "not be modified at runtime";
         return -ENOSYS;
       }
     }
 
     std::string error_message;
-    return set_val_impl(v, opt, &error_message);
+    int r = set_val_impl(v, opt, &error_message);
+    if (r == 0) {
+      if (err_ss) *err_ss << "Set " << opt.name << " to " << v;
+    } else {
+      if (err_ss) *err_ss << error_message;
+    }
+    return r;
   }
 
-  // couldn't find a configuration option with key 'key'
+  if (err_ss) *err_ss << "Configuration option not found: '" << key << "'";
   return -ENOENT;
 }
 
index cb5a9a4e91c1c665c2b7b059abd59fed01f0c503..e12228a2b27b8ee86054891db5911148f3c1dad4 100644 (file)
@@ -148,9 +148,11 @@ public:
 
   // Set a configuration value.
   // Metavariables will be expanded.
-  int set_val(const std::string &key, const char *val, bool meta=true);
-  int set_val(const std::string &key, const string& s, bool meta=true) {
-    return set_val(key, s.c_str(), meta);
+  int set_val(const std::string &key, const char *val, bool meta=true,
+              std::stringstream *err_ss=nullptr);
+  int set_val(const std::string &key, const string& s, bool meta=true,
+              std::stringstream *err_ss=nullptr) {
+    return set_val(key, s.c_str(), meta, err_ss);
   }
 
   // Get a configuration value.