^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 2017 Oracle. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author: Darrick J. Wong <darrick.wong@oracle.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "xfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include "xfs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "xfs_shared.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "xfs_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "xfs_trans_resv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "xfs_mount.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "xfs_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "xfs_log_format.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "xfs_trans.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "xfs_sb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "xfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "xfs_icache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include "xfs_alloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "xfs_alloc_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "xfs_ialloc.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include "xfs_ialloc_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "xfs_refcount_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include "xfs_rmap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include "xfs_rmap_btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include "xfs_log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include "xfs_trans_priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include "xfs_attr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include "xfs_reflink.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "scrub/scrub.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "scrub/common.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "scrub/trace.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "scrub/repair.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "scrub/health.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* Common code for the metadata scrubbers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * Handling operational errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * The *_process_error() family of functions are used to process error return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * codes from functions called as part of a scrub operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * If there's no error, we return true to tell the caller that it's ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * to move on to the next check in its list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * For non-verifier errors (e.g. ENOMEM) we return false to tell the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * caller that something bad happened, and we preserve *error so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * the caller can return the *error up the stack to userspace.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * Verifier errors (EFSBADCRC/EFSCORRUPTED) are recorded by setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * OFLAG_CORRUPT in sm_flags and the *error is cleared. In other words,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * we track verifier errors (and failed scrub checks) via OFLAG_CORRUPT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * not via return codes. We return false to tell the caller that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * something bad happened. Since the error has been cleared, the caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * will (presumably) return that zero and scrubbing will move on to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * whatever's next.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * ftrace can be used to record the precise metadata location and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * approximate code location of the failed operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* Check for operational errors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) __xchk_process_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) xfs_agnumber_t agno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) xfs_agblock_t bno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int *error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) __u32 errflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) void *ret_ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) switch (*error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) case -EDEADLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* Used to restart an op with deadlock avoidance. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) trace_xchk_deadlock_retry(sc->ip, sc->sm, *error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) case -EFSBADCRC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) case -EFSCORRUPTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* Note the badness but don't abort. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) sc->sm->sm_flags |= errflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) *error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /* fall through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) trace_xchk_op_error(sc, agno, bno, *error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) ret_ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) xchk_process_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) xfs_agnumber_t agno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) xfs_agblock_t bno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int *error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return __xchk_process_error(sc, agno, bno, error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) XFS_SCRUB_OFLAG_CORRUPT, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) xchk_xref_process_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) xfs_agnumber_t agno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) xfs_agblock_t bno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int *error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return __xchk_process_error(sc, agno, bno, error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) XFS_SCRUB_OFLAG_XFAIL, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* Check for operational errors for a file offset. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) __xchk_fblock_process_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int whichfork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) xfs_fileoff_t offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int *error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) __u32 errflag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) void *ret_ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) switch (*error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) case -EDEADLOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /* Used to restart an op with deadlock avoidance. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) trace_xchk_deadlock_retry(sc->ip, sc->sm, *error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) case -EFSBADCRC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) case -EFSCORRUPTED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Note the badness but don't abort. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) sc->sm->sm_flags |= errflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) *error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* fall through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) trace_xchk_file_op_error(sc, whichfork, offset, *error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) ret_ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) xchk_fblock_process_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int whichfork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) xfs_fileoff_t offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int *error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return __xchk_fblock_process_error(sc, whichfork, offset, error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) XFS_SCRUB_OFLAG_CORRUPT, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) xchk_fblock_xref_process_error(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int whichfork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) xfs_fileoff_t offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) int *error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) return __xchk_fblock_process_error(sc, whichfork, offset, error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) XFS_SCRUB_OFLAG_XFAIL, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * Handling scrub corruption/optimization/warning checks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * The *_set_{corrupt,preen,warning}() family of functions are used to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * record the presence of metadata that is incorrect (corrupt), could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * optimized somehow (preen), or should be flagged for administrative
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * review but is not incorrect (warn).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * ftrace can be used to record the precise metadata location and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * approximate code location of the failed check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* Record a block which could be optimized. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) xchk_block_set_preen(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct xfs_buf *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_PREEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) trace_xchk_block_preen(sc, bp->b_bn, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * Record an inode which could be optimized. The trace data will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * include the block given by bp if bp is given; otherwise it will use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * the block location of the inode record itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) xchk_ino_set_preen(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) xfs_ino_t ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_PREEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) trace_xchk_ino_preen(sc, ino, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* Record something being wrong with the filesystem primary superblock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) xchk_set_corrupt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct xfs_scrub *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) trace_xchk_fs_error(sc, 0, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* Record a corrupt block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) xchk_block_set_corrupt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct xfs_buf *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) trace_xchk_block_error(sc, bp->b_bn, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Record a corruption while cross-referencing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) xchk_block_xref_set_corrupt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct xfs_buf *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) trace_xchk_block_error(sc, bp->b_bn, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Record a corrupt inode. The trace data will include the block given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * by bp if bp is given; otherwise it will use the block location of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * inode record itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) xchk_ino_set_corrupt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) xfs_ino_t ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) trace_xchk_ino_error(sc, ino, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* Record a corruption while cross-referencing with an inode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) xchk_ino_xref_set_corrupt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) xfs_ino_t ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) trace_xchk_ino_error(sc, ino, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /* Record corruption in a block indexed by a file fork. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) xchk_fblock_set_corrupt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) int whichfork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) xfs_fileoff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) trace_xchk_fblock_error(sc, whichfork, offset, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* Record a corruption while cross-referencing a fork block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) xchk_fblock_xref_set_corrupt(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int whichfork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) xfs_fileoff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) trace_xchk_fblock_error(sc, whichfork, offset, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * Warn about inodes that need administrative review but is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * incorrect.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) xchk_ino_set_warning(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) xfs_ino_t ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_WARNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) trace_xchk_ino_warning(sc, ino, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* Warn about a block indexed by a file fork that needs review. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) xchk_fblock_set_warning(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int whichfork,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) xfs_fileoff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_WARNING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) trace_xchk_fblock_warning(sc, whichfork, offset, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /* Signal an incomplete scrub. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) xchk_set_incomplete(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct xfs_scrub *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_INCOMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) trace_xchk_incomplete(sc, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * rmap scrubbing -- compute the number of blocks with a given owner,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * at least according to the reverse mapping data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) struct xchk_rmap_ownedby_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) const struct xfs_owner_info *oinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) xfs_filblks_t *blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) STATIC int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) xchk_count_rmap_ownedby_irec(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) struct xfs_btree_cur *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) struct xfs_rmap_irec *rec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) void *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) struct xchk_rmap_ownedby_info *sroi = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) bool irec_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) bool oinfo_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) irec_attr = rec->rm_flags & XFS_RMAP_ATTR_FORK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) oinfo_attr = sroi->oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) if (rec->rm_owner != sroi->oinfo->oi_owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) || irec_attr == oinfo_attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) (*sroi->blocks) += rec->rm_blockcount;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * Calculate the number of blocks the rmap thinks are owned by something.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * The caller should pass us an rmapbt cursor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) xchk_count_rmap_ownedby_ag(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct xfs_btree_cur *cur,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) const struct xfs_owner_info *oinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) xfs_filblks_t *blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct xchk_rmap_ownedby_info sroi = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) .oinfo = oinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) .blocks = blocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) *blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return xfs_rmap_query_all(cur, xchk_count_rmap_ownedby_irec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) &sroi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * AG scrubbing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) * These helpers facilitate locking an allocation group's header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * buffers, setting up cursors for all btrees that are present, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * cleaning everything up once we're through.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /* Decide if we want to return an AG header read failure. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) want_ag_read_header_failure(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) unsigned int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /* Return all AG header read failures when scanning btrees. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (sc->sm->sm_type != XFS_SCRUB_TYPE_AGF &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) sc->sm->sm_type != XFS_SCRUB_TYPE_AGFL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) sc->sm->sm_type != XFS_SCRUB_TYPE_AGI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) * If we're scanning a given type of AG header, we only want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) * see read failures from that specific header. We'd like the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) * other headers to cross-check them, but this isn't required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (sc->sm->sm_type == type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) * Grab all the headers for an AG.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) * The headers should be released by xchk_ag_free, but as a fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * safe we attach all the buffers we grab to the scrub transaction so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) * they'll all be freed when we cancel it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) xchk_ag_read_headers(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) xfs_agnumber_t agno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct xfs_buf **agi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) struct xfs_buf **agf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct xfs_buf **agfl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct xfs_mount *mp = sc->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) error = xfs_ialloc_read_agi(mp, sc->tp, agno, agi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGI))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, agf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGF))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) error = xfs_alloc_read_agfl(mp, sc->tp, agno, agfl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGFL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) /* Release all the AG btree cursors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) xchk_ag_btcur_free(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) struct xchk_ag *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (sa->refc_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) xfs_btree_del_cursor(sa->refc_cur, XFS_BTREE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (sa->rmap_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) xfs_btree_del_cursor(sa->rmap_cur, XFS_BTREE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (sa->fino_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) xfs_btree_del_cursor(sa->fino_cur, XFS_BTREE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (sa->ino_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) xfs_btree_del_cursor(sa->ino_cur, XFS_BTREE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (sa->cnt_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) xfs_btree_del_cursor(sa->cnt_cur, XFS_BTREE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (sa->bno_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) xfs_btree_del_cursor(sa->bno_cur, XFS_BTREE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) sa->refc_cur = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) sa->rmap_cur = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) sa->fino_cur = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) sa->ino_cur = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) sa->bno_cur = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) sa->cnt_cur = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /* Initialize all the btree cursors for an AG. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) xchk_ag_btcur_init(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) struct xchk_ag *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) struct xfs_mount *mp = sc->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) xfs_agnumber_t agno = sa->agno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) xchk_perag_get(sc->mp, sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (sa->agf_bp &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_BNO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /* Set up a bnobt cursor for cross-referencing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) sa->bno_cur = xfs_allocbt_init_cursor(mp, sc->tp, sa->agf_bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) agno, XFS_BTNUM_BNO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) if (!sa->bno_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) if (sa->agf_bp &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_CNT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) /* Set up a cntbt cursor for cross-referencing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) sa->cnt_cur = xfs_allocbt_init_cursor(mp, sc->tp, sa->agf_bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) agno, XFS_BTNUM_CNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (!sa->cnt_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /* Set up a inobt cursor for cross-referencing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (sa->agi_bp &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_INO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) sa->ino_cur = xfs_inobt_init_cursor(mp, sc->tp, sa->agi_bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) agno, XFS_BTNUM_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (!sa->ino_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) /* Set up a finobt cursor for cross-referencing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (sa->agi_bp && xfs_sb_version_hasfinobt(&mp->m_sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_FINO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) sa->fino_cur = xfs_inobt_init_cursor(mp, sc->tp, sa->agi_bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) agno, XFS_BTNUM_FINO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) if (!sa->fino_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /* Set up a rmapbt cursor for cross-referencing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) if (sa->agf_bp && xfs_sb_version_hasrmapbt(&mp->m_sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_RMAP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) sa->rmap_cur = xfs_rmapbt_init_cursor(mp, sc->tp, sa->agf_bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) if (!sa->rmap_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /* Set up a refcountbt cursor for cross-referencing. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (sa->agf_bp && xfs_sb_version_hasreflink(&mp->m_sb) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) xchk_ag_btree_healthy_enough(sc, sa->pag, XFS_BTNUM_REFC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) sa->refc_cur = xfs_refcountbt_init_cursor(mp, sc->tp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) sa->agf_bp, agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (!sa->refc_cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) /* Release the AG header context and btree cursors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) xchk_ag_free(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct xchk_ag *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) xchk_ag_btcur_free(sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (sa->agfl_bp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) xfs_trans_brelse(sc->tp, sa->agfl_bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) sa->agfl_bp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (sa->agf_bp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) xfs_trans_brelse(sc->tp, sa->agf_bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) sa->agf_bp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (sa->agi_bp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) xfs_trans_brelse(sc->tp, sa->agi_bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) sa->agi_bp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (sa->pag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) xfs_perag_put(sa->pag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) sa->pag = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) sa->agno = NULLAGNUMBER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * For scrub, grab the AGI and the AGF headers, in that order. Locking
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * order requires us to get the AGI before the AGF. We use the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * transaction to avoid deadlocking on crosslinked metadata buffers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * either the caller passes one in (bmap scrub) or we have to create a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * transaction ourselves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) xchk_ag_init(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) xfs_agnumber_t agno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct xchk_ag *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) sa->agno = agno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) error = xchk_ag_read_headers(sc, agno, &sa->agi_bp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) &sa->agf_bp, &sa->agfl_bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) return xchk_ag_btcur_init(sc, sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * Grab the per-ag structure if we haven't already gotten it. Teardown of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * xchk_ag will release it for us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) xchk_perag_get(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) struct xfs_mount *mp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) struct xchk_ag *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) if (!sa->pag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) sa->pag = xfs_perag_get(mp, sa->agno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) /* Per-scrubber setup functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) * Grab an empty transaction so that we can re-grab locked buffers if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) * one of our btrees turns out to be cyclic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * If we're going to repair something, we need to ask for the largest possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) * log reservation so that we can handle the worst case scenario for metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) * updates while rebuilding a metadata item. We also need to reserve as many
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) * blocks in the head transaction as we think we're going to need to rebuild
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) * the metadata object.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) xchk_trans_alloc(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) uint resblks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return xfs_trans_alloc(sc->mp, &M_RES(sc->mp)->tr_itruncate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) resblks, 0, 0, &sc->tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) return xfs_trans_alloc_empty(sc->mp, &sc->tp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) /* Set us up with a transaction and an empty context. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) xchk_setup_fs(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) struct xfs_inode *ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) uint resblks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) resblks = xrep_calc_ag_resblks(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) return xchk_trans_alloc(sc, resblks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) /* Set us up with AG headers and btree cursors. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) xchk_setup_ag_btree(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) struct xfs_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) bool force_log)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) struct xfs_mount *mp = sc->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * If the caller asks us to checkpont the log, do so. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) * expensive operation should be performed infrequently and only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * as a last resort. Any caller that sets force_log should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * document why they need to do so.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (force_log) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) error = xchk_checkpoint_log(mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) error = xchk_setup_fs(sc, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) return xchk_ag_init(sc, sc->sm->sm_agno, &sc->sa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) /* Push everything out of the log onto disk. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) xchk_checkpoint_log(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct xfs_mount *mp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) error = xfs_log_force(mp, XFS_LOG_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) xfs_ail_push_all_sync(mp->m_ail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) * Given an inode and the scrub control structure, grab either the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * inode referenced in the control structure or the inode passed in.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * The inode is not locked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) xchk_get_inode(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) struct xfs_inode *ip_in)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) struct xfs_imap imap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) struct xfs_mount *mp = sc->mp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) struct xfs_inode *ip = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) /* We want to scan the inode we already had opened. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) if (sc->sm->sm_ino == 0 || sc->sm->sm_ino == ip_in->i_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) sc->ip = ip_in;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) /* Look up the inode, see if the generation number matches. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) if (xfs_internal_inum(mp, sc->sm->sm_ino))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) error = xfs_iget(mp, NULL, sc->sm->sm_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) XFS_IGET_UNTRUSTED | XFS_IGET_DONTCACHE, 0, &ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) switch (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) case -ENOENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) /* Inode doesn't exist, just bail out. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) /* Got an inode, continue. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) case -EINVAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) * -EINVAL with IGET_UNTRUSTED could mean one of several
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) * things: userspace gave us an inode number that doesn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * correspond to fs space, or doesn't have an inobt entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * or it could simply mean that the inode buffer failed the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * read verifiers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) * Try just the inode mapping lookup -- if it succeeds, then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) * the inode buffer verifier failed and something needs fixing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) * Otherwise, we really couldn't find it so tell userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) * that it no longer exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) error = xfs_imap(sc->mp, sc->tp, sc->sm->sm_ino, &imap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) XFS_IGET_UNTRUSTED | XFS_IGET_DONTCACHE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) error = -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) /* fall through */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) trace_xchk_op_error(sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) XFS_INO_TO_AGNO(mp, sc->sm->sm_ino),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) XFS_INO_TO_AGBNO(mp, sc->sm->sm_ino),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) error, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (VFS_I(ip)->i_generation != sc->sm->sm_gen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) xfs_irele(ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) sc->ip = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) /* Set us up to scrub a file's contents. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) xchk_setup_inode_contents(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) struct xfs_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) unsigned int resblks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) error = xchk_get_inode(sc, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) /* Got the inode, lock it and we're ready to go. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) sc->ilock_flags = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) xfs_ilock(sc->ip, sc->ilock_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) error = xchk_trans_alloc(sc, resblks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) sc->ilock_flags |= XFS_ILOCK_EXCL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) xfs_ilock(sc->ip, XFS_ILOCK_EXCL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) /* scrub teardown will unlock and release the inode for us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) * Predicate that decides if we need to evaluate the cross-reference check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) * If there was an error accessing the cross-reference btree, just delete
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) * the cursor and skip the check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) xchk_should_check_xref(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) int *error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) struct xfs_btree_cur **curpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) /* No point in xref if we already know we're corrupt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) if (xchk_skip_xref(sc->sm))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) if (*error == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (curpp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) /* If we've already given up on xref, just bail out. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (!*curpp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) /* xref error, delete cursor and bail out. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) xfs_btree_del_cursor(*curpp, XFS_BTREE_ERROR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) *curpp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XFAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) trace_xchk_xref_error(sc, *error, __return_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) * Errors encountered during cross-referencing with another
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) * data structure should not cause this scrubber to abort.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) *error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) /* Run the structure verifiers on in-memory buffers to detect bad memory. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) xchk_buffer_recheck(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) struct xfs_scrub *sc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) struct xfs_buf *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) xfs_failaddr_t fa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) if (bp->b_ops == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) xchk_block_set_corrupt(sc, bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) if (bp->b_ops->verify_struct == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) xchk_set_incomplete(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) fa = bp->b_ops->verify_struct(bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) if (!fa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) trace_xchk_block_error(sc, bp->b_bn, fa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) * Scrub the attr/data forks of a metadata inode. The metadata inode must be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) * pointed to by sc->ip and the ILOCK must be held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) xchk_metadata_inode_forks(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) struct xfs_scrub *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) __u32 smtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) bool shared;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) /* Metadata inodes don't live on the rt device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) if (sc->ip->i_d.di_flags & XFS_DIFLAG_REALTIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) xchk_ino_set_corrupt(sc, sc->ip->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) /* They should never participate in reflink. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) if (xfs_is_reflink_inode(sc->ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) xchk_ino_set_corrupt(sc, sc->ip->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) /* They also should never have extended attributes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) if (xfs_inode_hasattr(sc->ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) xchk_ino_set_corrupt(sc, sc->ip->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) /* Invoke the data fork scrubber. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) smtype = sc->sm->sm_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) sc->sm->sm_type = XFS_SCRUB_TYPE_BMBTD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) error = xchk_bmap_data(sc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) sc->sm->sm_type = smtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) /* Look for incorrect shared blocks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (xfs_sb_version_hasreflink(&sc->mp->m_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) error = xfs_reflink_inode_has_shared_extents(sc->tp, sc->ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) &shared);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) &error))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) if (shared)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) xchk_ino_set_corrupt(sc, sc->ip->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * Try to lock an inode in violation of the usual locking order rules. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) * example, trying to get the IOLOCK while in transaction context, or just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) * plain breaking AG-order or inode-order inode locking rules. Either way,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * the only way to avoid an ABBA deadlock is to use trylock and back off if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) * we can't.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) xchk_ilock_inverted(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) struct xfs_inode *ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) uint lock_mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) for (i = 0; i < 20; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (xfs_ilock_nowait(ip, lock_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) delay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) return -EDEADLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) /* Pause background reaping of resources. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) xchk_stop_reaping(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) struct xfs_scrub *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) sc->flags |= XCHK_REAPING_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) xfs_stop_block_reaping(sc->mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) /* Restart background reaping of resources. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) xchk_start_reaping(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) struct xfs_scrub *sc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) xfs_start_block_reaping(sc->mp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) sc->flags &= ~XCHK_REAPING_DISABLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) }