diff mbox series

[13/19] xfs: tidy up xfs_rtallocate_extent_exact

Message ID 20231214063438.290538-14-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
Use common code for both xfs_rtallocate_range calls by moving
the !isfree logic into the non-default branch.

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

Comments

Darrick J. Wong Dec. 14, 2023, 9:17 p.m. UTC | #1
On Thu, Dec 14, 2023 at 07:34:32AM +0100, Christoph Hellwig wrote:
> Use common code for both xfs_rtallocate_range calls by moving
> the !isfree logic into the non-default branch.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/xfs_rtalloc.c | 34 +++++++++++++---------------------
>  1 file changed, 13 insertions(+), 21 deletions(-)
> 
> diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
> index 5f42422a976a3e..ea6f221c6a193c 100644
> --- a/fs/xfs/xfs_rtalloc.c
> +++ b/fs/xfs/xfs_rtalloc.c
> @@ -349,32 +349,24 @@ xfs_rtallocate_extent_exact(
>  	if (error)
>  		return error;
>  
> -	if (isfree) {
> +	if (!isfree) {
>  		/*
> -		 * If it is, allocate it and return success.
> +		 * If not, allocate what there is, if it's at least minlen.
>  		 */
> -		error = xfs_rtallocate_range(args, start, maxlen);
> -		if (error)
> -			return error;
> -		*len = maxlen;
> -		*rtx = start;
> -		return 0;
> -	}
> -	/*
> -	 * If not, allocate what there is, if it's at least minlen.
> -	 */
> -	maxlen = next - start;
> -	if (maxlen < minlen)
> -		return -ENOSPC;
> -
> -	/*
> -	 * Trim off tail of extent, if prod is specified.
> -	 */
> -	if (prod > 1 && (i = maxlen % prod)) {
> -		maxlen -= i;
> +		maxlen = next - start;
>  		if (maxlen < minlen)
>  			return -ENOSPC;
> +
> +		/*
> +		 * Trim off tail of extent, if prod is specified.
> +		 */
> +		if (prod > 1 && (i = maxlen % prod)) {
> +			maxlen -= i;
> +			if (maxlen < minlen)
> +				return -ENOSPC;
> +		}
>  	}
> +
>  	/*
>  	 * Allocate what we can and return it.
>  	 */
> -- 
> 2.39.2
> 
>
diff mbox series

Patch

diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 5f42422a976a3e..ea6f221c6a193c 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -349,32 +349,24 @@  xfs_rtallocate_extent_exact(
 	if (error)
 		return error;
 
-	if (isfree) {
+	if (!isfree) {
 		/*
-		 * If it is, allocate it and return success.
+		 * If not, allocate what there is, if it's at least minlen.
 		 */
-		error = xfs_rtallocate_range(args, start, maxlen);
-		if (error)
-			return error;
-		*len = maxlen;
-		*rtx = start;
-		return 0;
-	}
-	/*
-	 * If not, allocate what there is, if it's at least minlen.
-	 */
-	maxlen = next - start;
-	if (maxlen < minlen)
-		return -ENOSPC;
-
-	/*
-	 * Trim off tail of extent, if prod is specified.
-	 */
-	if (prod > 1 && (i = maxlen % prod)) {
-		maxlen -= i;
+		maxlen = next - start;
 		if (maxlen < minlen)
 			return -ENOSPC;
+
+		/*
+		 * Trim off tail of extent, if prod is specified.
+		 */
+		if (prod > 1 && (i = maxlen % prod)) {
+			maxlen -= i;
+			if (maxlen < minlen)
+				return -ENOSPC;
+		}
 	}
+
 	/*
 	 * Allocate what we can and return it.
 	 */