mirror of
https://github.com/ceph/ceph
synced 2024-12-29 15:03:33 +00:00
mon/ConfigMonitor: unify module options with built-in options
Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
parent
2b47f3db14
commit
ff09eb6715
@ -5,6 +5,7 @@
|
||||
|
||||
#include "mon/Monitor.h"
|
||||
#include "mon/ConfigMonitor.h"
|
||||
#include "mon/MgrMonitor.h"
|
||||
#include "mon/OSDMonitor.h"
|
||||
#include "messages/MConfig.h"
|
||||
#include "messages/MGetConfig.h"
|
||||
@ -152,20 +153,27 @@ bool ConfigMonitor::preprocess_command(MonOpRequestRef op)
|
||||
|
||||
bufferlist odata;
|
||||
if (prefix == "config help") {
|
||||
stringstream ss;
|
||||
string name;
|
||||
cmd_getval(g_ceph_context, cmdmap, "key", name);
|
||||
const Option *opt = g_conf().find_option(name);
|
||||
if (!opt) {
|
||||
opt = mon->mgrmon()->find_module_option(name);
|
||||
}
|
||||
if (opt) {
|
||||
if (f) {
|
||||
f->dump_object("option", *opt);
|
||||
} else {
|
||||
opt->print(&ss);
|
||||
}
|
||||
} else {
|
||||
ss << "configuration option '" << name << "' not recognized";
|
||||
err = -ENOENT;
|
||||
goto reply;
|
||||
}
|
||||
if (f) {
|
||||
f->dump_object("option", *opt);
|
||||
f->flush(odata);
|
||||
} else {
|
||||
stringstream ss;
|
||||
opt->print(&ss);
|
||||
odata.append(ss.str());
|
||||
}
|
||||
} else if (prefix == "config dump") {
|
||||
@ -261,6 +269,9 @@ bool ConfigMonitor::preprocess_command(MonOpRequestRef op)
|
||||
goto reply;
|
||||
}
|
||||
const Option *opt = g_conf().find_option(name);
|
||||
if (!opt) {
|
||||
opt = mon->mgrmon()->find_module_option(name);
|
||||
}
|
||||
if (!opt) {
|
||||
err = -ENOENT;
|
||||
goto reply;
|
||||
@ -410,21 +421,22 @@ bool ConfigMonitor::prepare_command(MonOpRequestRef op)
|
||||
cmd_getval(g_ceph_context, cmdmap, "value", value);
|
||||
|
||||
if (prefix == "config set") {
|
||||
if (name.substr(0, 4) != "mgr/") {
|
||||
const Option *opt = g_conf().find_option(name);
|
||||
if (!opt) {
|
||||
ss << "unrecognized config option '" << name << "'";
|
||||
err = -EINVAL;
|
||||
goto reply;
|
||||
}
|
||||
const Option *opt = g_conf().find_option(name);
|
||||
if (!opt) {
|
||||
opt = mon->mgrmon()->find_module_option(name);
|
||||
}
|
||||
if (!opt) {
|
||||
ss << "unrecognized config option '" << name << "'";
|
||||
err = -EINVAL;
|
||||
goto reply;
|
||||
}
|
||||
|
||||
Option::value_t real_value;
|
||||
string errstr;
|
||||
err = opt->parse_value(value, &real_value, &errstr, &value);
|
||||
if (err < 0) {
|
||||
ss << "error parsing value: " << errstr;
|
||||
goto reply;
|
||||
}
|
||||
Option::value_t real_value;
|
||||
string errstr;
|
||||
err = opt->parse_value(value, &real_value, &errstr, &value);
|
||||
if (err < 0) {
|
||||
ss << "error parsing value: " << errstr;
|
||||
goto reply;
|
||||
}
|
||||
}
|
||||
|
||||
@ -513,6 +525,9 @@ bool ConfigMonitor::prepare_command(MonOpRequestRef op)
|
||||
}
|
||||
// a known and worthy option?
|
||||
const Option *o = g_conf().find_option(j.key);
|
||||
if (!o) {
|
||||
o = mon->mgrmon()->find_module_option(j.key);
|
||||
}
|
||||
if (!o ||
|
||||
o->flags & Option::FLAG_NO_MON_UPDATE) {
|
||||
goto skip;
|
||||
@ -639,58 +654,48 @@ void ConfigMonitor::load_config()
|
||||
string who;
|
||||
if (last_slash == std::string::npos) {
|
||||
name = key;
|
||||
} else if (auto mgrpos = key.find("/mgr/"); mgrpos != std::string::npos) {
|
||||
name = key.substr(mgrpos + 1);
|
||||
who = key.substr(0, mgrpos);
|
||||
} else {
|
||||
name = key.substr(last_slash + 1);
|
||||
who = key.substr(0, last_slash);
|
||||
}
|
||||
|
||||
const Option *opt = g_conf().find_option(name);
|
||||
if (!opt) {
|
||||
opt = mon->mgrmon()->find_module_option(name);
|
||||
}
|
||||
if (!opt) {
|
||||
dout(10) << __func__ << " unrecognized option '" << name << "'" << dendl;
|
||||
opt = new Option(name, Option::TYPE_STR, Option::LEVEL_UNKNOWN);
|
||||
// FIXME: this will be leaked!
|
||||
}
|
||||
|
||||
string err;
|
||||
int r = opt->pre_validate(&value, &err);
|
||||
if (r < 0) {
|
||||
dout(10) << __func__ << " pre-validate failed on '" << name << "' = '"
|
||||
<< value << "' for " << name << dendl;
|
||||
}
|
||||
|
||||
MaskedOption mopt(opt);
|
||||
mopt.raw_value = value;
|
||||
string section_name;
|
||||
if (key.find("/mgr/") != std::string::npos) {
|
||||
// mgr module option, "something/mgr/foo"
|
||||
name = key.substr(key.find("/mgr/") + 1);
|
||||
MaskedOption mopt(new Option(name, Option::TYPE_STR,
|
||||
Option::LEVEL_UNKNOWN));
|
||||
mopt.raw_value = value;
|
||||
if (who.size() &&
|
||||
!ConfigMap::parse_mask(who, §ion_name, &mopt.mask)) {
|
||||
derr << __func__ << " ignoring key " << key << dendl;
|
||||
} else {
|
||||
Section *section = &config_map.global;;
|
||||
section_name = "mgr";
|
||||
if (section_name.find('.') != std::string::npos) {
|
||||
section = &config_map.by_id[section_name];
|
||||
} else {
|
||||
section = &config_map.by_type[section_name];
|
||||
if (section_name.size()) {
|
||||
if (section_name.find('.') != std::string::npos) {
|
||||
section = &config_map.by_id[section_name];
|
||||
} else {
|
||||
section = &config_map.by_type[section_name];
|
||||
}
|
||||
}
|
||||
section->options.insert(make_pair(name, std::move(mopt)));
|
||||
++num;
|
||||
} else {
|
||||
// normal option
|
||||
const Option *opt = g_conf().find_option(name);
|
||||
if (!opt) {
|
||||
dout(10) << __func__ << " unrecognized option '" << name << "'" << dendl;
|
||||
opt = new Option(name, Option::TYPE_STR, Option::LEVEL_UNKNOWN);
|
||||
}
|
||||
string err;
|
||||
int r = opt->pre_validate(&value, &err);
|
||||
if (r < 0) {
|
||||
dout(10) << __func__ << " pre-validate failed on '" << name << "' = '"
|
||||
<< value << "' for " << name << dendl;
|
||||
}
|
||||
|
||||
MaskedOption mopt(opt);
|
||||
mopt.raw_value = value;
|
||||
if (who.size() &&
|
||||
!ConfigMap::parse_mask(who, §ion_name, &mopt.mask)) {
|
||||
derr << __func__ << " ignoring key " << key << dendl;
|
||||
} else {
|
||||
Section *section = &config_map.global;;
|
||||
if (section_name.size()) {
|
||||
if (section_name.find('.') != std::string::npos) {
|
||||
section = &config_map.by_id[section_name];
|
||||
} else {
|
||||
section = &config_map.by_type[section_name];
|
||||
}
|
||||
}
|
||||
section->options.insert(make_pair(name, std::move(mopt)));
|
||||
++num;
|
||||
}
|
||||
++num;
|
||||
}
|
||||
it->next();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user