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 | 50 +++++++++++++++++++++++++++++---------------------
14 1 file changed, 29 insertions(+), 21 deletions(-)
16 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
17 index a673558fe5f8..14360a1aae81 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,8 +2114,18 @@ 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);
62 - ext4_commit_super(sb, 1);
64 + es->s_journal_dev = cpu_to_le32(journal_devnum);
65 + if (DUMMY_ENCRYPTION_ENABLED(sbi))
66 + ext4_set_feature_encrypt(sb);
67 + res = ext4_handle_dirty_super(handle, sb);
70 + res = ext4_journal_stop(handle);
73 + if (!sbi->s_journal)
74 + ext4_commit_super(sb, 1);
76 if (test_opt(sb, DEBUG))
77 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
78 @@ -4048,12 +4068,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
82 - if (DUMMY_ENCRYPTION_ENABLED(sbi) && !(sb->s_flags & MS_RDONLY) &&
83 - !ext4_has_feature_encrypt(sb)) {
84 - ext4_set_feature_encrypt(sb);
85 - ext4_commit_super(sb, 1);
89 * Get the # of file system overhead blocks from the
90 * superblock if present.
91 @@ -4102,7 +4116,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
95 - if (ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY))
96 + err = ext4_setup_super(sb, es, journal_devnum, sb->s_flags & MS_RDONLY);
98 + goto failed_mount4a;
100 sb->s_flags |= MS_RDONLY;
102 /* determine the minimum size of new large inodes, if present */
103 @@ -4561,15 +4578,6 @@ static int ext4_load_journal(struct super_block *sb,
105 EXT4_SB(sb)->s_journal = journal;
106 ext4_clear_journal_err(sb, es);
108 - if (!really_read_only && journal_devnum &&
109 - journal_devnum != le32_to_cpu(es->s_journal_dev)) {
110 - es->s_journal_dev = cpu_to_le32(journal_devnum);
112 - /* Make sure we flush the recovery flag to disk. */
113 - ext4_commit_super(sb, 1);
119 @@ -5032,7 +5040,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
121 ext4_clear_journal_err(sb, es);
122 sbi->s_mount_state = le16_to_cpu(es->s_state);
123 - if (!ext4_setup_super(sb, es, 0))
124 + if (!ext4_setup_super(sb, es, 0, 0))
125 sb->s_flags &= ~MS_RDONLY;
126 if (ext4_has_feature_mmp(sb))
127 if (ext4_multi_mount_protect(sb,