1 ext4: journal superblock changes
3 There are a number of changes to the ext4 superblock during the mount
4 process which are done without using the journal, but instead via the
5 brute-force call to ext4_commit_super(). Concentrate these changes to
6 ext4_setup_super(), and make them using the journalling mechanism.
8 Not only is this more efficient, but it also avoids some cases where
9 the ext4 superblock's checksum was not properly set.
11 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
13 fs/ext4/super.c | 47 +++++++++++++++++++++++++++--------------------
14 1 file changed, 27 insertions(+), 20 deletions(-)
16 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
17 index a673558fe5f8..67cb11f15aba 100644
20 @@ -2064,9 +2064,10 @@ int ext4_seq_options_show(struct seq_file *seq, void *offset)
23 static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
25 + unsigned long journal_devnum, int read_only)
27 struct ext4_sb_info *sbi = EXT4_SB(sb);
31 if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
32 @@ -2074,7 +2075,7 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
33 "forcing read-only mode");
37 + if (read_only || res)
39 if (!(sbi->s_mount_state & EXT4_VALID_FS))
40 ext4_msg(sb, KERN_WARNING, "warning: mounting unchecked fs, "
41 @@ -2095,6 +2096,15 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
42 ext4_msg(sb, KERN_WARNING,
43 "warning: checktime reached, "
44 "running e2fsck is recommended");
45 + handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1);
47 + return PTR_ERR(handle);
48 + res = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh);
51 + ext4_journal_stop(handle);
55 es->s_state &= cpu_to_le16(~EXT4_VALID_FS);
56 if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
57 @@ -2104,7 +2114,16 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
58 ext4_update_dynamic_rev(sb);
60 ext4_set_feature_journal_needs_recovery(sb);
63 + es->s_journal_dev = cpu_to_le32(journal_devnum);
64 + if (DUMMY_ENCRYPTION_ENABLED(sbi))
65 + ext4_set_feature_encrypt(sb);
66 + res = ext4_handle_dirty_super(handle, sb);
69 + res = ext4_journal_stop(handle);
72 ext4_commit_super(sb, 1);
74 if (test_opt(sb, DEBUG))
75 @@ -4048,12 +4067,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
79 - if (DUMMY_ENCRYPTION_ENABLED(sbi) && !(sb->s_flags & MS_RDONLY) &&
80 - !ext4_has_feature_encrypt(sb)) {
81 - ext4_set_feature_encrypt(sb);
82 - ext4_commit_super(sb, 1);
86 * Get the # of file system overhead blocks from the
87 * superblock if present.
88 @@ -4102,7 +4115,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
92 - if (ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY))
93 + err = ext4_setup_super(sb, es, journal_devnum, sb->s_flags & MS_RDONLY);
95 + goto failed_mount4a;
97 sb->s_flags |= MS_RDONLY;
99 /* determine the minimum size of new large inodes, if present */
100 @@ -4561,15 +4577,6 @@ static int ext4_load_journal(struct super_block *sb,
102 EXT4_SB(sb)->s_journal = journal;
103 ext4_clear_journal_err(sb, es);
105 - if (!really_read_only && journal_devnum &&
106 - journal_devnum != le32_to_cpu(es->s_journal_dev)) {
107 - es->s_journal_dev = cpu_to_le32(journal_devnum);
109 - /* Make sure we flush the recovery flag to disk. */
110 - ext4_commit_super(sb, 1);
116 @@ -5032,7 +5039,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
118 ext4_clear_journal_err(sb, es);
119 sbi->s_mount_state = le16_to_cpu(es->s_state);
120 - if (!ext4_setup_super(sb, es, 0))
121 + if (!ext4_setup_super(sb, es, 0, 0))
122 sb->s_flags &= ~MS_RDONLY;
123 if (ext4_has_feature_mmp(sb))
124 if (ext4_multi_mount_protect(sb,