diff mbox series

[2/8] ext4: fix unit mismatch in ext4_mb_new_blocks_simple

Message ID 20230321161220.418652-3-shikemeng@huaweicloud.com
State Superseded
Headers show
Series Some fixes and cleanup to mballoc | expand

Commit Message

Kemeng Shi March 21, 2023, 4:12 p.m. UTC
The "i" returned from mb_find_next_zero_bit is in cluster unit and we
need offset "block" corresponding to "i" in block unit. Convert "i" to
block unit to fix the unit mismatch.

Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
 fs/ext4/mballoc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Comments

Ojaswin Mujoo April 7, 2023, 11:01 a.m. UTC | #1
On Wed, Mar 22, 2023 at 12:12:14AM +0800, Kemeng Shi wrote:
> The "i" returned from mb_find_next_zero_bit is in cluster unit and we
> need offset "block" corresponding to "i" in block unit. Convert "i" to
> block unit to fix the unit mismatch.
> 
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>

Feel free to add:

Reviewed-by: Ojaswin Mujoo <ojaswin@linux.ibm.com>

Regards,
ojaswin

> ---
>  fs/ext4/mballoc.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 6318c763a239..7f695830621a 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -5761,6 +5761,7 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
>  {
>  	struct buffer_head *bitmap_bh;
>  	struct super_block *sb = ar->inode->i_sb;
> +	struct ext4_sb_info *sbi = EXT4_SB(sb);
>  	ext4_group_t group;
>  	ext4_grpblk_t blkoff;
>  	ext4_grpblk_t max = EXT4_CLUSTERS_PER_GROUP(sb);
> @@ -5789,7 +5790,8 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
>  			if (i >= max)
>  				break;
>  			if (ext4_fc_replay_check_excluded(sb,
> -				ext4_group_first_block_no(sb, group) + i)) {
> +				ext4_group_first_block_no(sb, group) +
> +				EXT4_C2B(sbi, i))) {
>  				blkoff = i + 1;
>  			} else
>  				break;
> @@ -5806,7 +5808,7 @@ static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
>  		return 0;
>  	}
>  
> -	block = ext4_group_first_block_no(sb, group) + i;
> +	block = ext4_group_first_block_no(sb, group) + EXT4_C2B(sbi, i);
>  	ext4_mb_mark_bb(sb, block, 1, 1);
>  	ar->len = 1;
>  
> -- 
> 2.30.0
>
diff mbox series

Patch

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 6318c763a239..7f695830621a 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -5761,6 +5761,7 @@  static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
 {
 	struct buffer_head *bitmap_bh;
 	struct super_block *sb = ar->inode->i_sb;
+	struct ext4_sb_info *sbi = EXT4_SB(sb);
 	ext4_group_t group;
 	ext4_grpblk_t blkoff;
 	ext4_grpblk_t max = EXT4_CLUSTERS_PER_GROUP(sb);
@@ -5789,7 +5790,8 @@  static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
 			if (i >= max)
 				break;
 			if (ext4_fc_replay_check_excluded(sb,
-				ext4_group_first_block_no(sb, group) + i)) {
+				ext4_group_first_block_no(sb, group) +
+				EXT4_C2B(sbi, i))) {
 				blkoff = i + 1;
 			} else
 				break;
@@ -5806,7 +5808,7 @@  static ext4_fsblk_t ext4_mb_new_blocks_simple(handle_t *handle,
 		return 0;
 	}
 
-	block = ext4_group_first_block_no(sb, group) + i;
+	block = ext4_group_first_block_no(sb, group) + EXT4_C2B(sbi, i);
 	ext4_mb_mark_bb(sb, block, 1, 1);
 	ar->len = 1;