1 ext4: don't count free clusters from a corrupt block group
3 From: "Darrick J. Wong" <darrick.wong@oracle.com>
5 A bg that's been flagged "corrupt" by definition has no free blocks,
6 so that the allocator won't be tempted to use the damaged bg.
7 Therefore, we shouldn't count the clusters in the damaged group when
8 calculating free counts.
10 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
11 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
12 Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
14 fs/ext4/balloc.c | 13 +++++++++++--
15 1 file changed, 11 insertions(+), 2 deletions(-)
17 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
18 index dc5d572..6ea7b14 100644
19 --- a/fs/ext4/balloc.c
20 +++ b/fs/ext4/balloc.c
21 @@ -640,6 +640,7 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
22 struct ext4_group_desc *gdp;
24 ext4_group_t ngroups = ext4_get_groups_count(sb);
25 + struct ext4_group_info *grp;
27 struct ext4_super_block *es;
28 ext4_fsblk_t bitmap_count;
29 @@ -655,7 +656,11 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
30 gdp = ext4_get_group_desc(sb, i, NULL);
33 - desc_count += ext4_free_group_clusters(sb, gdp);
35 + if (EXT4_SB(sb)->s_group_info)
36 + grp = ext4_get_group_info(sb, i);
37 + if (!grp || !EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
38 + desc_count += ext4_free_group_clusters(sb, gdp);
40 bitmap_bh = ext4_read_block_bitmap(sb, i);
41 if (bitmap_bh == NULL)
42 @@ -679,7 +684,11 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
43 gdp = ext4_get_group_desc(sb, i, NULL);
46 - desc_count += ext4_free_group_clusters(sb, gdp);
48 + if (EXT4_SB(sb)->s_group_info)
49 + grp = ext4_get_group_info(sb, i);
50 + if (!grp || !EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
51 + desc_count += ext4_free_group_clusters(sb, gdp);