Merge pull request #1019 from dachary/wip-show-config-value

common: evaluate --show-config* after CEPH_ARGS

Reviewed-by: Sage Weil <sage@inktank.com>
This commit is contained in:
Sage Weil 2013-12-30 08:12:18 -08:00
commit 85edc9f695
3 changed files with 43 additions and 16 deletions

View File

@ -357,6 +357,10 @@ int md_config_t::parse_argv(std::vector<const char*>& args)
return -ENOSYS;
}
bool show_config = false;
bool show_config_value = false;
string show_config_value_arg;
// In this function, don't change any parts of the configuration directly.
// Instead, use set_val to set them. This will allow us to send the proper
// observer notifications later.
@ -373,24 +377,11 @@ int md_config_t::parse_argv(std::vector<const char*>& args)
_exit(0);
}
else if (ceph_argparse_flag(args, i, "--show_config", (char*)NULL)) {
expand_all_meta();
_show_config(&cout, NULL);
_exit(0);
show_config = true;
}
else if (ceph_argparse_witharg(args, i, &val, "--show_config_value", (char*)NULL)) {
char *buf = 0;
int r = _get_val(val.c_str(), &buf, -1);
if (r < 0) {
if (r == -ENOENT)
std::cerr << "failed to get config option '" << val << "': option not found" << std::endl;
else
std::cerr << "failed to get config option '" << val << "': " << strerror(-r) << std::endl;
_exit(1);
}
string s = buf;
expand_meta(s);
std::cout << s << std::endl;
_exit(0);
show_config_value = true;
show_config_value_arg = val;
}
else if (ceph_argparse_flag(args, i, "--foreground", "-f", (char*)NULL)) {
set_val_or_die("daemonize", "false");
@ -429,6 +420,31 @@ int md_config_t::parse_argv(std::vector<const char*>& args)
parse_option(args, i, NULL);
}
}
if (show_config) {
expand_all_meta();
_show_config(&cout, NULL);
_exit(0);
}
if (show_config_value) {
char *buf = 0;
int r = _get_val(show_config_value_arg.c_str(), &buf, -1);
if (r < 0) {
if (r == -ENOENT)
std::cerr << "failed to get config option '" <<
show_config_value_arg << "': option not found" << std::endl;
else
std::cerr << "failed to get config option '" <<
show_config_value_arg << "': " << strerror(-r) << std::endl;
_exit(1);
}
string s = buf;
expand_meta(s);
std::cout << s << std::endl;
_exit(0);
}
return 0;
}

View File

@ -3,3 +3,8 @@
$ ceph-conf -n osd.0 --show-config-value log_file -c /dev/null
/var/log/ceph/ceph-osd.0.log
$ CEPH_ARGS="--fsid 96a3abe6-7552-4635-a79b-f3c096ff8b95" ceph-conf -n osd.0 --show-config-value fsid -c /dev/null
96a3abe6-7552-4635-a79b-f3c096ff8b95
$ ceph-conf -n osd.0 --show-config-value INVALID -c /dev/null
failed to get config option 'INVALID': option not found
[1]

View File

@ -0,0 +1,6 @@
$ ceph-conf -n osd.0 --show-config -c /dev/null | grep ceph-osd
admin_socket = /var/run/ceph/ceph-osd.0.asok
log_file = /var/log/ceph/ceph-osd.0.log
mon_debug_dump_location = /var/log/ceph/ceph-osd.0.tdump
$ CEPH_ARGS="--fsid 96a3abe6-7552-4635-a79b-f3c096ff8b95" ceph-conf -n osd.0 --show-config -c /dev/null | grep fsid
fsid = 96a3abe6-7552-4635-a79b-f3c096ff8b95