Mon: Make ceph osd metadata support dump all osds

Impl #12801
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
This commit is contained in:
Haomai Wang 2015-08-29 22:45:41 +08:00
parent 128f5a2504
commit 7841455ca6
4 changed files with 29 additions and 12 deletions

View File

@ -829,7 +829,7 @@ Subcommand ``metadata`` fetches metadata for osd <id>.
Usage::
ceph osd metadata <int[0-]>
ceph osd metadata {int[0-]} (default all)
Subcommand ``out`` sets osd(s) <id> [<id>...] out.

View File

@ -435,8 +435,8 @@ COMMAND("osd find " \
"find osd <id> in the CRUSH map and show its location", \
"osd", "r", "cli,rest")
COMMAND("osd metadata " \
"name=id,type=CephInt,range=0", \
"fetch metadata for osd <id>", \
"name=id,type=CephInt,range=0,req=false", \
"fetch metadata for osd {id} (default all)", \
"osd", "r", "cli,rest")
COMMAND("osd map " \
"name=pool,type=CephPoolname " \

View File

@ -3058,14 +3058,15 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op)
f->close_section();
f->flush(rdata);
} else if (prefix == "osd metadata") {
int64_t osd;
if (!cmd_getval(g_ceph_context, cmdmap, "id", osd)) {
int64_t osd = -1;
if (cmd_vartype_stringify(cmdmap["id"]).size() &&
!cmd_getval(g_ceph_context, cmdmap, "id", osd)) {
ss << "unable to parse osd id value '"
<< cmd_vartype_stringify(cmdmap["id"]) << "'";
r = -EINVAL;
goto reply;
}
if (!osdmap.exists(osd)) {
if (osd >= 0 && !osdmap.exists(osd)) {
ss << "osd." << osd << " does not exist";
r = -ENOENT;
goto reply;
@ -3073,11 +3074,27 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op)
string format;
cmd_getval(g_ceph_context, cmdmap, "format", format);
boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty"));
f->open_object_section("osd_metadata");
r = dump_osd_metadata(osd, f.get(), &ss);
if (r < 0)
goto reply;
f->close_section();
if (osd >= 0) {
f->open_object_section("osd_metadata");
f->dump_unsigned("id", osd);
r = dump_osd_metadata(osd, f.get(), &ss);
if (r < 0)
goto reply;
f->close_section();
} else {
f->open_array_section("osd_metadata");
for (int i=0; i<osdmap.get_max_osd(); ++i) {
if (osdmap.exists(i)) {
f->open_object_section("osd");
f->dump_unsigned("id", i);
r = dump_osd_metadata(i, f.get(), NULL);
if (r < 0)
goto reply;
f->close_section();
}
}
f->close_section();
}
f->flush(rdata);
} else if (prefix == "osd map") {
string poolstr, objstr, namespacestr;

View File

@ -552,7 +552,7 @@ class TestOSD(TestArgparse):
'toomany']))
def test_metadata(self):
self.check_1_natural_arg('osd', 'metadata')
self.check_0_or_1_natural_arg('osd', 'metadata')
def test_scrub(self):
self.check_1_string_arg('osd', 'scrub')