xfs: t_firstblock is tracking AGs not blocks
authorDave Chinner <dchinner@redhat.com>
Fri, 10 Feb 2023 17:11:06 +0000 (04:11 +1100)
committerDave Chinner <dchinner@redhat.com>
Fri, 10 Feb 2023 17:11:06 +0000 (04:11 +1100)
The tp->t_firstblock field is now raelly tracking the highest AG we
have locked, not the block number of the highest allocation we've
made. It's purpose is to prevent AGF locking deadlocks, so rename it
to "highest AG" and simplify the implementation to just track the
agno rather than a fsbno.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Allison Henderson <allison.henderson@oracle.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
fs/xfs/libxfs/xfs_alloc.c
fs/xfs/libxfs/xfs_bmap.c
fs/xfs/libxfs/xfs_bmap_btree.c
fs/xfs/libxfs/xfs_btree.c
fs/xfs/xfs_bmap_util.c
fs/xfs/xfs_inode.c
fs/xfs/xfs_reflink.c
fs/xfs/xfs_trace.h
fs/xfs/xfs_trans.c
fs/xfs/xfs_trans.h

index ffe6345bfafcb80c6aad89b39658b12afec71f5d..974b23abca60eb92930ac84eece1e285c60a1032 100644 (file)
@@ -3169,8 +3169,8 @@ xfs_alloc_vextent(
        mp = args->mp;
        type = args->otype = args->type;
        args->agbno = NULLAGBLOCK;
-       if (args->tp->t_firstblock != NULLFSBLOCK)
-               minimum_agno = XFS_FSB_TO_AGNO(mp, args->tp->t_firstblock);
+       if (args->tp->t_highest_agno != NULLAGNUMBER)
+               minimum_agno = args->tp->t_highest_agno;
        /*
         * Just fix this up, for the case where the last a.g. is shorter
         * (or there's only one a.g.) and the caller couldn't easily figure
@@ -3375,11 +3375,9 @@ xfs_alloc_vextent(
         * deadlocks.
         */
        if (args->agbp &&
-           (args->tp->t_firstblock == NULLFSBLOCK ||
-            args->pag->pag_agno > minimum_agno)) {
-               args->tp->t_firstblock = XFS_AGB_TO_FSB(mp,
-                                       args->pag->pag_agno, 0);
-       }
+           (args->tp->t_highest_agno == NULLAGNUMBER ||
+            args->pag->pag_agno > minimum_agno))
+               args->tp->t_highest_agno = args->pag->pag_agno;
        xfs_perag_put(args->pag);
        return 0;
 error0:
index 31a0738d017e086cd2a2f245990371f9d6010f88..504fd69fe2c6062caf174a17610cbe52982b6aa8 100644 (file)
@@ -4192,7 +4192,7 @@ xfs_bmapi_minleft(
 {
        struct xfs_ifork        *ifp = xfs_ifork_ptr(ip, fork);
 
-       if (tp && tp->t_firstblock != NULLFSBLOCK)
+       if (tp && tp->t_highest_agno != NULLAGNUMBER)
                return 0;
        if (ifp->if_format != XFS_DINODE_FMT_BTREE)
                return 1;
@@ -6079,7 +6079,7 @@ xfs_bmap_finish_one(
        struct xfs_bmbt_irec            *bmap = &bi->bi_bmap;
        int                             error = 0;
 
-       ASSERT(tp->t_firstblock == NULLFSBLOCK);
+       ASSERT(tp->t_highest_agno == NULLAGNUMBER);
 
        trace_xfs_bmap_deferred(tp->t_mountp,
                        XFS_FSB_TO_AGNO(tp->t_mountp, bmap->br_startblock),
index 76a0f0d260a47e94c8cfd1d07530b346e2563146..afd9b2d962a31d74d251e0137bbe48b50498f2c4 100644 (file)
@@ -184,11 +184,11 @@ xfs_bmbt_update_cursor(
        struct xfs_btree_cur    *src,
        struct xfs_btree_cur    *dst)
 {
-       ASSERT((dst->bc_tp->t_firstblock != NULLFSBLOCK) ||
+       ASSERT((dst->bc_tp->t_highest_agno != NULLAGNUMBER) ||
               (dst->bc_ino.ip->i_diflags & XFS_DIFLAG_REALTIME));
 
        dst->bc_ino.allocated += src->bc_ino.allocated;
-       dst->bc_tp->t_firstblock = src->bc_tp->t_firstblock;
+       dst->bc_tp->t_highest_agno = src->bc_tp->t_highest_agno;
 
        src->bc_ino.allocated = 0;
 }
@@ -218,7 +218,7 @@ xfs_bmbt_alloc_block(
         * we have to ensure that we attempt to locate the entire set of bmbt
         * allocations in the same AG, as xfs_bmapi_write() would have reserved.
         */
-       if (cur->bc_tp->t_firstblock == NULLFSBLOCK)
+       if (cur->bc_tp->t_highest_agno == NULLAGNUMBER)
                args.minleft = xfs_bmapi_minleft(cur->bc_tp, cur->bc_ino.ip,
                                        cur->bc_ino.whichfork);
 
index da8c769887fddccf4088493ab04e28084445bdf8..c4649cc624e1bc6b9a511a29c2eb5345a6b88fa0 100644 (file)
@@ -2943,7 +2943,7 @@ xfs_btree_split(
        DECLARE_COMPLETION_ONSTACK(done);
 
        if (cur->bc_btnum != XFS_BTNUM_BMAP ||
-           cur->bc_tp->t_firstblock == NULLFSBLOCK)
+           cur->bc_tp->t_highest_agno == NULLAGNUMBER)
                return __xfs_btree_split(cur, level, ptrp, key, curp, stat);
 
        args.cur = cur;
index 867645b74d889ddc96f768f7e74d15690840c1e1..a09dd2606479270d107c63da7ab030447431e8ca 100644 (file)
@@ -1410,7 +1410,7 @@ xfs_swap_extent_rmap(
 
                /* Unmap the old blocks in the source file. */
                while (tirec.br_blockcount) {
-                       ASSERT(tp->t_firstblock == NULLFSBLOCK);
+                       ASSERT(tp->t_highest_agno == NULLAGNUMBER);
                        trace_xfs_swap_extent_rmap_remap_piece(tip, &tirec);
 
                        /* Read extent from the source file */
index d354ea2b74f96d8eed57c375b031e3916263bbfb..dbe274b8065dd4f5b9075442b75fce32fb3235a0 100644 (file)
@@ -1367,7 +1367,7 @@ xfs_itruncate_extents_flags(
 
        unmap_len = XFS_MAX_FILEOFF - first_unmap_block + 1;
        while (unmap_len > 0) {
-               ASSERT(tp->t_firstblock == NULLFSBLOCK);
+               ASSERT(tp->t_highest_agno == NULLAGNUMBER);
                error = __xfs_bunmapi(tp, ip, first_unmap_block, &unmap_len,
                                flags, XFS_ITRUNC_MAX_EXTENTS);
                if (error)
index 5535778a98f925d0ce158cc64f09c3981fe3670e..57bf59ff48543eb9b5a596d311bc9f90e1c0060f 100644 (file)
@@ -610,7 +610,7 @@ xfs_reflink_cancel_cow_blocks(
                        if (error)
                                break;
                } else if (del.br_state == XFS_EXT_UNWRITTEN || cancel_real) {
-                       ASSERT((*tpp)->t_firstblock == NULLFSBLOCK);
+                       ASSERT((*tpp)->t_highest_agno == NULLAGNUMBER);
 
                        /* Free the CoW orphan record. */
                        xfs_refcount_free_cow_extent(*tpp, del.br_startblock,
index adddaeb44a563906ce2231b7869fa7583c2c1302..2ac98d8ddbfde99c243b64c23602fc356c5b3521 100644 (file)
@@ -1801,7 +1801,7 @@ DECLARE_EVENT_CLASS(xfs_alloc_class,
                __field(char, wasfromfl)
                __field(int, resv)
                __field(int, datatype)
-               __field(xfs_fsblock_t, firstblock)
+               __field(xfs_agnumber_t, highest_agno)
        ),
        TP_fast_assign(
                __entry->dev = args->mp->m_super->s_dev;
@@ -1822,12 +1822,12 @@ DECLARE_EVENT_CLASS(xfs_alloc_class,
                __entry->wasfromfl = args->wasfromfl;
                __entry->resv = args->resv;
                __entry->datatype = args->datatype;
-               __entry->firstblock = args->tp->t_firstblock;
+               __entry->highest_agno = args->tp->t_highest_agno;
        ),
        TP_printk("dev %d:%d agno 0x%x agbno 0x%x minlen %u maxlen %u mod %u "
                  "prod %u minleft %u total %u alignment %u minalignslop %u "
                  "len %u type %s otype %s wasdel %d wasfromfl %d resv %d "
-                 "datatype 0x%x firstblock 0x%llx",
+                 "datatype 0x%x highest_agno 0x%x",
                  MAJOR(__entry->dev), MINOR(__entry->dev),
                  __entry->agno,
                  __entry->agbno,
@@ -1846,7 +1846,7 @@ DECLARE_EVENT_CLASS(xfs_alloc_class,
                  __entry->wasfromfl,
                  __entry->resv,
                  __entry->datatype,
-                 (unsigned long long)__entry->firstblock)
+                 __entry->highest_agno)
 )
 
 #define DEFINE_ALLOC_EVENT(name) \
index 7bd16fbff534103752574dfaa9687178200a543c..53ab544e4c2cbf09676a221b3001e2139c8b493d 100644 (file)
@@ -102,7 +102,7 @@ xfs_trans_dup(
        INIT_LIST_HEAD(&ntp->t_items);
        INIT_LIST_HEAD(&ntp->t_busy);
        INIT_LIST_HEAD(&ntp->t_dfops);
-       ntp->t_firstblock = NULLFSBLOCK;
+       ntp->t_highest_agno = NULLAGNUMBER;
 
        ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
        ASSERT(tp->t_ticket != NULL);
@@ -278,7 +278,7 @@ retry:
        INIT_LIST_HEAD(&tp->t_items);
        INIT_LIST_HEAD(&tp->t_busy);
        INIT_LIST_HEAD(&tp->t_dfops);
-       tp->t_firstblock = NULLFSBLOCK;
+       tp->t_highest_agno = NULLAGNUMBER;
 
        error = xfs_trans_reserve(tp, resp, blocks, rtextents);
        if (error == -ENOSPC && want_retry) {
index 55819785941cc426d1be9a1422da6083694f8d54..6e3646d524ceb6060bbf7219d367918a03a700f2 100644 (file)
@@ -132,7 +132,7 @@ typedef struct xfs_trans {
        unsigned int            t_rtx_res;      /* # of rt extents resvd */
        unsigned int            t_rtx_res_used; /* # of resvd rt extents used */
        unsigned int            t_flags;        /* misc flags */
-       xfs_fsblock_t           t_firstblock;   /* first block allocated */
+       xfs_agnumber_t          t_highest_agno; /* highest AGF locked */
        struct xlog_ticket      *t_ticket;      /* log mgr ticket */
        struct xfs_mount        *t_mountp;      /* ptr to fs mount struct */
        struct xfs_dquot_acct   *t_dqinfo;      /* acctg info for dquots */