From: John Spray Date: Fri, 14 Jul 2017 00:34:42 +0000 (-0400) Subject: common: run validator on all defaults X-Git-Tag: v12.1.2~192^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b0fbd7151c9196cd030b6f07e51612514915c942;p=ceph.git common: run validator on all defaults RBD relies on this behaviour to get the int-ized form for rbd_default_features. Signed-off-by: John Spray --- diff --git a/src/common/config.cc b/src/common/config.cc index 7ce4c82067d4..39a48cae8845 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -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(&i.second.daemon_value); + const Option &opt = i.second; + bool has_daemon_default = !boost::get(&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(&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