Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mon/OSDMonitor: implement 'osd crush ls <node>' #16920

Merged
merged 1 commit into from
Aug 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/release-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ Major Changes from Kraken
disable the named mgr module. The module must be present in the
configured `mgr_module_path` on the host(s) where `ceph-mgr` is
running.
- ``ceph osd crush ls <node>`` will list items (OSDs or other CRUSH nodes)
directly beneath a given CRUSH node.
- ``ceph osd crush swap-bucket <src> <dest>`` will swap the
contents of two CRUSH buckets in the hierarchy while preserving
the buckets' ids. This allows an entire subtree of devices to
Expand Down
3 changes: 3 additions & 0 deletions src/mon/MonCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ COMMAND("osd crush tree "
"name=shadow,type=CephChoices,strings=--show-shadow,req=false", \
"dump crush buckets and items in a tree view",
"osd", "r", "cli,rest")
COMMAND("osd crush ls name=node,type=CephString,goodchars=goodchars=[A-Za-z0-9-_.]",
Copy link
Member

@xiexingguo xiexingguo Aug 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for coding style consistency, might want to append an extra \ at each end of line..

"list items beneath a node in the CRUSH tree",
"osd", "r", "cli,rest")
COMMAND("osd crush class ls", \
"list all crush device classes", \
"osd", "r", "cli,rest")
Expand Down
37 changes: 37 additions & 0 deletions src/mon/OSDMonitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4984,6 +4984,43 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op)
show_shadow);
rdata.append(ss.str());
}
} else if (prefix == "osd crush ls") {
string name;
if (!cmd_getval(g_ceph_context, cmdmap, "node", name)) {
ss << "no node specified";
r = -EINVAL;
goto reply;
}
if (!osdmap.crush->name_exists(name)) {
ss << "node '" << name << "' does not exist";
r = -ENOENT;
goto reply;
}
int id = osdmap.crush->get_item_id(name);
list<int> result;
if (id >= 0) {
result.push_back(id);
} else {
int num = osdmap.crush->get_bucket_size(id);
for (int i = 0; i < num; ++i) {
result.push_back(osdmap.crush->get_bucket_item(id, i));
}
}
if (f) {
f->open_array_section("items");
for (auto i : result) {
f->dump_string("item", osdmap.crush->get_item_name(i));
}
f->close_section();
f->flush(rdata);
} else {
ostringstream ss;
for (auto i : result) {
ss << osdmap.crush->get_item_name(i) << "\n";
}
rdata.append(ss.str());
}
r = 0;
} else if (prefix == "osd crush class ls") {
boost::scoped_ptr<Formatter> f(Formatter::create(format, "json-pretty", "json-pretty"));
f->open_array_section("crush_classes");
Expand Down