[1/2] ext4: Don't count free clusters from a corrupt block group

Submitted by Darrick J. Wong on Sept. 28, 2013, 12:13 a.m.

Details

Message ID 20130928001357.25857.94425.stgit@birch.djwong.org
State Accepted, archived
Headers show

Commit Message

Darrick J. Wong Sept. 28, 2013, 12:13 a.m.
A bg that's been flagged "corrupt" by definition has no free blocks, so that
the allocator won't be tempted to use the damaged bg.  Therefore, we shouldn't
count the clusters in the damaged group when calculating free counts.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/ext4/balloc.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)



--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Zheng Liu Sept. 29, 2013, 6:20 a.m.
On Fri, Sep 27, 2013 at 05:13:57PM -0700, Darrick J. Wong wrote:
> A bg that's been flagged "corrupt" by definition has no free blocks, so that
> the allocator won't be tempted to use the damaged bg.  Therefore, we shouldn't
> count the clusters in the damaged group when calculating free counts.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>

                                                - Zheng

> ---
>  fs/ext4/balloc.c |   13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> 
> diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
> index dc5d572..6ea7b14 100644
> --- a/fs/ext4/balloc.c
> +++ b/fs/ext4/balloc.c
> @@ -640,6 +640,7 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
>  	struct ext4_group_desc *gdp;
>  	ext4_group_t i;
>  	ext4_group_t ngroups = ext4_get_groups_count(sb);
> +	struct ext4_group_info *grp;
>  #ifdef EXT4FS_DEBUG
>  	struct ext4_super_block *es;
>  	ext4_fsblk_t bitmap_count;
> @@ -655,7 +656,11 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
>  		gdp = ext4_get_group_desc(sb, i, NULL);
>  		if (!gdp)
>  			continue;
> -		desc_count += ext4_free_group_clusters(sb, gdp);
> +		grp = NULL;
> +		if (EXT4_SB(sb)->s_group_info)
> +			grp = ext4_get_group_info(sb, i);
> +		if (!grp || !EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
> +			desc_count += ext4_free_group_clusters(sb, gdp);
>  		brelse(bitmap_bh);
>  		bitmap_bh = ext4_read_block_bitmap(sb, i);
>  		if (bitmap_bh == NULL)
> @@ -679,7 +684,11 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
>  		gdp = ext4_get_group_desc(sb, i, NULL);
>  		if (!gdp)
>  			continue;
> -		desc_count += ext4_free_group_clusters(sb, gdp);
> +		grp = NULL;
> +		if (EXT4_SB(sb)->s_group_info)
> +			grp = ext4_get_group_info(sb, i);
> +		if (!grp || !EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
> +			desc_count += ext4_free_group_clusters(sb, gdp);
>  	}
>  
>  	return desc_count;
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Theodore Ts'o Oct. 30, 2013, 3:21 p.m.
On Fri, Sep 27, 2013 at 05:13:57PM -0700, Darrick J. Wong wrote:
> A bg that's been flagged "corrupt" by definition has no free blocks, so that
> the allocator won't be tempted to use the damaged bg.  Therefore, we shouldn't
> count the clusters in the damaged group when calculating free counts.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Thanks, applied.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch hide | download patch | download mbox

diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index dc5d572..6ea7b14 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -640,6 +640,7 @@  ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
 	struct ext4_group_desc *gdp;
 	ext4_group_t i;
 	ext4_group_t ngroups = ext4_get_groups_count(sb);
+	struct ext4_group_info *grp;
 #ifdef EXT4FS_DEBUG
 	struct ext4_super_block *es;
 	ext4_fsblk_t bitmap_count;
@@ -655,7 +656,11 @@  ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
 		gdp = ext4_get_group_desc(sb, i, NULL);
 		if (!gdp)
 			continue;
-		desc_count += ext4_free_group_clusters(sb, gdp);
+		grp = NULL;
+		if (EXT4_SB(sb)->s_group_info)
+			grp = ext4_get_group_info(sb, i);
+		if (!grp || !EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
+			desc_count += ext4_free_group_clusters(sb, gdp);
 		brelse(bitmap_bh);
 		bitmap_bh = ext4_read_block_bitmap(sb, i);
 		if (bitmap_bh == NULL)
@@ -679,7 +684,11 @@  ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
 		gdp = ext4_get_group_desc(sb, i, NULL);
 		if (!gdp)
 			continue;
-		desc_count += ext4_free_group_clusters(sb, gdp);
+		grp = NULL;
+		if (EXT4_SB(sb)->s_group_info)
+			grp = ext4_get_group_info(sb, i);
+		if (!grp || !EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
+			desc_count += ext4_free_group_clusters(sb, gdp);
 	}
 
 	return desc_count;