]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: make --dump-journal preserve offset
authorSage Weil <sage.weil@dreamhost.com>
Tue, 1 Feb 2011 17:28:15 +0000 (09:28 -0800)
committerSage Weil <sage.weil@dreamhost.com>
Tue, 1 Feb 2011 17:28:15 +0000 (09:28 -0800)
Suggest user use tar -S to preserve sparseness.

Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/mds/Dumper.cc
src/mds/Dumper.h

index 8d037f93076c0b20b1bbadd46f21455fb93d0be5..069f73fcf985f23ac9af477de47aaf41ac5b4cec 100644 (file)
@@ -16,6 +16,7 @@
 #include "osdc/Journaler.h"
 #include "mds/mdstypes.h"
 #include "mon/MonClient.h"
+#include "common/errno.h"
 
 Dumper::~Dumper()
 {
@@ -77,7 +78,8 @@ void Dumper::dump(const char *dump_file)
 {
   bool done = false;
   Cond cond;
-  inodeno_t ino = MDS_INO_LOG_OFFSET + strtol(g_conf.id, 0, 0);;
+  int rank = strtol(g_conf.id, 0, 0);
+  inodeno_t ino = MDS_INO_LOG_OFFSET + rank;
 
   lock.Lock();
   journaler->recover(new C_SafeCond(&lock, &cond, &done));
@@ -99,8 +101,33 @@ void Dumper::dump(const char *dump_file)
     cond.Wait(lock);
   lock.Unlock();
 
-  cout << "read " << bl.length() << " bytes" << std::endl;
-  bl.write_file(dump_file);
+  cout << "read " << bl.length() << " bytes at offset " << start << std::endl;
+
+  int fd = ::open(dump_file, O_WRONLY|O_CREAT|O_TRUNC, 0644);
+  if (fd >= 0) {
+    // include an informative header
+    char buf[200];
+    memset(buf, 0, sizeof(buf));
+    sprintf(buf, "Ceph mds%d journal dump\n start offset %llu (0x%llx)\n       length %llu (0x%llx)\n%c",
+           rank, 
+           (unsigned long long)start, (unsigned long long)start,
+           (unsigned long long)bl.length(), (unsigned long long)bl.length(),
+           4);
+    ::write(fd, buf, sizeof(buf));
+
+    // write the data
+    ::lseek64(fd, start, SEEK_SET);
+    bl.write_fd(fd);
+    ::close(fd);
+
+    cout << "wrote " << bl.length() << " bytes at offset " << start << " to " << dump_file << "\n"
+        << "NOTE: this is a _sparse_ file; you can\n"
+        << "\t$ tar cSzf " << dump_file << ".tgz " << dump_file << "\n"
+        << "      to efficiently compress it while preserving sparseness." << std::endl;
+  } else {
+    int err = errno;
+    derr << "unable to open " << dump_file << ": " << cpp_strerror(err) << dendl;
+  }
   messenger->shutdown();
 
   // wait for messenger to finish
index 580455060950ddc976e90b232760849c231f2ee6..aa9db8af56dc035e1b03dc4f92e9363054bc7f6c 100644 (file)
@@ -40,6 +40,8 @@ public:
   Mutex lock;
   SafeTimer timer;
 
+  int rank;
+
   /*
    * The messenger should be a valid SimpleMessenger. You should call bind()
    * before passing it in, but not do anything else.