Skip to content

Commit 5012284

Browse files
committed
ext4: fix check to prevent initializing reserved inodes
Commit 8844618: "ext4: only look at the bg_flags field if it is valid" will complain if block group zero does not have the EXT4_BG_INODE_ZEROED flag set. Unfortunately, this is not correct, since a freshly created file system has this flag cleared. It gets almost immediately after the file system is mounted read-write --- but the following somewhat unlikely sequence will end up triggering a false positive report of a corrupted file system: mkfs.ext4 /dev/vdc mount -o ro /dev/vdc /vdc mount -o remount,rw /dev/vdc Instead, when initializing the inode table for block group zero, test to make sure that itable_unused count is not too large, since that is the case that will result in some or all of the reserved inodes getting cleared. This fixes the failures reported by Eric Whiteney when running generic/230 and generic/231 in the the nojournal test case. Fixes: 8844618 ("ext4: only look at the bg_flags field if it is valid") Reported-by: Eric Whitney <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 8d5a803 commit 5012284

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

fs/ext4/ialloc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,10 @@ int ext4_init_inode_table(struct super_block *sb, ext4_group_t group,
13881388
ext4_itable_unused_count(sb, gdp)),
13891389
sbi->s_inodes_per_block);
13901390

1391-
if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group)) {
1391+
if ((used_blks < 0) || (used_blks > sbi->s_itb_per_group) ||
1392+
((group == 0) && ((EXT4_INODES_PER_GROUP(sb) -
1393+
ext4_itable_unused_count(sb, gdp)) <
1394+
EXT4_FIRST_INO(sb)))) {
13921395
ext4_error(sb, "Something is wrong with group %u: "
13931396
"used itable blocks: %d; "
13941397
"itable unused count: %u",

fs/ext4/super.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3141,14 +3141,8 @@ static ext4_group_t ext4_has_uninit_itable(struct super_block *sb)
31413141
if (!gdp)
31423142
continue;
31433143

3144-
if (gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED))
3145-
continue;
3146-
if (group != 0)
3144+
if (!(gdp->bg_flags & cpu_to_le16(EXT4_BG_INODE_ZEROED)))
31473145
break;
3148-
ext4_error(sb, "Inode table for bg 0 marked as "
3149-
"needing zeroing");
3150-
if (sb_rdonly(sb))
3151-
return ngroups;
31523146
}
31533147

31543148
return group;

0 commit comments

Comments
 (0)