]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: pass refcount intent directly through the log intent code
authorDarrick J. Wong <djwong@kernel.org>
Fri, 17 Feb 2023 02:31:42 +0000 (18:31 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 6 Apr 2023 00:05:53 +0000 (17:05 -0700)
Source kernel commit: 0b11553ec54a6d88907e60d0595dbcef98539747

Pass the incore refcount intent through the CUI logging code instead of
repeatedly boxing and unboxing parameters.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
libxfs/defer_item.c
libxfs/xfs_refcount.c
libxfs/xfs_refcount.h

index 56f44e3210112321db0b6f0dbc561f8f97662db6..b95b54e524c456cfe9db015ea12f8376f3458081 100644 (file)
@@ -305,27 +305,19 @@ xfs_refcount_update_finish_item(
        struct list_head                *item,
        struct xfs_btree_cur            **state)
 {
-       struct xfs_refcount_intent      *refc;
-       xfs_fsblock_t                   new_fsb;
-       xfs_extlen_t                    new_aglen;
+       struct xfs_refcount_intent      *ri;
        int                             error;
 
-       refc = container_of(item, struct xfs_refcount_intent, ri_list);
-       error = xfs_refcount_finish_one(tp,
-                       refc->ri_type,
-                       refc->ri_startblock,
-                       refc->ri_blockcount,
-                       &new_fsb, &new_aglen,
-                       state);
+       ri = container_of(item, struct xfs_refcount_intent, ri_list);
+       error = xfs_refcount_finish_one(tp, ri, state);
+
        /* Did we run out of reservation?  Requeue what we didn't finish. */
-       if (!error && new_aglen > 0) {
-               ASSERT(refc->ri_type == XFS_REFCOUNT_INCREASE ||
-                      refc->ri_type == XFS_REFCOUNT_DECREASE);
-               refc->ri_startblock = new_fsb;
-               refc->ri_blockcount = new_aglen;
+       if (!error && ri->ri_blockcount > 0) {
+               ASSERT(ri->ri_type == XFS_REFCOUNT_INCREASE ||
+                      ri->ri_type == XFS_REFCOUNT_DECREASE);
                return -EAGAIN;
        }
-       kmem_cache_free(xfs_refcount_intent_cache, refc);
+       kmem_cache_free(xfs_refcount_intent_cache, ri);
        return error;
 }
 
@@ -341,10 +333,10 @@ STATIC void
 xfs_refcount_update_cancel_item(
        struct list_head                *item)
 {
-       struct xfs_refcount_intent      *refc;
+       struct xfs_refcount_intent      *ri;
 
-       refc = container_of(item, struct xfs_refcount_intent, ri_list);
-       kmem_cache_free(xfs_refcount_intent_cache, refc);
+       ri = container_of(item, struct xfs_refcount_intent, ri_list);
+       kmem_cache_free(xfs_refcount_intent_cache, ri);
 }
 
 const struct xfs_defer_op_type xfs_refcount_update_defer_type = {
index 29258bddbcd55e63781116b9b9612547633b02ee..e9954f4b70864789ef1750c49595747fbd5d4671 100644 (file)
@@ -1212,37 +1212,33 @@ out_error:
 STATIC int
 xfs_refcount_adjust(
        struct xfs_btree_cur    *cur,
-       xfs_agblock_t           agbno,
-       xfs_extlen_t            aglen,
-       xfs_agblock_t           *new_agbno,
-       xfs_extlen_t            *new_aglen,
+       xfs_agblock_t           *agbno,
+       xfs_extlen_t            *aglen,
        enum xfs_refc_adjust_op adj)
 {
        bool                    shape_changed;
        int                     shape_changes = 0;
        int                     error;
 
-       *new_agbno = agbno;
-       *new_aglen = aglen;
        if (adj == XFS_REFCOUNT_ADJUST_INCREASE)
-               trace_xfs_refcount_increase(cur->bc_mp, cur->bc_ag.pag->pag_agno,
-                               agbno, aglen);
+               trace_xfs_refcount_increase(cur->bc_mp,
+                               cur->bc_ag.pag->pag_agno, *agbno, *aglen);
        else
-               trace_xfs_refcount_decrease(cur->bc_mp, cur->bc_ag.pag->pag_agno,
-                               agbno, aglen);
+               trace_xfs_refcount_decrease(cur->bc_mp,
+                               cur->bc_ag.pag->pag_agno, *agbno, *aglen);
 
        /*
         * Ensure that no rcextents cross the boundary of the adjustment range.
         */
        error = xfs_refcount_split_extent(cur, XFS_REFC_DOMAIN_SHARED,
-                       agbno, &shape_changed);
+                       *agbno, &shape_changed);
        if (error)
                goto out_error;
        if (shape_changed)
                shape_changes++;
 
        error = xfs_refcount_split_extent(cur, XFS_REFC_DOMAIN_SHARED,
-                       agbno + aglen, &shape_changed);
+                       *agbno + *aglen, &shape_changed);
        if (error)
                goto out_error;
        if (shape_changed)
@@ -1252,7 +1248,7 @@ xfs_refcount_adjust(
         * Try to merge with the left or right extents of the range.
         */
        error = xfs_refcount_merge_extents(cur, XFS_REFC_DOMAIN_SHARED,
-                       new_agbno, new_aglen, adj, &shape_changed);
+                       agbno, aglen, adj, &shape_changed);
        if (error)
                goto out_error;
        if (shape_changed)
@@ -1261,7 +1257,7 @@ xfs_refcount_adjust(
                cur->bc_ag.refc.shape_changes++;
 
        /* Now that we've taken care of the ends, adjust the middle extents */
-       error = xfs_refcount_adjust_extents(cur, new_agbno, new_aglen, adj);
+       error = xfs_refcount_adjust_extents(cur, agbno, aglen, adj);
        if (error)
                goto out_error;
 
@@ -1297,21 +1293,20 @@ xfs_refcount_finish_one_cleanup(
 static inline int
 xfs_refcount_continue_op(
        struct xfs_btree_cur            *cur,
-       xfs_fsblock_t                   startblock,
-       xfs_agblock_t                   new_agbno,
-       xfs_extlen_t                    new_len,
-       xfs_fsblock_t                   *new_fsbno)
+       struct xfs_refcount_intent      *ri,
+       xfs_agblock_t                   new_agbno)
 {
        struct xfs_mount                *mp = cur->bc_mp;
        struct xfs_perag                *pag = cur->bc_ag.pag;
 
-       if (XFS_IS_CORRUPT(mp, !xfs_verify_agbext(pag, new_agbno, new_len)))
+       if (XFS_IS_CORRUPT(mp, !xfs_verify_agbext(pag, new_agbno,
+                                       ri->ri_blockcount)))
                return -EFSCORRUPTED;
 
-       *new_fsbno = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno);
+       ri->ri_startblock = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno);
 
-       ASSERT(xfs_verify_fsbext(mp, *new_fsbno, new_len));
-       ASSERT(pag->pag_agno == XFS_FSB_TO_AGNO(mp, *new_fsbno));
+       ASSERT(xfs_verify_fsbext(mp, ri->ri_startblock, ri->ri_blockcount));
+       ASSERT(pag->pag_agno == XFS_FSB_TO_AGNO(mp, ri->ri_startblock));
 
        return 0;
 }
@@ -1326,11 +1321,7 @@ xfs_refcount_continue_op(
 int
 xfs_refcount_finish_one(
        struct xfs_trans                *tp,
-       enum xfs_refcount_intent_type   type,
-       xfs_fsblock_t                   startblock,
-       xfs_extlen_t                    blockcount,
-       xfs_fsblock_t                   *new_fsb,
-       xfs_extlen_t                    *new_len,
+       struct xfs_refcount_intent      *ri,
        struct xfs_btree_cur            **pcur)
 {
        struct xfs_mount                *mp = tp->t_mountp;
@@ -1338,17 +1329,16 @@ xfs_refcount_finish_one(
        struct xfs_buf                  *agbp = NULL;
        int                             error = 0;
        xfs_agblock_t                   bno;
-       xfs_agblock_t                   new_agbno;
        unsigned long                   nr_ops = 0;
        int                             shape_changes = 0;
        struct xfs_perag                *pag;
 
-       pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, startblock));
-       bno = XFS_FSB_TO_AGBNO(mp, startblock);
+       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, startblock),
-                       type, XFS_FSB_TO_AGBNO(mp, startblock),
-                       blockcount);
+       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;
@@ -1379,42 +1369,42 @@ xfs_refcount_finish_one(
        }
        *pcur = rcur;
 
-       switch (type) {
+       switch (ri->ri_type) {
        case XFS_REFCOUNT_INCREASE:
-               error = xfs_refcount_adjust(rcur, bno, blockcount, &new_agbno,
-                               new_len, XFS_REFCOUNT_ADJUST_INCREASE);
+               error = xfs_refcount_adjust(rcur, &bno, &ri->ri_blockcount,
+                               XFS_REFCOUNT_ADJUST_INCREASE);
                if (error)
                        goto out_drop;
-               if (*new_len > 0)
-                       error = xfs_refcount_continue_op(rcur, startblock,
-                                       new_agbno, *new_len, new_fsb);
+               if (ri->ri_blockcount > 0)
+                       error = xfs_refcount_continue_op(rcur, ri, bno);
                break;
        case XFS_REFCOUNT_DECREASE:
-               error = xfs_refcount_adjust(rcur, bno, blockcount, &new_agbno,
-                               new_len, XFS_REFCOUNT_ADJUST_DECREASE);
+               error = xfs_refcount_adjust(rcur, &bno, &ri->ri_blockcount,
+                               XFS_REFCOUNT_ADJUST_DECREASE);
                if (error)
                        goto out_drop;
-               if (*new_len > 0)
-                       error = xfs_refcount_continue_op(rcur, startblock,
-                                       new_agbno, *new_len, new_fsb);
+               if (ri->ri_blockcount > 0)
+                       error = xfs_refcount_continue_op(rcur, ri, bno);
                break;
        case XFS_REFCOUNT_ALLOC_COW:
-               *new_fsb = startblock + blockcount;
-               *new_len = 0;
-               error = __xfs_refcount_cow_alloc(rcur, bno, blockcount);
+               error = __xfs_refcount_cow_alloc(rcur, bno, ri->ri_blockcount);
+               if (error)
+                       goto out_drop;
+               ri->ri_blockcount = 0;
                break;
        case XFS_REFCOUNT_FREE_COW:
-               *new_fsb = startblock + blockcount;
-               *new_len = 0;
-               error = __xfs_refcount_cow_free(rcur, bno, blockcount);
+               error = __xfs_refcount_cow_free(rcur, bno, ri->ri_blockcount);
+               if (error)
+                       goto out_drop;
+               ri->ri_blockcount = 0;
                break;
        default:
                ASSERT(0);
                error = -EFSCORRUPTED;
        }
-       if (!error && *new_len > 0)
-               trace_xfs_refcount_finish_one_leftover(mp, pag->pag_agno, type,
-                               bno, blockcount, new_agbno, *new_len);
+       if (!error && ri->ri_blockcount > 0)
+               trace_xfs_refcount_finish_one_leftover(mp, pag->pag_agno,
+                               ri->ri_type, bno, ri->ri_blockcount);
 out_drop:
        xfs_perag_put(pag);
        return error;
index 452f30556f5a9ad9606ddd46ad3b59f5da81fc41..c633477ce3cef0eb3ab3367d42f9f2a19e71407e 100644 (file)
@@ -75,9 +75,7 @@ void xfs_refcount_decrease_extent(struct xfs_trans *tp,
 extern void xfs_refcount_finish_one_cleanup(struct xfs_trans *tp,
                struct xfs_btree_cur *rcur, int error);
 extern int xfs_refcount_finish_one(struct xfs_trans *tp,
-               enum xfs_refcount_intent_type type, xfs_fsblock_t startblock,
-               xfs_extlen_t blockcount, xfs_fsblock_t *new_fsb,
-               xfs_extlen_t *new_len, struct xfs_btree_cur **pcur);
+               struct xfs_refcount_intent *ri, struct xfs_btree_cur **pcur);
 
 extern int xfs_refcount_find_shared(struct xfs_btree_cur *cur,
                xfs_agblock_t agbno, xfs_extlen_t aglen, xfs_agblock_t *fbno,