From 5ed8cdc19150382c946a373ec940d76f98e6ecb7 Mon Sep 17 00:00:00 2001 From: Bo Cai Date: Mon, 14 Sep 2015 19:50:47 +0800 Subject: [PATCH] tools:print the map infomation in human readable format. Signed-off-by: Bo Cai --- src/tools/ceph_monstore_tool.cc | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index eec3924ccc8..ea1dcf4da83 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 -- 2.47.3