/* * Check that an inode's allocation status matches ir_free in the inobt * record. First we try querying the in-core inode state, and if the inode * isn't loaded we examine the on-disk inode directly. * * Since there can be 1:M and M:1 mappings between inobt records and inode * clusters, we pass in the inode location information as an inobt record; * the index of an inode cluster within the inobt record (as well as the * cluster buffer itself); and the index of the inode within the cluster. * * @irec is the inobt record. * @irec_ino is the inode offset from the start of the record. * @dip is the on-disk inode. */ STATIC int xchk_iallocbt_check_cluster_ifree( struct xchk_btree *bs, struct xfs_inobt_rec_incore *irec, 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; bool ino_inuse; bool freemask_ok; int error = 0; if (xchk_should_terminate(bs->sc, &error)) return error; /* * Given an inobt record and the offset of an inode from the start of * 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_private.a.agno, agino); irec_free = (irec->ir_free & XFS_INOBT_MASK(irec_ino)); if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC || (dip->di_version >= 3 && be64_to_cpu(dip->di_ino) != fsino)) { xchk_btree_set_corrupt(bs->sc, bs->cur, 0); goto out; } error = xfs_icache_inode_is_allocated(mp, bs->cur->bc_tp, fsino, &ino_inuse); if (error == -ENODATA) { /* Not cached, just read the disk buffer */ freemask_ok = irec_free ^ !!(dip->di_mode); if (!bs->sc->try_harder && !freemask_ok) return -EDEADLOCK; } else if (error < 0) { /* * Inode is only half assembled, or there was an IO error, * or the verifier failed, so don't bother trying to check. * The inode scrubber can deal with this. */ goto out; } else { /* Inode is all there. */ freemask_ok = irec_free ^ ino_inuse; } if (!freemask_ok) xchk_btree_set_corrupt(bs->sc, bs->cur, 0); out: return 0; }
/* * Repair probe -- userspace uses this to probe if we're willing to repair a * given mountpoint. */ int xrep_probe( struct xfs_scrub *sc) { int error = 0; if (xchk_should_terminate(sc, &error)) return error; return 0; }