add patch remove-unused-mode-parameter
[ext4-patch-queue.git] / add-journal-no-cleanup-option
bloba1b3f5997c02c9c4fccc0118cdf8fe6658b543ea
1 ext4, jbd2: add the journal_nocleanup mount option
3 This debugging option is useful for generating test cases for the
4 journal replay code.
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 ---
8  fs/ext4/ext4.h       |  1 +
9  fs/ext4/super.c      | 12 +++++++++++-
10  fs/jbd2/journal.c    | 12 +++++++++---
11  include/linux/jbd2.h |  1 +
12  4 files changed, 22 insertions(+), 4 deletions(-)
14 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
15 index 9ebde0cd632e..e247c2a2a06c 100644
16 --- a/fs/ext4/ext4.h
17 +++ b/fs/ext4/ext4.h
18 @@ -1150,6 +1150,7 @@ struct ext4_inode_info {
19  #define EXT4_MOUNT_DIOREAD_NOLOCK      0x400000 /* Enable support for dio read nolocking */
20  #define EXT4_MOUNT_JOURNAL_CHECKSUM    0x800000 /* Journal checksums */
21  #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT        0x1000000 /* Journal Async Commit */
22 +#define EXT4_MOUNT_JOURNAL_NOCLEANUP   0x2000000 /* Preserve the journal on unmount */
23  #define EXT4_MOUNT_DELALLOC            0x8000000 /* Delalloc support */
24  #define EXT4_MOUNT_DATA_ERR_ABORT      0x10000000 /* Abort on file data write */
25  #define EXT4_MOUNT_BLOCK_VALIDITY      0x20000000 /* Block validity checking */
26 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
27 index c9202be4cc1a..40d9cac94797 100644
28 --- a/fs/ext4/super.c
29 +++ b/fs/ext4/super.c
30 @@ -889,7 +889,8 @@ static void ext4_put_super(struct super_block *sb)
31         ext4_mb_release(sb);
32         ext4_ext_release(sb);
34 -       if (!(sb->s_flags & MS_RDONLY) && !aborted) {
35 +       if (!(sb->s_flags & MS_RDONLY) && !aborted &&
36 +           !test_opt(sb, JOURNAL_NOCLEANUP)) {
37                 ext4_clear_feature_journal_needs_recovery(sb);
38                 es->s_state = cpu_to_le16(sbi->s_mount_state);
39         }
40 @@ -1348,6 +1349,7 @@ enum {
41         Opt_nomblk_io_submit, Opt_block_validity, Opt_noblock_validity,
42         Opt_inode_readahead_blks, Opt_journal_ioprio,
43         Opt_dioread_nolock, Opt_dioread_lock,
44 +       Opt_journal_nocleanup, Opt_journal_cleanup,
45         Opt_discard, Opt_nodiscard, Opt_init_itable, Opt_noinit_itable,
46         Opt_max_dir_size_kb, Opt_nojournal_checksum, Opt_nombcache,
47  };
48 @@ -1434,6 +1436,8 @@ static const match_table_t tokens = {
49         {Opt_test_dummy_encryption, "test_dummy_encryption"},
50         {Opt_nombcache, "nombcache"},
51         {Opt_nombcache, "no_mbcache"},  /* for backward compatibility */
52 +       {Opt_journal_nocleanup, "journal_nocleanup"},
53 +       {Opt_journal_cleanup, "journal_cleanup"},
54         {Opt_removed, "check=none"},    /* mount option from ext2/3 */
55         {Opt_removed, "nocheck"},       /* mount option from ext2/3 */
56         {Opt_removed, "reservation"},   /* mount option from ext2/3 */
57 @@ -1642,6 +1646,8 @@ static const struct mount_opts {
58         {Opt_max_dir_size_kb, 0, MOPT_GTE0},
59         {Opt_test_dummy_encryption, 0, MOPT_GTE0},
60         {Opt_nombcache, EXT4_MOUNT_NO_MBCACHE, MOPT_SET},
61 +       {Opt_journal_nocleanup, EXT4_MOUNT_JOURNAL_NOCLEANUP, MOPT_SET},
62 +       {Opt_journal_cleanup, EXT4_MOUNT_JOURNAL_NOCLEANUP, MOPT_CLEAR},
63         {Opt_err, 0, 0}
64  };
66 @@ -4423,6 +4429,10 @@ static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
67                 journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR;
68         else
69                 journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR;
70 +       if (test_opt(sb, JOURNAL_NOCLEANUP))
71 +               journal->j_flags |= JBD2_NO_CLEANUP;
72 +       else
73 +               journal->j_flags &= ~JBD2_NO_CLEANUP;
74         write_unlock(&journal->j_state_lock);
75  }
77 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
78 index 7c6254330951..352c9491e668 100644
79 --- a/fs/jbd2/journal.c
80 +++ b/fs/jbd2/journal.c
81 @@ -1708,6 +1708,11 @@ int jbd2_journal_destroy(journal_t *journal)
82         if (journal->j_running_transaction)
83                 jbd2_journal_commit_transaction(journal);
85 +       if (journal->j_flags & JBD2_NO_CLEANUP) {
86 +               jbd2_journal_destroy_checkpoint(journal);
87 +               journal->j_checkpoint_transactions = NULL;
88 +       }
90         /* Force any old transactions to disk */
92         /* Totally anal locking here... */
93 @@ -1735,7 +1740,9 @@ int jbd2_journal_destroy(journal_t *journal)
94         spin_unlock(&journal->j_list_lock);
96         if (journal->j_sb_buffer) {
97 -               if (!is_journal_aborted(journal)) {
98 +               if (is_journal_aborted(journal))
99 +                       err = -EIO;
100 +               else if ((journal->j_flags & JBD2_NO_CLEANUP) == 0) {
101                         mutex_lock_io(&journal->j_checkpoint_mutex);
103                         write_lock(&journal->j_state_lock);
104 @@ -1746,8 +1753,7 @@ int jbd2_journal_destroy(journal_t *journal)
105                         jbd2_mark_journal_empty(journal,
106                                         REQ_SYNC | REQ_PREFLUSH | REQ_FUA);
107                         mutex_unlock(&journal->j_checkpoint_mutex);
108 -               } else
109 -                       err = -EIO;
110 +               }
111                 brelse(journal->j_sb_buffer);
112         }
114 diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
115 index 606b6bce3a5b..fd14143d244b 100644
116 --- a/include/linux/jbd2.h
117 +++ b/include/linux/jbd2.h
118 @@ -1130,6 +1130,7 @@ JBD2_FEATURE_INCOMPAT_FUNCS(csum3,                CSUM_V3)
119                                                  * data write error in ordered
120                                                  * mode */
121  #define JBD2_REC_ERR   0x080   /* The errno in the sb has been recorded */
122 +#define JBD2_NO_CLEANUP        0x100   /* Don't flush empty the journal on shutdown  */
124  /*
125   * Function declarations for the journaling transaction and buffer