update add-blkdiscard-ioctl patch
[ext4-patch-queue.git] / dont-count-free-clusters-from-a-corrupt-block-group
blobcfde8874d56ff1c46afe7c4c5df4fd77dfe24e8e
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>
13 ---
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;
23         ext4_group_t i;
24         ext4_group_t ngroups = ext4_get_groups_count(sb);
25 +       struct ext4_group_info *grp;
26  #ifdef EXT4FS_DEBUG
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);
31                 if (!gdp)
32                         continue;
33 -               desc_count += ext4_free_group_clusters(sb, gdp);
34 +               grp = NULL;
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);
39                 brelse(bitmap_bh);
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);
44                 if (!gdp)
45                         continue;
46 -               desc_count += ext4_free_group_clusters(sb, gdp);
47 +               grp = NULL;
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);
52         }
54         return desc_count;