xfs: add a xfs_agino_to_ino helper

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>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
This commit is contained in:
Christoph Hellwig 2024-11-03 20:18:28 -08:00 committed by Darrick J. Wong
parent 856a920ac2
commit 6abd82ab6e
9 changed files with 37 additions and 44 deletions

View File

@ -346,4 +346,12 @@ xfs_agbno_to_daddr(
return XFS_AGB_TO_DADDR(pag->pag_mount, pag->pag_agno, agbno); 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 */ #endif /* __LIBXFS_AG_H */

View File

@ -914,8 +914,7 @@ sparse_alloc:
if (error == -EFSCORRUPTED) { if (error == -EFSCORRUPTED) {
xfs_alert(args.mp, xfs_alert(args.mp,
"invalid sparse inode record: ino 0x%llx holemask 0x%x count %u", "invalid sparse inode record: ino 0x%llx holemask 0x%x count %u",
XFS_AGINO_TO_INO(args.mp, pag->pag_agno, xfs_agino_to_ino(pag, rec.ir_startino),
rec.ir_startino),
rec.ir_holemask, rec.ir_count); rec.ir_holemask, rec.ir_count);
xfs_force_shutdown(args.mp, SHUTDOWN_CORRUPT_INCORE); xfs_force_shutdown(args.mp, SHUTDOWN_CORRUPT_INCORE);
} }
@ -1334,7 +1333,7 @@ alloc_inode:
ASSERT(offset < XFS_INODES_PER_CHUNK); ASSERT(offset < XFS_INODES_PER_CHUNK);
ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) % ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) %
XFS_INODES_PER_CHUNK) == 0); 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)) { if (xfs_ag_has_sickness(pag, XFS_SICK_AG_INODES)) {
error = xfs_dialloc_check_ino(pag, tp, ino); error = xfs_dialloc_check_ino(pag, tp, ino);
@ -1615,7 +1614,7 @@ xfs_dialloc_ag(
ASSERT(offset < XFS_INODES_PER_CHUNK); ASSERT(offset < XFS_INODES_PER_CHUNK);
ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) % ASSERT((XFS_AGINO_TO_OFFSET(mp, rec.ir_startino) %
XFS_INODES_PER_CHUNK) == 0); 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)) { if (xfs_ag_has_sickness(pag, XFS_SICK_AG_INODES)) {
error = xfs_dialloc_check_ino(pag, tp, ino); 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 && if (!xfs_has_ikeep(mp) && rec.ir_free == XFS_INOBT_ALL_FREE &&
mp->m_sb.sb_inopblock <= XFS_INODES_PER_CHUNK) { mp->m_sb.sb_inopblock <= XFS_INODES_PER_CHUNK) {
xic->deleted = true; xic->deleted = true;
xic->first_ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, xic->first_ino = xfs_agino_to_ino(pag, rec.ir_startino);
rec.ir_startino);
xic->alloc = xfs_inobt_irec_to_allocmask(&rec); xic->alloc = xfs_inobt_irec_to_allocmask(&rec);
/* /*
@ -2322,10 +2320,10 @@ xfs_difree(
return -EINVAL; return -EINVAL;
} }
agino = XFS_INO_TO_AGINO(mp, inode); agino = XFS_INO_TO_AGINO(mp, inode);
if (inode != XFS_AGINO_TO_INO(mp, pag->pag_agno, agino)) { if (inode != xfs_agino_to_ino(pag, agino)) {
xfs_warn(mp, "%s: inode != XFS_AGINO_TO_INO() (%llu != %llu).", xfs_warn(mp, "%s: inode != xfs_agino_to_ino() (%llu != %llu).",
__func__, (unsigned long long)inode, __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); ASSERT(0);
return -EINVAL; return -EINVAL;
} }
@ -2456,7 +2454,7 @@ xfs_imap(
agino = XFS_INO_TO_AGINO(mp, ino); agino = XFS_INO_TO_AGINO(mp, ino);
agbno = XFS_AGINO_TO_AGBNO(mp, agino); agbno = XFS_AGINO_TO_AGBNO(mp, agino);
if (agbno >= mp->m_sb.sb_agblocks || 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; error = -EINVAL;
#ifdef DEBUG #ifdef DEBUG
/* /*
@ -2471,11 +2469,11 @@ xfs_imap(
__func__, (unsigned long long)agbno, __func__, (unsigned long long)agbno,
(unsigned long)mp->m_sb.sb_agblocks); (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, 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, __func__, ino,
XFS_AGINO_TO_INO(mp, pag->pag_agno, agino)); xfs_agino_to_ino(pag, agino));
} }
xfs_stack_trace(); xfs_stack_trace();
#endif /* DEBUG */ #endif /* DEBUG */

View File

@ -1038,12 +1038,10 @@ xrep_iunlink_reload_next(
{ {
struct xfs_scrub *sc = ragi->sc; struct xfs_scrub *sc = ragi->sc;
struct xfs_inode *ip; struct xfs_inode *ip;
xfs_ino_t ino;
xfs_agino_t ret = NULLAGINO; xfs_agino_t ret = NULLAGINO;
int error; int error;
ino = XFS_AGINO_TO_INO(sc->mp, sc->sa.pag->pag_agno, agino); error = xchk_iget(ragi->sc, xfs_agino_to_ino(sc->sa.pag, agino), &ip);
error = xchk_iget(ragi->sc, ino, &ip);
if (error) if (error)
return ret; return ret;
@ -1278,9 +1276,7 @@ xrep_iunlink_mark_ondisk_rec(
* on because we haven't actually scrubbed the inobt or the * on because we haven't actually scrubbed the inobt or the
* inodes yet. * inodes yet.
*/ */
error = xchk_iget(ragi->sc, error = xchk_iget(ragi->sc, xfs_agino_to_ino(sc->sa.pag, agino),
XFS_AGINO_TO_INO(mp, sc->sa.pag->pag_agno,
agino),
&ip); &ip);
if (error) if (error)
continue; continue;
@ -1539,15 +1535,13 @@ xrep_iunlink_relink_next(
ip = xfs_iunlink_lookup(pag, agino); ip = xfs_iunlink_lookup(pag, agino);
if (!ip) { if (!ip) {
xfs_ino_t ino;
xfs_agino_t prev_agino; xfs_agino_t prev_agino;
/* /*
* No inode exists in cache. Load it off the disk so that we * No inode exists in cache. Load it off the disk so that we
* can reinsert it into the incore unlinked list. * can reinsert it into the incore unlinked list.
*/ */
ino = XFS_AGINO_TO_INO(sc->mp, pag->pag_agno, agino); error = xchk_iget(sc, xfs_agino_to_ino(pag, agino), &ip);
error = xchk_iget(sc, ino, &ip);
if (error) if (error)
return -EFSCORRUPTED; return -EFSCORRUPTED;
@ -1601,15 +1595,13 @@ xrep_iunlink_relink_prev(
ip = xfs_iunlink_lookup(pag, agino); ip = xfs_iunlink_lookup(pag, agino);
if (!ip) { if (!ip) {
xfs_ino_t ino;
xfs_agino_t next_agino; xfs_agino_t next_agino;
/* /*
* No inode exists in cache. Load it off the disk so that we * No inode exists in cache. Load it off the disk so that we
* can reinsert it into the incore unlinked list. * can reinsert it into the incore unlinked list.
*/ */
ino = XFS_AGINO_TO_INO(sc->mp, pag->pag_agno, agino); error = xchk_iget(sc, xfs_agino_to_ino(pag, agino), &ip);
error = xchk_iget(sc, ino, &ip);
if (error) if (error)
return -EFSCORRUPTED; return -EFSCORRUPTED;

View File

@ -1336,7 +1336,7 @@ xchk_inode_is_allocated(
} }
/* reject inode numbers outside existing AGs */ /* 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)) if (!xfs_verify_ino(mp, ino))
return -EINVAL; return -EINVAL;

View File

@ -303,7 +303,6 @@ xchk_iallocbt_check_cluster_ifree(
unsigned int irec_ino, unsigned int irec_ino,
struct xfs_dinode *dip) struct xfs_dinode *dip)
{ {
struct xfs_mount *mp = bs->cur->bc_mp;
xfs_ino_t fsino; xfs_ino_t fsino;
xfs_agino_t agino; xfs_agino_t agino;
bool irec_free; bool irec_free;
@ -319,7 +318,7 @@ xchk_iallocbt_check_cluster_ifree(
* the record, compute which fs inode we're talking about. * the record, compute which fs inode we're talking about.
*/ */
agino = irec->ir_startino + irec_ino; 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)); irec_free = (irec->ir_free & XFS_INOBT_MASK(irec_ino));
if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC || if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC ||

View File

@ -146,15 +146,12 @@ xrep_ibt_check_ifree(
struct xfs_scrub *sc = ri->sc; struct xfs_scrub *sc = ri->sc;
struct xfs_mount *mp = sc->mp; struct xfs_mount *mp = sc->mp;
struct xfs_dinode *dip; struct xfs_dinode *dip;
xfs_ino_t fsino;
xfs_agino_t agino; xfs_agino_t agino;
xfs_agnumber_t agno = ri->sc->sa.pag->pag_agno;
unsigned int cluster_buf_base; unsigned int cluster_buf_base;
unsigned int offset; unsigned int offset;
int error; int error;
agino = cluster_ag_base + cluster_index; agino = cluster_ag_base + cluster_index;
fsino = XFS_AGINO_TO_INO(mp, agno, agino);
/* Inode uncached or half assembled, read disk buffer */ /* Inode uncached or half assembled, read disk buffer */
cluster_buf_base = XFS_INO_TO_OFFSET(mp, cluster_ag_base); 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) if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC)
return -EFSCORRUPTED; 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; return -EFSCORRUPTED;
/* Will the in-core inode tell us if it's in use? */ /* Will the in-core inode tell us if it's in use? */

View File

@ -1516,7 +1516,6 @@ xfs_iunlink_reload_next(
struct xfs_perag *pag = agibp->b_pag; struct xfs_perag *pag = agibp->b_pag;
struct xfs_mount *mp = pag->pag_mount; struct xfs_mount *mp = pag->pag_mount;
struct xfs_inode *next_ip = NULL; struct xfs_inode *next_ip = NULL;
xfs_ino_t ino;
int error; int error;
ASSERT(next_agino != NULLAGINO); 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 * but we'd rather shut down now since we're already running in a weird
* situation. * situation.
*/ */
ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, next_agino); error = xfs_iget(mp, tp, xfs_agino_to_ino(pag, next_agino),
error = xfs_iget(mp, tp, ino, XFS_IGET_UNTRUSTED, 0, &next_ip); XFS_IGET_UNTRUSTED, 0, &next_ip);
if (error) { if (error) {
xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI); xfs_ag_mark_sick(pag, XFS_SICK_AG_AGI);
return error; return error;

View File

@ -176,7 +176,6 @@ xfs_iwalk_ag_recs(
struct xfs_mount *mp = iwag->mp; struct xfs_mount *mp = iwag->mp;
struct xfs_trans *tp = iwag->tp; struct xfs_trans *tp = iwag->tp;
struct xfs_perag *pag = iwag->pag; struct xfs_perag *pag = iwag->pag;
xfs_ino_t ino;
unsigned int i, j; unsigned int i, j;
int error; int error;
@ -207,9 +206,10 @@ xfs_iwalk_ag_recs(
continue; continue;
/* Otherwise call our function. */ /* Otherwise call our function. */
ino = XFS_AGINO_TO_INO(mp, pag->pag_agno, error = iwag->iwalk_fn(mp, tp,
irec->ir_startino + j); xfs_agino_to_ino(pag,
error = iwag->iwalk_fn(mp, tp, ino, iwag->data); irec->ir_startino + j),
iwag->data);
if (error) if (error)
return error; return error;
} }
@ -304,7 +304,7 @@ xfs_iwalk_ag_start(
return -EFSCORRUPTED; 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); irec->ir_startino + XFS_INODES_PER_CHUNK - 1);
/* /*
@ -424,7 +424,7 @@ xfs_iwalk_ag(
break; break;
/* Make sure that we always move forward. */ /* 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 && if (iwag->lastino != NULLFSINO &&
XFS_IS_CORRUPT(mp, iwag->lastino >= rec_fsino)) { XFS_IS_CORRUPT(mp, iwag->lastino >= rec_fsino)) {
xfs_btree_mark_sick(cur); xfs_btree_mark_sick(cur);

View File

@ -2726,9 +2726,8 @@ xlog_recover_iunlink_bucket(
agino = be32_to_cpu(agi->agi_unlinked[bucket]); agino = be32_to_cpu(agi->agi_unlinked[bucket]);
while (agino != NULLAGINO) { while (agino != NULLAGINO) {
error = xfs_iget(mp, NULL, error = xfs_iget(mp, NULL, xfs_agino_to_ino(pag, agino), 0, 0,
XFS_AGINO_TO_INO(mp, pag->pag_agno, agino), &ip);
0, 0, &ip);
if (error) if (error)
break; break;