]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools:support printing the crushmap in readable fashion. 5921/head
authorBo Cai <cai.bo@h3c.com>
Tue, 20 Oct 2015 07:23:49 +0000 (15:23 +0800)
committerBo Cai <cai.bo@h3c.com>
Mon, 23 Nov 2015 05:09:38 +0000 (13:09 +0800)
Signed-off-by: Bo Cai <cai.bo@h3c.com>
src/tools/ceph_monstore_tool.cc

index ea1dcf4da83f37f67f171657aaee586b06a84d66..b2bb8b60e82818b810712612b147fa3bbff5f5c3 100644 (file)
@@ -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);