From: David Zafman Date: Mon, 9 Feb 2015 20:24:19 +0000 (-0800) Subject: ceph-objectstore-tool: Add dump-journal op X-Git-Tag: v9.0.2~168^2~26 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=381605e34a44edb9acfcfb5a56bd598b020e022f;p=ceph.git ceph-objectstore-tool: Add dump-journal op Have dump-journal op directly dump a filestore journal without mounting or try to dump after mounting. Fixes: #11135 Signed-off-by: David Zafman --- diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index c5640a157e51..7d66c6d46e75 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -26,6 +26,7 @@ #include "os/ObjectStore.h" #include "os/FileStore.h" +#include "os/FileJournal.h" #include "osd/PGLog.h" #include "osd/OSD.h" @@ -2291,6 +2292,20 @@ bool ends_with(const string& check, const string& ending) return check.size() >= ending.size() && check.rfind(ending) == (check.size() - ending.size()); } +// Based on FileStore::dump_journal(), set-up enough to only dump +int mydump_journal(Formatter *f, string journalpath, bool m_journal_dio) +{ + int r; + + if (!journalpath.length()) + return -EINVAL; + + FileJournal *journal = new FileJournal(uuid_d(), NULL, NULL, journalpath.c_str(), m_journal_dio); + r = journal->_fdump(*f, false); + delete journal; + return r; +} + int main(int argc, char **argv) { string dpath, jpath, pgidstr, op, file, object, objcmd, arg1, arg2, type, format; @@ -2311,7 +2326,7 @@ int main(int argc, char **argv) ("pgid", po::value(&pgidstr), "PG id, mandatory except for import, list-lost, fix-lost, list-pgs, set-allow-sharded-objects") ("op", po::value(&op), - "Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects]") + "Arg is one of [info, log, remove, export, import, list, list-lost, fix-lost, list-pgs, rm-past-intervals, set-allow-sharded-objects, dump-journal]") ("file", po::value(&file), "path of file to export or import") ("format", po::value(&format)->default_value("json-pretty"), @@ -2409,14 +2424,15 @@ int main(int argc, char **argv) myexit(ret != 0); } - if (!vm.count("data-path")) { + if (!vm.count("type")) { + type = "filestore"; + } + if (!vm.count("data-path") && + !(op == "dump-journal" && type == "filestore")) { cerr << "Must provide --data-path" << std::endl; usage(desc); myexit(1); } - if (!vm.count("type")) { - type = "filestore"; - } if (type == "filestore" && !vm.count("journal-path")) { cerr << "Must provide --journal-path" << std::endl; usage(desc); @@ -2490,6 +2506,27 @@ int main(int argc, char **argv) } g_conf->apply_changes(NULL); + // Special list handling. Treating pretty_format as human readable, + // with one object per line and not an enclosing array. + human_readable = ends_with(format, "-pretty"); + if (op == "list" && human_readable) { + // Remove -pretty from end of format which we know is there + format = format.substr(0, format.size() - strlen("-pretty")); + } + + formatter = Formatter::create(format); + if (formatter == NULL) { + cerr << "unrecognized format: " << format << std::endl; + myexit(1); + } + + // Special handling for filestore journal, so we can dump it without mounting + if (op == "dump-journal" && type == "filestore") { + int ret = mydump_journal(formatter, jpath, g_conf->journal_dio); + formatter->flush(cout); + myexit(ret != 0); + } + //Verify that data-path really exists struct stat st; if (::stat(dpath.c_str(), &st) == -1) { @@ -2675,7 +2712,7 @@ int main(int argc, char **argv) if (op != "list" && op != "import" && op != "list-lost" && op != "fix-lost" && op != "list-pgs" && op != "set-allow-sharded-objects" && - (pgidstr.length() == 0)) { + op != "dump-journal-mount" && (pgidstr.length() == 0)) { cerr << "Must provide pgid" << std::endl; usage(desc); ret = 1; @@ -2787,6 +2824,19 @@ int main(int argc, char **argv) if (ret == 0) cout << "Import successful" << std::endl; goto out; + } else if (op == "dump-journal-mount") { + // Undocumented feature to dump journal with mounted fs + // This doesn't support the format option, but it uses the + // ObjectStore::dump_journal() and mounts to get replay to run. + int r = fs->dump_journal(cout); + if (r) { + if (r == -EOPNOTSUPP) { + cerr << "Object store type \"" << type << "\" doesn't support journal dump" << std::endl; + } else { + cerr << "Journal dump failed with error " << r << std::endl; + } + } + goto out; } log_oid = OSD::make_pg_log_oid(pgid); @@ -2818,21 +2868,6 @@ int main(int argc, char **argv) goto out; } - // Special list handling. Treating pretty_format as human readable, - // with one object per line and not an enclosing array. - human_readable = ends_with(format, "-pretty"); - if (op == "list" && human_readable) { - // Remove -pretty from end of format which we know is there - format = format.substr(0, format.size() - strlen("-pretty")); - } - - formatter = Formatter::create(format); - if (formatter == NULL) { - cerr << "unrecognized format: " << format << std::endl; - ret = 1; - goto out; - } - if (op == "list") { r = do_list(fs, pgidstr, object, formatter, debug, human_readable); if (r) {