[sheepdog] [PATCH v3 1/3] journal: ignore invalid journal files

Hitoshi Mitake mitake.hitoshi at gmail.com
Sun Apr 14 17:54:17 CEST 2013


Even if journal files are broken, we can do nothing for recoverying
it. It is better to inform it as log messages and continue the
initialization process.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
v3: handle empty journal files

 sheep/journal.c |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/sheep/journal.c b/sheep/journal.c
index 2e1d21f..92a005e 100644
--- a/sheep/journal.c
+++ b/sheep/journal.c
@@ -207,6 +207,16 @@ static int do_recover(int fd)
 		return -1;
 	}
 
+	if (!st.st_size) {
+		/*
+		 * An empty journal file can be produced when sheep crashes
+		 * between ftruncate() and prealloc() of commit_data().
+		 * Such a file should be ignored simply.
+		 */
+		close(fd);
+		return 0;
+	}
+
 	map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
 	close(fd);
 	if (map == MAP_FAILED) {
@@ -245,31 +255,29 @@ skip:
  * we actually only recover one jfile, the other would be empty. This process
  * is fast with buffered IO that only take several secends at most.
  */
-static int check_recover_journal_file(const char *p)
+static void check_recover_journal_file(const char *p)
 {
 	int old = 0, new = 0;
 
 	if (get_old_new_jfile(p, &old, &new) < 0)
-		return -1;
+		return;
 
 	/* No journal file found */
 	if (old == 0)
-		return 0;
+		return;
 
 	if (do_recover(old) < 0)
-		return -1;
+		panic("recoverying from journal file (old) failed");
 	if (do_recover(new) < 0)
-		return -1;
-
-	return 0;
+		panic("recoverying from journal file (new) failed");
 }
 
 int journal_file_init(const char *path, size_t size, bool skip)
 {
 	int fd;
 
-	if (!skip && check_recover_journal_file(path) < 0)
-		return -1;
+	if (!skip)
+		check_recover_journal_file(path);
 
 	jfile_size = (size * 1024 * 1024) / 2;
 
-- 
1.7.5.1




More information about the sheepdog mailing list