1 ext4, jbd2: add the journal_nocleanup mount option
3 This debugging option is useful for generating test cases for the
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
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 01d52b98f9a7..103fcfb19b9f 100644
18 @@ -1148,6 +1148,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 fe2797f29515..ba1489c5c4c3 100644
30 @@ -867,7 +867,8 @@ static void ext4_put_super(struct super_block *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);
40 @@ -1308,6 +1309,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,
48 @@ -1392,6 +1394,8 @@ static const match_table_t tokens = {
49 {Opt_noinit_itable, "noinit_itable"},
50 {Opt_max_dir_size_kb, "max_dir_size_kb=%u"},
51 {Opt_test_dummy_encryption, "test_dummy_encryption"},
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 @@ -1598,6 +1602,8 @@ static const struct mount_opts {
58 {Opt_jqfmt_vfsv1, QFMT_VFS_V1, MOPT_QFMT},
59 {Opt_max_dir_size_kb, 0, MOPT_GTE0},
60 {Opt_test_dummy_encryption, 0, MOPT_GTE0},
61 + {Opt_journal_nocleanup, EXT4_MOUNT_JOURNAL_NOCLEANUP, MOPT_SET},
62 + {Opt_journal_cleanup, EXT4_MOUNT_JOURNAL_NOCLEANUP, MOPT_CLEAR},
66 @@ -4345,6 +4351,10 @@ static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
67 journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR;
69 journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR;
70 + if (test_opt(sb, JOURNAL_NOCLEANUP))
71 + journal->j_flags |= JBD2_NO_CLEANUP;
73 + journal->j_flags &= ~JBD2_NO_CLEANUP;
74 write_unlock(&journal->j_state_lock);
77 diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
78 index d50c1867d122..a7f655829e6b 100644
79 --- a/fs/jbd2/journal.c
80 +++ b/fs/jbd2/journal.c
81 @@ -1685,6 +1685,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;
90 /* Force any old transactions to disk */
92 /* Totally anal locking here... */
93 @@ -1712,7 +1717,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))
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 @@ -1723,8 +1730,7 @@ int jbd2_journal_destroy(journal_t *journal)
105 jbd2_mark_journal_empty(journal,
106 REQ_PREFLUSH | REQ_FUA);
107 mutex_unlock(&journal->j_checkpoint_mutex);
111 brelse(journal->j_sb_buffer);
114 diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
115 index dfaa1f4dcb0c..9a07b0485784 100644
116 --- a/include/linux/jbd2.h
117 +++ b/include/linux/jbd2.h
118 @@ -1128,6 +1128,7 @@ JBD2_FEATURE_INCOMPAT_FUNCS(csum3, CSUM_V3)
119 * data write error in ordered
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 */
125 * Function declarations for the journaling transaction and buffer