]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: introduce xfs_alloc_vextent_exact_bno()
authorDave Chinner <dchinner@redhat.com>
Tue, 9 May 2023 09:30:26 +0000 (11:30 +0200)
committerCarlos Maiolino <cem@kernel.org>
Wed, 10 May 2023 12:30:42 +0000 (14:30 +0200)
Source kernel commit: 5f36b2ce79f254dd00cdc88374271df7ce843d56

Two of the callers to xfs_alloc_vextent_this_ag() actually want
exact block number allocation, not anywhere-in-ag allocation. Split
this out from _this_ag() as a first class citizen so no external
extent allocation code needs to care about args->type anymore.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Carlos Maiolino <cem@kernel.org>
libxfs/xfs_ag.c
libxfs/xfs_alloc.c
libxfs/xfs_alloc.h
libxfs/xfs_bmap.c
libxfs/xfs_ialloc.c

index 554afdb17ddcb8f859e390629476591ddef590d4..224ee005ca8fa1a226b4077e765f353a133acf8e 100644 (file)
@@ -886,7 +886,6 @@ xfs_ag_shrink_space(
                .tp     = *tpp,
                .mp     = mp,
                .pag    = pag,
-               .type   = XFS_ALLOCTYPE_THIS_BNO,
                .minlen = delta,
                .maxlen = delta,
                .oinfo  = XFS_RMAP_OINFO_SKIP_UPDATE,
@@ -918,8 +917,6 @@ xfs_ag_shrink_space(
        if (delta >= aglen)
                return -EINVAL;
 
-       args.fsbno = XFS_AGB_TO_FSB(mp, pag->pag_agno, aglen - delta);
-
        /*
         * Make sure that the last inode cluster cannot overlap with the new
         * end of the AG, even if it's sparse.
@@ -937,7 +934,8 @@ xfs_ag_shrink_space(
                return error;
 
        /* internal log shouldn't also show up in the free space btrees */
-       error = xfs_alloc_vextent_this_ag(&args);
+       error = xfs_alloc_vextent_exact_bno(&args,
+                       XFS_AGB_TO_FSB(mp, pag->pag_agno, aglen - delta));
        if (!error && args.agbno == NULLAGBLOCK)
                error = -ENOSPC;
 
index 797d1a2aa81b921760f9a42fe04d6e17f6b7f995..993403c089934a83b53e73ff8b90cedd71a87c5e 100644 (file)
@@ -3268,28 +3268,34 @@ xfs_alloc_vextent_set_fsbno(
  */
 int
 xfs_alloc_vextent_this_ag(
-       struct xfs_alloc_arg    *args)
+       struct xfs_alloc_arg    *args,
+       xfs_agnumber_t          agno)
 {
        struct xfs_mount        *mp = args->mp;
        xfs_agnumber_t          minimum_agno = 0;
+       xfs_rfsblock_t          target = XFS_AGB_TO_FSB(mp, agno, 0);
        int                     error;
 
        if (args->tp->t_highest_agno != NULLAGNUMBER)
                minimum_agno = args->tp->t_highest_agno;
 
-       error = xfs_alloc_vextent_check_args(args, args->fsbno);
+       if (minimum_agno > agno) {
+               trace_xfs_alloc_vextent_skip_deadlock(args);
+               args->fsbno = NULLFSBLOCK;
+               return 0;
+       }
+
+       error = xfs_alloc_vextent_check_args(args, target);
        if (error) {
                if (error == -ENOSPC)
                        return 0;
                return error;
        }
 
-       args->agno = XFS_FSB_TO_AGNO(mp, args->fsbno);
-       if (minimum_agno > args->agno) {
-               trace_xfs_alloc_vextent_skip_deadlock(args);
-               args->fsbno = NULLFSBLOCK;
-               return 0;
-       }
+       args->agno = agno;
+       args->agbno = 0;
+       args->fsbno = target;
+       args->type = XFS_ALLOCTYPE_THIS_AG;
 
        error = xfs_alloc_ag_vextent(args);
        xfs_alloc_vextent_set_fsbno(args, minimum_agno);
@@ -3468,12 +3474,51 @@ xfs_alloc_vextent_first_ag(
        start_agno = max(minimum_agno, XFS_FSB_TO_AGNO(mp, target));
        args->type = XFS_ALLOCTYPE_THIS_AG;
        args->fsbno = target;
-       error =  xfs_alloc_vextent_iterate_ags(args, minimum_agno,
+       error = xfs_alloc_vextent_iterate_ags(args, minimum_agno,
                        start_agno, 0);
        xfs_alloc_vextent_set_fsbno(args, minimum_agno);
        return error;
 }
 
+/*
+ * Allocate within a single AG only.
+ */
+int
+xfs_alloc_vextent_exact_bno(
+       struct xfs_alloc_arg    *args,
+       xfs_fsblock_t           target)
+{
+       struct xfs_mount        *mp = args->mp;
+       xfs_agnumber_t          minimum_agno = 0;
+       int                     error;
+
+       if (args->tp->t_highest_agno != NULLAGNUMBER)
+               minimum_agno = args->tp->t_highest_agno;
+
+       error = xfs_alloc_vextent_check_args(args, target);
+       if (error) {
+               if (error == -ENOSPC)
+                       return 0;
+               return error;
+       }
+
+       args->agno = XFS_FSB_TO_AGNO(mp, target);
+       if (minimum_agno > args->agno) {
+               trace_xfs_alloc_vextent_skip_deadlock(args);
+               return 0;
+       }
+
+       args->agbno = XFS_FSB_TO_AGBNO(mp, target);
+       args->fsbno = target;
+       args->type = XFS_ALLOCTYPE_THIS_BNO;
+       error = xfs_alloc_ag_vextent(args);
+       if (error)
+               return error;
+
+       xfs_alloc_vextent_set_fsbno(args, minimum_agno);
+       return 0;
+}
+
 /*
  * Allocate an extent as close to the target as possible. If there are not
  * viable candidates in the AG, then fail the allocation.
index 45a428e770f0713a92f686da1f3d114aaeb1de42..63d5ad4ed8a3c91a95dc3045ec63ac1d4d7a0402 100644 (file)
@@ -114,10 +114,10 @@ xfs_alloc_log_agf(
        uint32_t        fields);/* mask of fields to be logged (XFS_AGF_...) */
 
 /*
- * Allocate an extent in the specific AG defined by args->fsbno. If there is no
- * space in that AG, then the allocation will fail.
+ * Allocate an extent anywhere in the specific AG given. If there is no
+ * space matching the requirements in that AG, then the allocation will fail.
  */
-int xfs_alloc_vextent_this_ag(struct xfs_alloc_arg *args);
+int xfs_alloc_vextent_this_ag(struct xfs_alloc_arg *args, xfs_agnumber_t agno);
 
 /*
  * Allocate an extent as close to the target as possible. If there are not
@@ -126,6 +126,13 @@ int xfs_alloc_vextent_this_ag(struct xfs_alloc_arg *args);
 int xfs_alloc_vextent_near_bno(struct xfs_alloc_arg *args,
                xfs_fsblock_t target);
 
+/*
+ * Allocate an extent exactly at the target given. If this is not possible
+ * then the allocation fails.
+ */
+int xfs_alloc_vextent_exact_bno(struct xfs_alloc_arg *args,
+               xfs_fsblock_t target);
+
 /*
  * Best effort full filesystem allocation scan.
  *
index ea52414256cec982c2ef9f288e7eb7e8f00d5c6d..df63dc5c504a181bbb030f3a7a7d42a3f4440ae8 100644 (file)
@@ -3507,7 +3507,6 @@ xfs_bmap_btalloc_at_eof(
                xfs_extlen_t    nextminlen = 0;
 
                atype = args->type;
-               args->type = XFS_ALLOCTYPE_THIS_BNO;
                args->alignment = 1;
 
                /*
@@ -3525,8 +3524,8 @@ xfs_bmap_btalloc_at_eof(
                else
                        args->minalignslop = 0;
 
-               args->pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, args->fsbno));
-               error = xfs_alloc_vextent_this_ag(args);
+               args->pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ap->blkno));
+               error = xfs_alloc_vextent_exact_bno(args, ap->blkno);
                xfs_perag_put(args->pag);
                if (error)
                        return error;
@@ -3539,7 +3538,6 @@ xfs_bmap_btalloc_at_eof(
                 */
                args->pag = NULL;
                args->type = atype;
-               args->fsbno = ap->blkno;
                args->alignment = stripe_align;
                args->minlen = nextminlen;
                args->minalignslop = 0;
index 77ea0ce26145f900995cf1d7413c666b9ba465d4..791880a30e6453ef356c7869be1eddd9d10c1104 100644 (file)
@@ -657,8 +657,6 @@ xfs_ialloc_ag_alloc(
                goto sparse_alloc;
        if (likely(newino != NULLAGINO &&
                  (args.agbno < be32_to_cpu(agi->agi_length)))) {
-               args.fsbno = XFS_AGB_TO_FSB(args.mp, pag->pag_agno, args.agbno);
-               args.type = XFS_ALLOCTYPE_THIS_BNO;
                args.prod = 1;
 
                /*
@@ -679,7 +677,9 @@ xfs_ialloc_ag_alloc(
 
                /* Allow space for the inode btree to split. */
                args.minleft = igeo->inobt_maxlevels;
-               error = xfs_alloc_vextent_this_ag(&args);
+               error = xfs_alloc_vextent_exact_bno(&args,
+                               XFS_AGB_TO_FSB(args.mp, pag->pag_agno,
+                                               args.agbno));
                if (error)
                        return error;