]> www.infradead.org Git - users/hch/xfs.git/commitdiff
xfs: add a xfs_agino_to_ino helper
authorChristoph Hellwig <hch@lst.de>
Sat, 31 Aug 2024 07:55:11 +0000 (10:55 +0300)
committerChristoph Hellwig <hch@lst.de>
Sun, 22 Sep 2024 05:37:27 +0000 (07:37 +0200)
Add a helpers to convert an agino to an ino 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>
fs/xfs/libxfs/xfs_ag.h
fs/xfs/libxfs/xfs_ialloc.c
fs/xfs/scrub/agheader_repair.c
fs/xfs/scrub/common.c
fs/xfs/scrub/ialloc.c
fs/xfs/scrub/ialloc_repair.c
fs/xfs/xfs_inode.c
fs/xfs/xfs_iwalk.c
fs/xfs/xfs_log_recover.c

index e8ed5a33caea0a540237c752d4a32497c0cdf04f..ef1f532673ea86b72a22d6705573fd2f3779f7d2 100644 (file)
@@ -345,4 +345,12 @@ xfs_agbno_to_daddr(
        return XFS_AGB_TO_DADDR(pag->pag_mount, pag->pag_agno, agbno);
 }
 
+static inline xfs_ino_t
+xfs_agino_to_ino(
+       struct xfs_perag        *pag,
+       xfs_agino_t             agino)
+{
+       return XFS_AGINO_TO_INO(pag->pag_mount, pag->pag_agno, agino);
+}
+
 #endif /* __LIBXFS_AG_H */
index cb7c75b2986adb3cefe4df84c110c34119101ee1..de65091655123866637c055374035fa614489651 100644 (file)
@@ -914,8 +914,7 @@ sparse_alloc:
                if (error == -EFSCORRUPTED) {
                        xfs_alert(args.mp,
        "invalid sparse inode record: ino 0x%llx holemask 0x%x count %u",
-                                 XFS_AGINO_TO_INO(args.mp, pag->pag_agno,
-                                                  rec.ir_startino),
+                                 xfs_agino_to_ino(pag, rec.ir_startino),
                                  rec.ir_holemask, rec.ir_count);
                        xfs_force_shutdown(args.mp, SHUTDOWN_CORRUPT_INCORE);
                }
@@ -1334,7 +1333,7 @@ alloc_inode:
        ASSERT(offset < XFS_INODES_PER_CHUNK);
        ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) %
                                   XFS_INODES_PER_CHUNK) == 0);
-       ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, rec.ir_startino + offset);
+       ino = xfs_agino_to_ino(pag, rec.ir_startino + offset);
 
        if (xfs_ag_has_sickness(pag, XFS_SICK_AG_INODES)) {
                error = xfs_dialloc_check_ino(pag, tp, ino);
@@ -1615,7 +1614,7 @@ xfs_dialloc_ag(
        ASSERT(offset < XFS_INODES_PER_CHUNK);
        ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) %
                                   XFS_INODES_PER_CHUNK) == 0);
-       ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, rec.ir_startino + offset);
+       ino = xfs_agino_to_ino(pag, rec.ir_startino + offset);
 
        if (xfs_ag_has_sickness(pag, XFS_SICK_AG_INODES)) {
                error = xfs_dialloc_check_ino(pag, tp, ino);
@@ -2122,8 +2121,7 @@ xfs_difree_inobt(
        if (!xfs_has_ikeep(mp) && rec.ir_free == XFS_INOBT_ALL_FREE &&
            mp->m_sb.sb_inopblock <= XFS_INODES_PER_CHUNK) {
                xic->deleted = true;
-               xic->first_ino = XFS_AGINO_TO_INO(mp, pag->pag_agno,
-                               rec.ir_startino);
+               xic->first_ino = xfs_agino_to_ino(pag, rec.ir_startino);
                xic->alloc = xfs_inobt_irec_to_allocmask(&rec);
 
                /*
@@ -2322,10 +2320,10 @@ xfs_difree(
                return -EINVAL;
        }
        agino = XFS_INO_TO_AGINO(mp, inode);
-       if (inode != XFS_AGINO_TO_INO(mp, pag->pag_agno, agino))  {
-               xfs_warn(mp, "%s: inode != XFS_AGINO_TO_INO() (%llu != %llu).",
+       if (inode != xfs_agino_to_ino(pag, agino))  {
+               xfs_warn(mp, "%s: inode != xfs_agino_to_ino() (%llu != %llu).",
                        __func__, (unsigned long long)inode,
-                       (unsigned long long)XFS_AGINO_TO_INO(mp, pag->pag_agno, agino));
+                       (unsigned long long)xfs_agino_to_ino(pag, agino));
                ASSERT(0);
                return -EINVAL;
        }
@@ -2456,7 +2454,7 @@ xfs_imap(
        agino = XFS_INO_TO_AGINO(mp, ino);
        agbno = XFS_AGINO_TO_AGBNO(mp, agino);
        if (agbno >= mp->m_sb.sb_agblocks ||
-           ino != XFS_AGINO_TO_INO(mp, pag->pag_agno, agino)) {
+           ino != xfs_agino_to_ino(pag, agino)) {
                error = -EINVAL;
 #ifdef DEBUG
                /*
@@ -2471,11 +2469,11 @@ xfs_imap(
                                __func__, (unsigned long long)agbno,
                                (unsigned long)mp->m_sb.sb_agblocks);
                }
-               if (ino != XFS_AGINO_TO_INO(mp, pag->pag_agno, agino)) {
+               if (ino != xfs_agino_to_ino(pag, agino)) {
                        xfs_alert(mp,
-               "%s: ino (0x%llx) != XFS_AGINO_TO_INO() (0x%llx)",
+               "%s: ino (0x%llx) != xfs_agino_to_ino() (0x%llx)",
                                __func__, ino,
-                               XFS_AGINO_TO_INO(mp, pag->pag_agno, agino));
+                               xfs_agino_to_ino(pag, agino));
                }
                xfs_stack_trace();
 #endif /* DEBUG */
index 2f98d90d7fd66d099c9f8f78725e77700c540a78..82a850eba6c88c70fe8428796efebe634797ce6f 100644 (file)
@@ -1038,12 +1038,10 @@ xrep_iunlink_reload_next(
 {
        struct xfs_scrub        *sc = ragi->sc;
        struct xfs_inode        *ip;
-       xfs_ino_t               ino;
        xfs_agino_t             ret = NULLAGINO;
        int                     error;
 
-       ino = XFS_AGINO_TO_INO(sc->mp, sc->sa.pag->pag_agno, agino);
-       error = xchk_iget(ragi->sc, ino, &ip);
+       error = xchk_iget(ragi->sc, xfs_agino_to_ino(sc->sa.pag, agino), &ip);
        if (error)
                return ret;
 
@@ -1278,9 +1276,7 @@ xrep_iunlink_mark_ondisk_rec(
                 * on because we haven't actually scrubbed the inobt or the
                 * inodes yet.
                 */
-               error = xchk_iget(ragi->sc,
-                               XFS_AGINO_TO_INO(mp, sc->sa.pag->pag_agno,
-                                                agino),
+               error = xchk_iget(ragi->sc, xfs_agino_to_ino(sc->sa.pag, agino),
                                &ip);
                if (error)
                        continue;
@@ -1539,15 +1535,13 @@ xrep_iunlink_relink_next(
 
        ip = xfs_iunlink_lookup(pag, agino);
        if (!ip) {
-               xfs_ino_t       ino;
                xfs_agino_t     prev_agino;
 
                /*
                 * No inode exists in cache.  Load it off the disk so that we
                 * can reinsert it into the incore unlinked list.
                 */
-               ino = XFS_AGINO_TO_INO(sc->mp, pag->pag_agno, agino);
-               error = xchk_iget(sc, ino, &ip);
+               error = xchk_iget(sc, xfs_agino_to_ino(pag, agino), &ip);
                if (error)
                        return -EFSCORRUPTED;
 
@@ -1601,15 +1595,13 @@ xrep_iunlink_relink_prev(
 
        ip = xfs_iunlink_lookup(pag, agino);
        if (!ip) {
-               xfs_ino_t       ino;
                xfs_agino_t     next_agino;
 
                /*
                 * No inode exists in cache.  Load it off the disk so that we
                 * can reinsert it into the incore unlinked list.
                 */
-               ino = XFS_AGINO_TO_INO(sc->mp, pag->pag_agno, agino);
-               error = xchk_iget(sc, ino, &ip);
+               error = xchk_iget(sc, xfs_agino_to_ino(pag, agino), &ip);
                if (error)
                        return -EFSCORRUPTED;
 
index 22f5f1a9d3f09b133524f1dc10deea4d91ea565b..28095ed490fbf600773b22de180f58a0026dae7f 100644 (file)
@@ -1336,7 +1336,7 @@ xchk_inode_is_allocated(
        }
 
        /* reject inode numbers outside existing AGs */
-       ino = XFS_AGINO_TO_INO(sc->mp, pag->pag_agno, agino);
+       ino = xfs_agino_to_ino(pag, agino);
        if (!xfs_verify_ino(mp, ino))
                return -EINVAL;
 
index 26938b90d22efc7b32b126699ecfa98b995620aa..c1c798076d66abeec1177a02837e0ac0d38f9eb8 100644 (file)
@@ -303,7 +303,6 @@ xchk_iallocbt_check_cluster_ifree(
        unsigned int                    irec_ino,
        struct xfs_dinode               *dip)
 {
-       struct xfs_mount                *mp = bs->cur->bc_mp;
        xfs_ino_t                       fsino;
        xfs_agino_t                     agino;
        bool                            irec_free;
@@ -319,7 +318,7 @@ xchk_iallocbt_check_cluster_ifree(
         * the record, compute which fs inode we're talking about.
         */
        agino = irec->ir_startino + irec_ino;
-       fsino = XFS_AGINO_TO_INO(mp, bs->cur->bc_ag.pag->pag_agno, agino);
+       fsino = xfs_agino_to_ino(bs->cur->bc_ag.pag, agino);
        irec_free = (irec->ir_free & XFS_INOBT_MASK(irec_ino));
 
        if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC ||
index 7e9a4062a1c0484eda6d446e83032fad5d62bd2c..98e0ee46375dab2e628ff2d031716ff91912dbef 100644 (file)
@@ -146,15 +146,12 @@ xrep_ibt_check_ifree(
        struct xfs_scrub        *sc = ri->sc;
        struct xfs_mount        *mp = sc->mp;
        struct xfs_dinode       *dip;
-       xfs_ino_t               fsino;
        xfs_agino_t             agino;
-       xfs_agnumber_t          agno = ri->sc->sa.pag->pag_agno;
        unsigned int            cluster_buf_base;
        unsigned int            offset;
        int                     error;
 
        agino = cluster_ag_base + cluster_index;
-       fsino = XFS_AGINO_TO_INO(mp, agno, agino);
 
        /* Inode uncached or half assembled, read disk buffer */
        cluster_buf_base = XFS_INO_TO_OFFSET(mp, cluster_ag_base);
@@ -165,7 +162,8 @@ xrep_ibt_check_ifree(
        if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC)
                return -EFSCORRUPTED;
 
-       if (dip->di_version >= 3 && be64_to_cpu(dip->di_ino) != fsino)
+       if (dip->di_version >= 3 &&
+           be64_to_cpu(dip->di_ino) != xfs_agino_to_ino(ri->sc->sa.pag, agino))
                return -EFSCORRUPTED;
 
        /* Will the in-core inode tell us if it's in use? */
index bcc277fc0a83e9f2ca8805c639f01b04fef26e91..a787dce6e081ce3406781ce552e7b5bb58de9c4b 100644 (file)
@@ -1516,7 +1516,6 @@ xfs_iunlink_reload_next(
        struct xfs_perag        *pag = agibp->b_pag;
        struct xfs_mount        *mp = pag->pag_mount;
        struct xfs_inode        *next_ip = NULL;
-       xfs_ino_t               ino;
        int                     error;
 
        ASSERT(next_agino != NULLAGINO);
@@ -1538,8 +1537,8 @@ xfs_iunlink_reload_next(
         * but we'd rather shut down now since we're already running in a weird
         * situation.
         */
-       ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, next_agino);
-       error = xfs_iget(mp, tp, ino, XFS_IGET_UNTRUSTED, 0, &next_ip);
+       error = xfs_iget(mp, tp, xfs_agino_to_ino(pag, next_agino),
+                       XFS_IGET_UNTRUSTED, 0, &next_ip);
        if (error) {
                xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI);
                return error;
index 894318886a56704023207008406f6599b6fda404..ab5252f19509a6fd3baf16ad9308206b25d53400 100644 (file)
@@ -176,7 +176,6 @@ xfs_iwalk_ag_recs(
        struct xfs_mount        *mp = iwag->mp;
        struct xfs_trans        *tp = iwag->tp;
        struct xfs_perag        *pag = iwag->pag;
-       xfs_ino_t               ino;
        unsigned int            i, j;
        int                     error;
 
@@ -207,9 +206,10 @@ xfs_iwalk_ag_recs(
                                continue;
 
                        /* Otherwise call our function. */
-                       ino = XFS_AGINO_TO_INO(mp, pag->pag_agno,
-                                               irec->ir_startino + j);
-                       error = iwag->iwalk_fn(mp, tp, ino, iwag->data);
+                       error = iwag->iwalk_fn(mp, tp,
+                                       xfs_agino_to_ino(pag,
+                                               irec->ir_startino + j),
+                                       iwag->data);
                        if (error)
                                return error;
                }
@@ -304,7 +304,7 @@ xfs_iwalk_ag_start(
                return -EFSCORRUPTED;
        }
 
-       iwag->lastino = XFS_AGINO_TO_INO(mp, pag->pag_agno,
+       iwag->lastino = xfs_agino_to_ino(pag,
                                irec->ir_startino + XFS_INODES_PER_CHUNK - 1);
 
        /*
@@ -424,7 +424,7 @@ xfs_iwalk_ag(
                        break;
 
                /* Make sure that we always move forward. */
-               rec_fsino = XFS_AGINO_TO_INO(mp, pag->pag_agno, irec->ir_startino);
+               rec_fsino = xfs_agino_to_ino(pag, irec->ir_startino);
                if (iwag->lastino != NULLFSINO &&
                    XFS_IS_CORRUPT(mp, iwag->lastino >= rec_fsino)) {
                        xfs_btree_mark_sick(cur);
index 2af02b32f419c2494e0a1c4134450d5c2172e85d..e67d4d82f1fc439250a8458260432bdfce2bd2f0 100644 (file)
@@ -2726,9 +2726,8 @@ xlog_recover_iunlink_bucket(
 
        agino = be32_to_cpu(agi->agi_unlinked[bucket]);
        while (agino != NULLAGINO) {
-               error = xfs_iget(mp, NULL,
-                               XFS_AGINO_TO_INO(mp, pag->pag_agno, agino),
-                               0, 0, &ip);
+               error = xfs_iget(mp, NULL, xfs_agino_to_ino(pag, agino), 0, 0,
+                               &ip);
                if (error)
                        break;