]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: give xfs_refcount_intent its own perag reference
authorDarrick J. Wong <djwong@kernel.org>
Tue, 30 May 2023 08:44:56 +0000 (10:44 +0200)
committerCarlos Maiolino <cem@kernel.org>
Fri, 9 Jun 2023 08:27:50 +0000 (10:27 +0200)
Source kernel commit: 00e7b3bac1dc8961bd5aa9d39e79131c6bd81181

Give the xfs_refcount_intent a passive reference to the perag structure
data.  This reference will be used to enable scrub intent draining
functionality in subsequent patches.  Any space being modified by a
refcount intent is already allocated, so we need to be able to operate
even if the AG is being shrunk or offlined.

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

index 8c511eb4eeccda0d1bc834457e7d74cab7de4ded..dc00d6d671d14ca150dc5277b3748d4a36c7fc3b 100644 (file)
@@ -310,14 +310,13 @@ xfs_refcount_update_diff_items(
        struct list_head                *a,
        struct list_head                *b)
 {
-       struct xfs_mount                *mp = priv;
        struct xfs_refcount_intent      *ra;
        struct xfs_refcount_intent      *rb;
 
        ra = container_of(a, struct xfs_refcount_intent, ri_list);
        rb = container_of(b, struct xfs_refcount_intent, ri_list);
-       return  XFS_FSB_TO_AGNO(mp, ra->ri_startblock) -
-               XFS_FSB_TO_AGNO(mp, rb->ri_startblock);
+
+       return ra->ri_pag->pag_agno - rb->ri_pag->pag_agno;
 }
 
 /* Get an CUI. */
@@ -345,6 +344,26 @@ xfs_refcount_update_create_done(
        return NULL;
 }
 
+/* Take a passive ref to the AG containing the space we're refcounting. */
+void
+xfs_refcount_update_get_group(
+       struct xfs_mount                *mp,
+       struct xfs_refcount_intent      *ri)
+{
+       xfs_agnumber_t                  agno;
+
+       agno = XFS_FSB_TO_AGNO(mp, ri->ri_startblock);
+       ri->ri_pag = xfs_perag_get(mp, agno);
+}
+
+/* Release a passive AG ref after finishing refcounting work. */
+static inline void
+xfs_refcount_update_put_group(
+       struct xfs_refcount_intent      *ri)
+{
+       xfs_perag_put(ri->ri_pag);
+}
+
 /* Process a deferred refcount update. */
 STATIC int
 xfs_refcount_update_finish_item(
@@ -365,6 +384,8 @@ xfs_refcount_update_finish_item(
                       ri->ri_type == XFS_REFCOUNT_DECREASE);
                return -EAGAIN;
        }
+
+       xfs_refcount_update_put_group(ri);
        kmem_cache_free(xfs_refcount_intent_cache, ri);
        return error;
 }
@@ -384,6 +405,8 @@ xfs_refcount_update_cancel_item(
        struct xfs_refcount_intent      *ri;
 
        ri = container_of(item, struct xfs_refcount_intent, ri_list);
+
+       xfs_refcount_update_put_group(ri);
        kmem_cache_free(xfs_refcount_intent_cache, ri);
 }
 
index e9954f4b70864789ef1750c49595747fbd5d4671..460da7e415aae0a803b2f37b7bfa37b15b544e1f 100644 (file)
@@ -1331,26 +1331,22 @@ xfs_refcount_finish_one(
        xfs_agblock_t                   bno;
        unsigned long                   nr_ops = 0;
        int                             shape_changes = 0;
-       struct xfs_perag                *pag;
 
-       pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ri->ri_startblock));
        bno = XFS_FSB_TO_AGBNO(mp, ri->ri_startblock);
 
        trace_xfs_refcount_deferred(mp, XFS_FSB_TO_AGNO(mp, ri->ri_startblock),
                        ri->ri_type, XFS_FSB_TO_AGBNO(mp, ri->ri_startblock),
                        ri->ri_blockcount);
 
-       if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_REFCOUNT_FINISH_ONE)) {
-               error = -EIO;
-               goto out_drop;
-       }
+       if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_REFCOUNT_FINISH_ONE))
+               return -EIO;
 
        /*
         * 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.pag != pag) {
+       if (rcur != NULL && rcur->bc_ag.pag != ri->ri_pag) {
                nr_ops = rcur->bc_ag.refc.nr_ops;
                shape_changes = rcur->bc_ag.refc.shape_changes;
                xfs_refcount_finish_one_cleanup(tp, rcur, 0);
@@ -1358,12 +1354,12 @@ xfs_refcount_finish_one(
                *pcur = NULL;
        }
        if (rcur == NULL) {
-               error = xfs_alloc_read_agf(pag, tp, XFS_ALLOC_FLAG_FREEING,
-                               &agbp);
+               error = xfs_alloc_read_agf(ri->ri_pag, tp,
+                               XFS_ALLOC_FLAG_FREEING, &agbp);
                if (error)
-                       goto out_drop;
+                       return error;
 
-               rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, pag);
+               rcur = xfs_refcountbt_init_cursor(mp, tp, agbp, ri->ri_pag);
                rcur->bc_ag.refc.nr_ops = nr_ops;
                rcur->bc_ag.refc.shape_changes = shape_changes;
        }
@@ -1374,7 +1370,7 @@ xfs_refcount_finish_one(
                error = xfs_refcount_adjust(rcur, &bno, &ri->ri_blockcount,
                                XFS_REFCOUNT_ADJUST_INCREASE);
                if (error)
-                       goto out_drop;
+                       return error;
                if (ri->ri_blockcount > 0)
                        error = xfs_refcount_continue_op(rcur, ri, bno);
                break;
@@ -1382,31 +1378,29 @@ xfs_refcount_finish_one(
                error = xfs_refcount_adjust(rcur, &bno, &ri->ri_blockcount,
                                XFS_REFCOUNT_ADJUST_DECREASE);
                if (error)
-                       goto out_drop;
+                       return error;
                if (ri->ri_blockcount > 0)
                        error = xfs_refcount_continue_op(rcur, ri, bno);
                break;
        case XFS_REFCOUNT_ALLOC_COW:
                error = __xfs_refcount_cow_alloc(rcur, bno, ri->ri_blockcount);
                if (error)
-                       goto out_drop;
+                       return error;
                ri->ri_blockcount = 0;
                break;
        case XFS_REFCOUNT_FREE_COW:
                error = __xfs_refcount_cow_free(rcur, bno, ri->ri_blockcount);
                if (error)
-                       goto out_drop;
+                       return error;
                ri->ri_blockcount = 0;
                break;
        default:
                ASSERT(0);
-               error = -EFSCORRUPTED;
+               return -EFSCORRUPTED;
        }
        if (!error && ri->ri_blockcount > 0)
-               trace_xfs_refcount_finish_one_leftover(mp, pag->pag_agno,
+               trace_xfs_refcount_finish_one_leftover(mp, ri->ri_pag->pag_agno,
                                ri->ri_type, bno, ri->ri_blockcount);
-out_drop:
-       xfs_perag_put(pag);
        return error;
 }
 
@@ -1434,6 +1428,7 @@ __xfs_refcount_add(
        ri->ri_startblock = startblock;
        ri->ri_blockcount = blockcount;
 
+       xfs_refcount_update_get_group(tp->t_mountp, ri);
        xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_REFCOUNT, &ri->ri_list);
 }
 
index c633477ce3cef0eb3ab3367d42f9f2a19e71407e..c89f0fcd1ee311681e89aab62116c0494db03291 100644 (file)
@@ -50,6 +50,7 @@ enum xfs_refcount_intent_type {
 
 struct xfs_refcount_intent {
        struct list_head                        ri_list;
+       struct xfs_perag                        *ri_pag;
        enum xfs_refcount_intent_type           ri_type;
        xfs_extlen_t                            ri_blockcount;
        xfs_fsblock_t                           ri_startblock;
@@ -67,6 +68,9 @@ xfs_refcount_check_domain(
        return true;
 }
 
+void xfs_refcount_update_get_group(struct xfs_mount *mp,
+               struct xfs_refcount_intent *ri);
+
 void xfs_refcount_increase_extent(struct xfs_trans *tp,
                struct xfs_bmbt_irec *irec);
 void xfs_refcount_decrease_extent(struct xfs_trans *tp,