2023-04-12 01:59:56 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-10-18 04:37:38 +00:00
|
|
|
/*
|
2023-04-12 01:59:57 +00:00
|
|
|
* Copyright (C) 2017-2023 Oracle. All Rights Reserved.
|
2023-04-12 01:59:56 +00:00
|
|
|
* Author: Darrick J. Wong <djwong@kernel.org>
|
2017-10-18 04:37:38 +00:00
|
|
|
*/
|
|
|
|
#include "xfs.h"
|
|
|
|
#include "xfs_fs.h"
|
|
|
|
#include "xfs_shared.h"
|
|
|
|
#include "xfs_format.h"
|
|
|
|
#include "xfs_trans_resv.h"
|
|
|
|
#include "xfs_mount.h"
|
|
|
|
#include "xfs_btree.h"
|
|
|
|
#include "xfs_sb.h"
|
2017-10-18 04:37:39 +00:00
|
|
|
#include "xfs_alloc.h"
|
2017-10-18 04:37:39 +00:00
|
|
|
#include "xfs_ialloc.h"
|
2018-01-17 02:53:08 +00:00
|
|
|
#include "xfs_rmap.h"
|
2021-06-02 00:48:24 +00:00
|
|
|
#include "xfs_ag.h"
|
2017-10-18 04:37:38 +00:00
|
|
|
#include "scrub/scrub.h"
|
|
|
|
#include "scrub/common.h"
|
|
|
|
|
2023-04-12 01:59:59 +00:00
|
|
|
int
|
|
|
|
xchk_setup_agheader(
|
|
|
|
struct xfs_scrub *sc)
|
|
|
|
{
|
|
|
|
if (xchk_need_intent_drain(sc))
|
|
|
|
xchk_fsgates_enable(sc, XCHK_FSGATES_DRAIN);
|
|
|
|
return xchk_setup_fs(sc);
|
|
|
|
}
|
|
|
|
|
2017-10-18 04:37:38 +00:00
|
|
|
/* Superblock */
|
|
|
|
|
2018-01-17 02:53:05 +00:00
|
|
|
/* Cross-reference with the other btrees. */
|
|
|
|
STATIC void
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_superblock_xref(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_buf *bp)
|
2018-01-17 02:53:05 +00:00
|
|
|
{
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
xfs_agnumber_t agno = sc->sm->sm_agno;
|
|
|
|
xfs_agblock_t agbno;
|
|
|
|
int error;
|
2018-01-17 02:53:06 +00:00
|
|
|
|
2018-01-17 02:53:05 +00:00
|
|
|
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
|
|
|
return;
|
2018-01-17 02:53:06 +00:00
|
|
|
|
|
|
|
agbno = XFS_SB_BLOCK(mp);
|
|
|
|
|
2021-08-06 18:06:35 +00:00
|
|
|
error = xchk_ag_init_existing(sc, agno, &sc->sa);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_xref_process_error(sc, agno, agbno, &error))
|
2018-01-17 02:53:06 +00:00
|
|
|
return;
|
|
|
|
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_xref_is_used_space(sc, agbno, 1);
|
|
|
|
xchk_xref_is_not_inode_chunk(sc, agbno, 1);
|
2023-04-12 02:00:15 +00:00
|
|
|
xchk_xref_is_only_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_xref_is_not_shared(sc, agbno, 1);
|
2023-04-12 02:00:12 +00:00
|
|
|
xchk_xref_is_not_cow_staging(sc, agbno, 1);
|
2018-01-17 02:53:06 +00:00
|
|
|
|
|
|
|
/* scrub teardown will take care of sc->sa for us */
|
2018-01-17 02:53:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-18 04:37:38 +00:00
|
|
|
/*
|
|
|
|
* Scrub the filesystem superblock.
|
|
|
|
*
|
|
|
|
* Note: We do /not/ attempt to check AG 0's superblock. Mount is
|
|
|
|
* responsible for validating all the geometry information in sb 0, so
|
|
|
|
* if the filesystem is capable of initiating online scrub, then clearly
|
|
|
|
* sb 0 is ok and we can use its information to check everything else.
|
|
|
|
*/
|
|
|
|
int
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_superblock(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2017-10-18 04:37:38 +00:00
|
|
|
{
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
struct xfs_buf *bp;
|
|
|
|
struct xfs_dsb *sb;
|
2021-08-06 18:06:35 +00:00
|
|
|
struct xfs_perag *pag;
|
2018-07-19 19:29:12 +00:00
|
|
|
xfs_agnumber_t agno;
|
|
|
|
uint32_t v2_ok;
|
|
|
|
__be32 features_mask;
|
|
|
|
int error;
|
|
|
|
__be16 vernum_mask;
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
agno = sc->sm->sm_agno;
|
|
|
|
if (agno == 0)
|
|
|
|
return 0;
|
|
|
|
|
2021-08-06 18:06:35 +00:00
|
|
|
/*
|
|
|
|
* Grab an active reference to the perag structure. If we can't get
|
|
|
|
* it, we're racing with something that's tearing down the AG, so
|
|
|
|
* signal that the AG no longer exists.
|
|
|
|
*/
|
|
|
|
pag = xfs_perag_get(mp, agno);
|
|
|
|
if (!pag)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2018-05-14 13:34:31 +00:00
|
|
|
error = xfs_sb_read_secondary(mp, sc->tp, agno, &bp);
|
2018-01-08 18:49:02 +00:00
|
|
|
/*
|
|
|
|
* The superblock verifier can return several different error codes
|
|
|
|
* if it thinks the superblock doesn't look right. For a mount these
|
|
|
|
* would all get bounced back to userspace, but if we're here then the
|
|
|
|
* fs mounted successfully, which means that this secondary superblock
|
|
|
|
* is simply incorrect. Treat all these codes the same way we treat
|
|
|
|
* any corruption.
|
|
|
|
*/
|
|
|
|
switch (error) {
|
|
|
|
case -EINVAL: /* also -EWRONGFS */
|
|
|
|
case -ENOSYS:
|
|
|
|
case -EFBIG:
|
|
|
|
error = -EFSCORRUPTED;
|
2021-04-20 22:54:36 +00:00
|
|
|
fallthrough;
|
2018-01-08 18:49:02 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_process_error(sc, agno, XFS_SB_BLOCK(mp), &error))
|
2021-08-06 18:06:35 +00:00
|
|
|
goto out_pag;
|
2017-10-18 04:37:38 +00:00
|
|
|
|
2020-03-10 15:57:30 +00:00
|
|
|
sb = bp->b_addr;
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify the geometries match. Fields that are permanently
|
|
|
|
* set by mkfs are checked; fields that can be updated later
|
|
|
|
* (and are not propagated to backup superblocks) are preen
|
|
|
|
* checked.
|
|
|
|
*/
|
|
|
|
if (sb->sb_blocksize != cpu_to_be32(mp->m_sb.sb_blocksize))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_dblocks != cpu_to_be64(mp->m_sb.sb_dblocks))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_rblocks != cpu_to_be64(mp->m_sb.sb_rblocks))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_rextents != cpu_to_be64(mp->m_sb.sb_rextents))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (!uuid_equal(&sb->sb_uuid, &mp->m_sb.sb_uuid))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_logstart != cpu_to_be64(mp->m_sb.sb_logstart))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_rootino != cpu_to_be64(mp->m_sb.sb_rootino))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_rbmino != cpu_to_be64(mp->m_sb.sb_rbmino))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_rsumino != cpu_to_be64(mp->m_sb.sb_rsumino))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_rextsize != cpu_to_be32(mp->m_sb.sb_rextsize))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_agblocks != cpu_to_be32(mp->m_sb.sb_agblocks))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_agcount != cpu_to_be32(mp->m_sb.sb_agcount))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_rbmblocks != cpu_to_be32(mp->m_sb.sb_rbmblocks))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_logblocks != cpu_to_be32(mp->m_sb.sb_logblocks))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
/* Check sb_versionnum bits that are set at mkfs time. */
|
|
|
|
vernum_mask = cpu_to_be16(~XFS_SB_VERSION_OKBITS |
|
|
|
|
XFS_SB_VERSION_NUMBITS |
|
|
|
|
XFS_SB_VERSION_ALIGNBIT |
|
|
|
|
XFS_SB_VERSION_DALIGNBIT |
|
|
|
|
XFS_SB_VERSION_SHAREDBIT |
|
|
|
|
XFS_SB_VERSION_LOGV2BIT |
|
|
|
|
XFS_SB_VERSION_SECTORBIT |
|
|
|
|
XFS_SB_VERSION_EXTFLGBIT |
|
|
|
|
XFS_SB_VERSION_DIRV2BIT);
|
|
|
|
if ((sb->sb_versionnum & vernum_mask) !=
|
|
|
|
(cpu_to_be16(mp->m_sb.sb_versionnum) & vernum_mask))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
/* Check sb_versionnum bits that can be set after mkfs time. */
|
|
|
|
vernum_mask = cpu_to_be16(XFS_SB_VERSION_ATTRBIT |
|
|
|
|
XFS_SB_VERSION_NLINKBIT |
|
|
|
|
XFS_SB_VERSION_QUOTABIT);
|
|
|
|
if ((sb->sb_versionnum & vernum_mask) !=
|
|
|
|
(cpu_to_be16(mp->m_sb.sb_versionnum) & vernum_mask))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_sectsize != cpu_to_be16(mp->m_sb.sb_sectsize))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_inodesize != cpu_to_be16(mp->m_sb.sb_inodesize))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_inopblock != cpu_to_be16(mp->m_sb.sb_inopblock))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (memcmp(sb->sb_fname, mp->m_sb.sb_fname, sizeof(sb->sb_fname)))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_blocklog != mp->m_sb.sb_blocklog)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_sectlog != mp->m_sb.sb_sectlog)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_inodelog != mp->m_sb.sb_inodelog)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_inopblog != mp->m_sb.sb_inopblog)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_agblklog != mp->m_sb.sb_agblklog)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_rextslog != mp->m_sb.sb_rextslog)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_imax_pct != mp->m_sb.sb_imax_pct)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip the summary counters since we track them in memory anyway.
|
|
|
|
* sb_icount, sb_ifree, sb_fdblocks, sb_frexents
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (sb->sb_uquotino != cpu_to_be64(mp->m_sb.sb_uquotino))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_gquotino != cpu_to_be64(mp->m_sb.sb_gquotino))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Skip the quota flags since repair will force quotacheck.
|
|
|
|
* sb_qflags
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (sb->sb_flags != mp->m_sb.sb_flags)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_shared_vn != mp->m_sb.sb_shared_vn)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_inoalignmt != cpu_to_be32(mp->m_sb.sb_inoalignmt))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_unit != cpu_to_be32(mp->m_sb.sb_unit))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_width != cpu_to_be32(mp->m_sb.sb_width))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_dirblklog != mp->m_sb.sb_dirblklog)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_logsectlog != mp->m_sb.sb_logsectlog)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_logsectsize != cpu_to_be16(mp->m_sb.sb_logsectsize))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_logsunit != cpu_to_be32(mp->m_sb.sb_logsunit))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
/* Do we see any invalid bits in sb_features2? */
|
|
|
|
if (!xfs_sb_version_hasmorebits(&mp->m_sb)) {
|
|
|
|
if (sb->sb_features2 != 0)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
} else {
|
|
|
|
v2_ok = XFS_SB_VERSION2_OKBITS;
|
2021-08-19 01:46:56 +00:00
|
|
|
if (xfs_sb_is_v5(&mp->m_sb))
|
2017-10-18 04:37:38 +00:00
|
|
|
v2_ok |= XFS_SB_VERSION2_CRCBIT;
|
|
|
|
|
|
|
|
if (!!(sb->sb_features2 & cpu_to_be32(~v2_ok)))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_features2 != sb->sb_bad_features2)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check sb_features2 flags that are set at mkfs time. */
|
|
|
|
features_mask = cpu_to_be32(XFS_SB_VERSION2_LAZYSBCOUNTBIT |
|
|
|
|
XFS_SB_VERSION2_PROJID32BIT |
|
|
|
|
XFS_SB_VERSION2_CRCBIT |
|
|
|
|
XFS_SB_VERSION2_FTYPE);
|
|
|
|
if ((sb->sb_features2 & features_mask) !=
|
|
|
|
(cpu_to_be32(mp->m_sb.sb_features2) & features_mask))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
/* Check sb_features2 flags that can be set after mkfs time. */
|
|
|
|
features_mask = cpu_to_be32(XFS_SB_VERSION2_ATTR2BIT);
|
|
|
|
if ((sb->sb_features2 & features_mask) !=
|
|
|
|
(cpu_to_be32(mp->m_sb.sb_features2) & features_mask))
|
xfs: fix online fsck handling of v5 feature bits on secondary supers
While I was auditing the code in xfs_repair that adds feature bits to
existing V5 filesystems, I decided to have a look at how online fsck
handles feature bits, and I found a few problems:
1) ATTR2 is added to the primary super when an xattr is set to a file,
but that isn't consistently propagated to secondary supers. This isn't
a corruption, merely a discrepancy that repair will fix if it ever has
to restore the primary from a secondary. Hence, if we find a mismatch
on a secondary, this is a preen condition, not a corruption.
2) There are more compat and ro_compat features now than there used to
be, but we mask off the newer features from testing. This means we
ignore inconsistencies in the INOBTCOUNT and BIGTIME features, which is
wrong. Get rid of the masking and compare directly.
3) NEEDSREPAIR, when set on a secondary, is ignored by everyone. Hence
a mismatch here should also be flagged for preening, and online repair
should clear the flag. Right now we ignore it due to (2).
4) log_incompat features are ephemeral, since we can clear the feature
bit as soon as the log no longer contains live records for a particular
log feature. As such, the only copy we care about is the one in the
primary super. If we find any bits set in the secondary super, we
should flag that for preening, and clear the bits if the user elects to
repair it.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-01-08 01:45:51 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
2021-08-19 01:46:37 +00:00
|
|
|
if (!xfs_has_crc(mp)) {
|
2017-10-18 04:37:38 +00:00
|
|
|
/* all v5 fields must be zero */
|
|
|
|
if (memchr_inv(&sb->sb_features_compat, 0,
|
|
|
|
sizeof(struct xfs_dsb) -
|
|
|
|
offsetof(struct xfs_dsb, sb_features_compat)))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
} else {
|
xfs: fix online fsck handling of v5 feature bits on secondary supers
While I was auditing the code in xfs_repair that adds feature bits to
existing V5 filesystems, I decided to have a look at how online fsck
handles feature bits, and I found a few problems:
1) ATTR2 is added to the primary super when an xattr is set to a file,
but that isn't consistently propagated to secondary supers. This isn't
a corruption, merely a discrepancy that repair will fix if it ever has
to restore the primary from a secondary. Hence, if we find a mismatch
on a secondary, this is a preen condition, not a corruption.
2) There are more compat and ro_compat features now than there used to
be, but we mask off the newer features from testing. This means we
ignore inconsistencies in the INOBTCOUNT and BIGTIME features, which is
wrong. Get rid of the masking and compare directly.
3) NEEDSREPAIR, when set on a secondary, is ignored by everyone. Hence
a mismatch here should also be flagged for preening, and online repair
should clear the flag. Right now we ignore it due to (2).
4) log_incompat features are ephemeral, since we can clear the feature
bit as soon as the log no longer contains live records for a particular
log feature. As such, the only copy we care about is the one in the
primary super. If we find any bits set in the secondary super, we
should flag that for preening, and clear the bits if the user elects to
repair it.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-01-08 01:45:51 +00:00
|
|
|
/* compat features must match */
|
|
|
|
if (sb->sb_features_compat !=
|
|
|
|
cpu_to_be32(mp->m_sb.sb_features_compat))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
xfs: fix online fsck handling of v5 feature bits on secondary supers
While I was auditing the code in xfs_repair that adds feature bits to
existing V5 filesystems, I decided to have a look at how online fsck
handles feature bits, and I found a few problems:
1) ATTR2 is added to the primary super when an xattr is set to a file,
but that isn't consistently propagated to secondary supers. This isn't
a corruption, merely a discrepancy that repair will fix if it ever has
to restore the primary from a secondary. Hence, if we find a mismatch
on a secondary, this is a preen condition, not a corruption.
2) There are more compat and ro_compat features now than there used to
be, but we mask off the newer features from testing. This means we
ignore inconsistencies in the INOBTCOUNT and BIGTIME features, which is
wrong. Get rid of the masking and compare directly.
3) NEEDSREPAIR, when set on a secondary, is ignored by everyone. Hence
a mismatch here should also be flagged for preening, and online repair
should clear the flag. Right now we ignore it due to (2).
4) log_incompat features are ephemeral, since we can clear the feature
bit as soon as the log no longer contains live records for a particular
log feature. As such, the only copy we care about is the one in the
primary super. If we find any bits set in the secondary super, we
should flag that for preening, and clear the bits if the user elects to
repair it.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-01-08 01:45:51 +00:00
|
|
|
/* ro compat features must match */
|
|
|
|
if (sb->sb_features_ro_compat !=
|
|
|
|
cpu_to_be32(mp->m_sb.sb_features_ro_compat))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
xfs: fix online fsck handling of v5 feature bits on secondary supers
While I was auditing the code in xfs_repair that adds feature bits to
existing V5 filesystems, I decided to have a look at how online fsck
handles feature bits, and I found a few problems:
1) ATTR2 is added to the primary super when an xattr is set to a file,
but that isn't consistently propagated to secondary supers. This isn't
a corruption, merely a discrepancy that repair will fix if it ever has
to restore the primary from a secondary. Hence, if we find a mismatch
on a secondary, this is a preen condition, not a corruption.
2) There are more compat and ro_compat features now than there used to
be, but we mask off the newer features from testing. This means we
ignore inconsistencies in the INOBTCOUNT and BIGTIME features, which is
wrong. Get rid of the masking and compare directly.
3) NEEDSREPAIR, when set on a secondary, is ignored by everyone. Hence
a mismatch here should also be flagged for preening, and online repair
should clear the flag. Right now we ignore it due to (2).
4) log_incompat features are ephemeral, since we can clear the feature
bit as soon as the log no longer contains live records for a particular
log feature. As such, the only copy we care about is the one in the
primary super. If we find any bits set in the secondary super, we
should flag that for preening, and clear the bits if the user elects to
repair it.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-01-08 01:45:51 +00:00
|
|
|
/*
|
|
|
|
* NEEDSREPAIR is ignored on a secondary super, so we should
|
|
|
|
* clear it when we find it, though it's not a corruption.
|
|
|
|
*/
|
|
|
|
features_mask = cpu_to_be32(XFS_SB_FEAT_INCOMPAT_NEEDSREPAIR);
|
|
|
|
if ((cpu_to_be32(mp->m_sb.sb_features_incompat) ^
|
|
|
|
sb->sb_features_incompat) & features_mask)
|
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
xfs: fix online fsck handling of v5 feature bits on secondary supers
While I was auditing the code in xfs_repair that adds feature bits to
existing V5 filesystems, I decided to have a look at how online fsck
handles feature bits, and I found a few problems:
1) ATTR2 is added to the primary super when an xattr is set to a file,
but that isn't consistently propagated to secondary supers. This isn't
a corruption, merely a discrepancy that repair will fix if it ever has
to restore the primary from a secondary. Hence, if we find a mismatch
on a secondary, this is a preen condition, not a corruption.
2) There are more compat and ro_compat features now than there used to
be, but we mask off the newer features from testing. This means we
ignore inconsistencies in the INOBTCOUNT and BIGTIME features, which is
wrong. Get rid of the masking and compare directly.
3) NEEDSREPAIR, when set on a secondary, is ignored by everyone. Hence
a mismatch here should also be flagged for preening, and online repair
should clear the flag. Right now we ignore it due to (2).
4) log_incompat features are ephemeral, since we can clear the feature
bit as soon as the log no longer contains live records for a particular
log feature. As such, the only copy we care about is the one in the
primary super. If we find any bits set in the secondary super, we
should flag that for preening, and clear the bits if the user elects to
repair it.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-01-08 01:45:51 +00:00
|
|
|
/* all other incompat features must match */
|
|
|
|
if ((cpu_to_be32(mp->m_sb.sb_features_incompat) ^
|
|
|
|
sb->sb_features_incompat) & ~features_mask)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
xfs: fix online fsck handling of v5 feature bits on secondary supers
While I was auditing the code in xfs_repair that adds feature bits to
existing V5 filesystems, I decided to have a look at how online fsck
handles feature bits, and I found a few problems:
1) ATTR2 is added to the primary super when an xattr is set to a file,
but that isn't consistently propagated to secondary supers. This isn't
a corruption, merely a discrepancy that repair will fix if it ever has
to restore the primary from a secondary. Hence, if we find a mismatch
on a secondary, this is a preen condition, not a corruption.
2) There are more compat and ro_compat features now than there used to
be, but we mask off the newer features from testing. This means we
ignore inconsistencies in the INOBTCOUNT and BIGTIME features, which is
wrong. Get rid of the masking and compare directly.
3) NEEDSREPAIR, when set on a secondary, is ignored by everyone. Hence
a mismatch here should also be flagged for preening, and online repair
should clear the flag. Right now we ignore it due to (2).
4) log_incompat features are ephemeral, since we can clear the feature
bit as soon as the log no longer contains live records for a particular
log feature. As such, the only copy we care about is the one in the
primary super. If we find any bits set in the secondary super, we
should flag that for preening, and clear the bits if the user elects to
repair it.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-01-08 01:45:51 +00:00
|
|
|
/*
|
|
|
|
* log incompat features protect newer log record types from
|
|
|
|
* older log recovery code. Log recovery doesn't check the
|
|
|
|
* secondary supers, so we can clear these if needed.
|
|
|
|
*/
|
|
|
|
if (sb->sb_features_log_incompat)
|
|
|
|
xchk_block_set_preen(sc, bp);
|
|
|
|
|
2017-10-18 04:37:38 +00:00
|
|
|
/* Don't care about sb_crc */
|
|
|
|
|
|
|
|
if (sb->sb_spino_align != cpu_to_be32(mp->m_sb.sb_spino_align))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
if (sb->sb_pquotino != cpu_to_be64(mp->m_sb.sb_pquotino))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_preen(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
|
|
|
/* Don't care about sb_lsn */
|
|
|
|
}
|
|
|
|
|
2021-08-19 01:46:37 +00:00
|
|
|
if (xfs_has_metauuid(mp)) {
|
2017-10-18 04:37:38 +00:00
|
|
|
/* The metadata UUID must be the same for all supers */
|
|
|
|
if (!uuid_equal(&sb->sb_meta_uuid, &mp->m_sb.sb_meta_uuid))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Everything else must be zero. */
|
|
|
|
if (memchr_inv(sb + 1, 0,
|
|
|
|
BBTOB(bp->b_length) - sizeof(struct xfs_dsb)))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2017-10-18 04:37:38 +00:00
|
|
|
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_superblock_xref(sc, bp);
|
2021-08-06 18:06:35 +00:00
|
|
|
out_pag:
|
|
|
|
xfs_perag_put(pag);
|
2017-10-18 04:37:38 +00:00
|
|
|
return error;
|
|
|
|
}
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
/* AGF */
|
|
|
|
|
2018-01-17 02:53:06 +00:00
|
|
|
/* Tally freespace record lengths. */
|
|
|
|
STATIC int
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf_record_bno_lengths(
|
2018-01-17 02:53:06 +00:00
|
|
|
struct xfs_btree_cur *cur,
|
2021-08-11 00:02:16 +00:00
|
|
|
const struct xfs_alloc_rec_incore *rec,
|
2018-01-17 02:53:06 +00:00
|
|
|
void *priv)
|
|
|
|
{
|
|
|
|
xfs_extlen_t *blocks = priv;
|
|
|
|
|
|
|
|
(*blocks) += rec->ar_blockcount;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check agf_freeblks */
|
|
|
|
static inline void
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf_xref_freeblks(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2018-01-17 02:53:06 +00:00
|
|
|
{
|
2020-03-10 15:57:29 +00:00
|
|
|
struct xfs_agf *agf = sc->sa.agf_bp->b_addr;
|
2018-07-19 19:29:12 +00:00
|
|
|
xfs_extlen_t blocks = 0;
|
|
|
|
int error;
|
2018-01-17 02:53:06 +00:00
|
|
|
|
|
|
|
if (!sc->sa.bno_cur)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error = xfs_alloc_query_all(sc->sa.bno_cur,
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf_record_bno_lengths, &blocks);
|
|
|
|
if (!xchk_should_check_xref(sc, &error, &sc->sa.bno_cur))
|
2018-01-17 02:53:06 +00:00
|
|
|
return;
|
|
|
|
if (blocks != be32_to_cpu(agf->agf_freeblks))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_xref_set_corrupt(sc, sc->sa.agf_bp);
|
2018-01-17 02:53:06 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 02:53:07 +00:00
|
|
|
/* Cross reference the AGF with the cntbt (freespace by length btree) */
|
|
|
|
static inline void
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf_xref_cntbt(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2018-01-17 02:53:07 +00:00
|
|
|
{
|
2020-03-10 15:57:29 +00:00
|
|
|
struct xfs_agf *agf = sc->sa.agf_bp->b_addr;
|
2018-07-19 19:29:12 +00:00
|
|
|
xfs_agblock_t agbno;
|
|
|
|
xfs_extlen_t blocks;
|
|
|
|
int have;
|
|
|
|
int error;
|
2018-01-17 02:53:07 +00:00
|
|
|
|
|
|
|
if (!sc->sa.cnt_cur)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Any freespace at all? */
|
|
|
|
error = xfs_alloc_lookup_le(sc->sa.cnt_cur, 0, -1U, &have);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_should_check_xref(sc, &error, &sc->sa.cnt_cur))
|
2018-01-17 02:53:07 +00:00
|
|
|
return;
|
|
|
|
if (!have) {
|
2019-02-25 17:36:36 +00:00
|
|
|
if (agf->agf_freeblks != cpu_to_be32(0))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_xref_set_corrupt(sc, sc->sa.agf_bp);
|
2018-01-17 02:53:07 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check agf_longest */
|
|
|
|
error = xfs_alloc_get_rec(sc->sa.cnt_cur, &agbno, &blocks, &have);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_should_check_xref(sc, &error, &sc->sa.cnt_cur))
|
2018-01-17 02:53:07 +00:00
|
|
|
return;
|
|
|
|
if (!have || blocks != be32_to_cpu(agf->agf_longest))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_xref_set_corrupt(sc, sc->sa.agf_bp);
|
2018-01-17 02:53:07 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 02:53:08 +00:00
|
|
|
/* Check the btree block counts in the AGF against the btrees. */
|
|
|
|
STATIC void
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf_xref_btreeblks(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2018-01-17 02:53:08 +00:00
|
|
|
{
|
2020-03-10 15:57:29 +00:00
|
|
|
struct xfs_agf *agf = sc->sa.agf_bp->b_addr;
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
xfs_agblock_t blocks;
|
|
|
|
xfs_agblock_t btreeblks;
|
|
|
|
int error;
|
2018-01-17 02:53:08 +00:00
|
|
|
|
2021-04-23 23:02:01 +00:00
|
|
|
/* agf_btreeblks didn't exist before lazysbcount */
|
2021-08-19 01:46:55 +00:00
|
|
|
if (!xfs_has_lazysbcount(sc->mp))
|
2021-04-23 23:02:01 +00:00
|
|
|
return;
|
|
|
|
|
2018-01-17 02:53:08 +00:00
|
|
|
/* Check agf_rmap_blocks; set up for agf_btreeblks check */
|
|
|
|
if (sc->sa.rmap_cur) {
|
|
|
|
error = xfs_btree_count_blocks(sc->sa.rmap_cur, &blocks);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_should_check_xref(sc, &error, &sc->sa.rmap_cur))
|
2018-01-17 02:53:08 +00:00
|
|
|
return;
|
|
|
|
btreeblks = blocks - 1;
|
|
|
|
if (blocks != be32_to_cpu(agf->agf_rmap_blocks))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_xref_set_corrupt(sc, sc->sa.agf_bp);
|
2018-01-17 02:53:08 +00:00
|
|
|
} else {
|
|
|
|
btreeblks = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No rmap cursor; we can't xref if we have the rmapbt feature.
|
|
|
|
* We also can't do it if we're missing the free space btree cursors.
|
|
|
|
*/
|
2021-08-19 01:46:37 +00:00
|
|
|
if ((xfs_has_rmapbt(mp) && !sc->sa.rmap_cur) ||
|
2018-01-17 02:53:08 +00:00
|
|
|
!sc->sa.bno_cur || !sc->sa.cnt_cur)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Check agf_btreeblks */
|
|
|
|
error = xfs_btree_count_blocks(sc->sa.bno_cur, &blocks);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_should_check_xref(sc, &error, &sc->sa.bno_cur))
|
2018-01-17 02:53:08 +00:00
|
|
|
return;
|
|
|
|
btreeblks += blocks - 1;
|
|
|
|
|
|
|
|
error = xfs_btree_count_blocks(sc->sa.cnt_cur, &blocks);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_should_check_xref(sc, &error, &sc->sa.cnt_cur))
|
2018-01-17 02:53:08 +00:00
|
|
|
return;
|
|
|
|
btreeblks += blocks - 1;
|
|
|
|
|
|
|
|
if (btreeblks != be32_to_cpu(agf->agf_btreeblks))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_xref_set_corrupt(sc, sc->sa.agf_bp);
|
2018-01-17 02:53:08 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 02:53:09 +00:00
|
|
|
/* Check agf_refcount_blocks against tree size */
|
|
|
|
static inline void
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf_xref_refcblks(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2018-01-17 02:53:09 +00:00
|
|
|
{
|
2020-03-10 15:57:29 +00:00
|
|
|
struct xfs_agf *agf = sc->sa.agf_bp->b_addr;
|
2018-07-19 19:29:12 +00:00
|
|
|
xfs_agblock_t blocks;
|
|
|
|
int error;
|
2018-01-17 02:53:09 +00:00
|
|
|
|
|
|
|
if (!sc->sa.refc_cur)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error = xfs_btree_count_blocks(sc->sa.refc_cur, &blocks);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_should_check_xref(sc, &error, &sc->sa.refc_cur))
|
2018-01-17 02:53:09 +00:00
|
|
|
return;
|
|
|
|
if (blocks != be32_to_cpu(agf->agf_refcount_blocks))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_xref_set_corrupt(sc, sc->sa.agf_bp);
|
2018-01-17 02:53:09 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 02:53:05 +00:00
|
|
|
/* Cross-reference with the other btrees. */
|
|
|
|
STATIC void
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf_xref(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2018-01-17 02:53:05 +00:00
|
|
|
{
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
xfs_agblock_t agbno;
|
2018-01-17 02:53:06 +00:00
|
|
|
|
2018-01-17 02:53:05 +00:00
|
|
|
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
|
|
|
return;
|
2018-01-17 02:53:06 +00:00
|
|
|
|
|
|
|
agbno = XFS_AGF_BLOCK(mp);
|
|
|
|
|
2021-03-22 16:51:53 +00:00
|
|
|
xchk_ag_btcur_init(sc, &sc->sa);
|
2018-01-17 02:53:06 +00:00
|
|
|
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_xref_is_used_space(sc, agbno, 1);
|
|
|
|
xchk_agf_xref_freeblks(sc);
|
|
|
|
xchk_agf_xref_cntbt(sc);
|
|
|
|
xchk_xref_is_not_inode_chunk(sc, agbno, 1);
|
2023-04-12 02:00:15 +00:00
|
|
|
xchk_xref_is_only_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf_xref_btreeblks(sc);
|
|
|
|
xchk_xref_is_not_shared(sc, agbno, 1);
|
2023-04-12 02:00:12 +00:00
|
|
|
xchk_xref_is_not_cow_staging(sc, agbno, 1);
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf_xref_refcblks(sc);
|
2018-01-17 02:53:06 +00:00
|
|
|
|
|
|
|
/* scrub teardown will take care of sc->sa for us */
|
2018-01-17 02:53:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-18 04:37:39 +00:00
|
|
|
/* Scrub the AGF. */
|
|
|
|
int
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2017-10-18 04:37:39 +00:00
|
|
|
{
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
struct xfs_agf *agf;
|
2019-04-26 01:26:23 +00:00
|
|
|
struct xfs_perag *pag;
|
2021-03-22 16:51:53 +00:00
|
|
|
xfs_agnumber_t agno = sc->sm->sm_agno;
|
2018-07-19 19:29:12 +00:00
|
|
|
xfs_agblock_t agbno;
|
|
|
|
xfs_agblock_t eoag;
|
|
|
|
xfs_agblock_t agfl_first;
|
|
|
|
xfs_agblock_t agfl_last;
|
|
|
|
xfs_agblock_t agfl_count;
|
|
|
|
xfs_agblock_t fl_count;
|
|
|
|
int level;
|
|
|
|
int error = 0;
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2021-03-22 16:51:53 +00:00
|
|
|
error = xchk_ag_read_headers(sc, agno, &sc->sa);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_process_error(sc, agno, XFS_AGF_BLOCK(sc->mp), &error))
|
2017-10-18 04:37:39 +00:00
|
|
|
goto out;
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_buffer_recheck(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2020-03-10 15:57:29 +00:00
|
|
|
agf = sc->sa.agf_bp->b_addr;
|
2021-08-06 18:06:35 +00:00
|
|
|
pag = sc->sa.pag;
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
/* Check the AG length */
|
|
|
|
eoag = be32_to_cpu(agf->agf_length);
|
2022-07-07 09:13:02 +00:00
|
|
|
if (eoag != pag->block_count)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
/* Check the AGF btree roots and levels */
|
|
|
|
agbno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_BNO]);
|
2022-07-07 09:13:02 +00:00
|
|
|
if (!xfs_verify_agbno(pag, agbno))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
agbno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_CNT]);
|
2022-07-07 09:13:02 +00:00
|
|
|
if (!xfs_verify_agbno(pag, agbno))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
level = be32_to_cpu(agf->agf_levels[XFS_BTNUM_BNO]);
|
2021-10-13 17:02:19 +00:00
|
|
|
if (level <= 0 || level > mp->m_alloc_maxlevels)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
level = be32_to_cpu(agf->agf_levels[XFS_BTNUM_CNT]);
|
2021-10-13 17:02:19 +00:00
|
|
|
if (level <= 0 || level > mp->m_alloc_maxlevels)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2021-08-19 01:46:37 +00:00
|
|
|
if (xfs_has_rmapbt(mp)) {
|
2017-10-18 04:37:39 +00:00
|
|
|
agbno = be32_to_cpu(agf->agf_roots[XFS_BTNUM_RMAP]);
|
2022-07-07 09:13:02 +00:00
|
|
|
if (!xfs_verify_agbno(pag, agbno))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
level = be32_to_cpu(agf->agf_levels[XFS_BTNUM_RMAP]);
|
2021-09-16 19:21:56 +00:00
|
|
|
if (level <= 0 || level > mp->m_rmap_maxlevels)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-19 01:46:37 +00:00
|
|
|
if (xfs_has_reflink(mp)) {
|
2017-10-18 04:37:39 +00:00
|
|
|
agbno = be32_to_cpu(agf->agf_refcount_root);
|
2022-07-07 09:13:02 +00:00
|
|
|
if (!xfs_verify_agbno(pag, agbno))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
level = be32_to_cpu(agf->agf_refcount_level);
|
2021-09-16 19:21:56 +00:00
|
|
|
if (level <= 0 || level > mp->m_refc_maxlevels)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check the AGFL counters */
|
|
|
|
agfl_first = be32_to_cpu(agf->agf_flfirst);
|
|
|
|
agfl_last = be32_to_cpu(agf->agf_fllast);
|
|
|
|
agfl_count = be32_to_cpu(agf->agf_flcount);
|
|
|
|
if (agfl_last > agfl_first)
|
|
|
|
fl_count = agfl_last - agfl_first + 1;
|
|
|
|
else
|
2018-03-07 01:08:32 +00:00
|
|
|
fl_count = xfs_agfl_size(mp) - agfl_first + agfl_last + 1;
|
2017-10-18 04:37:39 +00:00
|
|
|
if (agfl_count != 0 && fl_count != agfl_count)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2019-04-26 01:26:23 +00:00
|
|
|
/* Do the incore counters match? */
|
|
|
|
if (pag->pagf_freeblks != be32_to_cpu(agf->agf_freeblks))
|
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
|
|
|
if (pag->pagf_flcount != be32_to_cpu(agf->agf_flcount))
|
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2021-08-19 01:46:55 +00:00
|
|
|
if (xfs_has_lazysbcount(sc->mp) &&
|
2021-04-23 23:02:01 +00:00
|
|
|
pag->pagf_btreeblks != be32_to_cpu(agf->agf_btreeblks))
|
2019-04-26 01:26:23 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
|
|
|
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agf_xref(sc);
|
2017-10-18 04:37:39 +00:00
|
|
|
out:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AGFL */
|
|
|
|
|
2018-07-19 19:29:11 +00:00
|
|
|
struct xchk_agfl_info {
|
2022-11-07 01:03:14 +00:00
|
|
|
/* Number of AGFL entries that the AGF claims are in use. */
|
|
|
|
unsigned int agflcount;
|
|
|
|
|
|
|
|
/* Number of AGFL entries that we found. */
|
2018-07-19 19:29:12 +00:00
|
|
|
unsigned int nr_entries;
|
2022-11-07 01:03:14 +00:00
|
|
|
|
|
|
|
/* Buffer to hold AGFL entries for extent checking. */
|
2018-07-19 19:29:12 +00:00
|
|
|
xfs_agblock_t *entries;
|
2022-11-07 01:03:14 +00:00
|
|
|
|
|
|
|
struct xfs_buf *agfl_bp;
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc;
|
2017-11-02 22:58:36 +00:00
|
|
|
};
|
|
|
|
|
2018-01-17 02:53:05 +00:00
|
|
|
/* Cross-reference with the other btrees. */
|
|
|
|
STATIC void
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agfl_block_xref(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc,
|
2018-12-12 16:46:23 +00:00
|
|
|
xfs_agblock_t agbno)
|
2018-01-17 02:53:05 +00:00
|
|
|
{
|
|
|
|
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
|
|
|
return;
|
2018-01-17 02:53:06 +00:00
|
|
|
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_xref_is_used_space(sc, agbno, 1);
|
|
|
|
xchk_xref_is_not_inode_chunk(sc, agbno, 1);
|
2023-04-12 02:00:15 +00:00
|
|
|
xchk_xref_is_only_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_AG);
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_xref_is_not_shared(sc, agbno, 1);
|
2023-04-12 02:00:12 +00:00
|
|
|
xchk_xref_is_not_cow_staging(sc, agbno, 1);
|
2018-01-17 02:53:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-18 04:37:39 +00:00
|
|
|
/* Scrub an AGFL block. */
|
|
|
|
STATIC int
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agfl_block(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_mount *mp,
|
|
|
|
xfs_agblock_t agbno,
|
|
|
|
void *priv)
|
2017-10-18 04:37:39 +00:00
|
|
|
{
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xchk_agfl_info *sai = priv;
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc = sai->sc;
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2022-07-07 09:13:02 +00:00
|
|
|
if (xfs_verify_agbno(sc->sa.pag, agbno) &&
|
2022-11-07 01:03:14 +00:00
|
|
|
sai->nr_entries < sai->agflcount)
|
2017-11-02 22:58:36 +00:00
|
|
|
sai->entries[sai->nr_entries++] = agbno;
|
|
|
|
else
|
2022-11-07 01:03:14 +00:00
|
|
|
xchk_block_set_corrupt(sc, sai->agfl_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2018-12-12 16:46:23 +00:00
|
|
|
xchk_agfl_block_xref(sc, agbno);
|
2018-01-17 02:53:05 +00:00
|
|
|
|
2018-05-14 13:34:34 +00:00
|
|
|
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
2019-08-28 21:37:57 +00:00
|
|
|
return -ECANCELED;
|
2018-05-14 13:34:34 +00:00
|
|
|
|
2017-10-18 04:37:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-02 22:58:36 +00:00
|
|
|
static int
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agblock_cmp(
|
2017-11-02 22:58:36 +00:00
|
|
|
const void *pa,
|
|
|
|
const void *pb)
|
|
|
|
{
|
|
|
|
const xfs_agblock_t *a = pa;
|
|
|
|
const xfs_agblock_t *b = pb;
|
|
|
|
|
|
|
|
return (int)*a - (int)*b;
|
|
|
|
}
|
|
|
|
|
2018-01-17 02:53:05 +00:00
|
|
|
/* Cross-reference with the other btrees. */
|
|
|
|
STATIC void
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agfl_xref(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2018-01-17 02:53:05 +00:00
|
|
|
{
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
xfs_agblock_t agbno;
|
2018-01-17 02:53:06 +00:00
|
|
|
|
2018-01-17 02:53:05 +00:00
|
|
|
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
|
|
|
return;
|
2018-01-17 02:53:06 +00:00
|
|
|
|
|
|
|
agbno = XFS_AGFL_BLOCK(mp);
|
|
|
|
|
2021-03-22 16:51:53 +00:00
|
|
|
xchk_ag_btcur_init(sc, &sc->sa);
|
2018-01-17 02:53:06 +00:00
|
|
|
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_xref_is_used_space(sc, agbno, 1);
|
|
|
|
xchk_xref_is_not_inode_chunk(sc, agbno, 1);
|
2023-04-12 02:00:15 +00:00
|
|
|
xchk_xref_is_only_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_xref_is_not_shared(sc, agbno, 1);
|
2023-04-12 02:00:12 +00:00
|
|
|
xchk_xref_is_not_cow_staging(sc, agbno, 1);
|
2018-01-17 02:53:06 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scrub teardown will take care of sc->sa for us. Leave sc->sa
|
|
|
|
* active so that the agfl block xref can use it too.
|
|
|
|
*/
|
2018-01-17 02:53:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-18 04:37:39 +00:00
|
|
|
/* Scrub the AGFL. */
|
|
|
|
int
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agfl(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2017-10-18 04:37:39 +00:00
|
|
|
{
|
2022-11-07 01:03:14 +00:00
|
|
|
struct xchk_agfl_info sai = {
|
|
|
|
.sc = sc,
|
|
|
|
};
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_agf *agf;
|
2021-03-22 16:51:53 +00:00
|
|
|
xfs_agnumber_t agno = sc->sm->sm_agno;
|
2018-07-19 19:29:12 +00:00
|
|
|
unsigned int i;
|
|
|
|
int error;
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2022-11-07 01:03:14 +00:00
|
|
|
/* Lock the AGF and AGI so that nobody can touch this AG. */
|
2021-03-22 16:51:53 +00:00
|
|
|
error = xchk_ag_read_headers(sc, agno, &sc->sa);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_process_error(sc, agno, XFS_AGFL_BLOCK(sc->mp), &error))
|
2022-11-07 01:03:14 +00:00
|
|
|
return error;
|
2017-10-18 04:37:39 +00:00
|
|
|
if (!sc->sa.agf_bp)
|
|
|
|
return -EFSCORRUPTED;
|
2022-11-07 01:03:14 +00:00
|
|
|
|
|
|
|
/* Try to read the AGFL, and verify its structure if we get it. */
|
|
|
|
error = xfs_alloc_read_agfl(sc->sa.pag, sc->tp, &sai.agfl_bp);
|
|
|
|
if (!xchk_process_error(sc, agno, XFS_AGFL_BLOCK(sc->mp), &error))
|
|
|
|
return error;
|
|
|
|
xchk_buffer_recheck(sc, sai.agfl_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agfl_xref(sc);
|
2018-01-17 02:53:05 +00:00
|
|
|
|
|
|
|
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
|
|
|
goto out;
|
|
|
|
|
2017-11-02 22:58:36 +00:00
|
|
|
/* Allocate buffer to ensure uniqueness of AGFL entries. */
|
2020-03-10 15:57:29 +00:00
|
|
|
agf = sc->sa.agf_bp->b_addr;
|
2022-11-07 01:03:14 +00:00
|
|
|
sai.agflcount = be32_to_cpu(agf->agf_flcount);
|
|
|
|
if (sai.agflcount > xfs_agfl_size(sc->mp)) {
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-11-02 22:58:36 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2022-11-07 01:03:14 +00:00
|
|
|
sai.entries = kvcalloc(sai.agflcount, sizeof(xfs_agblock_t),
|
2022-11-07 01:03:15 +00:00
|
|
|
XCHK_GFP_FLAGS);
|
2017-11-02 22:58:36 +00:00
|
|
|
if (!sai.entries) {
|
|
|
|
error = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-10-18 04:37:39 +00:00
|
|
|
/* Check the blocks in the AGFL. */
|
2022-11-07 01:03:14 +00:00
|
|
|
error = xfs_agfl_walk(sc->mp, sc->sa.agf_bp->b_addr, sai.agfl_bp,
|
|
|
|
xchk_agfl_block, &sai);
|
2019-08-28 21:37:57 +00:00
|
|
|
if (error == -ECANCELED) {
|
2018-05-14 13:34:34 +00:00
|
|
|
error = 0;
|
|
|
|
goto out_free;
|
|
|
|
}
|
2017-11-02 22:58:36 +00:00
|
|
|
if (error)
|
|
|
|
goto out_free;
|
|
|
|
|
2022-11-07 01:03:14 +00:00
|
|
|
if (sai.agflcount != sai.nr_entries) {
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-11-02 22:58:36 +00:00
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort entries, check for duplicates. */
|
|
|
|
sort(sai.entries, sai.nr_entries, sizeof(sai.entries[0]),
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agblock_cmp, NULL);
|
2017-11-02 22:58:36 +00:00
|
|
|
for (i = 1; i < sai.nr_entries; i++) {
|
|
|
|
if (sai.entries[i] == sai.entries[i - 1]) {
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agf_bp);
|
2017-11-02 22:58:36 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out_free:
|
2022-11-07 01:03:14 +00:00
|
|
|
kvfree(sai.entries);
|
2017-10-18 04:37:39 +00:00
|
|
|
out:
|
|
|
|
return error;
|
|
|
|
}
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
/* AGI */
|
|
|
|
|
2018-01-17 02:53:07 +00:00
|
|
|
/* Check agi_count/agi_freecount */
|
|
|
|
static inline void
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agi_xref_icounts(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2018-01-17 02:53:07 +00:00
|
|
|
{
|
2020-03-10 15:57:29 +00:00
|
|
|
struct xfs_agi *agi = sc->sa.agi_bp->b_addr;
|
2018-07-19 19:29:12 +00:00
|
|
|
xfs_agino_t icount;
|
|
|
|
xfs_agino_t freecount;
|
|
|
|
int error;
|
2018-01-17 02:53:07 +00:00
|
|
|
|
|
|
|
if (!sc->sa.ino_cur)
|
|
|
|
return;
|
|
|
|
|
|
|
|
error = xfs_ialloc_count_inodes(sc->sa.ino_cur, &icount, &freecount);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_should_check_xref(sc, &error, &sc->sa.ino_cur))
|
2018-01-17 02:53:07 +00:00
|
|
|
return;
|
|
|
|
if (be32_to_cpu(agi->agi_count) != icount ||
|
|
|
|
be32_to_cpu(agi->agi_freecount) != freecount)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_xref_set_corrupt(sc, sc->sa.agi_bp);
|
2018-01-17 02:53:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-26 17:48:50 +00:00
|
|
|
/* Check agi_[fi]blocks against tree size */
|
|
|
|
static inline void
|
|
|
|
xchk_agi_xref_fiblocks(
|
|
|
|
struct xfs_scrub *sc)
|
|
|
|
{
|
|
|
|
struct xfs_agi *agi = sc->sa.agi_bp->b_addr;
|
|
|
|
xfs_agblock_t blocks;
|
|
|
|
int error = 0;
|
|
|
|
|
2021-08-19 01:46:55 +00:00
|
|
|
if (!xfs_has_inobtcounts(sc->mp))
|
2020-08-26 17:48:50 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (sc->sa.ino_cur) {
|
|
|
|
error = xfs_btree_count_blocks(sc->sa.ino_cur, &blocks);
|
|
|
|
if (!xchk_should_check_xref(sc, &error, &sc->sa.ino_cur))
|
|
|
|
return;
|
|
|
|
if (blocks != be32_to_cpu(agi->agi_iblocks))
|
|
|
|
xchk_block_xref_set_corrupt(sc, sc->sa.agi_bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc->sa.fino_cur) {
|
|
|
|
error = xfs_btree_count_blocks(sc->sa.fino_cur, &blocks);
|
|
|
|
if (!xchk_should_check_xref(sc, &error, &sc->sa.fino_cur))
|
|
|
|
return;
|
|
|
|
if (blocks != be32_to_cpu(agi->agi_fblocks))
|
|
|
|
xchk_block_xref_set_corrupt(sc, sc->sa.agi_bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 02:53:05 +00:00
|
|
|
/* Cross-reference with the other btrees. */
|
|
|
|
STATIC void
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agi_xref(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2018-01-17 02:53:05 +00:00
|
|
|
{
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
xfs_agblock_t agbno;
|
2018-01-17 02:53:06 +00:00
|
|
|
|
2018-01-17 02:53:05 +00:00
|
|
|
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
|
|
|
return;
|
2018-01-17 02:53:06 +00:00
|
|
|
|
|
|
|
agbno = XFS_AGI_BLOCK(mp);
|
|
|
|
|
2021-03-22 16:51:53 +00:00
|
|
|
xchk_ag_btcur_init(sc, &sc->sa);
|
2018-01-17 02:53:06 +00:00
|
|
|
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_xref_is_used_space(sc, agbno, 1);
|
|
|
|
xchk_xref_is_not_inode_chunk(sc, agbno, 1);
|
|
|
|
xchk_agi_xref_icounts(sc);
|
2023-04-12 02:00:15 +00:00
|
|
|
xchk_xref_is_only_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_FS);
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_xref_is_not_shared(sc, agbno, 1);
|
2023-04-12 02:00:12 +00:00
|
|
|
xchk_xref_is_not_cow_staging(sc, agbno, 1);
|
2020-08-26 17:48:50 +00:00
|
|
|
xchk_agi_xref_fiblocks(sc);
|
2018-01-17 02:53:06 +00:00
|
|
|
|
|
|
|
/* scrub teardown will take care of sc->sa for us */
|
2018-01-17 02:53:05 +00:00
|
|
|
}
|
|
|
|
|
2017-10-18 04:37:39 +00:00
|
|
|
/* Scrub the AGI. */
|
|
|
|
int
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agi(
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_scrub *sc)
|
2017-10-18 04:37:39 +00:00
|
|
|
{
|
2018-07-19 19:29:12 +00:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
struct xfs_agi *agi;
|
2019-04-26 01:26:23 +00:00
|
|
|
struct xfs_perag *pag;
|
2021-09-16 19:21:56 +00:00
|
|
|
struct xfs_ino_geometry *igeo = M_IGEO(sc->mp);
|
2021-03-22 16:51:53 +00:00
|
|
|
xfs_agnumber_t agno = sc->sm->sm_agno;
|
2018-07-19 19:29:12 +00:00
|
|
|
xfs_agblock_t agbno;
|
|
|
|
xfs_agblock_t eoag;
|
|
|
|
xfs_agino_t agino;
|
|
|
|
xfs_agino_t first_agino;
|
|
|
|
xfs_agino_t last_agino;
|
|
|
|
xfs_agino_t icount;
|
|
|
|
int i;
|
|
|
|
int level;
|
|
|
|
int error = 0;
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2021-03-22 16:51:53 +00:00
|
|
|
error = xchk_ag_read_headers(sc, agno, &sc->sa);
|
2018-07-19 19:29:11 +00:00
|
|
|
if (!xchk_process_error(sc, agno, XFS_AGI_BLOCK(sc->mp), &error))
|
2017-10-18 04:37:39 +00:00
|
|
|
goto out;
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_buffer_recheck(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2020-03-10 15:57:29 +00:00
|
|
|
agi = sc->sa.agi_bp->b_addr;
|
2021-08-06 18:06:35 +00:00
|
|
|
pag = sc->sa.pag;
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
/* Check the AG length */
|
|
|
|
eoag = be32_to_cpu(agi->agi_length);
|
2022-07-07 09:13:02 +00:00
|
|
|
if (eoag != pag->block_count)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
/* Check btree roots and levels */
|
|
|
|
agbno = be32_to_cpu(agi->agi_root);
|
2022-07-07 09:13:02 +00:00
|
|
|
if (!xfs_verify_agbno(pag, agbno))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
level = be32_to_cpu(agi->agi_level);
|
2021-09-16 19:21:56 +00:00
|
|
|
if (level <= 0 || level > igeo->inobt_maxlevels)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2021-08-19 01:46:37 +00:00
|
|
|
if (xfs_has_finobt(mp)) {
|
2017-10-18 04:37:39 +00:00
|
|
|
agbno = be32_to_cpu(agi->agi_free_root);
|
2022-07-07 09:13:02 +00:00
|
|
|
if (!xfs_verify_agbno(pag, agbno))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
level = be32_to_cpu(agi->agi_free_level);
|
2021-09-16 19:21:56 +00:00
|
|
|
if (level <= 0 || level > igeo->inobt_maxlevels)
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check inode counters */
|
2018-06-07 14:53:33 +00:00
|
|
|
xfs_agino_range(mp, agno, &first_agino, &last_agino);
|
2017-10-18 04:37:39 +00:00
|
|
|
icount = be32_to_cpu(agi->agi_count);
|
|
|
|
if (icount > last_agino - first_agino + 1 ||
|
|
|
|
icount < be32_to_cpu(agi->agi_freecount))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
/* Check inode pointers */
|
|
|
|
agino = be32_to_cpu(agi->agi_newino);
|
2022-07-07 09:13:10 +00:00
|
|
|
if (!xfs_verify_agino_or_null(pag, agino))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
agino = be32_to_cpu(agi->agi_dirino);
|
2022-07-07 09:13:10 +00:00
|
|
|
if (!xfs_verify_agino_or_null(pag, agino))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
|
|
|
/* Check unlinked inode buckets */
|
|
|
|
for (i = 0; i < XFS_AGI_UNLINKED_BUCKETS; i++) {
|
|
|
|
agino = be32_to_cpu(agi->agi_unlinked[i]);
|
2022-07-07 09:13:10 +00:00
|
|
|
if (!xfs_verify_agino_or_null(pag, agino))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (agi->agi_pad32 != cpu_to_be32(0))
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
2017-10-18 04:37:39 +00:00
|
|
|
|
2019-04-26 01:26:23 +00:00
|
|
|
/* Do the incore counters match? */
|
|
|
|
if (pag->pagi_count != be32_to_cpu(agi->agi_count))
|
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
|
|
|
if (pag->pagi_freecount != be32_to_cpu(agi->agi_freecount))
|
|
|
|
xchk_block_set_corrupt(sc, sc->sa.agi_bp);
|
|
|
|
|
2018-07-19 19:29:11 +00:00
|
|
|
xchk_agi_xref(sc);
|
2017-10-18 04:37:39 +00:00
|
|
|
out:
|
|
|
|
return error;
|
|
|
|
}
|