add patch forbid-overflowing-inode-code-when-resizing
[ext4-patch-queue.git] / handle-errors-on-ext4_commit_super
bloba48ea92eb0ff2284e682d71298edc0dd19af3130
1 ext4: handle errors on ext4_commit_super
3 From: Jaegeuk Kim <jaegeuk@kernel.org>
5 When remounting ext4 from ro to rw, currently it allows its transition,
6 even if ext4_commit_super() returns EIO. Even worse thing is, after that,
7 fs/buffer complains buffer dirty bits like:
9  Call trace:
10  [<ffffff9750c259dc>] mark_buffer_dirty+0x184/0x1a4
11  [<ffffff9750cb398c>] __ext4_handle_dirty_super+0x4c/0xfc
12  [<ffffff9750c7a9fc>] ext4_file_open+0x154/0x1c0
13  [<ffffff9750bea51c>] do_dentry_open+0x114/0x2d0
14  [<ffffff9750bea75c>] vfs_open+0x5c/0x94
15  [<ffffff9750bf879c>] path_openat+0x668/0xfe8
16  [<ffffff9750bf8088>] do_filp_open+0x74/0x120
17  [<ffffff9750beac98>] do_sys_open+0x148/0x254
18  [<ffffff9750beade0>] SyS_openat+0x10/0x18
19  [<ffffff9750a83ab0>] el0_svc_naked+0x24/0x28
20  EXT4-fs (dm-1): previous I/O error to superblock detected
21  Buffer I/O error on dev dm-1, logical block 0, lost sync page write
22  EXT4-fs (dm-1): re-mounted. Opts: (null)
23  Buffer I/O error on dev dm-1, logical block 80, lost async page write
25 Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
26 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
27 ---
28  fs/ext4/super.c | 35 +++++++++++++++++++++--------------
29  1 file changed, 21 insertions(+), 14 deletions(-)
31 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
32 index d6d6e7db73d6..1388e56bb3f5 100644
33 --- a/fs/ext4/super.c
34 +++ b/fs/ext4/super.c
35 @@ -2146,12 +2146,12 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
36                             int read_only)
37  {
38         struct ext4_sb_info *sbi = EXT4_SB(sb);
39 -       int res = 0;
40 +       int err = 0;
42         if (le32_to_cpu(es->s_rev_level) > EXT4_MAX_SUPP_REV) {
43                 ext4_msg(sb, KERN_ERR, "revision level too high, "
44                          "forcing read-only mode");
45 -               res = SB_RDONLY;
46 +               err = -EROFS;
47         }
48         if (read_only)
49                 goto done;
50 @@ -2184,7 +2184,7 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
51         if (sbi->s_journal)
52                 ext4_set_feature_journal_needs_recovery(sb);
54 -       ext4_commit_super(sb, 1);
55 +       err = ext4_commit_super(sb, 1);
56  done:
57         if (test_opt(sb, DEBUG))
58                 printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, "
59 @@ -2196,7 +2196,7 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,
60                         sbi->s_mount_opt, sbi->s_mount_opt2);
62         cleancache_init_fs(sb);
63 -       return res;
64 +       return err;
65  }
67  int ext4_alloc_flex_bg_array(struct super_block *sb, ext4_group_t ngroup)
68 @@ -4254,8 +4254,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
69                 goto failed_mount4;
70         }
72 -       if (ext4_setup_super(sb, es, sb_rdonly(sb)))
73 +       ret = ext4_setup_super(sb, es, sb_rdonly(sb));
74 +       if (ret == -EROFS) {
75                 sb->s_flags |= SB_RDONLY;
76 +               ret = 0;
77 +       } else if (ret)
78 +               goto failed_mount4a;
80         /* determine the minimum size of new large inodes, if present */
81         if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE &&
82 @@ -4790,11 +4794,7 @@ static int ext4_commit_super(struct super_block *sb, int sync)
83                 unlock_buffer(sbh);
84                 error = __sync_dirty_buffer(sbh,
85                         REQ_SYNC | (test_opt(sb, BARRIER) ? REQ_FUA : 0));
86 -               if (error)
87 -                       return error;
89 -               error = buffer_write_io_error(sbh);
90 -               if (error) {
91 +               if (buffer_write_io_error(sbh)) {
92                         ext4_msg(sb, KERN_ERR, "I/O error while writing "
93                                "superblock");
94                         clear_buffer_write_io_error(sbh);
95 @@ -5195,8 +5195,12 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
96                         if (sbi->s_journal)
97                                 ext4_clear_journal_err(sb, es);
98                         sbi->s_mount_state = le16_to_cpu(es->s_state);
99 -                       if (!ext4_setup_super(sb, es, 0))
100 -                               sb->s_flags &= ~SB_RDONLY;
102 +                       err = ext4_setup_super(sb, es, 0);
103 +                       if (err)
104 +                               goto restore_opts;
106 +                       sb->s_flags &= ~SB_RDONLY;
107                         if (ext4_has_feature_mmp(sb))
108                                 if (ext4_multi_mount_protect(sb,
109                                                 le64_to_cpu(es->s_mmp_block))) {
110 @@ -5220,8 +5224,11 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
111         }
113         ext4_setup_system_zone(sb);
114 -       if (sbi->s_journal == NULL && !(old_sb_flags & SB_RDONLY))
115 -               ext4_commit_super(sb, 1);
116 +       if (sbi->s_journal == NULL && !(old_sb_flags & SB_RDONLY)) {
117 +               err = ext4_commit_super(sb, 1);
118 +               if (err)
119 +                       goto restore_opts;
120 +       }
122  #ifdef CONFIG_QUOTA
123         /* Release old quota file names */