Work around bugs in jmap revoke processing and in the cleaner
[ext4-patch-queue.git] / journal-superblock-changes
blobd8477bd78661a36aa8dddf9d519900267f1b3e7b
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>
12 ---
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
18 --- a/fs/ext4/super.c
19 +++ b/fs/ext4/super.c
20 @@ -2064,9 +2064,10 @@ int ext4_seq_options_show(struct seq_file *seq, void *offset)
21  }
23  static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
24 -                           int read_only)
25 +                           unsigned long journal_devnum, int read_only)
26  {
27         struct ext4_sb_info *sbi = EXT4_SB(sb);
28 +       handle_t *handle;
29         int res = 0;
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");
34                 res = MS_RDONLY;
35         }
36 -       if (read_only)
37 +       if (read_only || res)
38                 goto done;
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);
46 +       if (IS_ERR(handle))
47 +               return PTR_ERR(handle);
48 +       res = ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh);
49 +       if (res) {
50 +       stop_journal:
51 +               ext4_journal_stop(handle);
52 +               return res;
53 +       }
54         if (!sbi->s_journal)
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);
59         if (sbi->s_journal)
60                 ext4_set_feature_journal_needs_recovery(sb);
62 -       ext4_commit_super(sb, 1);
63 +       if (journal_devnum)
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);
68 +       if (res)
69 +               goto stop_journal;
70 +       res = ext4_journal_stop(handle);
71 +       if (res)
72 +               return res;
73 +       if (!sbi->s_journal)
74 +               ext4_commit_super(sb, 1);
75  done:
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)
79                 goto failed_mount_wq;
80         }
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);
86 -       }
88         /*
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)
92                 goto failed_mount4;
93         }
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);
97 +       if (err < 0)
98 +               goto failed_mount4a;
99 +       if (err)
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);
114 -       }
116         return 0;
119 @@ -5032,7 +5040,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
120                         if (sbi->s_journal)
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,