diff options
author | Sage Weil <sage@inktank.com> | 2012-12-20 11:04:29 -0800 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2012-12-20 11:04:29 -0800 |
commit | 17c627b5e4b763f08af05f28597acc4a7b28ae78 (patch) | |
tree | 1d47d436a5e125f26ec40c12b23c0859e5b1eca0 | |
parent | f38d891138bc59809a6daf389ed3f66e81357daa (diff) | |
parent | 2e49d5c4b7daaabb3b6a64f670b15756db2286a2 (diff) | |
download | ceph-17c627b5e4b763f08af05f28597acc4a7b28ae78.tar.gz |
Merge remote-tracking branch 'gh/wip-cephtool' into next
-rwxr-xr-x | qa/workunits/cephtool/test.sh | 24 | ||||
-rw-r--r-- | src/mon/OSDMonitor.cc | 32 | ||||
-rw-r--r-- | src/osd/OSD.cc | 8 | ||||
-rw-r--r-- | src/tools/common.cc | 20 |
4 files changed, 81 insertions, 3 deletions
diff --git a/qa/workunits/cephtool/test.sh b/qa/workunits/cephtool/test.sh new file mode 100755 index 00000000000..22ca2008651 --- /dev/null +++ b/qa/workunits/cephtool/test.sh @@ -0,0 +1,24 @@ +#!/bin/sh -x + +set -e + +ceph status +ceph -s +ceph quorum_status + +ceph osd dump +ceph osd tree +ceph pg dump +ceph mon dump +ceph mds dump + +ceph tell osd.0 version +ceph tell osd.9999 version && exit 1 +ceph tell osd.foo version && exit 1 + +for id in `ceph osd ls` ; do + ceph tell osd.$id version +done + +echo OK + diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 7522bc133ad..7b49eee72c6 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -1702,6 +1702,7 @@ bool OSDMonitor::preprocess_command(MMonCommand *m) } else if (m->cmd[1] == "dump" || m->cmd[1] == "tree" || + m->cmd[1] == "ls" || m->cmd[1] == "getmap" || m->cmd[1] == "getcrushmap") { string format = "plain"; @@ -1753,6 +1754,37 @@ bool OSDMonitor::preprocess_command(MMonCommand *m) rdata.append(ds); ss << "dumped osdmap epoch " << p->get_epoch(); } + } else if (cmd == "ls") { + stringstream ds; + if (format == "json") { + JSONFormatter jf(true); + jf.open_array_section("osds"); + for (int i = 0; i < osdmap.get_max_osd(); i++) { + if (osdmap.exists(i)) { + jf.dump_int("osd", i); + } + } + jf.close_section(); + jf.flush(ds); + r = 0; + } else if (format == "plain") { + bool first = true; + for (int i = 0; i < osdmap.get_max_osd(); i++) { + if (osdmap.exists(i)) { + if (!first) + ds << "\n"; + first = false; + ds << i; + } + } + r = 0; + } else { + ss << "unrecognized format '" << format << "'"; + r = -EINVAL; + } + if (r == 0) { + rdata.append(ds); + } } else if (cmd == "tree") { stringstream ds; if (format == "json") { diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 217dd23b152..59c6366265c 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -34,6 +34,7 @@ #include "Watch.h" #include "common/ceph_argparse.h" +#include "common/version.h" #include "os/FileStore.h" #include "os/FileJournal.h" @@ -2872,7 +2873,12 @@ void OSD::do_command(Connection *con, tid_t tid, vector<string>& cmd, bufferlist dout(20) << "do_command tid " << tid << " " << cmd << dendl; - if (cmd[0] == "injectargs") { + if (cmd[0] == "version") { + ss << pretty_version_to_str(); + r = 0; + goto out; + } + else if (cmd[0] == "injectargs") { if (cmd.size() < 2) { r = -EINVAL; ss << "ignoring empty injectargs"; diff --git a/src/tools/common.cc b/src/tools/common.cc index 9a454f7e7d8..9a3763a34ae 100644 --- a/src/tools/common.cc +++ b/src/tools/common.cc @@ -140,12 +140,14 @@ static void send_command(CephToolCtx *ctx) reply_rs = "error mapping pgid to an osd"; reply_rc = -EINVAL; reply = true; + cmd_cond.Signal(); return; } if (r == 0) { reply_rs = "pgid currently maps to no osd"; reply_rc = -ENOENT; reply = true; + cmd_cond.Signal(); return; } pending_target.set_name(entity_name_t::OSD(osds[0])); @@ -156,14 +158,23 @@ static void send_command(CephToolCtx *ctx) char *end; int n = strtoll(start, &end, 10); if (end <= start) { + stringstream ss; + ss << "invalid osd id " << pending_target; + reply_rs = ss.str(); reply_rc = -EINVAL; reply = true; + cmd_cond.Signal(); return; } if (!osdmap->is_up(n)) { + stringstream ss; + ss << pending_target << " is not up"; + reply_rs = ss.str(); reply_rc = -ESRCH; reply = true; + cmd_cond.Signal(); + return; } else { if (!ctx->concise) *ctx->log << ceph_clock_now(g_ceph_context) << " " << pending_target << " <- " << pending_cmd << std::endl; @@ -186,6 +197,7 @@ static void send_command(CephToolCtx *ctx) reply_rc = -EINVAL; reply = true; + cmd_cond.Signal(); } static void handle_osd_map(CephToolCtx *ctx, MOSDMap *m) @@ -282,8 +294,12 @@ int do_command(CephToolCtx *ctx, << reply_from.name << " -> '" << reply_rs << "' (" << reply_rc << ")" << std::endl; - else - cout << reply_rs << std::endl; + else { + if (reply_rc >= 0) + cout << reply_rs << std::endl; + else + cerr << reply_rs << std::endl; + } return reply_rc; } |