From bd9484750f546974047dacd9176a8072be846596 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 (cherry picked from commit 5ed8cdc19150382c946a373ec940d76f98e6ecb7) --- 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 c979bcdabe38e..6b890b218279b 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -24,6 +24,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; @@ -551,6 +554,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"); @@ -560,6 +564,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 @@ -620,7 +626,31 @@ int main(int argc, char **argv) { err = EINVAL; 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.39.5