From b7faf678ed0241abc7eb86b9baaa6db669a22d53 Mon Sep 17 00:00:00 2001 From: Bo Cai Date: Tue, 20 Oct 2015 15:23:49 +0800 Subject: [PATCH] tools:support printing the crushmap in readable fashion. Signed-off-by: Bo Cai --- src/tools/ceph_monstore_tool.cc | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index ea1dcf4da83f3..b2bb8b60e8281 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -26,6 +26,7 @@ #include "mon/MonMap.h" #include "mds/MDSMap.h" #include "osd/OSDMap.h" +#include "crush/CrushCompiler.h" namespace po = boost::program_options; using namespace std; @@ -196,6 +197,8 @@ void usage(const char *n, po::options_description &d) << " (default: last committed)\n" << " get mdsmap [-- options] get mdsmap (version VER if specified)\n" << " (default: last committed)\n" + << " get crushmap [-- options] get crushmap (version VER if specified)\n" + << " (default: last committed)\n" << " dump-keys dumps store keys to FILE\n" << " (default: stdout)\n" << " dump-paxos [-- options] dump paxos transactions\n" @@ -592,7 +595,11 @@ int main(int argc, char **argv) { } if (v == 0) { - v = st.get(map_type, "last_committed"); + if (map_type == "crushmap") { + v = st.get("osdmap", "last_committed"); + } else { + v = st.get(map_type, "last_committed"); + } } int fd = STDOUT_FILENO; @@ -610,6 +617,12 @@ int main(int argc, char **argv) { r = 0; if (map_type == "osdmap") { r = st.get(map_type, st.combine_strings("full", v), bl); + } else if (map_type == "crushmap") { + bufferlist tmp; + r = st.get("osdmap", st.combine_strings("full", v), tmp); + OSDMap osdmap; + osdmap.decode(tmp); + osdmap.crush->encode(bl); } else { r = st.get(map_type, v, bl); } @@ -635,9 +648,15 @@ int main(int argc, char **argv) { MDSMap mdsmap; mdsmap.decode(bl); mdsmap.print(ss); + } else if (map_type == "crushmap") { + CrushWrapper cw; + bufferlist::iterator it = bl.begin(); + cw.decode(it); + CrushCompiler cc(cw, std::cerr, 0); + cc.decompile(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; + << "You can only specify[osdmap|monmap|mdsmap|crushmap]" << std::endl; } out.append(ss); out.write_fd(fd); -- 2.47.3