914dddf72665322e561344c7076e4fd3cf4a0440
[openwrt/staging/wigyori.git] / target / linux / generic / backport-4.9 / 500-ext4-fix-check-to-prevent-initializing-reserved-inod.patch
1 From 5012284700775a4e6e3fbe7eac4c543c4874b559 Mon Sep 17 00:00:00 2001
2 From: Theodore Ts'o <tytso@mit.edu>
3 Date: Sat, 28 Jul 2018 08:12:04 -0400
4 Subject: [PATCH] ext4: fix check to prevent initializing reserved inodes
5
6 Commit 8844618d8aa7: "ext4: only look at the bg_flags field if it is
7 valid" will complain if block group zero does not have the
8 EXT4_BG_INODE_ZEROED flag set. Unfortunately, this is not correct,
9 since a freshly created file system has this flag cleared. It gets
10 almost immediately after the file system is mounted read-write --- but
11 the following somewhat unlikely sequence will end up triggering a
12 false positive report of a corrupted file system:
13
14 mkfs.ext4 /dev/vdc
15 mount -o ro /dev/vdc /vdc
16 mount -o remount,rw /dev/vdc
17
18 Instead, when initializing the inode table for block group zero, test
19 to make sure that itable_unused count is not too large, since that is
20 the case that will result in some or all of the reserved inodes
21 getting cleared.
22
23 This fixes the failures reported by Eric Whiteney when running
24 generic/230 and generic/231 in the the nojournal test case.
25
26 Fixes: 8844618d8aa7 ("ext4: only look at the bg_flags field if it is valid")
27 Reported-by: Eric Whitney <enwlinux@gmail.com>
28 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
29 ---
30 fs/ext4/ialloc.c | 5 ++++-
31 fs/ext4/super.c | 8 +-------
32 2 files changed, 5 insertions(+), 8 deletions(-)
33
34 --- a/fs/ext4/ialloc.c
35 +++ b/fs/ext4/ialloc.c
36 @@ -1316,7 +1316,10 @@ int ext4_init_inode_table(struct super_b
37 ext4_itable_unused_count(sb, gdp)),
38 sbi->s_inodes_per_block);
39
40 - if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group)) {
41 + if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group) ||
42 + ((group == 0) && ((EXT4_INODES_PER_GROUP(sb) -
43 + ext4_itable_unused_count(sb, gdp)) <
44 + EXT4_FIRST_INO(sb)))) {
45 ext4_error(sb, "Something is wrong with group %u: "
46 "used itable blocks: %d; "
47 "itable unused count: %u",
48 --- a/fs/ext4/super.c
49 +++ b/fs/ext4/super.c
50 @@ -3031,14 +3031,8 @@ static ext4_group_t ext4_has_uninit_itab
51 if (!gdp)
52 continue;
53
54 - if (gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED))
55 - continue;
56 - if (group != 0)
57 + if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED)))
58 break;
59 - ext4_error(sb, "Inode table for bg 0 marked as "
60 - "needing zeroing");
61 - if (sb->s_flags & MS_RDONLY)
62 - return ngroups;
63 }
64
65 return group;