[PATCH 24/50] xfs: use xfs_alloc_vextent_this_ag() in _iterate_ags()

Dave Chinner
2022-06-11T01:27:20Z

Because the core of the per-ag iteration is calling "this ag"
allocation on one AG at a time. This brings the number of callers of
xfs_alloc_ag_vextent() down to 1.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
fs/xfs/libxfs/xfs_alloc.c | 57 +++++++++++++++++++--------------------
1 file changed, 28 insertions(+), 29 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
index 2978b4afe2e4..9c40d93c63d4 100644
--- a/fs/xfs/libxfs/xfs_alloc.c
+++ b/fs/xfs/libxfs/xfs_alloc.c
@@ -3224,6 +3224,28 @@ xfs_alloc_vextent_set_fsbno(
/*
* Allocate within a single AG only.
*/
+static int
+__xfs_alloc_vextent_this_ag(
+ struct xfs_alloc_arg *args)
+{
+ struct xfs_mount *mp = args->mp;
+ int error;
+
+ error = xfs_alloc_fix_freelist(args, 0);
+ if (error) {
+ trace_xfs_alloc_vextent_nofix(args);
+ return error;
+ }
+ if (!args->agbp) {
+ /* cannot allocate in this AG at all */
+ trace_xfs_alloc_vextent_noagbp(args);
+ args->agbno = NULLAGBLOCK;
+ return 0;
+ }
+ args->agbno = XFS_FSB_TO_AGBNO(mp, args->fsbno);
+ return xfs_alloc_ag_vextent(args);
+}
+
static int
xfs_alloc_vextent_this_ag(
struct xfs_alloc_arg *args)
@@ -3240,24 +3262,13 @@ xfs_alloc_vextent_this_ag(

args->agno = XFS_FSB_TO_AGNO(mp, args->fsbno);
args->pag = xfs_perag_get(mp, args->agno);
- error = xfs_alloc_fix_freelist(args, 0);
- if (error) {
- trace_xfs_alloc_vextent_nofix(args);
- goto out_error;
- }
- if (!args->agbp) {
- trace_xfs_alloc_vextent_noagbp(args);
- goto out_error;
- }
- args->agbno = XFS_FSB_TO_AGBNO(mp, args->fsbno);
- error = xfs_alloc_ag_vextent(args);
+ error = __xfs_alloc_vextent_this_ag(args);
+ xfs_perag_put(args->pag);
if (error)
- goto out_error;
+ return error;

xfs_alloc_vextent_set_fsbno(args);
-out_error:
- xfs_perag_put(args->pag);
- return error;
+ return 0;
}

/*
@@ -3295,24 +3306,12 @@ xfs_alloc_vextent_iterate_ags(
args->agno = start_agno;
for (;;) {
args->pag = xfs_perag_get(mp, args->agno);
- error = xfs_alloc_fix_freelist(args, flags);
- if (error) {
- trace_xfs_alloc_vextent_nofix(args);
- break;
- }
- /*
- * If we get a buffer back then the allocation will fly.
- */
- if (args->agbp) {
- error = xfs_alloc_ag_vextent(args);
+ error = __xfs_alloc_vextent_this_ag(args);
+ if (error || args->agbp)
break;
- }

trace_xfs_alloc_vextent_loopfailed(args);

- /*
- * Didn't work, figure out the next iteration.
- */
if (args->agno == start_agno &&
args->otype == XFS_ALLOCTYPE_START_BNO)
args->type = XFS_ALLOCTYPE_THIS_AG;
--
2.35.1