]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
Recreate journal that had been removed previously due to corruption
authorKalpak Shah <kalpak@clusterfs.com>
Thu, 21 Jun 2007 15:59:06 +0000 (11:59 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Thu, 21 Jun 2007 15:59:06 +0000 (11:59 -0400)
If the journal had been removed because it was corrupt, the
E2F_FLAG_JOURNAL_INODE flag will be set.  If this flag is set, then
recreate the filesystem after checking the filesystem.

Signed-off-by: Kalpak Shah <kalpak@clusterfs.com>
Signed-off-by: Andreas Dilger <adilger@clusterfs.com>
e2fsck/journal.c
e2fsck/problem.c
e2fsck/problem.h
e2fsck/unix.c
tests/f_badjourblks/expect.1
tests/f_badjourblks/expect.2
tests/f_miss_journal/expect.1
tests/f_miss_journal/expect.2

index 519df487cf0144c48ebf49bb61516365e8a9025a..1f10305d8af52519edb16dabd017184e70afb992 100644 (file)
@@ -420,7 +420,7 @@ static errcode_t e2fsck_journal_fix_bad_inode(e2fsck_t ctx,
                                       "filesystem is now ext2 only ***\n\n");
                        sb->s_feature_compat &= ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
                        sb->s_journal_inum = 0;
-                       ctx->flags |= E2F_FLAG_JOURNAL_INODE; /* FIXME: todo */
+                       ctx->flags |= E2F_FLAG_JOURNAL_INODE;
                        e2fsck_clear_recover(ctx, 1);
                        return 0;
                }
index 9f4af50973065eee2ba309741c61034e40dab283..87de64596df6c4989074b54e74db751089d622e0 100644 (file)
@@ -1494,6 +1494,11 @@ static struct e2fsck_problem problem_table[] = {
          " +(%i--%j)",
          PROMPT_NONE, PR_LATCH_IBITMAP | PR_PREEN_OK | PR_PREEN_NOMSG },
 
+       /* Recreate journal if E2F_FLAG_JOURNAL_INODE flag is set */
+       { PR_6_RECREATE_JOURNAL,
+         N_("Recreate journal to make the filesystem ext3 again?\n"),
+         PROMPT_FIX, PR_PREEN_OK | PR_NO_OK },
+
        { 0 }
 };
 
index 560907ac7c20c3ad090855dedb1a507fb241e828..28fe9646ea22fc19e31ee8fe2b8c87197c23c972 100644 (file)
@@ -900,6 +900,13 @@ struct problem_context {
 /* Inode rangeused, but not marked used in bitmap */
 #define PR_5_INODE_RANGE_USED          0x050017
 
+/*
+ * Post-Pass 5 errors
+ */
+
+/* Recreate the journal if E2F_FLAG_JOURNAL_INODE flag is set */
+#define PR_6_RECREATE_JOURNAL          0x060001
+
 /*
  * Function declarations
  */
index 72091f882c79b2a6e79c7d57f0292a79d1900fa1..b01a62a389e001ef5789440783a30becf65259e5 100644 (file)
@@ -851,6 +851,7 @@ int main (int argc, char *argv[])
        e2fsck_t        ctx;
        struct problem_context pctx;
        int flags, run_result;
+       int journal_size;
        
        clear_problem_context(&pctx);
 #ifdef MTRACE
@@ -1184,8 +1185,47 @@ restart:
                         " but we'll try to go on...\n"));
        }
 
+       /*
+        * Save the journal size in megabytes.
+        * Try and use the journal size from the backup else let e2fsck
+        * find the default journal size.
+        */
+       if (sb->s_jnl_backup_type == EXT3_JNL_BACKUP_BLOCKS)
+               journal_size = sb->s_jnl_blocks[16] >> 20;
+       else
+               journal_size = -1;
+
        run_result = e2fsck_run(ctx);
        e2fsck_clear_progbar(ctx);
+
+       if (ctx->flags & E2F_FLAG_JOURNAL_INODE) {
+               if (fix_problem(ctx, PR_6_RECREATE_JOURNAL, &pctx)) {
+                       if (journal_size < 1024)
+                               journal_size = ext2fs_default_journal_size(fs->super->s_blocks_count);
+                       if (journal_size < 0) {
+                               fs->super->s_feature_compat &=
+                                       ~EXT3_FEATURE_COMPAT_HAS_JOURNAL;
+                               com_err(ctx->program_name, 0, 
+                                       _("Couldn't determine journal size"));
+                               goto no_journal;
+                       }
+                       printf(_("Creating journal (%d blocks): "),
+                              journal_size);
+                       fflush(stdout);
+                       retval = ext2fs_add_journal_inode(fs,
+                                                         journal_size, 0);
+                       if (retval) {
+                               com_err("Error ", retval,
+                                       _("\n\twhile trying to create journal"));
+                               goto no_journal;
+                       }
+                       printf(_(" Done.\n"));
+                       printf(_("\n*** journal has been re-created - "
+                                      "filesystem is now ext3 again ***\n"));
+               }
+       }
+no_journal:
+
        if (run_result == E2F_FLAG_RESTART) {
                printf(_("Restarting e2fsck from the beginning...\n"));
                retval = e2fsck_reset_context(ctx);
index 8684286e9b819953214eb2c8f2a9b1717cf28b2f..5a0bfef524a25937c68ef61dbcea2f4f5dea499c 100644 (file)
@@ -19,7 +19,13 @@ Fix? yes
 Free blocks count wrong (7112, counted=8142).
 Fix? yes
 
+Recreate journal to make the filesystem ext3 again?
+Fix? yes
+
+Creating journal (1024 blocks):  Done.
+
+*** journal has been re-created - filesystem is now ext3 again ***
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 11/256 files (0.0% non-contiguous), 50/8192 blocks
+test_filesys: 11/256 files (0.0% non-contiguous), 1080/8192 blocks
 Exit status is 1
index 32ca977575d990a586a759819f4d21d9d656d8bb..632dc71bbdce638ed7af8cfbc532e77fed167e9e 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/256 files (0.0% non-contiguous), 50/8192 blocks
+test_filesys: 11/256 files (0.0% non-contiguous), 1080/8192 blocks
 Exit status is 0
index 140cb518cdee95ec6a4575bdb52b0115fb9a2352..cad69f6325106eaf01e66e37430857805c082d57 100644 (file)
@@ -17,7 +17,13 @@ Fix? yes
 Free blocks count wrong (968, counted=1998).
 Fix? yes
 
+Recreate journal to make the filesystem ext3 again?
+Fix? yes
+
+Creating journal (1024 blocks):  Done.
+
+*** journal has been re-created - filesystem is now ext3 again ***
 
 test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
-test_filesys: 11/256 files (0.0% non-contiguous), 50/2048 blocks
+test_filesys: 11/256 files (0.0% non-contiguous), 1080/2048 blocks
 Exit status is 1
index 834a12046d099677a063d28931a4f9af1bc8a31a..1e8c47f9ee2fe2b861db3593859ae4338e2afda0 100644 (file)
@@ -3,5 +3,5 @@ Pass 2: Checking directory structure
 Pass 3: Checking directory connectivity
 Pass 4: Checking reference counts
 Pass 5: Checking group summary information
-test_filesys: 11/256 files (0.0% non-contiguous), 50/2048 blocks
+test_filesys: 11/256 files (0.0% non-contiguous), 1080/2048 blocks
 Exit status is 0