From: Kefu Chai Date: Mon, 14 Dec 2015 04:13:40 +0000 (+0800) Subject: Merge pull request #5921 from caibo2014/add-tool-feature X-Git-Tag: v10.0.2~45 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3cbb824db59101a80280221581ef5a1f11e94fb3;p=ceph.git Merge pull request #5921 from caibo2014/add-tool-feature tools:support printing part cluster map in readable fashion Reviewed-by: Kefu Chai --- 3cbb824db59101a80280221581ef5a1f11e94fb3 diff --cc src/tools/ceph_monstore_tool.cc index c979bcdabe38,b2bb8b60e828..83ad9ce88ab7 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@@ -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