]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Merge pull request #5921 from caibo2014/add-tool-feature
authorKefu Chai <tchaikov@gmail.com>
Mon, 14 Dec 2015 04:13:40 +0000 (12:13 +0800)
committerKefu Chai <tchaikov@gmail.com>
Mon, 14 Dec 2015 04:13:40 +0000 (12:13 +0800)
tools:support printing part cluster map in readable fashion

Reviewed-by: Kefu Chai <kchai@redhat.com>
1  2 
src/tools/ceph_monstore_tool.cc

index c979bcdabe38ed98bb9dfe8a4b5808e67966280b,b2bb8b60e82818b810712612b147fa3bbff5f5c3..83ad9ce88ab7601ef692653df34055f1ffce605e
@@@ -618,9 -629,40 +637,39 @@@ int main(int argc, char **argv) 
      if (r < 0) {
        std::cerr << "Error getting map: " << cpp_strerror(r) << std::endl;
        err = EINVAL;
 -      ::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 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|crushmap]" << std::endl;
+       }
+       out.append(ss);
+       out.write_fd(fd);
+     } else {
+       bl.write_fd(fd);
+     }
  
      if (!outpath.empty()) {
        std::cout << "wrote " << map_type