From 9b30040d949ec6ed17ca48b56f3ca847012d5397 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 26 Apr 2011 09:40:15 -0700 Subject: [PATCH] mds: undump-journal Signed-off-by: Sage Weil --- src/cmds.cc | 12 ++++++- src/mds/Dumper.cc | 84 +++++++++++++++++++++++++++++++++++++++++++++++ src/mds/Dumper.h | 1 + 3 files changed, 96 insertions(+), 1 deletion(-) diff --git a/src/cmds.cc b/src/cmds.cc index defae529e6708..4038d77ad747a 100644 --- a/src/cmds.cc +++ b/src/cmds.cc @@ -71,13 +71,18 @@ int main(int argc, const char **argv) // mds specific args int shadow = 0; int dump_journal = -1; + int undump_journal = -1; const char *dump_file = NULL; int reset_journal = -1; FOR_EACH_ARG(args) { if (CEPH_ARGPARSE_EQ("dump-journal", '\0')) { CEPH_ARGPARSE_SET_ARG_VAL(&dump_journal, OPT_INT); CEPH_ARGPARSE_SET_ARG_VAL(&dump_file, OPT_STR); - dout(0) << "dumping journal for mds" << dump_journal << " to " << dump_file << dendl; + cout << "dumping journal for mds" << dump_journal << " to " << dump_file << std::endl; + } else if (CEPH_ARGPARSE_EQ("undump-journal", '\0')) { + CEPH_ARGPARSE_SET_ARG_VAL(&undump_journal, OPT_INT); + CEPH_ARGPARSE_SET_ARG_VAL(&dump_file, OPT_STR); + cout << "undumping journal for mds" << dump_journal << " to " << dump_file << std::endl; } else if (CEPH_ARGPARSE_EQ("reset-journal", '\0')) { CEPH_ARGPARSE_SET_ARG_VAL(&reset_journal, OPT_INT); } else if (CEPH_ARGPARSE_EQ("journal-check", '\0')) { @@ -125,6 +130,11 @@ int main(int argc, const char **argv) journal_dumper->init(dump_journal); journal_dumper->dump(dump_file); mc.shutdown(); + } else if (undump_journal >= 0) { + Dumper *journal_dumper = new Dumper(messenger, &mc); + journal_dumper->init(undump_journal); + journal_dumper->undump(dump_file); + mc.shutdown(); } else if (reset_journal >= 0) { Resetter *jr = new Resetter(messenger, &mc); jr->init(reset_journal); diff --git a/src/mds/Dumper.cc b/src/mds/Dumper.cc index 53c71db348959..71fadb899b4a9 100644 --- a/src/mds/Dumper.cc +++ b/src/mds/Dumper.cc @@ -143,3 +143,87 @@ void Dumper::dump(const char *dump_file) shutdown(); } + +void Dumper::undump(const char *dump_file) +{ + cout << "undump " << dump_file << std::endl; + + int fd = ::open(dump_file, O_RDONLY); + if (fd < 0) { + derr << "couldn't open " << dump_file << ": " << cpp_strerror(errno) << dendl; + return; + } + + // Ceph mds0 journal dump + // start offset 232401996 (0xdda2c4c) + // length 1097504 (0x10bf20) + + char buf[200]; + int r = safe_read(fd, buf, sizeof(buf)); + if (r < 0) + return; + + long long unsigned start, len; + sscanf(strstr(buf, "start offset"), "start offset %llu", &start); + sscanf(strstr(buf, "length"), "length %llu", &len); + + cout << "start " << start << " len " << len << std::endl; + + inodeno_t ino = MDS_INO_LOG_OFFSET + rank; + unsigned pg_pool = CEPH_METADATA_RULE; + + Journaler::Header h; + h.trimmed_pos = start; + h.expire_pos = start; + h.write_pos = start+len; + h.magic = CEPH_FS_ONDISK_MAGIC; + + h.layout = g_default_file_layout; + h.layout.fl_pg_preferred = -1; + h.layout.fl_pg_pool = pg_pool; + + bufferlist hbl; + ::encode(h, hbl); + + object_t oid = file_object_t(ino, 0); + object_locator_t oloc(pg_pool); + SnapContext snapc; + + bool done = false; + Cond cond; + + cout << "writing header " << oid << std::endl; + objecter->write_full(oid, oloc, snapc, hbl, g_clock.now(), 0, + NULL, + new C_SafeCond(&lock, &cond, &done)); + + lock.Lock(); + while (!done) + cond.Wait(lock); + lock.Unlock(); + + // read + Filer filer(objecter); + uint64_t pos = start; + uint64_t left = len; + while (left > 0) { + bufferlist j; + lseek64(fd, pos, SEEK_SET); + uint64_t l = MIN(left, 1024*1024); + j.read_fd(fd, l); + cout << " writing " << pos << "~" << l << std::endl; + filer.write(ino, &h.layout, snapc, pos, l, j, g_clock.now(), 0, NULL, new C_SafeCond(&lock, &cond, &done)); + + lock.Lock(); + while (!done) + cond.Wait(lock); + lock.Unlock(); + + pos += l; + left -= l; + } + + cout << "done." << std::endl; +} + + diff --git a/src/mds/Dumper.h b/src/mds/Dumper.h index aa9db8af56dc0..6ce45d60de78c 100644 --- a/src/mds/Dumper.h +++ b/src/mds/Dumper.h @@ -76,6 +76,7 @@ public: void init(int rank); void shutdown(); void dump(const char *dumpfile); + void undump(const char *dumpfile); }; #endif /* JOURNAL_DUMPER_H_ */ -- 2.39.5