// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2017-2023 Oracle. All Rights Reserved.
* Author: Darrick J. Wong <djwong@kernel.org>
*/
#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_log_format.h"
#include "xfs_trans.h"
#include "xfs_inode.h"
#include "xfs_icache.h"
#include "xfs_alloc.h"
#include "xfs_alloc_btree.h"
#include "xfs_ialloc.h"
#include "xfs_ialloc_btree.h"
#include "xfs_refcount_btree.h"
#include "xfs_rmap.h"
#include "xfs_rmap_btree.h"
#include "xfs_log.h"
#include "xfs_trans_priv.h"
#include "xfs_da_format.h"
#include "xfs_da_btree.h"
#include "xfs_dir2_priv.h"
#include "xfs_dir2.h"
#include "xfs_attr.h"
#include "xfs_reflink.h"
#include "xfs_ag.h"
#include "xfs_error.h"
#include "xfs_quota.h"
#include "xfs_exchmaps.h"
#include "xfs_rtbitmap.h"
#include "scrub/scrub.h"
#include "scrub/common.h"
#include "scrub/trace.h"
#include "scrub/repair.h"
#include "scrub/health.h"
/* Common code for the metadata scrubbers. */
/*
* Handling operational errors.
*
* The *_process_error() family of functions are used to process error return
* codes from functions called as part of a scrub operation.
*
* If there's no error, we return true to tell the caller that it's ok
* to move on to the next check in its list.
*
* For non-verifier errors (e.g. ENOMEM) we return false to tell the
* caller that something bad happened, and we preserve *error so that
* the caller can return the *error up the stack to userspace.
*
* Verifier errors (EFSBADCRC/EFSCORRUPTED) are recorded by setting
* OFLAG_CORRUPT in sm_flags and the *error is cleared. In other words,
* we track verifier errors (and failed scrub checks) via OFLAG_CORRUPT,
* not via return codes. We return false to tell the caller that
* something bad happened. Since the error has been cleared, the caller
* will (presumably) return that zero and scrubbing will move on to
* whatever's next.
*
* ftrace can be used to record the precise metadata location and the
* approximate code location of the failed operation.
*/
/* Check for operational errors. */
static bool
__xchk_process_error(
struct xfs_scrub *sc,
xfs_agnumber_t agno,
xfs_agblock_t bno,
int *error,
__u32 errflag,