]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: undump-journal
authorSage Weil <sage@newdream.net>
Tue, 26 Apr 2011 16:40:15 +0000 (09:40 -0700)
committerSage Weil <sage@newdream.net>
Tue, 26 Apr 2011 16:40:15 +0000 (09:40 -0700)
Signed-off-by: Sage Weil <sage@newdream.net>
src/cmds.cc
src/mds/Dumper.cc
src/mds/Dumper.h

index defae529e6708780537da89e72b0bf0b89bf0118..4038d77ad747a9efa70662190168fcbbc3262ce8 100644 (file)
@@ -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);
index 53c71db348959fa0a1625656f55b6532501aaff6..71fadb899b4a9be3222cf238d2ec5f8eef57adfc 100644 (file)
@@ -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;
+}
+
+
index aa9db8af56dc035e1b03dc4f92e9363054bc7f6c..6ce45d60de78c0ae6fa5c10c38b0c810520396d2 100644 (file)
@@ -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_ */