]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: run validator on all defaults
authorJohn Spray <john.spray@redhat.com>
Fri, 14 Jul 2017 00:34:42 +0000 (20:34 -0400)
committerJohn Spray <john.spray@redhat.com>
Fri, 21 Jul 2017 10:27:29 +0000 (06:27 -0400)
RBD relies on this behaviour to get the int-ized
form for rbd_default_features.

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

index 7ce4c82067d41dd8696c95bca2ba49fec251e0f8..39a48cae88451bc077554d3ab76d78c568766f96 100644 (file)
@@ -112,12 +112,32 @@ md_config_t::md_config_t(bool is_daemon)
 
   // Load default values from the schema
   for (const auto &i : schema) {
-    bool has_daemon_default = !boost::get<boost::blank>(&i.second.daemon_value);
+    const Option &opt = i.second;
+    bool has_daemon_default = !boost::get<boost::blank>(&opt.daemon_value);
+    Option::value_t default_val;
     if (is_daemon && has_daemon_default) {
-      values[i.first] = i.second.daemon_value;
+      default_val = opt.daemon_value;
     } else {
-      values[i.first] = i.second.value;
+      default_val = opt.value;
     }
+
+    if (opt.type == Option::TYPE_STR) {
+      // We call pre_validate as a sanity check, but also to get any
+      // side effect (value modification) from the validator.
+      std::string *def_str = boost::get<std::string>(&default_val);
+      std::string err;
+      if (opt.pre_validate(def_str, &err) != 0) {
+        std::cerr << "Default value " << opt.name << "=" << *def_str << " is "
+                     "invalid: " << err << std::endl;
+
+        // This is the compiled-in default that is failing its own option's
+        // validation, so this is super-invalid and should never make it
+        // past a pull request: crash out.
+        assert(false);
+      }
+    }
+
+    values[i.first] = default_val;
   }
 
   // Copy out values (defaults) into any legacy (C struct member) fields