Skip to content

Commit

Permalink
mon: add osd info to obtain info on specific osd
Browse files Browse the repository at this point in the history
Signed-off-by: Joao Eduardo Luis <[email protected]>
  • Loading branch information
jecluis authored and Joao Eduardo Luis committed Jul 15, 2019
1 parent d8b0896 commit 85d5e29
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
25 changes: 25 additions & 0 deletions qa/workunits/cephtool/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,31 @@ function test_mon_osd()
ceph osd dump | grep 'osd.0.*in'
ceph osd find 0

ceph osd info 0
ceph osd info osd.0
expect_false ceph osd info osd.xyz
expect_false ceph osd info xyz
expect_false ceph osd info 42
expect_false ceph osd info osd.42

ceph osd info
info_json=$(ceph osd info --format=json | jq -cM '.')
dump_json=$(ceph osd dump --format=json | jq -cM '.osds')
[[ "${info_json}" == "${dump_json}" ]]

info_json=$(ceph osd info 0 --format=json | jq -cM '.')
dump_json=$(ceph osd dump --format=json | \
jq -cM '.osds[] | select(.osd == 0)')
[[ "${info_json}" == "${dump_json}" ]]

info_plain="$(ceph osd info)"
dump_plain="$(ceph osd dump | grep '^osd')"
[[ "${info_plain}" == "${dump_plain}" ]]

info_plain="$(ceph osd info 0)"
dump_plain="$(ceph osd dump | grep '^osd.0')"
[[ "${info_plain}" == "${dump_plain}" ]]

ceph osd add-nodown 0 1
ceph health detail | grep 'NODOWN'
ceph osd rm-nodown 0 1
Expand Down
4 changes: 4 additions & 0 deletions src/mon/MonCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,10 @@ COMMAND("osd stat", "print summary of OSD map", "osd", "r")
COMMAND("osd dump " \
"name=epoch,type=CephInt,range=0,req=false",
"print summary of OSD map", "osd", "r")
COMMAND("osd info " \
"name=id,type=CephOsdName,req=false",
"print osd's {id} information (instead of all osds from map)",
"osd", "r")
COMMAND("osd tree " \
"name=epoch,type=CephInt,range=0,req=false " \
"name=states,type=CephChoices,strings=up|down|in|out|destroyed,n=N,req=false", \
Expand Down
31 changes: 30 additions & 1 deletion src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4822,7 +4822,8 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op)
prefix == "osd ls" ||
prefix == "osd getmap" ||
prefix == "osd getcrushmap" ||
prefix == "osd ls-tree") {
prefix == "osd ls-tree" ||
prefix == "osd info") {
string val;

epoch_t epoch = 0;
Expand Down Expand Up @@ -4889,6 +4890,34 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op)
}
}
rdata.append(ds);
} else if (prefix == "osd info") {
int64_t osd_id;
bool do_single_osd = true;
if (!cmd_getval(cct, cmdmap, "id", osd_id)) {
do_single_osd = false;
}

if (do_single_osd && !osdmap.exists(osd_id)) {
ss << "osd." << osd_id << " does not exist";
r = -EINVAL;
goto reply;
}

if (f) {
if (do_single_osd) {
osdmap.dump_osd(osd_id, f.get());
} else {
osdmap.dump_osds(f.get());
}
f->flush(ds);
} else {
if (do_single_osd) {
osdmap.print_osd(osd_id, ds);
} else {
osdmap.print_osds(ds);
}
}
rdata.append(ds);
} else if (prefix == "osd tree" || prefix == "osd tree-from") {
string bucket;
if (prefix == "osd tree-from") {
Expand Down

0 comments on commit 85d5e29

Please sign in to comment.