tools:support printing part cluster map in readable fashion
Reviewed-by: Kefu Chai <kchai@redhat.com>
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