diff mbox series

xfs: simplify sector number calculation in xfs_zero_extent

Message ID 20241031130854.163004-1-hch@lst.de (mailing list archive)
State Under Review
Headers show
Series xfs: simplify sector number calculation in xfs_zero_extent | expand

Commit Message

Christoph Hellwig Oct. 31, 2024, 1:08 p.m. UTC
xfs_zero_extent does some really odd gymnstics to calculate the block
layer sectors numbers passed to blkdev_issue_zeroout.  This is because it
used to call sb_issue_zeroout and the calculations in that helper got
open coded here in the rather misleadingly named commit 3dc29161070a
("dax: use sb_issue_zerout instead of calling dax_clear_sectors").

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_bmap_util.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

Comments

Darrick J. Wong Oct. 31, 2024, 4:37 p.m. UTC | #1
On Thu, Oct 31, 2024 at 02:08:35PM +0100, Christoph Hellwig wrote:
> xfs_zero_extent does some really odd gymnstics to calculate the block
> layer sectors numbers passed to blkdev_issue_zeroout.  This is because it
> used to call sb_issue_zeroout and the calculations in that helper got
> open coded here in the rather misleadingly named commit 3dc29161070a
> ("dax: use sb_issue_zerout instead of calling dax_clear_sectors").
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  fs/xfs/xfs_bmap_util.c | 17 ++++-------------
>  1 file changed, 4 insertions(+), 13 deletions(-)
> 
> diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
> index ba6092fcdeb8..05fd768f7dcd 100644
> --- a/fs/xfs/xfs_bmap_util.c
> +++ b/fs/xfs/xfs_bmap_util.c
> @@ -49,10 +49,6 @@ xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb)
>  
>  /*
>   * Routine to zero an extent on disk allocated to the specific inode.
> - *
> - * The VFS functions take a linearised filesystem block offset, so we have to
> - * convert the sparse xfs fsb to the right format first.
> - * VFS types are real funky, too.
>   */
>  int
>  xfs_zero_extent(
> @@ -60,15 +56,10 @@ xfs_zero_extent(
>  	xfs_fsblock_t		start_fsb,
>  	xfs_off_t		count_fsb)
>  {
> -	struct xfs_mount	*mp = ip->i_mount;
> -	struct xfs_buftarg	*target = xfs_inode_buftarg(ip);
> -	xfs_daddr_t		sector = xfs_fsb_to_db(ip, start_fsb);
> -	sector_t		block = XFS_BB_TO_FSBT(mp, sector);
> -
> -	return blkdev_issue_zeroout(target->bt_bdev,
> -		block << (mp->m_super->s_blocksize_bits - 9),
> -		count_fsb << (mp->m_super->s_blocksize_bits - 9),

Groossssss, this is a good cleanup.
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> -		GFP_KERNEL, 0);
> +	return blkdev_issue_zeroout(xfs_inode_buftarg(ip)->bt_bdev,
> +			xfs_fsb_to_db(ip, start_fsb),
> +			XFS_FSB_TO_BB(ip->i_mount, count_fsb),
> +			GFP_KERNEL, 0);
>  }
>  
>  /*
> -- 
> 2.45.2
> 
>
Chaitanya Kulkarni Oct. 31, 2024, 6:40 p.m. UTC | #2
On 10/31/24 06:08, Christoph Hellwig wrote:
> xfs_zero_extent does some really odd gymnstics to calculate the block
> layer sectors numbers passed to blkdev_issue_zeroout.  This is because it
> used to call sb_issue_zeroout and the calculations in that helper got
> open coded here in the rather misleadingly named commit 3dc29161070a
> ("dax: use sb_issue_zerout instead of calling dax_clear_sectors").
>
> Signed-off-by: Christoph Hellwig<hch@lst.de>

much cleaner like what xfs_discard_rtdev_extents() and 
xfs_discard_extents()
is doing. Looks good.

Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com>

-ck
diff mbox series

Patch

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index ba6092fcdeb8..05fd768f7dcd 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -49,10 +49,6 @@  xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb)
 
 /*
  * Routine to zero an extent on disk allocated to the specific inode.
- *
- * The VFS functions take a linearised filesystem block offset, so we have to
- * convert the sparse xfs fsb to the right format first.
- * VFS types are real funky, too.
  */
 int
 xfs_zero_extent(
@@ -60,15 +56,10 @@  xfs_zero_extent(
 	xfs_fsblock_t		start_fsb,
 	xfs_off_t		count_fsb)
 {
-	struct xfs_mount	*mp = ip->i_mount;
-	struct xfs_buftarg	*target = xfs_inode_buftarg(ip);
-	xfs_daddr_t		sector = xfs_fsb_to_db(ip, start_fsb);
-	sector_t		block = XFS_BB_TO_FSBT(mp, sector);
-
-	return blkdev_issue_zeroout(target->bt_bdev,
-		block << (mp->m_super->s_blocksize_bits - 9),
-		count_fsb << (mp->m_super->s_blocksize_bits - 9),
-		GFP_KERNEL, 0);
+	return blkdev_issue_zeroout(xfs_inode_buftarg(ip)->bt_bdev,
+			xfs_fsb_to_db(ip, start_fsb),
+			XFS_FSB_TO_BB(ip->i_mount, count_fsb),
+			GFP_KERNEL, 0);
 }
 
 /*