diff mbox series

[09/10] xfs: simplify extent lookup in xfs_can_free_eofblocks

Message ID 20240623053532.857496-10-hch@lst.de (mailing list archive)
State Superseded, archived
Headers show
Series [01/10] xfs: fix freeing speculative preallocations for preallocated files | expand

Commit Message

Christoph Hellwig June 23, 2024, 5:34 a.m. UTC
xfs_can_free_eofblocks just cares if there is an extent beyond EOF.
Replace the call to xfs_bmapi_read with a xfs_iext_lookup_extent
as we've already checked that extents are read in earlier.

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

Comments

Darrick J. Wong June 24, 2024, 3:51 p.m. UTC | #1
On Sun, Jun 23, 2024 at 07:34:54AM +0200, Christoph Hellwig wrote:
> xfs_can_free_eofblocks just cares if there is an extent beyond EOF.
> Replace the call to xfs_bmapi_read with a xfs_iext_lookup_extent
> as we've already checked that extents are read in earlier.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

I guess that works :)
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/xfs_bmap_util.c | 22 +++++++---------------
>  1 file changed, 7 insertions(+), 15 deletions(-)
> 
> diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
> index a4d9fbc21b8343..52863b784b023f 100644
> --- a/fs/xfs/xfs_bmap_util.c
> +++ b/fs/xfs/xfs_bmap_util.c
> @@ -492,12 +492,12 @@ bool
>  xfs_can_free_eofblocks(
>  	struct xfs_inode	*ip)
>  {
> -	struct xfs_bmbt_irec	imap;
>  	struct xfs_mount	*mp = ip->i_mount;
> +	bool			found_blocks = false;
>  	xfs_fileoff_t		end_fsb;
>  	xfs_fileoff_t		last_fsb;
> -	int			nimaps = 1;
> -	int			error;
> +	struct xfs_bmbt_irec	imap;
> +	struct xfs_iext_cursor	icur;
>  
>  	/*
>  	 * Caller must either hold the exclusive io lock; or be inactivating
> @@ -544,21 +544,13 @@ xfs_can_free_eofblocks(
>  		return false;
>  
>  	/*
> -	 * Look up the mapping for the first block past EOF.  If we can't find
> -	 * it, there's nothing to free.
> +	 * Check if there is an post-EOF extent to free.
>  	 */
>  	xfs_ilock(ip, XFS_ILOCK_SHARED);
> -	error = xfs_bmapi_read(ip, end_fsb, last_fsb - end_fsb, &imap, &nimaps,
> -			0);
> +	if (xfs_iext_lookup_extent(ip, &ip->i_df, end_fsb, &icur, &imap))
> +		found_blocks = true;
>  	xfs_iunlock(ip, XFS_ILOCK_SHARED);
> -	if (error || nimaps == 0)
> -		return false;
> -
> -	/*
> -	 * If there's a real mapping there or there are delayed allocation
> -	 * reservations, then we have post-EOF blocks to try to free.
> -	 */
> -	return imap.br_startblock != HOLESTARTBLOCK || ip->i_delayed_blks;
> +	return found_blocks;
>  }
>  
>  /*
> -- 
> 2.43.0
> 
>
diff mbox series

Patch

diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index a4d9fbc21b8343..52863b784b023f 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -492,12 +492,12 @@  bool
 xfs_can_free_eofblocks(
 	struct xfs_inode	*ip)
 {
-	struct xfs_bmbt_irec	imap;
 	struct xfs_mount	*mp = ip->i_mount;
+	bool			found_blocks = false;
 	xfs_fileoff_t		end_fsb;
 	xfs_fileoff_t		last_fsb;
-	int			nimaps = 1;
-	int			error;
+	struct xfs_bmbt_irec	imap;
+	struct xfs_iext_cursor	icur;
 
 	/*
 	 * Caller must either hold the exclusive io lock; or be inactivating
@@ -544,21 +544,13 @@  xfs_can_free_eofblocks(
 		return false;
 
 	/*
-	 * Look up the mapping for the first block past EOF.  If we can't find
-	 * it, there's nothing to free.
+	 * Check if there is an post-EOF extent to free.
 	 */
 	xfs_ilock(ip, XFS_ILOCK_SHARED);
-	error = xfs_bmapi_read(ip, end_fsb, last_fsb - end_fsb, &imap, &nimaps,
-			0);
+	if (xfs_iext_lookup_extent(ip, &ip->i_df, end_fsb, &icur, &imap))
+		found_blocks = true;
 	xfs_iunlock(ip, XFS_ILOCK_SHARED);
-	if (error || nimaps == 0)
-		return false;
-
-	/*
-	 * If there's a real mapping there or there are delayed allocation
-	 * reservations, then we have post-EOF blocks to try to free.
-	 */
-	return imap.br_startblock != HOLESTARTBLOCK || ip->i_delayed_blks;
+	return found_blocks;
 }
 
 /*