]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: pass perags through to the busy extent code
authorDave Chinner <dchinner@redhat.com>
Fri, 15 Oct 2021 20:28:25 +0000 (16:28 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Fri, 15 Oct 2021 20:28:25 +0000 (16:28 -0400)
Source kernel commit: 45d0662117565e6100f9e0cf356cd873542c95b1

All of the callers of the busy extent API either have perag
references available to use so we can pass a perag to the busy
extent functions rather than having them have to do unnecessary
lookups.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/libxfs_priv.h
libxfs/xfs_alloc.c
libxfs/xfs_alloc.h
libxfs/xfs_alloc_btree.c
libxfs/xfs_rmap.c
libxfs/xfs_rmap_btree.c

index 7b4e8f55226ec1a78293c9bad738dbf578845b1d..15bae1ffde885edfe63c0f4992a1e0c3b7f6963b 100644 (file)
@@ -485,8 +485,8 @@ void __xfs_buf_mark_corrupt(struct xfs_buf *bp, xfs_failaddr_t fa);
 
 #define xfs_extent_busy_reuse(mp,ag,bno,len,user)      ((void) 0)
 /* avoid unused variable warning */
-#define xfs_extent_busy_insert(tp,ag,bno,len,flags)({  \
-       xfs_agnumber_t __foo = ag;                      \
+#define xfs_extent_busy_insert(tp,pag,bno,len,flags)({         \
+       struct xfs_perag *__foo = pag;                  \
        __foo = __foo; /* no set-but-unused warning */  \
 })
 #define xfs_extent_busy_trim(args,bno,len,busy_gen)    ({      \
index 37f107517635c03949c2e875d0372d77f4ceda1a..c69761eba684d6f4bb0945995c698ed5a26ce5e9 100644 (file)
@@ -1059,7 +1059,7 @@ xfs_alloc_ag_vextent_small(
        if (fbno == NULLAGBLOCK)
                goto out;
 
-       xfs_extent_busy_reuse(args->mp, args->agno, fbno, 1,
+       xfs_extent_busy_reuse(args->mp, args->pag, fbno, 1,
                              (args->datatype & XFS_ALLOC_NOBUSY));
 
        if (args->datatype & XFS_ALLOC_USERDATA) {
@@ -1174,7 +1174,7 @@ xfs_alloc_ag_vextent(
                if (error)
                        return error;
 
-               ASSERT(!xfs_extent_busy_search(args->mp, args->agno,
+               ASSERT(!xfs_extent_busy_search(args->mp, args->pag,
                                              args->agbno, args->len));
        }
 
@@ -3288,7 +3288,7 @@ error0:
 int
 xfs_free_extent_fix_freelist(
        struct xfs_trans        *tp,
-       xfs_agnumber_t          agno,
+       struct xfs_perag        *pag,
        struct xfs_buf          **agbp)
 {
        struct xfs_alloc_arg    args;
@@ -3297,7 +3297,8 @@ xfs_free_extent_fix_freelist(
        memset(&args, 0, sizeof(struct xfs_alloc_arg));
        args.tp = tp;
        args.mp = tp->t_mountp;
-       args.agno = agno;
+       args.agno = pag->pag_agno;
+       args.pag = pag;
 
        /*
         * validate that the block number is legal - the enables us to detect
@@ -3306,17 +3307,12 @@ xfs_free_extent_fix_freelist(
        if (args.agno >= args.mp->m_sb.sb_agcount)
                return -EFSCORRUPTED;
 
-       args.pag = xfs_perag_get(args.mp, args.agno);
-       ASSERT(args.pag);
-
        error = xfs_alloc_fix_freelist(&args, XFS_ALLOC_FLAG_FREEING);
        if (error)
-               goto out;
+               return error;
 
        *agbp = args.agbp;
-out:
-       xfs_perag_put(args.pag);
-       return error;
+       return 0;
 }
 
 /*
@@ -3340,6 +3336,7 @@ __xfs_free_extent(
        struct xfs_agf                  *agf;
        int                             error;
        unsigned int                    busy_flags = 0;
+       struct xfs_perag                *pag;
 
        ASSERT(len != 0);
        ASSERT(type != XFS_AG_RESV_AGFL);
@@ -3348,33 +3345,37 @@ __xfs_free_extent(
                        XFS_ERRTAG_FREE_EXTENT))
                return -EIO;
 
-       error = xfs_free_extent_fix_freelist(tp, agno, &agbp);
+       pag = xfs_perag_get(mp, agno);
+       error = xfs_free_extent_fix_freelist(tp, pag, &agbp);
        if (error)
-               return error;
+               goto err;
        agf = agbp->b_addr;
 
        if (XFS_IS_CORRUPT(mp, agbno >= mp->m_sb.sb_agblocks)) {
                error = -EFSCORRUPTED;
-               goto err;
+               goto err_release;
        }
 
        /* validate the extent size is legal now we have the agf locked */
        if (XFS_IS_CORRUPT(mp, agbno + len > be32_to_cpu(agf->agf_length))) {
                error = -EFSCORRUPTED;
-               goto err;
+               goto err_release;
        }
 
        error = xfs_free_ag_extent(tp, agbp, agno, agbno, len, oinfo, type);
        if (error)
-               goto err;
+               goto err_release;
 
        if (skip_discard)
                busy_flags |= XFS_EXTENT_BUSY_SKIP_DISCARD;
-       xfs_extent_busy_insert(tp, agno, agbno, len, busy_flags);
+       xfs_extent_busy_insert(tp, pag, agbno, len, busy_flags);
+       xfs_perag_put(pag);
        return 0;
 
-err:
+err_release:
        xfs_trans_brelse(tp, agbp);
+err:
+       xfs_perag_put(pag);
        return error;
 }
 
index a4427c5775c252e2672dc36200bf359b06dbb325..e30900b6f8ba4b53d0ae49f7464f7a6be2845b06 100644 (file)
@@ -214,7 +214,7 @@ int xfs_alloc_read_agfl(struct xfs_mount *mp, struct xfs_trans *tp,
 int xfs_free_agfl_block(struct xfs_trans *, xfs_agnumber_t, xfs_agblock_t,
                        struct xfs_buf *, struct xfs_owner_info *);
 int xfs_alloc_fix_freelist(struct xfs_alloc_arg *args, int flags);
-int xfs_free_extent_fix_freelist(struct xfs_trans *tp, xfs_agnumber_t agno,
+int xfs_free_extent_fix_freelist(struct xfs_trans *tp, struct xfs_perag *pag,
                struct xfs_buf **agbp);
 
 xfs_extlen_t xfs_prealloc_blocks(struct xfs_mount *mp);
index fa1d3a0f115497bc61dab33fff6772746eb9d849..00a17bb0ac084643e1f0aeaf0c9375bac691986d 100644 (file)
@@ -70,7 +70,7 @@ xfs_allocbt_alloc_block(
        }
 
        atomic64_inc(&cur->bc_mp->m_allocbt_blks);
-       xfs_extent_busy_reuse(cur->bc_mp, cur->bc_ag.agno, bno, 1, false);
+       xfs_extent_busy_reuse(cur->bc_mp, cur->bc_ag.agbp->b_pag, bno, 1, false);
 
        new->s = cpu_to_be32(bno);
 
@@ -84,7 +84,6 @@ xfs_allocbt_free_block(
        struct xfs_buf          *bp)
 {
        struct xfs_buf          *agbp = cur->bc_ag.agbp;
-       struct xfs_agf          *agf = agbp->b_addr;
        xfs_agblock_t           bno;
        int                     error;
 
@@ -94,7 +93,7 @@ xfs_allocbt_free_block(
                return error;
 
        atomic64_dec(&cur->bc_mp->m_allocbt_blks);
-       xfs_extent_busy_insert(cur->bc_tp, be32_to_cpu(agf->agf_seqno), bno, 1,
+       xfs_extent_busy_insert(cur->bc_tp, agbp->b_pag, bno, 1,
                              XFS_EXTENT_BUSY_SKIP_DISCARD);
        return 0;
 }
index 631c62c0078064f80f8833364b325e55ebc42e72..6323ccdc21f220cc247cfccf5ad5ca9f7c93c15d 100644 (file)
@@ -11,6 +11,7 @@
 #include "xfs_trans_resv.h"
 #include "xfs_bit.h"
 #include "xfs_mount.h"
+#include "xfs_sb.h"
 #include "xfs_defer.h"
 #include "xfs_btree.h"
 #include "xfs_trans.h"
@@ -2362,31 +2363,32 @@ xfs_rmap_finish_one(
        struct xfs_btree_cur            **pcur)
 {
        struct xfs_mount                *mp = tp->t_mountp;
+       struct xfs_perag                *pag;
        struct xfs_btree_cur            *rcur;
        struct xfs_buf                  *agbp = NULL;
        int                             error = 0;
-       xfs_agnumber_t                  agno;
        struct xfs_owner_info           oinfo;
        xfs_agblock_t                   bno;
        bool                            unwritten;
 
-       agno = XFS_FSB_TO_AGNO(mp, startblock);
-       ASSERT(agno != NULLAGNUMBER);
+       pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, startblock));
        bno = XFS_FSB_TO_AGBNO(mp, startblock);
 
-       trace_xfs_rmap_deferred(mp, agno, type, bno, owner, whichfork,
+       trace_xfs_rmap_deferred(mp, pag->pag_agno, type, bno, owner, whichfork,
                        startoff, blockcount, state);
 
-       if (XFS_TEST_ERROR(false, mp,
-                       XFS_ERRTAG_RMAP_FINISH_ONE))
-               return -EIO;
+       if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_RMAP_FINISH_ONE)) {
+               error = -EIO;
+               goto out_drop;
+       }
+
 
        /*
         * If we haven't gotten a cursor or the cursor AG doesn't match
         * the startblock, get one now.
         */
        rcur = *pcur;
-       if (rcur != NULL && rcur->bc_ag.agno != agno) {
+       if (rcur != NULL && rcur->bc_ag.agno != pag->pag_agno) {
                xfs_rmap_finish_one_cleanup(tp, rcur, 0);
                rcur = NULL;
                *pcur = NULL;
@@ -2397,13 +2399,15 @@ xfs_rmap_finish_one(
                 * rmapbt, because a shape change could cause us to
                 * allocate blocks.
                 */
-               error = xfs_free_extent_fix_freelist(tp, agno, &agbp);
+               error = xfs_free_extent_fix_freelist(tp, pag, &agbp);
                if (error)
-                       return error;
-               if (XFS_IS_CORRUPT(tp->t_mountp, !agbp))
-                       return -EFSCORRUPTED;
+                       goto out_drop;
+               if (XFS_IS_CORRUPT(tp->t_mountp, !agbp)) {
+                       error = -EFSCORRUPTED;
+                       goto out_drop;
+               }
 
-               rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, agno);
+               rcur = xfs_rmapbt_init_cursor(mp, tp, agbp, pag->pag_agno);
        }
        *pcur = rcur;
 
@@ -2441,6 +2445,8 @@ xfs_rmap_finish_one(
                ASSERT(0);
                error = -EFSCORRUPTED;
        }
+out_drop:
+       xfs_perag_put(pag);
        return error;
 }
 
index bcbe9833db492c37c17068c08337c46f568df342..7abca87e48aa051d92197e6cc00f4aaf5245f582 100644 (file)
@@ -98,8 +98,7 @@ xfs_rmapbt_alloc_block(
                return 0;
        }
 
-       xfs_extent_busy_reuse(cur->bc_mp, cur->bc_ag.agno, bno, 1,
-                       false);
+       xfs_extent_busy_reuse(cur->bc_mp, agbp->b_pag, bno, 1, false);
 
        new->s = cpu_to_be32(bno);
        be32_add_cpu(&agf->agf_rmap_blocks, 1);
@@ -131,10 +130,10 @@ xfs_rmapbt_free_block(
        if (error)
                return error;
 
-       xfs_extent_busy_insert(cur->bc_tp, be32_to_cpu(agf->agf_seqno), bno, 1,
+       pag = cur->bc_ag.agbp->b_pag;
+       xfs_extent_busy_insert(cur->bc_tp, pag, bno, 1,
                              XFS_EXTENT_BUSY_SKIP_DISCARD);
 
-       pag = cur->bc_ag.agbp->b_pag;
        xfs_ag_resv_free_extent(pag, XFS_AG_RESV_RMAPBT, NULL, 1);
        return 0;
 }