diff mbox series

[07/19] xfs: reflow the tail end of xfs_bmap_rtalloc

Message ID 20231214063438.290538-8-hch@lst.de (mailing list archive)
State Superseded
Headers show
Series [01/19] xfs: consider minlen sized extents in xfs_rtallocate_extent_block | expand

Commit Message

Christoph Hellwig Dec. 14, 2023, 6:34 a.m. UTC
Reorder the tail end of xfs_bmap_rtalloc so that the successfully
allocation is in the main path, and the error handling is on a branch.

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

Comments

Darrick J. Wong Dec. 14, 2023, 8:51 p.m. UTC | #1
On Thu, Dec 14, 2023 at 07:34:26AM +0100, Christoph Hellwig wrote:
> Reorder the tail end of xfs_bmap_rtalloc so that the successfully
> allocation is in the main path, and the error handling is on a branch.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Looks ok to me
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/xfs_rtalloc.c | 60 ++++++++++++++++++++++----------------------
>  1 file changed, 30 insertions(+), 30 deletions(-)
> 
> diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
> index dac148d53af3ec..158a631379378e 100644
> --- a/fs/xfs/xfs_rtalloc.c
> +++ b/fs/xfs/xfs_rtalloc.c
> @@ -1479,39 +1479,39 @@ xfs_bmap_rtalloc(
>  	raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
>  	error = xfs_rtallocate_extent(ap->tp, rtx, raminlen, ralen, &ralen,
>  			ap->wasdel, prod, &rtx);
> -	if (!error) {
> -		ap->blkno = xfs_rtx_to_rtb(mp, rtx);
> -		ap->length = xfs_rtxlen_to_extlen(mp, ralen);
> -		xfs_bmap_alloc_account(ap);
> -		return 0;
> -	}
> -
> -	if (error != -ENOSPC)
> -		return error;
> +	if (error == -ENOSPC) {
> +		if (align > mp->m_sb.sb_rextsize) {
> +			/*
> +			 * We previously enlarged the request length to try to
> +			 * satisfy an extent size hint.  The allocator didn't
> +			 * return anything, so reset the parameters to the
> +			 * original values and try again without alignment
> +			 * criteria.
> +			 */
> +			ap->offset = orig_offset;
> +			ap->length = orig_length;
> +			minlen = align = mp->m_sb.sb_rextsize;
> +			goto retry;
> +		}
>  
> -	if (align > mp->m_sb.sb_rextsize) {
> -		/*
> -		 * We previously enlarged the request length to try to satisfy
> -		 * an extent size hint.  The allocator didn't return anything,
> -		 * so reset the parameters to the original values and try again
> -		 * without alignment criteria.
> -		 */
> -		ap->offset = orig_offset;
> -		ap->length = orig_length;
> -		minlen = align = mp->m_sb.sb_rextsize;
> -		goto retry;
> -	}
> +		if (!ignore_locality && ap->blkno != 0) {
> +			/*
> +			 * If we can't allocate near a specific rt extent, try
> +			 * again without locality criteria.
> +			 */
> +			ignore_locality = true;
> +			goto retry;
> +		}
>  
> -	if (!ignore_locality && ap->blkno != 0) {
> -		/*
> -		 * If we can't allocate near a specific rt extent, try again
> -		 * without locality criteria.
> -		 */
> -		ignore_locality = true;
> -		goto retry;
> +		ap->blkno = NULLFSBLOCK;
> +		ap->length = 0;
> +		return 0;
>  	}
> +	if (error)
> +		return error;
>  
> -	ap->blkno = NULLFSBLOCK;
> -	ap->length = 0;
> +	ap->blkno = xfs_rtx_to_rtb(mp, rtx);
> +	ap->length = xfs_rtxlen_to_extlen(mp, ralen);
> +	xfs_bmap_alloc_account(ap);
>  	return 0;
>  }
> -- 
> 2.39.2
> 
>
diff mbox series

Patch

diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index dac148d53af3ec..158a631379378e 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -1479,39 +1479,39 @@  xfs_bmap_rtalloc(
 	raminlen = max_t(xfs_rtxlen_t, 1, xfs_extlen_to_rtxlen(mp, minlen));
 	error = xfs_rtallocate_extent(ap->tp, rtx, raminlen, ralen, &ralen,
 			ap->wasdel, prod, &rtx);
-	if (!error) {
-		ap->blkno = xfs_rtx_to_rtb(mp, rtx);
-		ap->length = xfs_rtxlen_to_extlen(mp, ralen);
-		xfs_bmap_alloc_account(ap);
-		return 0;
-	}
-
-	if (error != -ENOSPC)
-		return error;
+	if (error == -ENOSPC) {
+		if (align > mp->m_sb.sb_rextsize) {
+			/*
+			 * We previously enlarged the request length to try to
+			 * satisfy an extent size hint.  The allocator didn't
+			 * return anything, so reset the parameters to the
+			 * original values and try again without alignment
+			 * criteria.
+			 */
+			ap->offset = orig_offset;
+			ap->length = orig_length;
+			minlen = align = mp->m_sb.sb_rextsize;
+			goto retry;
+		}
 
-	if (align > mp->m_sb.sb_rextsize) {
-		/*
-		 * We previously enlarged the request length to try to satisfy
-		 * an extent size hint.  The allocator didn't return anything,
-		 * so reset the parameters to the original values and try again
-		 * without alignment criteria.
-		 */
-		ap->offset = orig_offset;
-		ap->length = orig_length;
-		minlen = align = mp->m_sb.sb_rextsize;
-		goto retry;
-	}
+		if (!ignore_locality && ap->blkno != 0) {
+			/*
+			 * If we can't allocate near a specific rt extent, try
+			 * again without locality criteria.
+			 */
+			ignore_locality = true;
+			goto retry;
+		}
 
-	if (!ignore_locality && ap->blkno != 0) {
-		/*
-		 * If we can't allocate near a specific rt extent, try again
-		 * without locality criteria.
-		 */
-		ignore_locality = true;
-		goto retry;
+		ap->blkno = NULLFSBLOCK;
+		ap->length = 0;
+		return 0;
 	}
+	if (error)
+		return error;
 
-	ap->blkno = NULLFSBLOCK;
-	ap->length = 0;
+	ap->blkno = xfs_rtx_to_rtb(mp, rtx);
+	ap->length = xfs_rtxlen_to_extlen(mp, ralen);
+	xfs_bmap_alloc_account(ap);
 	return 0;
 }