From: Bo Cai Date: Mon, 14 Sep 2015 11:50:47 +0000 (+0800) Subject: tools:print the map infomation in human readable format. X-Git-Tag: v10.0.2~45^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5ed8cdc19150382c946a373ec940d76f98e6ecb7;p=ceph.git tools:print the map infomation in human readable format. Signed-off-by: Bo Cai --- diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index eec3924ccc83..ea1dcf4da83f 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -23,6 +23,9 @@ #include "include/stringify.h" #include "mon/MonitorDBStore.h" #include "mon/Paxos.h" +#include "mon/MonMap.h" +#include "mds/MDSMap.h" +#include "osd/OSDMap.h" namespace po = boost::program_options; using namespace std; @@ -550,6 +553,7 @@ int main(int argc, char **argv) { } else if (cmd == "get") { unsigned v = 0; string outpath; + bool readable = false; string map_type; // visible options for this command po::options_description op_desc("Allowed 'get' options"); @@ -559,6 +563,8 @@ int main(int argc, char **argv) { "output file (default: stdout)") ("version,v", po::value(&v), "map version to obtain") + ("readable,r", po::value(&readable)->default_value(false), + "print the map infomation in human readable format") ; // this is going to be a positional argument; we don't want to show // it as an option during --help, but we do want to have it captured @@ -613,7 +619,31 @@ int main(int argc, char **argv) { ::close(fd); goto done; } - bl.write_fd(fd); + + if (readable) { + stringstream ss; + bufferlist out; + if (map_type == "monmap") { + MonMap monmap; + monmap.decode(bl); + monmap.print(ss); + } else if (map_type == "osdmap") { + OSDMap osdmap; + osdmap.decode(bl); + osdmap.print(ss); + } else if (map_type == "mdsmap") { + MDSMap mdsmap; + mdsmap.decode(bl); + mdsmap.print(ss); + } else { + std::cerr << "This type of readable map does not exist: " << map_type << std::endl + << "You can only specify[osdmap|monmap|mdsmap]" << std::endl; + } + out.append(ss); + out.write_fd(fd); + } else { + bl.write_fd(fd); + } if (!outpath.empty()) { std::cout << "wrote " << map_type