18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2017 Oracle. All Rights Reserved. 48c2ecf20Sopenharmony_ci * Author: Darrick J. Wong <darrick.wong@oracle.com> 58c2ecf20Sopenharmony_ci */ 68c2ecf20Sopenharmony_ci#include "xfs.h" 78c2ecf20Sopenharmony_ci#include "xfs_fs.h" 88c2ecf20Sopenharmony_ci#include "xfs_shared.h" 98c2ecf20Sopenharmony_ci#include "xfs_format.h" 108c2ecf20Sopenharmony_ci#include "xfs_trans_resv.h" 118c2ecf20Sopenharmony_ci#include "xfs_mount.h" 128c2ecf20Sopenharmony_ci#include "xfs_btree.h" 138c2ecf20Sopenharmony_ci#include "xfs_log_format.h" 148c2ecf20Sopenharmony_ci#include "xfs_trans.h" 158c2ecf20Sopenharmony_ci#include "xfs_inode.h" 168c2ecf20Sopenharmony_ci#include "xfs_ialloc.h" 178c2ecf20Sopenharmony_ci#include "xfs_ialloc_btree.h" 188c2ecf20Sopenharmony_ci#include "xfs_icache.h" 198c2ecf20Sopenharmony_ci#include "xfs_rmap.h" 208c2ecf20Sopenharmony_ci#include "scrub/scrub.h" 218c2ecf20Sopenharmony_ci#include "scrub/common.h" 228c2ecf20Sopenharmony_ci#include "scrub/btree.h" 238c2ecf20Sopenharmony_ci#include "scrub/trace.h" 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* 268c2ecf20Sopenharmony_ci * Set us up to scrub inode btrees. 278c2ecf20Sopenharmony_ci * If we detect a discrepancy between the inobt and the inode, 288c2ecf20Sopenharmony_ci * try again after forcing logged inode cores out to disk. 298c2ecf20Sopenharmony_ci */ 308c2ecf20Sopenharmony_ciint 318c2ecf20Sopenharmony_cixchk_setup_ag_iallocbt( 328c2ecf20Sopenharmony_ci struct xfs_scrub *sc, 338c2ecf20Sopenharmony_ci struct xfs_inode *ip) 348c2ecf20Sopenharmony_ci{ 358c2ecf20Sopenharmony_ci return xchk_setup_ag_btree(sc, ip, sc->flags & XCHK_TRY_HARDER); 368c2ecf20Sopenharmony_ci} 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* Inode btree scrubber. */ 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct xchk_iallocbt { 418c2ecf20Sopenharmony_ci /* Number of inodes we see while scanning inobt. */ 428c2ecf20Sopenharmony_ci unsigned long long inodes; 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci /* Expected next startino, for big block filesystems. */ 458c2ecf20Sopenharmony_ci xfs_agino_t next_startino; 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci /* Expected end of the current inode cluster. */ 488c2ecf20Sopenharmony_ci xfs_agino_t next_cluster_ino; 498c2ecf20Sopenharmony_ci}; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/* 528c2ecf20Sopenharmony_ci * If we're checking the finobt, cross-reference with the inobt. 538c2ecf20Sopenharmony_ci * Otherwise we're checking the inobt; if there is an finobt, make sure 548c2ecf20Sopenharmony_ci * we have a record or not depending on freecount. 558c2ecf20Sopenharmony_ci */ 568c2ecf20Sopenharmony_cistatic inline void 578c2ecf20Sopenharmony_cixchk_iallocbt_chunk_xref_other( 588c2ecf20Sopenharmony_ci struct xfs_scrub *sc, 598c2ecf20Sopenharmony_ci struct xfs_inobt_rec_incore *irec, 608c2ecf20Sopenharmony_ci xfs_agino_t agino) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci struct xfs_btree_cur **pcur; 638c2ecf20Sopenharmony_ci bool has_irec; 648c2ecf20Sopenharmony_ci int error; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci if (sc->sm->sm_type == XFS_SCRUB_TYPE_FINOBT) 678c2ecf20Sopenharmony_ci pcur = &sc->sa.ino_cur; 688c2ecf20Sopenharmony_ci else 698c2ecf20Sopenharmony_ci pcur = &sc->sa.fino_cur; 708c2ecf20Sopenharmony_ci if (!(*pcur)) 718c2ecf20Sopenharmony_ci return; 728c2ecf20Sopenharmony_ci error = xfs_ialloc_has_inode_record(*pcur, agino, agino, &has_irec); 738c2ecf20Sopenharmony_ci if (!xchk_should_check_xref(sc, &error, pcur)) 748c2ecf20Sopenharmony_ci return; 758c2ecf20Sopenharmony_ci if (((irec->ir_freecount > 0 && !has_irec) || 768c2ecf20Sopenharmony_ci (irec->ir_freecount == 0 && has_irec))) 778c2ecf20Sopenharmony_ci xchk_btree_xref_set_corrupt(sc, *pcur, 0); 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* Cross-reference with the other btrees. */ 818c2ecf20Sopenharmony_ciSTATIC void 828c2ecf20Sopenharmony_cixchk_iallocbt_chunk_xref( 838c2ecf20Sopenharmony_ci struct xfs_scrub *sc, 848c2ecf20Sopenharmony_ci struct xfs_inobt_rec_incore *irec, 858c2ecf20Sopenharmony_ci xfs_agino_t agino, 868c2ecf20Sopenharmony_ci xfs_agblock_t agbno, 878c2ecf20Sopenharmony_ci xfs_extlen_t len) 888c2ecf20Sopenharmony_ci{ 898c2ecf20Sopenharmony_ci if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) 908c2ecf20Sopenharmony_ci return; 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci xchk_xref_is_used_space(sc, agbno, len); 938c2ecf20Sopenharmony_ci xchk_iallocbt_chunk_xref_other(sc, irec, agino); 948c2ecf20Sopenharmony_ci xchk_xref_is_owned_by(sc, agbno, len, &XFS_RMAP_OINFO_INODES); 958c2ecf20Sopenharmony_ci xchk_xref_is_not_shared(sc, agbno, len); 968c2ecf20Sopenharmony_ci} 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci/* Is this chunk worth checking? */ 998c2ecf20Sopenharmony_ciSTATIC bool 1008c2ecf20Sopenharmony_cixchk_iallocbt_chunk( 1018c2ecf20Sopenharmony_ci struct xchk_btree *bs, 1028c2ecf20Sopenharmony_ci struct xfs_inobt_rec_incore *irec, 1038c2ecf20Sopenharmony_ci xfs_agino_t agino, 1048c2ecf20Sopenharmony_ci xfs_extlen_t len) 1058c2ecf20Sopenharmony_ci{ 1068c2ecf20Sopenharmony_ci struct xfs_mount *mp = bs->cur->bc_mp; 1078c2ecf20Sopenharmony_ci xfs_agnumber_t agno = bs->cur->bc_ag.agno; 1088c2ecf20Sopenharmony_ci xfs_agblock_t bno; 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci bno = XFS_AGINO_TO_AGBNO(mp, agino); 1118c2ecf20Sopenharmony_ci if (bno + len <= bno || 1128c2ecf20Sopenharmony_ci !xfs_verify_agbno(mp, agno, bno) || 1138c2ecf20Sopenharmony_ci !xfs_verify_agbno(mp, agno, bno + len - 1)) 1148c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci xchk_iallocbt_chunk_xref(bs->sc, irec, agino, bno, len); 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci return true; 1198c2ecf20Sopenharmony_ci} 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci/* Count the number of free inodes. */ 1228c2ecf20Sopenharmony_cistatic unsigned int 1238c2ecf20Sopenharmony_cixchk_iallocbt_freecount( 1248c2ecf20Sopenharmony_ci xfs_inofree_t freemask) 1258c2ecf20Sopenharmony_ci{ 1268c2ecf20Sopenharmony_ci BUILD_BUG_ON(sizeof(freemask) != sizeof(__u64)); 1278c2ecf20Sopenharmony_ci return hweight64(freemask); 1288c2ecf20Sopenharmony_ci} 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci/* 1318c2ecf20Sopenharmony_ci * Check that an inode's allocation status matches ir_free in the inobt 1328c2ecf20Sopenharmony_ci * record. First we try querying the in-core inode state, and if the inode 1338c2ecf20Sopenharmony_ci * isn't loaded we examine the on-disk inode directly. 1348c2ecf20Sopenharmony_ci * 1358c2ecf20Sopenharmony_ci * Since there can be 1:M and M:1 mappings between inobt records and inode 1368c2ecf20Sopenharmony_ci * clusters, we pass in the inode location information as an inobt record; 1378c2ecf20Sopenharmony_ci * the index of an inode cluster within the inobt record (as well as the 1388c2ecf20Sopenharmony_ci * cluster buffer itself); and the index of the inode within the cluster. 1398c2ecf20Sopenharmony_ci * 1408c2ecf20Sopenharmony_ci * @irec is the inobt record. 1418c2ecf20Sopenharmony_ci * @irec_ino is the inode offset from the start of the record. 1428c2ecf20Sopenharmony_ci * @dip is the on-disk inode. 1438c2ecf20Sopenharmony_ci */ 1448c2ecf20Sopenharmony_ciSTATIC int 1458c2ecf20Sopenharmony_cixchk_iallocbt_check_cluster_ifree( 1468c2ecf20Sopenharmony_ci struct xchk_btree *bs, 1478c2ecf20Sopenharmony_ci struct xfs_inobt_rec_incore *irec, 1488c2ecf20Sopenharmony_ci unsigned int irec_ino, 1498c2ecf20Sopenharmony_ci struct xfs_dinode *dip) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci struct xfs_mount *mp = bs->cur->bc_mp; 1528c2ecf20Sopenharmony_ci xfs_ino_t fsino; 1538c2ecf20Sopenharmony_ci xfs_agino_t agino; 1548c2ecf20Sopenharmony_ci bool irec_free; 1558c2ecf20Sopenharmony_ci bool ino_inuse; 1568c2ecf20Sopenharmony_ci bool freemask_ok; 1578c2ecf20Sopenharmony_ci int error = 0; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci if (xchk_should_terminate(bs->sc, &error)) 1608c2ecf20Sopenharmony_ci return error; 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci /* 1638c2ecf20Sopenharmony_ci * Given an inobt record and the offset of an inode from the start of 1648c2ecf20Sopenharmony_ci * the record, compute which fs inode we're talking about. 1658c2ecf20Sopenharmony_ci */ 1668c2ecf20Sopenharmony_ci agino = irec->ir_startino + irec_ino; 1678c2ecf20Sopenharmony_ci fsino = XFS_AGINO_TO_INO(mp, bs->cur->bc_ag.agno, agino); 1688c2ecf20Sopenharmony_ci irec_free = (irec->ir_free & XFS_INOBT_MASK(irec_ino)); 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci if (be16_to_cpu(dip->di_magic) != XFS_DINODE_MAGIC || 1718c2ecf20Sopenharmony_ci (dip->di_version >= 3 && be64_to_cpu(dip->di_ino) != fsino)) { 1728c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 1738c2ecf20Sopenharmony_ci goto out; 1748c2ecf20Sopenharmony_ci } 1758c2ecf20Sopenharmony_ci 1768c2ecf20Sopenharmony_ci error = xfs_icache_inode_is_allocated(mp, bs->cur->bc_tp, fsino, 1778c2ecf20Sopenharmony_ci &ino_inuse); 1788c2ecf20Sopenharmony_ci if (error == -ENODATA) { 1798c2ecf20Sopenharmony_ci /* Not cached, just read the disk buffer */ 1808c2ecf20Sopenharmony_ci freemask_ok = irec_free ^ !!(dip->di_mode); 1818c2ecf20Sopenharmony_ci if (!(bs->sc->flags & XCHK_TRY_HARDER) && !freemask_ok) 1828c2ecf20Sopenharmony_ci return -EDEADLOCK; 1838c2ecf20Sopenharmony_ci } else if (error < 0) { 1848c2ecf20Sopenharmony_ci /* 1858c2ecf20Sopenharmony_ci * Inode is only half assembled, or there was an IO error, 1868c2ecf20Sopenharmony_ci * or the verifier failed, so don't bother trying to check. 1878c2ecf20Sopenharmony_ci * The inode scrubber can deal with this. 1888c2ecf20Sopenharmony_ci */ 1898c2ecf20Sopenharmony_ci goto out; 1908c2ecf20Sopenharmony_ci } else { 1918c2ecf20Sopenharmony_ci /* Inode is all there. */ 1928c2ecf20Sopenharmony_ci freemask_ok = irec_free ^ ino_inuse; 1938c2ecf20Sopenharmony_ci } 1948c2ecf20Sopenharmony_ci if (!freemask_ok) 1958c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 1968c2ecf20Sopenharmony_ciout: 1978c2ecf20Sopenharmony_ci return 0; 1988c2ecf20Sopenharmony_ci} 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci/* 2018c2ecf20Sopenharmony_ci * Check that the holemask and freemask of a hypothetical inode cluster match 2028c2ecf20Sopenharmony_ci * what's actually on disk. If sparse inodes are enabled, the cluster does 2038c2ecf20Sopenharmony_ci * not actually have to map to inodes if the corresponding holemask bit is set. 2048c2ecf20Sopenharmony_ci * 2058c2ecf20Sopenharmony_ci * @cluster_base is the first inode in the cluster within the @irec. 2068c2ecf20Sopenharmony_ci */ 2078c2ecf20Sopenharmony_ciSTATIC int 2088c2ecf20Sopenharmony_cixchk_iallocbt_check_cluster( 2098c2ecf20Sopenharmony_ci struct xchk_btree *bs, 2108c2ecf20Sopenharmony_ci struct xfs_inobt_rec_incore *irec, 2118c2ecf20Sopenharmony_ci unsigned int cluster_base) 2128c2ecf20Sopenharmony_ci{ 2138c2ecf20Sopenharmony_ci struct xfs_imap imap; 2148c2ecf20Sopenharmony_ci struct xfs_mount *mp = bs->cur->bc_mp; 2158c2ecf20Sopenharmony_ci struct xfs_dinode *dip; 2168c2ecf20Sopenharmony_ci struct xfs_buf *cluster_bp; 2178c2ecf20Sopenharmony_ci unsigned int nr_inodes; 2188c2ecf20Sopenharmony_ci xfs_agnumber_t agno = bs->cur->bc_ag.agno; 2198c2ecf20Sopenharmony_ci xfs_agblock_t agbno; 2208c2ecf20Sopenharmony_ci unsigned int cluster_index; 2218c2ecf20Sopenharmony_ci uint16_t cluster_mask = 0; 2228c2ecf20Sopenharmony_ci uint16_t ir_holemask; 2238c2ecf20Sopenharmony_ci int error = 0; 2248c2ecf20Sopenharmony_ci 2258c2ecf20Sopenharmony_ci nr_inodes = min_t(unsigned int, XFS_INODES_PER_CHUNK, 2268c2ecf20Sopenharmony_ci M_IGEO(mp)->inodes_per_cluster); 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci /* Map this inode cluster */ 2298c2ecf20Sopenharmony_ci agbno = XFS_AGINO_TO_AGBNO(mp, irec->ir_startino + cluster_base); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci /* Compute a bitmask for this cluster that can be used for holemask. */ 2328c2ecf20Sopenharmony_ci for (cluster_index = 0; 2338c2ecf20Sopenharmony_ci cluster_index < nr_inodes; 2348c2ecf20Sopenharmony_ci cluster_index += XFS_INODES_PER_HOLEMASK_BIT) 2358c2ecf20Sopenharmony_ci cluster_mask |= XFS_INOBT_MASK((cluster_base + cluster_index) / 2368c2ecf20Sopenharmony_ci XFS_INODES_PER_HOLEMASK_BIT); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci /* 2398c2ecf20Sopenharmony_ci * Map the first inode of this cluster to a buffer and offset. 2408c2ecf20Sopenharmony_ci * Be careful about inobt records that don't align with the start of 2418c2ecf20Sopenharmony_ci * the inode buffer when block sizes are large enough to hold multiple 2428c2ecf20Sopenharmony_ci * inode chunks. When this happens, cluster_base will be zero but 2438c2ecf20Sopenharmony_ci * ir_startino can be large enough to make im_boffset nonzero. 2448c2ecf20Sopenharmony_ci */ 2458c2ecf20Sopenharmony_ci ir_holemask = (irec->ir_holemask & cluster_mask); 2468c2ecf20Sopenharmony_ci imap.im_blkno = XFS_AGB_TO_DADDR(mp, agno, agbno); 2478c2ecf20Sopenharmony_ci imap.im_len = XFS_FSB_TO_BB(mp, M_IGEO(mp)->blocks_per_cluster); 2488c2ecf20Sopenharmony_ci imap.im_boffset = XFS_INO_TO_OFFSET(mp, irec->ir_startino) << 2498c2ecf20Sopenharmony_ci mp->m_sb.sb_inodelog; 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci if (imap.im_boffset != 0 && cluster_base != 0) { 2528c2ecf20Sopenharmony_ci ASSERT(imap.im_boffset == 0 || cluster_base == 0); 2538c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 2548c2ecf20Sopenharmony_ci return 0; 2558c2ecf20Sopenharmony_ci } 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci trace_xchk_iallocbt_check_cluster(mp, agno, irec->ir_startino, 2588c2ecf20Sopenharmony_ci imap.im_blkno, imap.im_len, cluster_base, nr_inodes, 2598c2ecf20Sopenharmony_ci cluster_mask, ir_holemask, 2608c2ecf20Sopenharmony_ci XFS_INO_TO_OFFSET(mp, irec->ir_startino + 2618c2ecf20Sopenharmony_ci cluster_base)); 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci /* The whole cluster must be a hole or not a hole. */ 2648c2ecf20Sopenharmony_ci if (ir_holemask != cluster_mask && ir_holemask != 0) { 2658c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 2668c2ecf20Sopenharmony_ci return 0; 2678c2ecf20Sopenharmony_ci } 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci /* If any part of this is a hole, skip it. */ 2708c2ecf20Sopenharmony_ci if (ir_holemask) { 2718c2ecf20Sopenharmony_ci xchk_xref_is_not_owned_by(bs->sc, agbno, 2728c2ecf20Sopenharmony_ci M_IGEO(mp)->blocks_per_cluster, 2738c2ecf20Sopenharmony_ci &XFS_RMAP_OINFO_INODES); 2748c2ecf20Sopenharmony_ci return 0; 2758c2ecf20Sopenharmony_ci } 2768c2ecf20Sopenharmony_ci 2778c2ecf20Sopenharmony_ci xchk_xref_is_owned_by(bs->sc, agbno, M_IGEO(mp)->blocks_per_cluster, 2788c2ecf20Sopenharmony_ci &XFS_RMAP_OINFO_INODES); 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci /* Grab the inode cluster buffer. */ 2818c2ecf20Sopenharmony_ci error = xfs_imap_to_bp(mp, bs->cur->bc_tp, &imap, &dip, &cluster_bp, 0); 2828c2ecf20Sopenharmony_ci if (!xchk_btree_xref_process_error(bs->sc, bs->cur, 0, &error)) 2838c2ecf20Sopenharmony_ci return error; 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_ci /* Check free status of each inode within this cluster. */ 2868c2ecf20Sopenharmony_ci for (cluster_index = 0; cluster_index < nr_inodes; cluster_index++) { 2878c2ecf20Sopenharmony_ci struct xfs_dinode *dip; 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci if (imap.im_boffset >= BBTOB(cluster_bp->b_length)) { 2908c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 2918c2ecf20Sopenharmony_ci break; 2928c2ecf20Sopenharmony_ci } 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci dip = xfs_buf_offset(cluster_bp, imap.im_boffset); 2958c2ecf20Sopenharmony_ci error = xchk_iallocbt_check_cluster_ifree(bs, irec, 2968c2ecf20Sopenharmony_ci cluster_base + cluster_index, dip); 2978c2ecf20Sopenharmony_ci if (error) 2988c2ecf20Sopenharmony_ci break; 2998c2ecf20Sopenharmony_ci imap.im_boffset += mp->m_sb.sb_inodesize; 3008c2ecf20Sopenharmony_ci } 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci xfs_trans_brelse(bs->cur->bc_tp, cluster_bp); 3038c2ecf20Sopenharmony_ci return error; 3048c2ecf20Sopenharmony_ci} 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci/* 3078c2ecf20Sopenharmony_ci * For all the inode clusters that could map to this inobt record, make sure 3088c2ecf20Sopenharmony_ci * that the holemask makes sense and that the allocation status of each inode 3098c2ecf20Sopenharmony_ci * matches the freemask. 3108c2ecf20Sopenharmony_ci */ 3118c2ecf20Sopenharmony_ciSTATIC int 3128c2ecf20Sopenharmony_cixchk_iallocbt_check_clusters( 3138c2ecf20Sopenharmony_ci struct xchk_btree *bs, 3148c2ecf20Sopenharmony_ci struct xfs_inobt_rec_incore *irec) 3158c2ecf20Sopenharmony_ci{ 3168c2ecf20Sopenharmony_ci unsigned int cluster_base; 3178c2ecf20Sopenharmony_ci int error = 0; 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci /* 3208c2ecf20Sopenharmony_ci * For the common case where this inobt record maps to multiple inode 3218c2ecf20Sopenharmony_ci * clusters this will call _check_cluster for each cluster. 3228c2ecf20Sopenharmony_ci * 3238c2ecf20Sopenharmony_ci * For the case that multiple inobt records map to a single cluster, 3248c2ecf20Sopenharmony_ci * this will call _check_cluster once. 3258c2ecf20Sopenharmony_ci */ 3268c2ecf20Sopenharmony_ci for (cluster_base = 0; 3278c2ecf20Sopenharmony_ci cluster_base < XFS_INODES_PER_CHUNK; 3288c2ecf20Sopenharmony_ci cluster_base += M_IGEO(bs->sc->mp)->inodes_per_cluster) { 3298c2ecf20Sopenharmony_ci error = xchk_iallocbt_check_cluster(bs, irec, cluster_base); 3308c2ecf20Sopenharmony_ci if (error) 3318c2ecf20Sopenharmony_ci break; 3328c2ecf20Sopenharmony_ci } 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci return error; 3358c2ecf20Sopenharmony_ci} 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci/* 3388c2ecf20Sopenharmony_ci * Make sure this inode btree record is aligned properly. Because a fs block 3398c2ecf20Sopenharmony_ci * contains multiple inodes, we check that the inobt record is aligned to the 3408c2ecf20Sopenharmony_ci * correct inode, not just the correct block on disk. This results in a finer 3418c2ecf20Sopenharmony_ci * grained corruption check. 3428c2ecf20Sopenharmony_ci */ 3438c2ecf20Sopenharmony_ciSTATIC void 3448c2ecf20Sopenharmony_cixchk_iallocbt_rec_alignment( 3458c2ecf20Sopenharmony_ci struct xchk_btree *bs, 3468c2ecf20Sopenharmony_ci struct xfs_inobt_rec_incore *irec) 3478c2ecf20Sopenharmony_ci{ 3488c2ecf20Sopenharmony_ci struct xfs_mount *mp = bs->sc->mp; 3498c2ecf20Sopenharmony_ci struct xchk_iallocbt *iabt = bs->private; 3508c2ecf20Sopenharmony_ci struct xfs_ino_geometry *igeo = M_IGEO(mp); 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_ci /* 3538c2ecf20Sopenharmony_ci * finobt records have different positioning requirements than inobt 3548c2ecf20Sopenharmony_ci * records: each finobt record must have a corresponding inobt record. 3558c2ecf20Sopenharmony_ci * That is checked in the xref function, so for now we only catch the 3568c2ecf20Sopenharmony_ci * obvious case where the record isn't at all aligned properly. 3578c2ecf20Sopenharmony_ci * 3588c2ecf20Sopenharmony_ci * Note that if a fs block contains more than a single chunk of inodes, 3598c2ecf20Sopenharmony_ci * we will have finobt records only for those chunks containing free 3608c2ecf20Sopenharmony_ci * inodes, and therefore expect chunk alignment of finobt records. 3618c2ecf20Sopenharmony_ci * Otherwise, we expect that the finobt record is aligned to the 3628c2ecf20Sopenharmony_ci * cluster alignment as told by the superblock. 3638c2ecf20Sopenharmony_ci */ 3648c2ecf20Sopenharmony_ci if (bs->cur->bc_btnum == XFS_BTNUM_FINO) { 3658c2ecf20Sopenharmony_ci unsigned int imask; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci imask = min_t(unsigned int, XFS_INODES_PER_CHUNK, 3688c2ecf20Sopenharmony_ci igeo->cluster_align_inodes) - 1; 3698c2ecf20Sopenharmony_ci if (irec->ir_startino & imask) 3708c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 3718c2ecf20Sopenharmony_ci return; 3728c2ecf20Sopenharmony_ci } 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_ci if (iabt->next_startino != NULLAGINO) { 3758c2ecf20Sopenharmony_ci /* 3768c2ecf20Sopenharmony_ci * We're midway through a cluster of inodes that is mapped by 3778c2ecf20Sopenharmony_ci * multiple inobt records. Did we get the record for the next 3788c2ecf20Sopenharmony_ci * irec in the sequence? 3798c2ecf20Sopenharmony_ci */ 3808c2ecf20Sopenharmony_ci if (irec->ir_startino != iabt->next_startino) { 3818c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 3828c2ecf20Sopenharmony_ci return; 3838c2ecf20Sopenharmony_ci } 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci iabt->next_startino += XFS_INODES_PER_CHUNK; 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci /* Are we done with the cluster? */ 3888c2ecf20Sopenharmony_ci if (iabt->next_startino >= iabt->next_cluster_ino) { 3898c2ecf20Sopenharmony_ci iabt->next_startino = NULLAGINO; 3908c2ecf20Sopenharmony_ci iabt->next_cluster_ino = NULLAGINO; 3918c2ecf20Sopenharmony_ci } 3928c2ecf20Sopenharmony_ci return; 3938c2ecf20Sopenharmony_ci } 3948c2ecf20Sopenharmony_ci 3958c2ecf20Sopenharmony_ci /* inobt records must be aligned to cluster and inoalignmnt size. */ 3968c2ecf20Sopenharmony_ci if (irec->ir_startino & (igeo->cluster_align_inodes - 1)) { 3978c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 3988c2ecf20Sopenharmony_ci return; 3998c2ecf20Sopenharmony_ci } 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci if (irec->ir_startino & (igeo->inodes_per_cluster - 1)) { 4028c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 4038c2ecf20Sopenharmony_ci return; 4048c2ecf20Sopenharmony_ci } 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci if (igeo->inodes_per_cluster <= XFS_INODES_PER_CHUNK) 4078c2ecf20Sopenharmony_ci return; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci /* 4108c2ecf20Sopenharmony_ci * If this is the start of an inode cluster that can be mapped by 4118c2ecf20Sopenharmony_ci * multiple inobt records, the next inobt record must follow exactly 4128c2ecf20Sopenharmony_ci * after this one. 4138c2ecf20Sopenharmony_ci */ 4148c2ecf20Sopenharmony_ci iabt->next_startino = irec->ir_startino + XFS_INODES_PER_CHUNK; 4158c2ecf20Sopenharmony_ci iabt->next_cluster_ino = irec->ir_startino + igeo->inodes_per_cluster; 4168c2ecf20Sopenharmony_ci} 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci/* Scrub an inobt/finobt record. */ 4198c2ecf20Sopenharmony_ciSTATIC int 4208c2ecf20Sopenharmony_cixchk_iallocbt_rec( 4218c2ecf20Sopenharmony_ci struct xchk_btree *bs, 4228c2ecf20Sopenharmony_ci union xfs_btree_rec *rec) 4238c2ecf20Sopenharmony_ci{ 4248c2ecf20Sopenharmony_ci struct xfs_mount *mp = bs->cur->bc_mp; 4258c2ecf20Sopenharmony_ci struct xchk_iallocbt *iabt = bs->private; 4268c2ecf20Sopenharmony_ci struct xfs_inobt_rec_incore irec; 4278c2ecf20Sopenharmony_ci uint64_t holes; 4288c2ecf20Sopenharmony_ci xfs_agnumber_t agno = bs->cur->bc_ag.agno; 4298c2ecf20Sopenharmony_ci xfs_agino_t agino; 4308c2ecf20Sopenharmony_ci xfs_extlen_t len; 4318c2ecf20Sopenharmony_ci int holecount; 4328c2ecf20Sopenharmony_ci int i; 4338c2ecf20Sopenharmony_ci int error = 0; 4348c2ecf20Sopenharmony_ci unsigned int real_freecount; 4358c2ecf20Sopenharmony_ci uint16_t holemask; 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci xfs_inobt_btrec_to_irec(mp, rec, &irec); 4388c2ecf20Sopenharmony_ci 4398c2ecf20Sopenharmony_ci if (irec.ir_count > XFS_INODES_PER_CHUNK || 4408c2ecf20Sopenharmony_ci irec.ir_freecount > XFS_INODES_PER_CHUNK) 4418c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci real_freecount = irec.ir_freecount + 4448c2ecf20Sopenharmony_ci (XFS_INODES_PER_CHUNK - irec.ir_count); 4458c2ecf20Sopenharmony_ci if (real_freecount != xchk_iallocbt_freecount(irec.ir_free)) 4468c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci agino = irec.ir_startino; 4498c2ecf20Sopenharmony_ci /* Record has to be properly aligned within the AG. */ 4508c2ecf20Sopenharmony_ci if (!xfs_verify_agino(mp, agno, agino) || 4518c2ecf20Sopenharmony_ci !xfs_verify_agino(mp, agno, agino + XFS_INODES_PER_CHUNK - 1)) { 4528c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 4538c2ecf20Sopenharmony_ci goto out; 4548c2ecf20Sopenharmony_ci } 4558c2ecf20Sopenharmony_ci 4568c2ecf20Sopenharmony_ci xchk_iallocbt_rec_alignment(bs, &irec); 4578c2ecf20Sopenharmony_ci if (bs->sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT) 4588c2ecf20Sopenharmony_ci goto out; 4598c2ecf20Sopenharmony_ci 4608c2ecf20Sopenharmony_ci iabt->inodes += irec.ir_count; 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci /* Handle non-sparse inodes */ 4638c2ecf20Sopenharmony_ci if (!xfs_inobt_issparse(irec.ir_holemask)) { 4648c2ecf20Sopenharmony_ci len = XFS_B_TO_FSB(mp, 4658c2ecf20Sopenharmony_ci XFS_INODES_PER_CHUNK * mp->m_sb.sb_inodesize); 4668c2ecf20Sopenharmony_ci if (irec.ir_count != XFS_INODES_PER_CHUNK) 4678c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci if (!xchk_iallocbt_chunk(bs, &irec, agino, len)) 4708c2ecf20Sopenharmony_ci goto out; 4718c2ecf20Sopenharmony_ci goto check_clusters; 4728c2ecf20Sopenharmony_ci } 4738c2ecf20Sopenharmony_ci 4748c2ecf20Sopenharmony_ci /* Check each chunk of a sparse inode cluster. */ 4758c2ecf20Sopenharmony_ci holemask = irec.ir_holemask; 4768c2ecf20Sopenharmony_ci holecount = 0; 4778c2ecf20Sopenharmony_ci len = XFS_B_TO_FSB(mp, 4788c2ecf20Sopenharmony_ci XFS_INODES_PER_HOLEMASK_BIT * mp->m_sb.sb_inodesize); 4798c2ecf20Sopenharmony_ci holes = ~xfs_inobt_irec_to_allocmask(&irec); 4808c2ecf20Sopenharmony_ci if ((holes & irec.ir_free) != holes || 4818c2ecf20Sopenharmony_ci irec.ir_freecount > irec.ir_count) 4828c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci for (i = 0; i < XFS_INOBT_HOLEMASK_BITS; i++) { 4858c2ecf20Sopenharmony_ci if (holemask & 1) 4868c2ecf20Sopenharmony_ci holecount += XFS_INODES_PER_HOLEMASK_BIT; 4878c2ecf20Sopenharmony_ci else if (!xchk_iallocbt_chunk(bs, &irec, agino, len)) 4888c2ecf20Sopenharmony_ci break; 4898c2ecf20Sopenharmony_ci holemask >>= 1; 4908c2ecf20Sopenharmony_ci agino += XFS_INODES_PER_HOLEMASK_BIT; 4918c2ecf20Sopenharmony_ci } 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci if (holecount > XFS_INODES_PER_CHUNK || 4948c2ecf20Sopenharmony_ci holecount + irec.ir_count != XFS_INODES_PER_CHUNK) 4958c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(bs->sc, bs->cur, 0); 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_cicheck_clusters: 4988c2ecf20Sopenharmony_ci error = xchk_iallocbt_check_clusters(bs, &irec); 4998c2ecf20Sopenharmony_ci if (error) 5008c2ecf20Sopenharmony_ci goto out; 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ciout: 5038c2ecf20Sopenharmony_ci return error; 5048c2ecf20Sopenharmony_ci} 5058c2ecf20Sopenharmony_ci 5068c2ecf20Sopenharmony_ci/* 5078c2ecf20Sopenharmony_ci * Make sure the inode btrees are as large as the rmap thinks they are. 5088c2ecf20Sopenharmony_ci * Don't bother if we're missing btree cursors, as we're already corrupt. 5098c2ecf20Sopenharmony_ci */ 5108c2ecf20Sopenharmony_ciSTATIC void 5118c2ecf20Sopenharmony_cixchk_iallocbt_xref_rmap_btreeblks( 5128c2ecf20Sopenharmony_ci struct xfs_scrub *sc, 5138c2ecf20Sopenharmony_ci int which) 5148c2ecf20Sopenharmony_ci{ 5158c2ecf20Sopenharmony_ci xfs_filblks_t blocks; 5168c2ecf20Sopenharmony_ci xfs_extlen_t inobt_blocks = 0; 5178c2ecf20Sopenharmony_ci xfs_extlen_t finobt_blocks = 0; 5188c2ecf20Sopenharmony_ci int error; 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci if (!sc->sa.ino_cur || !sc->sa.rmap_cur || 5218c2ecf20Sopenharmony_ci (xfs_sb_version_hasfinobt(&sc->mp->m_sb) && !sc->sa.fino_cur) || 5228c2ecf20Sopenharmony_ci xchk_skip_xref(sc->sm)) 5238c2ecf20Sopenharmony_ci return; 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci /* Check that we saw as many inobt blocks as the rmap says. */ 5268c2ecf20Sopenharmony_ci error = xfs_btree_count_blocks(sc->sa.ino_cur, &inobt_blocks); 5278c2ecf20Sopenharmony_ci if (!xchk_process_error(sc, 0, 0, &error)) 5288c2ecf20Sopenharmony_ci return; 5298c2ecf20Sopenharmony_ci 5308c2ecf20Sopenharmony_ci if (sc->sa.fino_cur) { 5318c2ecf20Sopenharmony_ci error = xfs_btree_count_blocks(sc->sa.fino_cur, &finobt_blocks); 5328c2ecf20Sopenharmony_ci if (!xchk_process_error(sc, 0, 0, &error)) 5338c2ecf20Sopenharmony_ci return; 5348c2ecf20Sopenharmony_ci } 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_ci error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, 5378c2ecf20Sopenharmony_ci &XFS_RMAP_OINFO_INOBT, &blocks); 5388c2ecf20Sopenharmony_ci if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur)) 5398c2ecf20Sopenharmony_ci return; 5408c2ecf20Sopenharmony_ci if (blocks != inobt_blocks + finobt_blocks) 5418c2ecf20Sopenharmony_ci xchk_btree_set_corrupt(sc, sc->sa.ino_cur, 0); 5428c2ecf20Sopenharmony_ci} 5438c2ecf20Sopenharmony_ci 5448c2ecf20Sopenharmony_ci/* 5458c2ecf20Sopenharmony_ci * Make sure that the inobt records point to the same number of blocks as 5468c2ecf20Sopenharmony_ci * the rmap says are owned by inodes. 5478c2ecf20Sopenharmony_ci */ 5488c2ecf20Sopenharmony_ciSTATIC void 5498c2ecf20Sopenharmony_cixchk_iallocbt_xref_rmap_inodes( 5508c2ecf20Sopenharmony_ci struct xfs_scrub *sc, 5518c2ecf20Sopenharmony_ci int which, 5528c2ecf20Sopenharmony_ci unsigned long long inodes) 5538c2ecf20Sopenharmony_ci{ 5548c2ecf20Sopenharmony_ci xfs_filblks_t blocks; 5558c2ecf20Sopenharmony_ci xfs_filblks_t inode_blocks; 5568c2ecf20Sopenharmony_ci int error; 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_ci if (!sc->sa.rmap_cur || xchk_skip_xref(sc->sm)) 5598c2ecf20Sopenharmony_ci return; 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci /* Check that we saw as many inode blocks as the rmap knows about. */ 5628c2ecf20Sopenharmony_ci error = xchk_count_rmap_ownedby_ag(sc, sc->sa.rmap_cur, 5638c2ecf20Sopenharmony_ci &XFS_RMAP_OINFO_INODES, &blocks); 5648c2ecf20Sopenharmony_ci if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur)) 5658c2ecf20Sopenharmony_ci return; 5668c2ecf20Sopenharmony_ci inode_blocks = XFS_B_TO_FSB(sc->mp, inodes * sc->mp->m_sb.sb_inodesize); 5678c2ecf20Sopenharmony_ci if (blocks != inode_blocks) 5688c2ecf20Sopenharmony_ci xchk_btree_xref_set_corrupt(sc, sc->sa.rmap_cur, 0); 5698c2ecf20Sopenharmony_ci} 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci/* Scrub the inode btrees for some AG. */ 5728c2ecf20Sopenharmony_ciSTATIC int 5738c2ecf20Sopenharmony_cixchk_iallocbt( 5748c2ecf20Sopenharmony_ci struct xfs_scrub *sc, 5758c2ecf20Sopenharmony_ci xfs_btnum_t which) 5768c2ecf20Sopenharmony_ci{ 5778c2ecf20Sopenharmony_ci struct xfs_btree_cur *cur; 5788c2ecf20Sopenharmony_ci struct xchk_iallocbt iabt = { 5798c2ecf20Sopenharmony_ci .inodes = 0, 5808c2ecf20Sopenharmony_ci .next_startino = NULLAGINO, 5818c2ecf20Sopenharmony_ci .next_cluster_ino = NULLAGINO, 5828c2ecf20Sopenharmony_ci }; 5838c2ecf20Sopenharmony_ci int error; 5848c2ecf20Sopenharmony_ci 5858c2ecf20Sopenharmony_ci cur = which == XFS_BTNUM_INO ? sc->sa.ino_cur : sc->sa.fino_cur; 5868c2ecf20Sopenharmony_ci error = xchk_btree(sc, cur, xchk_iallocbt_rec, &XFS_RMAP_OINFO_INOBT, 5878c2ecf20Sopenharmony_ci &iabt); 5888c2ecf20Sopenharmony_ci if (error) 5898c2ecf20Sopenharmony_ci return error; 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci xchk_iallocbt_xref_rmap_btreeblks(sc, which); 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_ci /* 5948c2ecf20Sopenharmony_ci * If we're scrubbing the inode btree, inode_blocks is the number of 5958c2ecf20Sopenharmony_ci * blocks pointed to by all the inode chunk records. Therefore, we 5968c2ecf20Sopenharmony_ci * should compare to the number of inode chunk blocks that the rmap 5978c2ecf20Sopenharmony_ci * knows about. We can't do this for the finobt since it only points 5988c2ecf20Sopenharmony_ci * to inode chunks with free inodes. 5998c2ecf20Sopenharmony_ci */ 6008c2ecf20Sopenharmony_ci if (which == XFS_BTNUM_INO) 6018c2ecf20Sopenharmony_ci xchk_iallocbt_xref_rmap_inodes(sc, which, iabt.inodes); 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci return error; 6048c2ecf20Sopenharmony_ci} 6058c2ecf20Sopenharmony_ci 6068c2ecf20Sopenharmony_ciint 6078c2ecf20Sopenharmony_cixchk_inobt( 6088c2ecf20Sopenharmony_ci struct xfs_scrub *sc) 6098c2ecf20Sopenharmony_ci{ 6108c2ecf20Sopenharmony_ci return xchk_iallocbt(sc, XFS_BTNUM_INO); 6118c2ecf20Sopenharmony_ci} 6128c2ecf20Sopenharmony_ci 6138c2ecf20Sopenharmony_ciint 6148c2ecf20Sopenharmony_cixchk_finobt( 6158c2ecf20Sopenharmony_ci struct xfs_scrub *sc) 6168c2ecf20Sopenharmony_ci{ 6178c2ecf20Sopenharmony_ci return xchk_iallocbt(sc, XFS_BTNUM_FINO); 6188c2ecf20Sopenharmony_ci} 6198c2ecf20Sopenharmony_ci 6208c2ecf20Sopenharmony_ci/* See if an inode btree has (or doesn't have) an inode chunk record. */ 6218c2ecf20Sopenharmony_cistatic inline void 6228c2ecf20Sopenharmony_cixchk_xref_inode_check( 6238c2ecf20Sopenharmony_ci struct xfs_scrub *sc, 6248c2ecf20Sopenharmony_ci xfs_agblock_t agbno, 6258c2ecf20Sopenharmony_ci xfs_extlen_t len, 6268c2ecf20Sopenharmony_ci struct xfs_btree_cur **icur, 6278c2ecf20Sopenharmony_ci bool should_have_inodes) 6288c2ecf20Sopenharmony_ci{ 6298c2ecf20Sopenharmony_ci bool has_inodes; 6308c2ecf20Sopenharmony_ci int error; 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci if (!(*icur) || xchk_skip_xref(sc->sm)) 6338c2ecf20Sopenharmony_ci return; 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ci error = xfs_ialloc_has_inodes_at_extent(*icur, agbno, len, &has_inodes); 6368c2ecf20Sopenharmony_ci if (!xchk_should_check_xref(sc, &error, icur)) 6378c2ecf20Sopenharmony_ci return; 6388c2ecf20Sopenharmony_ci if (has_inodes != should_have_inodes) 6398c2ecf20Sopenharmony_ci xchk_btree_xref_set_corrupt(sc, *icur, 0); 6408c2ecf20Sopenharmony_ci} 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci/* xref check that the extent is not covered by inodes */ 6438c2ecf20Sopenharmony_civoid 6448c2ecf20Sopenharmony_cixchk_xref_is_not_inode_chunk( 6458c2ecf20Sopenharmony_ci struct xfs_scrub *sc, 6468c2ecf20Sopenharmony_ci xfs_agblock_t agbno, 6478c2ecf20Sopenharmony_ci xfs_extlen_t len) 6488c2ecf20Sopenharmony_ci{ 6498c2ecf20Sopenharmony_ci xchk_xref_inode_check(sc, agbno, len, &sc->sa.ino_cur, false); 6508c2ecf20Sopenharmony_ci xchk_xref_inode_check(sc, agbno, len, &sc->sa.fino_cur, false); 6518c2ecf20Sopenharmony_ci} 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci/* xref check that the extent is covered by inodes */ 6548c2ecf20Sopenharmony_civoid 6558c2ecf20Sopenharmony_cixchk_xref_is_inode_chunk( 6568c2ecf20Sopenharmony_ci struct xfs_scrub *sc, 6578c2ecf20Sopenharmony_ci xfs_agblock_t agbno, 6588c2ecf20Sopenharmony_ci xfs_extlen_t len) 6598c2ecf20Sopenharmony_ci{ 6608c2ecf20Sopenharmony_ci xchk_xref_inode_check(sc, agbno, len, &sc->sa.ino_cur, true); 6618c2ecf20Sopenharmony_ci} 662