diff mbox

[10/18] xfs: simplify xfs_map_blocks by using xfs_iext_lookup_extent directly

Message ID 20180530100013.31358-11-hch@lst.de (mailing list archive)
State New, archived
Headers show

Commit Message

Christoph Hellwig May 30, 2018, 10 a.m. UTC
xfs_bmapi_read adds zero value in xfs_map_blocks.  Replace it with a
direct call to the low-level extent lookup function.

Note that we now always pass a 0 length to the trace points as we ask
for an unspecified len.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/xfs_aops.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

Comments

Darrick J. Wong May 30, 2018, 5:32 p.m. UTC | #1
On Wed, May 30, 2018 at 12:00:05PM +0200, Christoph Hellwig wrote:
> xfs_bmapi_read adds zero value in xfs_map_blocks.  Replace it with a
> direct call to the low-level extent lookup function.
> 
> Note that we now always pass a 0 length to the trace points as we ask
> for an unspecified len.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
>  fs/xfs/xfs_aops.c | 19 +++++--------------
>  1 file changed, 5 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
> index 587493e9c8a1..cef2bc3cf98b 100644
> --- a/fs/xfs/xfs_aops.c
> +++ b/fs/xfs/xfs_aops.c
> @@ -387,7 +387,6 @@ xfs_map_blocks(
>  	int			whichfork = XFS_DATA_FORK;
>  	struct xfs_iext_cursor	icur;
>  	int			error = 0;
> -	int			nimaps = 1;
>  
>  	if (XFS_FORCED_SHUTDOWN(mp))
>  		return -EIO;
> @@ -429,24 +428,16 @@ xfs_map_blocks(
>  		goto allocate_blocks;
>  	}
>  
> -	error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb,
> -				imap, &nimaps, XFS_BMAPI_ENTIRE);
> +	if (!xfs_iext_lookup_extent(ip, &ip->i_df, offset_fsb, &icur, imap))
> +		imap->br_startoff = end_fsb;	/* fake a hole past EOF */
>  	xfs_iunlock(ip, XFS_ILOCK_SHARED);
> -	if (error)
> -		return error;
>  
> -	if (!nimaps) {
> -		/*
> -		 * Lookup returns no match? Beyond eof? regardless,
> -		 * return it as a hole so we don't write it
> -		 */
> +	if (imap->br_startoff > offset_fsb) {
> +		/* landed in a hole or beyond EOF */
> +		imap->br_blockcount = imap->br_startoff - offset_fsb;
>  		imap->br_startoff = offset_fsb;
> -		imap->br_blockcount = end_fsb - offset_fsb;
>  		imap->br_startblock = HOLESTARTBLOCK;
>  		*type = XFS_IO_HOLE;
> -	} else if (imap->br_startblock == HOLESTARTBLOCK) {
> -		/* landed in a hole */
> -		*type = XFS_IO_HOLE;
>  	} else {
>  		if (isnullstartblock(imap->br_startblock)) {
>  			/* got a delalloc extent */
> -- 
> 2.17.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Brian Foster May 31, 2018, 1:46 p.m. UTC | #2
On Wed, May 30, 2018 at 12:00:05PM +0200, Christoph Hellwig wrote:
> xfs_bmapi_read adds zero value in xfs_map_blocks.  Replace it with a
> direct call to the low-level extent lookup function.
> 
> Note that we now always pass a 0 length to the trace points as we ask
> for an unspecified len.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---

Reviewed-by: Brian Foster <bfoster@redhat.com>

>  fs/xfs/xfs_aops.c | 19 +++++--------------
>  1 file changed, 5 insertions(+), 14 deletions(-)
> 
> diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
> index 587493e9c8a1..cef2bc3cf98b 100644
> --- a/fs/xfs/xfs_aops.c
> +++ b/fs/xfs/xfs_aops.c
> @@ -387,7 +387,6 @@ xfs_map_blocks(
>  	int			whichfork = XFS_DATA_FORK;
>  	struct xfs_iext_cursor	icur;
>  	int			error = 0;
> -	int			nimaps = 1;
>  
>  	if (XFS_FORCED_SHUTDOWN(mp))
>  		return -EIO;
> @@ -429,24 +428,16 @@ xfs_map_blocks(
>  		goto allocate_blocks;
>  	}
>  
> -	error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb,
> -				imap, &nimaps, XFS_BMAPI_ENTIRE);
> +	if (!xfs_iext_lookup_extent(ip, &ip->i_df, offset_fsb, &icur, imap))
> +		imap->br_startoff = end_fsb;	/* fake a hole past EOF */
>  	xfs_iunlock(ip, XFS_ILOCK_SHARED);
> -	if (error)
> -		return error;
>  
> -	if (!nimaps) {
> -		/*
> -		 * Lookup returns no match? Beyond eof? regardless,
> -		 * return it as a hole so we don't write it
> -		 */
> +	if (imap->br_startoff > offset_fsb) {
> +		/* landed in a hole or beyond EOF */
> +		imap->br_blockcount = imap->br_startoff - offset_fsb;
>  		imap->br_startoff = offset_fsb;
> -		imap->br_blockcount = end_fsb - offset_fsb;
>  		imap->br_startblock = HOLESTARTBLOCK;
>  		*type = XFS_IO_HOLE;
> -	} else if (imap->br_startblock == HOLESTARTBLOCK) {
> -		/* landed in a hole */
> -		*type = XFS_IO_HOLE;
>  	} else {
>  		if (isnullstartblock(imap->br_startblock)) {
>  			/* got a delalloc extent */
> -- 
> 2.17.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 587493e9c8a1..cef2bc3cf98b 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -387,7 +387,6 @@  xfs_map_blocks(
 	int			whichfork = XFS_DATA_FORK;
 	struct xfs_iext_cursor	icur;
 	int			error = 0;
-	int			nimaps = 1;
 
 	if (XFS_FORCED_SHUTDOWN(mp))
 		return -EIO;
@@ -429,24 +428,16 @@  xfs_map_blocks(
 		goto allocate_blocks;
 	}
 
-	error = xfs_bmapi_read(ip, offset_fsb, end_fsb - offset_fsb,
-				imap, &nimaps, XFS_BMAPI_ENTIRE);
+	if (!xfs_iext_lookup_extent(ip, &ip->i_df, offset_fsb, &icur, imap))
+		imap->br_startoff = end_fsb;	/* fake a hole past EOF */
 	xfs_iunlock(ip, XFS_ILOCK_SHARED);
-	if (error)
-		return error;
 
-	if (!nimaps) {
-		/*
-		 * Lookup returns no match? Beyond eof? regardless,
-		 * return it as a hole so we don't write it
-		 */
+	if (imap->br_startoff > offset_fsb) {
+		/* landed in a hole or beyond EOF */
+		imap->br_blockcount = imap->br_startoff - offset_fsb;
 		imap->br_startoff = offset_fsb;
-		imap->br_blockcount = end_fsb - offset_fsb;
 		imap->br_startblock = HOLESTARTBLOCK;
 		*type = XFS_IO_HOLE;
-	} else if (imap->br_startblock == HOLESTARTBLOCK) {
-		/* landed in a hole */
-		*type = XFS_IO_HOLE;
 	} else {
 		if (isnullstartblock(imap->br_startblock)) {
 			/* got a delalloc extent */