]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
tools:print the map infomation in human readable format.
authorBo Cai <cai.bo@h3c.com>
Mon, 14 Sep 2015 11:50:47 +0000 (19:50 +0800)
committerBo Cai <cai.bo@h3c.com>
Wed, 11 Nov 2015 16:27:31 +0000 (00:27 +0800)
Signed-off-by: Bo Cai <cai.bo@h3c.com>
src/tools/ceph_monstore_tool.cc

index eec3924ccc83250dec9626a8ac1edcea312e7545..ea1dcf4da83f37f67f171657aaee586b06a84d66 100644 (file)
@@ -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<unsigned>(&v),
        "map version to obtain")
+      ("readable,r", po::value<bool>(&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