]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: add xfs_agbno_to_fsb and xfs_agbno_to_daddr helpers
authorChristoph Hellwig <hch@lst.de>
Mon, 25 Nov 2024 21:14:12 +0000 (13:14 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 24 Dec 2024 02:01:23 +0000 (18:01 -0800)
Source kernel commit: 856a920ac2bbb2352ef6aa9e1e052f2e80677df7

Add helpers to convert an agbno to a daddr or fsbno based on a pag
structure.

This provides a simpler conversion and better type safety compared to the
existing code that passes the mount structure and the agno separately.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
libxfs/xfs_ag.c
libxfs/xfs_ag.h
libxfs/xfs_alloc.c
libxfs/xfs_btree.c
libxfs/xfs_ialloc.c
libxfs/xfs_ialloc_btree.c
libxfs/xfs_refcount.c
libxfs/xfs_refcount_btree.c

index 62fc21fe7109b9d1868b350ab4f8c00984524363..a6b5a7d71bbf80953595a9b840af64bebe293bca 100644 (file)
@@ -867,7 +867,7 @@ xfs_ag_shrink_space(
 
        /* internal log shouldn't also show up in the free space btrees */
        error = xfs_alloc_vextent_exact_bno(&args,
-                       XFS_AGB_TO_FSB(mp, pag->pag_agno, aglen - delta));
+                       xfs_agbno_to_fsb(pag, aglen - delta));
        if (!error && args.agbno == NULLAGBLOCK)
                error = -ENOSPC;
 
index 958ca82524292ff88ec592157e52ca8d66111d39..c0a30141ddc330ed20e74350c2cc0e6e6fd91475 100644 (file)
@@ -330,4 +330,20 @@ int xfs_ag_extend_space(struct xfs_perag *pag, struct xfs_trans *tp,
                        xfs_extlen_t len);
 int xfs_ag_get_geometry(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
 
+static inline xfs_fsblock_t
+xfs_agbno_to_fsb(
+       struct xfs_perag        *pag,
+       xfs_agblock_t           agbno)
+{
+       return XFS_AGB_TO_FSB(pag->pag_mount, pag->pag_agno, agbno);
+}
+
+static inline xfs_daddr_t
+xfs_agbno_to_daddr(
+       struct xfs_perag        *pag,
+       xfs_agblock_t           agbno)
+{
+       return XFS_AGB_TO_DADDR(pag->pag_mount, pag->pag_agno, agbno);
+}
+
 #endif /* __LIBXFS_AG_H */
index 1f4740cced73a1e522deeb5909d83ad3bb9731a6..19b38eaf45dd071857b1182c48b08f0eb85d8241 100644 (file)
@@ -1255,7 +1255,7 @@ xfs_alloc_ag_vextent_small(
                struct xfs_buf  *bp;
 
                error = xfs_trans_get_buf(args->tp, args->mp->m_ddev_targp,
-                               XFS_AGB_TO_DADDR(args->mp, args->agno, fbno),
+                               xfs_agbno_to_daddr(args->pag, fbno),
                                args->mp->m_bsize, 0, &bp);
                if (error)
                        goto error;
@@ -2929,9 +2929,8 @@ xfs_alloc_fix_freelist(
                 * Deferring the free disconnects freeing up the AGFL slot from
                 * freeing the block.
                 */
-               error = xfs_free_extent_later(tp,
-                               XFS_AGB_TO_FSB(mp, args->agno, bno), 1,
-                               &targs.oinfo, XFS_AG_RESV_AGFL, 0);
+               error = xfs_free_extent_later(tp, xfs_agbno_to_fsb(pag, bno),
+                               1, &targs.oinfo, XFS_AG_RESV_AGFL, 0);
                if (error)
                        goto out_agbp_relse;
        }
@@ -3590,7 +3589,7 @@ xfs_alloc_vextent_finish(
                goto out_drop_perag;
        }
 
-       args->fsbno = XFS_AGB_TO_FSB(mp, args->agno, args->agbno);
+       args->fsbno = xfs_agbno_to_fsb(args->pag, args->agbno);
 
        ASSERT(args->len >= args->minlen);
        ASSERT(args->len <= args->maxlen);
@@ -3642,7 +3641,6 @@ xfs_alloc_vextent_this_ag(
        struct xfs_alloc_arg    *args,
        xfs_agnumber_t          agno)
 {
-       struct xfs_mount        *mp = args->mp;
        xfs_agnumber_t          minimum_agno;
        uint32_t                alloc_flags = 0;
        int                     error;
@@ -3655,8 +3653,8 @@ xfs_alloc_vextent_this_ag(
 
        trace_xfs_alloc_vextent_this_ag(args);
 
-       error = xfs_alloc_vextent_check_args(args, XFS_AGB_TO_FSB(mp, agno, 0),
-                       &minimum_agno);
+       error = xfs_alloc_vextent_check_args(args,
+                       xfs_agbno_to_fsb(args->pag, 0), &minimum_agno);
        if (error) {
                if (error == -ENOSPC)
                        return 0;
index bb53b6d7af22f641f1b79eeee08baa7efe165d58..4f04a92f6513bf1264010c9ec5e8654ecef5035e 100644 (file)
@@ -1015,21 +1015,20 @@ xfs_btree_readahead_agblock(
        struct xfs_btree_block  *block)
 {
        struct xfs_mount        *mp = cur->bc_mp;
-       xfs_agnumber_t          agno = cur->bc_ag.pag->pag_agno;
        xfs_agblock_t           left = be32_to_cpu(block->bb_u.s.bb_leftsib);
        xfs_agblock_t           right = be32_to_cpu(block->bb_u.s.bb_rightsib);
        int                     rval = 0;
 
        if ((lr & XFS_BTCUR_LEFTRA) && left != NULLAGBLOCK) {
                xfs_buf_readahead(mp->m_ddev_targp,
-                               XFS_AGB_TO_DADDR(mp, agno, left),
+                               xfs_agbno_to_daddr(cur->bc_ag.pag, left),
                                mp->m_bsize, cur->bc_ops->buf_ops);
                rval++;
        }
 
        if ((lr & XFS_BTCUR_RIGHTRA) && right != NULLAGBLOCK) {
                xfs_buf_readahead(mp->m_ddev_targp,
-                               XFS_AGB_TO_DADDR(mp, agno, right),
+                               xfs_agbno_to_daddr(cur->bc_ag.pag, right),
                                mp->m_bsize, cur->bc_ops->buf_ops);
                rval++;
        }
@@ -1089,7 +1088,7 @@ xfs_btree_ptr_to_daddr(
 
        switch (cur->bc_ops->type) {
        case XFS_BTREE_TYPE_AG:
-               *daddr = XFS_AGB_TO_DADDR(cur->bc_mp, cur->bc_ag.pag->pag_agno,
+               *daddr = xfs_agbno_to_daddr(cur->bc_ag.pag,
                                be32_to_cpu(ptr->s));
                break;
        case XFS_BTREE_TYPE_INODE:
index 10d88eb0b5bc325f0d740b72b6e078845b6cf861..6694ee2370411a4f7a20ee63570bab89c353fdf0 100644 (file)
@@ -763,8 +763,7 @@ xfs_ialloc_ag_alloc(
                /* Allow space for the inode btree to split. */
                args.minleft = igeo->inobt_maxlevels;
                error = xfs_alloc_vextent_exact_bno(&args,
-                               XFS_AGB_TO_FSB(args.mp, pag->pag_agno,
-                                               args.agbno));
+                               xfs_agbno_to_fsb(pag, args.agbno));
                if (error)
                        return error;
 
@@ -806,8 +805,8 @@ xfs_ialloc_ag_alloc(
                 */
                args.minleft = igeo->inobt_maxlevels;
                error = xfs_alloc_vextent_near_bno(&args,
-                               XFS_AGB_TO_FSB(args.mp, pag->pag_agno,
-                                               be32_to_cpu(agi->agi_root)));
+                               xfs_agbno_to_fsb(pag,
+                                       be32_to_cpu(agi->agi_root)));
                if (error)
                        return error;
        }
@@ -819,8 +818,8 @@ xfs_ialloc_ag_alloc(
        if (isaligned && args.fsbno == NULLFSBLOCK) {
                args.alignment = igeo->cluster_align;
                error = xfs_alloc_vextent_near_bno(&args,
-                               XFS_AGB_TO_FSB(args.mp, pag->pag_agno,
-                                               be32_to_cpu(agi->agi_root)));
+                               xfs_agbno_to_fsb(pag,
+                                       be32_to_cpu(agi->agi_root)));
                if (error)
                        return error;
        }
@@ -855,8 +854,8 @@ sparse_alloc:
                                 igeo->ialloc_blks;
 
                error = xfs_alloc_vextent_near_bno(&args,
-                               XFS_AGB_TO_FSB(args.mp, pag->pag_agno,
-                                               be32_to_cpu(agi->agi_root)));
+                               xfs_agbno_to_fsb(pag,
+                                       be32_to_cpu(agi->agi_root)));
                if (error)
                        return error;
 
@@ -1973,7 +1972,6 @@ xfs_difree_inode_chunk(
        struct xfs_inobt_rec_incore     *rec)
 {
        struct xfs_mount                *mp = tp->t_mountp;
-       xfs_agnumber_t                  agno = pag->pag_agno;
        xfs_agblock_t                   sagbno = XFS_AGINO_TO_AGBNO(mp,
                                                        rec->ir_startino);
        int                             startidx, endidx;
@@ -1984,8 +1982,7 @@ xfs_difree_inode_chunk(
 
        if (!xfs_inobt_issparse(rec->ir_holemask)) {
                /* not sparse, calculate extent info directly */
-               return xfs_free_extent_later(tp,
-                               XFS_AGB_TO_FSB(mp, agno, sagbno),
+               return xfs_free_extent_later(tp, xfs_agbno_to_fsb(pag, sagbno),
                                M_IGEO(mp)->ialloc_blks, &XFS_RMAP_OINFO_INODES,
                                XFS_AG_RESV_NONE, 0);
        }
@@ -2031,9 +2028,9 @@ xfs_difree_inode_chunk(
 
                ASSERT(agbno % mp->m_sb.sb_spino_align == 0);
                ASSERT(contigblk % mp->m_sb.sb_spino_align == 0);
-               error = xfs_free_extent_later(tp,
-                               XFS_AGB_TO_FSB(mp, agno, agbno), contigblk,
-                               &XFS_RMAP_OINFO_INODES, XFS_AG_RESV_NONE, 0);
+               error = xfs_free_extent_later(tp, xfs_agbno_to_fsb(pag, agbno),
+                               contigblk, &XFS_RMAP_OINFO_INODES,
+                               XFS_AG_RESV_NONE, 0);
                if (error)
                        return error;
 
@@ -2503,7 +2500,7 @@ xfs_imap(
                offset = XFS_INO_TO_OFFSET(mp, ino);
                ASSERT(offset < mp->m_sb.sb_inopblock);
 
-               imap->im_blkno = XFS_AGB_TO_DADDR(mp, pag->pag_agno, agbno);
+               imap->im_blkno = xfs_agbno_to_daddr(pag, agbno);
                imap->im_len = XFS_FSB_TO_BB(mp, 1);
                imap->im_boffset = (unsigned short)(offset <<
                                                        mp->m_sb.sb_inodelog);
@@ -2533,7 +2530,7 @@ out_map:
        offset = ((agbno - cluster_agbno) * mp->m_sb.sb_inopblock) +
                XFS_INO_TO_OFFSET(mp, ino);
 
-       imap->im_blkno = XFS_AGB_TO_DADDR(mp, pag->pag_agno, cluster_agbno);
+       imap->im_blkno = xfs_agbno_to_daddr(pag, cluster_agbno);
        imap->im_len = XFS_FSB_TO_BB(mp, M_IGEO(mp)->blocks_per_cluster);
        imap->im_boffset = (unsigned short)(offset << mp->m_sb.sb_inodelog);
 
index ffca4a80219d6ddf50de488006574fde38de306a..f80368b4d5fa5fff0da3c50514c81c25051f8792 100644 (file)
@@ -119,7 +119,7 @@ __xfs_inobt_alloc_block(
        args.resv = resv;
 
        error = xfs_alloc_vextent_near_bno(&args,
-                       XFS_AGB_TO_FSB(args.mp, args.pag->pag_agno, sbno));
+                       xfs_agbno_to_fsb(args.pag, sbno));
        if (error)
                return error;
 
index 22f8afb27ece1cc7ebdab0a4b03d0167a2aba9dd..eeddec68a08539924f086c0fdfe9fc91481ffecc 100644 (file)
@@ -1153,8 +1153,7 @@ xfs_refcount_adjust_extents(
                                        goto out_error;
                                }
                        } else {
-                               fsbno = XFS_AGB_TO_FSB(cur->bc_mp,
-                                               cur->bc_ag.pag->pag_agno,
+                               fsbno = xfs_agbno_to_fsb(cur->bc_ag.pag,
                                                tmp.rc_startblock);
                                error = xfs_free_extent_later(cur->bc_tp, fsbno,
                                                  tmp.rc_blockcount, NULL,
@@ -1216,8 +1215,7 @@ xfs_refcount_adjust_extents(
                        }
                        goto advloop;
                } else {
-                       fsbno = XFS_AGB_TO_FSB(cur->bc_mp,
-                                       cur->bc_ag.pag->pag_agno,
+                       fsbno = xfs_agbno_to_fsb(cur->bc_ag.pag,
                                        ext.rc_startblock);
                        error = xfs_free_extent_later(cur->bc_tp, fsbno,
                                        ext.rc_blockcount, NULL,
@@ -1319,7 +1317,7 @@ xfs_refcount_continue_op(
                return -EFSCORRUPTED;
        }
 
-       ri->ri_startblock = XFS_AGB_TO_FSB(mp, pag->pag_agno, new_agbno);
+       ri->ri_startblock = xfs_agbno_to_fsb(pag, new_agbno);
 
        ASSERT(xfs_verify_fsbext(mp, ri->ri_startblock, ri->ri_blockcount));
        ASSERT(pag->pag_agno == XFS_FSB_TO_AGNO(mp, ri->ri_startblock));
@@ -1955,8 +1953,7 @@ xfs_refcount_recover_cow_leftovers(
                        goto out_free;
 
                /* Free the orphan record */
-               fsb = XFS_AGB_TO_FSB(mp, pag->pag_agno,
-                               rr->rr_rrec.rc_startblock);
+               fsb = xfs_agbno_to_fsb(pag, rr->rr_rrec.rc_startblock);
                xfs_refcount_free_cow_extent(tp, fsb,
                                rr->rr_rrec.rc_blockcount);
 
index 9028dea06b0c071f7159f797f51e5c160b423152..5913f4176889eac1edd939e0b6945ba84762992c 100644 (file)
@@ -73,8 +73,7 @@ xfs_refcountbt_alloc_block(
        args.resv = XFS_AG_RESV_METADATA;
 
        error = xfs_alloc_vextent_near_bno(&args,
-                       XFS_AGB_TO_FSB(args.mp, args.pag->pag_agno,
-                                       xfs_refc_block(args.mp)));
+                       xfs_agbno_to_fsb(args.pag, xfs_refc_block(args.mp)));
        if (error)
                goto out_error;
        if (args.fsbno == NULLFSBLOCK) {