{
string dpath, jpath, pgidstr, op, file, object, objcmd, arg1, arg2, type, format;
spg_t pgid;
+ unsigned epoch = 0;
ghobject_t ghobj;
bool human_readable, no_overwrite;
bool force;
("pgid", po::value<string>(&pgidstr),
"PG id, mandatory for info, log, remove, export, rm-past-intervals")
("op", po::value<string>(&op),
- "Arg is one of [info, log, remove, export, import, list, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects, dump-journal, dump-super]")
+ "Arg is one of [info, log, remove, export, import, list, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects, dump-journal, dump-super, "
+ "get-osdmap, set-osdmap]")
+ ("epoch", po::value<unsigned>(&epoch),
+ "epoch# for get-osdmap, the current epoch in use if not specified")
("file", po::value<string>(&file),
- "path of file to export or import")
+ "path of file to export, import, get-osdmap or set-osdmap")
("format", po::value<string>(&format)->default_value("json-pretty"),
"Output format which may be json, json-pretty, xml, xml-pretty")
("debug", "Enable diagnostic output to stderr")
outistty = isatty(STDOUT_FILENO);
file_fd = fd_none;
- if (op == "export" && !dry_run) {
+ if ((op == "export" || op == "get-osdmap") && !dry_run) {
if (!vm.count("file") || file == "-") {
if (outistty) {
cerr << "stdout is a tty and no --file filename specified" << std::endl;
}
if (vm.count("file") && file_fd == fd_none && !dry_run) {
- cerr << "--file option only applies to import, export or set-osdmap" << std::endl;
+ cerr << "--file option only applies to import, export, "
+ << "get-osdmap or set-osdmap" << std::endl;
myexit(1);
}
}
}
goto out;
+ } else if (op == "get-osdmap") {
+ bufferlist bl;
+ OSDMap osdmap;
+ if (epoch == 0) {
+ epoch = superblock.current_epoch;
+ }
+ ret = get_osdmap(fs, epoch, osdmap, bl);
+ if (ret) {
+ cerr << "Failed to get osdmap#" << epoch << ": "
+ << cpp_strerror(ret) << std::endl;
+ goto out;
+ }
+ ret = bl.write_fd(file_fd);
+ if (ret) {
+ cerr << "Failed to write to " << file << ": " << cpp_strerror(ret) << std::endl;
+ } else {
+ cout << "osdmap#" << epoch << " exported." << std::endl;
+ }
+ goto out;
} else if (op == "set-osdmap") {
bufferlist bl;
ret = get_fd_data(file_fd, bl);
// before complaining about a bad pgid
if (!vm.count("objcmd") && op != "export" && op != "info" && op != "log" && op != "rm-past-intervals") {
cerr << "Must provide --op (info, log, remove, export, import, list, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects, dump-journal, dump-super, "
- "set-osdmap)"
+ "set-osdmap, get-osdmap)"
<< std::endl;
usage(desc);
ret = 1;