[PATCH 08/12] xfs: push the calls to xfs_rtallocate_range out to xfs_bmap_rtalloc

Darrick J. Wong
2024-08-23T00:11:01Z

From: Christoph Hellwig <hch@lst.de>

Currently the various low-level RT allocator functions call into
xfs_rtallocate_range directly, which ties them into the locking protocol
for the RT bitmap. As these helpers already return the allocated range,
lift the call to xfs_rtallocate_range into xfs_bmap_rtalloc so that it
happens as high as possible in the stack, which will simplify future
changes to the locking protocol.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
fs/xfs/xfs_rtalloc.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
index 8da59d941db3c..a98e22c76280b 100644
--- a/fs/xfs/xfs_rtalloc.c
+++ b/fs/xfs/xfs_rtalloc.c
@@ -261,9 +261,9 @@ xfs_rtallocate_extent_block(
/*
* i for maxlen is all free, allocate and return that.
*/
- bestlen = maxlen;
- besti = i;
- goto allocate;
+ *len = maxlen;
+ *rtx = i;
+ return 0;
}

/*
@@ -314,12 +314,8 @@ xfs_rtallocate_extent_block(
}

/*
- * Allocate besti for bestlen & return that.
+ * Pick besti for bestlen & return that.
*/
-allocate:
- error = xfs_rtallocate_range(args, besti, bestlen);
- if (error)
- return error;
*len = bestlen;
*rtx = besti;
return 0;
@@ -373,12 +369,6 @@ xfs_rtallocate_extent_exact(
}
}

- /*
- * Allocate what we can and return it.
- */
- error = xfs_rtallocate_range(args, start, maxlen);
- if (error)
- return error;
*len = maxlen;
*rtx = start;
return 0;
@@ -431,7 +421,6 @@ xfs_rtallocate_extent_near(
if (error != -ENOSPC)
return error;

-
bbno = xfs_rtx_to_rbmblock(mp, start);
i = 0;
j = -1;
@@ -554,11 +543,11 @@ xfs_rtalloc_sumlevel(
xfs_rtxnum_t *rtx) /* out: start rtext allocated */
{
xfs_fileoff_t i; /* bitmap block number */
+ int error;

for (i = 0; i < args->mp->m_sb.sb_rbmblocks; i++) {
xfs_suminfo_t sum; /* summary information for extents */
xfs_rtxnum_t n; /* next rtext to be tried */
- int error;

error = xfs_rtget_summary(args, l, i, &sum);
if (error)
@@ -1473,9 +1462,12 @@ xfs_bmap_rtalloc(
error = xfs_rtallocate_extent_size(&args, raminlen,
ralen, &ralen, prod, &rtx);
}
- xfs_rtbuf_cache_relse(&args);

- if (error == -ENOSPC) {
+ if (error) {
+ xfs_rtbuf_cache_relse(&args);
+ if (error != -ENOSPC)
+ return error;
+
if (align > mp->m_sb.sb_rextsize) {
/*
* We previously enlarged the request length to try to
@@ -1503,14 +1495,20 @@ xfs_bmap_rtalloc(
ap->length = 0;
return 0;
}
+
+ error = xfs_rtallocate_range(&args, rtx, ralen);
if (error)
- return error;
+ goto out_release;

xfs_trans_mod_sb(ap->tp, ap->wasdel ?
XFS_TRANS_SB_RES_FREXTENTS : XFS_TRANS_SB_FREXTENTS,
-(long)ralen);
+
ap->blkno = xfs_rtx_to_rtb(mp, rtx);
ap->length = xfs_rtxlen_to_extlen(mp, ralen);
xfs_bmap_alloc_account(ap);
- return 0;
+
+out_release:
+ xfs_rtbuf_cache_relse(&args);
+ return error;
}