2018-06-06 09:42:14 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-10-18 11:37:36 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Oracle. All Rights Reserved.
|
|
|
|
* Author: Darrick J. Wong <darrick.wong@oracle.com>
|
|
|
|
*/
|
|
|
|
#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_defer.h"
|
|
|
|
#include "xfs_btree.h"
|
|
|
|
#include "xfs_bit.h"
|
|
|
|
#include "xfs_log_format.h"
|
|
|
|
#include "xfs_trans.h"
|
|
|
|
#include "xfs_sb.h"
|
|
|
|
#include "xfs_inode.h"
|
2017-10-18 11:37:42 +07:00
|
|
|
#include "xfs_icache.h"
|
|
|
|
#include "xfs_itable.h"
|
2017-10-18 11:37:36 +07:00
|
|
|
#include "xfs_alloc.h"
|
|
|
|
#include "xfs_alloc_btree.h"
|
|
|
|
#include "xfs_bmap.h"
|
|
|
|
#include "xfs_bmap_btree.h"
|
|
|
|
#include "xfs_ialloc.h"
|
|
|
|
#include "xfs_ialloc_btree.h"
|
|
|
|
#include "xfs_refcount.h"
|
|
|
|
#include "xfs_refcount_btree.h"
|
|
|
|
#include "xfs_rmap.h"
|
|
|
|
#include "xfs_rmap_btree.h"
|
2017-10-18 11:37:40 +07:00
|
|
|
#include "xfs_log.h"
|
|
|
|
#include "xfs_trans_priv.h"
|
2018-05-14 20:34:33 +07:00
|
|
|
#include "xfs_attr.h"
|
|
|
|
#include "xfs_reflink.h"
|
2017-10-18 11:37:36 +07:00
|
|
|
#include "scrub/xfs_scrub.h"
|
|
|
|
#include "scrub/scrub.h"
|
|
|
|
#include "scrub/common.h"
|
|
|
|
#include "scrub/trace.h"
|
2017-10-18 11:37:38 +07:00
|
|
|
#include "scrub/btree.h"
|
2018-05-30 12:18:08 +07:00
|
|
|
#include "scrub/repair.h"
|
2017-10-18 11:37:36 +07:00
|
|
|
|
|
|
|
/* Common code for the metadata scrubbers. */
|
|
|
|
|
2017-10-18 11:37:36 +07:00
|
|
|
/*
|
|
|
|
* 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. */
|
2018-01-17 09:52:14 +07:00
|
|
|
static bool
|
2018-07-20 02:29:11 +07:00
|
|
|
__xchk_process_error(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
xfs_agnumber_t agno,
|
|
|
|
xfs_agblock_t bno,
|
2018-01-17 09:52:14 +07:00
|
|
|
int *error,
|
|
|
|
__u32 errflag,
|
|
|
|
void *ret_ip)
|
2017-10-18 11:37:36 +07:00
|
|
|
{
|
|
|
|
switch (*error) {
|
|
|
|
case 0:
|
|
|
|
return true;
|
|
|
|
case -EDEADLOCK:
|
|
|
|
/* Used to restart an op with deadlock avoidance. */
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_deadlock_retry(sc->ip, sc->sm, *error);
|
2017-10-18 11:37:36 +07:00
|
|
|
break;
|
|
|
|
case -EFSBADCRC:
|
|
|
|
case -EFSCORRUPTED:
|
|
|
|
/* Note the badness but don't abort. */
|
2018-01-17 09:52:14 +07:00
|
|
|
sc->sm->sm_flags |= errflag;
|
2017-10-18 11:37:36 +07:00
|
|
|
*error = 0;
|
|
|
|
/* fall through */
|
|
|
|
default:
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_op_error(sc, agno, bno, *error,
|
2018-01-17 09:52:14 +07:00
|
|
|
ret_ip);
|
2017-10-18 11:37:36 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_process_error(
|
2018-01-17 09:52:14 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
xfs_agnumber_t agno,
|
|
|
|
xfs_agblock_t bno,
|
|
|
|
int *error)
|
|
|
|
{
|
2018-07-20 02:29:11 +07:00
|
|
|
return __xchk_process_error(sc, agno, bno, error,
|
2018-01-17 09:52:14 +07:00
|
|
|
XFS_SCRUB_OFLAG_CORRUPT, __return_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_xref_process_error(
|
2018-01-17 09:52:14 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
xfs_agnumber_t agno,
|
|
|
|
xfs_agblock_t bno,
|
|
|
|
int *error)
|
|
|
|
{
|
2018-07-20 02:29:11 +07:00
|
|
|
return __xchk_process_error(sc, agno, bno, error,
|
2018-01-17 09:52:14 +07:00
|
|
|
XFS_SCRUB_OFLAG_XFAIL, __return_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for operational errors for a file offset. */
|
|
|
|
static bool
|
2018-07-20 02:29:11 +07:00
|
|
|
__xchk_fblock_process_error(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset,
|
2018-01-17 09:52:14 +07:00
|
|
|
int *error,
|
|
|
|
__u32 errflag,
|
|
|
|
void *ret_ip)
|
2017-10-18 11:37:36 +07:00
|
|
|
{
|
|
|
|
switch (*error) {
|
|
|
|
case 0:
|
|
|
|
return true;
|
|
|
|
case -EDEADLOCK:
|
|
|
|
/* Used to restart an op with deadlock avoidance. */
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_deadlock_retry(sc->ip, sc->sm, *error);
|
2017-10-18 11:37:36 +07:00
|
|
|
break;
|
|
|
|
case -EFSBADCRC:
|
|
|
|
case -EFSCORRUPTED:
|
|
|
|
/* Note the badness but don't abort. */
|
2018-01-17 09:52:14 +07:00
|
|
|
sc->sm->sm_flags |= errflag;
|
2017-10-18 11:37:36 +07:00
|
|
|
*error = 0;
|
|
|
|
/* fall through */
|
|
|
|
default:
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_file_op_error(sc, whichfork, offset, *error,
|
2018-01-17 09:52:14 +07:00
|
|
|
ret_ip);
|
2017-10-18 11:37:36 +07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-17 09:52:14 +07:00
|
|
|
bool
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_fblock_process_error(
|
2018-01-17 09:52:14 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset,
|
|
|
|
int *error)
|
|
|
|
{
|
2018-07-20 02:29:11 +07:00
|
|
|
return __xchk_fblock_process_error(sc, whichfork, offset, error,
|
2018-01-17 09:52:14 +07:00
|
|
|
XFS_SCRUB_OFLAG_CORRUPT, __return_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_fblock_xref_process_error(
|
2018-01-17 09:52:14 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset,
|
|
|
|
int *error)
|
|
|
|
{
|
2018-07-20 02:29:11 +07:00
|
|
|
return __xchk_fblock_process_error(sc, whichfork, offset, error,
|
2018-01-17 09:52:14 +07:00
|
|
|
XFS_SCRUB_OFLAG_XFAIL, __return_address);
|
|
|
|
}
|
|
|
|
|
2017-10-18 11:37:36 +07:00
|
|
|
/*
|
|
|
|
* Handling scrub corruption/optimization/warning checks.
|
|
|
|
*
|
|
|
|
* The *_set_{corrupt,preen,warning}() family of functions are used to
|
|
|
|
* record the presence of metadata that is incorrect (corrupt), could be
|
|
|
|
* optimized somehow (preen), or should be flagged for administrative
|
|
|
|
* review but is not incorrect (warn).
|
|
|
|
*
|
|
|
|
* ftrace can be used to record the precise metadata location and
|
|
|
|
* approximate code location of the failed check.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Record a block which could be optimized. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_block_set_preen(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_PREEN;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_block_preen(sc, bp->b_bn, __return_address);
|
2017-10-18 11:37:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Record an inode which could be optimized. The trace data will
|
|
|
|
* include the block given by bp if bp is given; otherwise it will use
|
|
|
|
* the block location of the inode record itself.
|
|
|
|
*/
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ino_set_preen(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
2018-03-24 00:06:54 +07:00
|
|
|
xfs_ino_t ino)
|
2017-10-18 11:37:36 +07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_PREEN;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_ino_preen(sc, ino, __return_address);
|
2017-10-18 11:37:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Record a corrupt block. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_block_set_corrupt(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_block_error(sc, bp->b_bn, __return_address);
|
2017-10-18 11:37:36 +07:00
|
|
|
}
|
|
|
|
|
2018-01-17 09:52:14 +07:00
|
|
|
/* Record a corruption while cross-referencing. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_block_xref_set_corrupt(
|
2018-01-17 09:52:14 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_block_error(sc, bp->b_bn, __return_address);
|
2018-01-17 09:52:14 +07:00
|
|
|
}
|
|
|
|
|
2017-10-18 11:37:36 +07:00
|
|
|
/*
|
|
|
|
* Record a corrupt inode. The trace data will include the block given
|
|
|
|
* by bp if bp is given; otherwise it will use the block location of the
|
|
|
|
* inode record itself.
|
|
|
|
*/
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ino_set_corrupt(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
2018-03-24 00:06:54 +07:00
|
|
|
xfs_ino_t ino)
|
2017-10-18 11:37:36 +07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_ino_error(sc, ino, __return_address);
|
2017-10-18 11:37:36 +07:00
|
|
|
}
|
|
|
|
|
2018-01-17 09:52:14 +07:00
|
|
|
/* Record a corruption while cross-referencing with an inode. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ino_xref_set_corrupt(
|
2018-01-17 09:52:14 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
2018-03-24 00:06:54 +07:00
|
|
|
xfs_ino_t ino)
|
2018-01-17 09:52:14 +07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_ino_error(sc, ino, __return_address);
|
2018-01-17 09:52:14 +07:00
|
|
|
}
|
|
|
|
|
2017-10-18 11:37:36 +07:00
|
|
|
/* Record corruption in a block indexed by a file fork. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_fblock_set_corrupt(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset)
|
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_fblock_error(sc, whichfork, offset, __return_address);
|
2017-10-18 11:37:36 +07:00
|
|
|
}
|
|
|
|
|
2018-01-17 09:52:14 +07:00
|
|
|
/* Record a corruption while cross-referencing a fork block. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_fblock_xref_set_corrupt(
|
2018-01-17 09:52:14 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset)
|
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_fblock_error(sc, whichfork, offset, __return_address);
|
2018-01-17 09:52:14 +07:00
|
|
|
}
|
|
|
|
|
2017-10-18 11:37:36 +07:00
|
|
|
/*
|
|
|
|
* Warn about inodes that need administrative review but is not
|
|
|
|
* incorrect.
|
|
|
|
*/
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ino_set_warning(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
2018-03-24 00:06:54 +07:00
|
|
|
xfs_ino_t ino)
|
2017-10-18 11:37:36 +07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_WARNING;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_ino_warning(sc, ino, __return_address);
|
2017-10-18 11:37:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Warn about a block indexed by a file fork that needs review. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_fblock_set_warning(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset)
|
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_WARNING;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_fblock_warning(sc, whichfork, offset, __return_address);
|
2017-10-18 11:37:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Signal an incomplete scrub. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_set_incomplete(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc)
|
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_INCOMPLETE;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_incomplete(sc, __return_address);
|
2017-10-18 11:37:36 +07:00
|
|
|
}
|
|
|
|
|
2018-01-17 09:53:08 +07:00
|
|
|
/*
|
|
|
|
* rmap scrubbing -- compute the number of blocks with a given owner,
|
|
|
|
* at least according to the reverse mapping data.
|
|
|
|
*/
|
|
|
|
|
2018-07-20 02:29:11 +07:00
|
|
|
struct xchk_rmap_ownedby_info {
|
2018-01-17 09:53:08 +07:00
|
|
|
struct xfs_owner_info *oinfo;
|
|
|
|
xfs_filblks_t *blocks;
|
|
|
|
};
|
|
|
|
|
|
|
|
STATIC int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_count_rmap_ownedby_irec(
|
2018-01-17 09:53:08 +07:00
|
|
|
struct xfs_btree_cur *cur,
|
|
|
|
struct xfs_rmap_irec *rec,
|
|
|
|
void *priv)
|
|
|
|
{
|
2018-07-20 02:29:11 +07:00
|
|
|
struct xchk_rmap_ownedby_info *sroi = priv;
|
2018-01-17 09:53:08 +07:00
|
|
|
bool irec_attr;
|
|
|
|
bool oinfo_attr;
|
|
|
|
|
|
|
|
irec_attr = rec->rm_flags & XFS_RMAP_ATTR_FORK;
|
|
|
|
oinfo_attr = sroi->oinfo->oi_flags & XFS_OWNER_INFO_ATTR_FORK;
|
|
|
|
|
|
|
|
if (rec->rm_owner != sroi->oinfo->oi_owner)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) || irec_attr == oinfo_attr)
|
|
|
|
(*sroi->blocks) += rec->rm_blockcount;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Calculate the number of blocks the rmap thinks are owned by something.
|
|
|
|
* The caller should pass us an rmapbt cursor.
|
|
|
|
*/
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_count_rmap_ownedby_ag(
|
2018-01-17 09:53:08 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
struct xfs_btree_cur *cur,
|
|
|
|
struct xfs_owner_info *oinfo,
|
|
|
|
xfs_filblks_t *blocks)
|
|
|
|
{
|
2018-07-20 02:29:11 +07:00
|
|
|
struct xchk_rmap_ownedby_info sroi;
|
2018-01-17 09:53:08 +07:00
|
|
|
|
|
|
|
sroi.oinfo = oinfo;
|
|
|
|
*blocks = 0;
|
|
|
|
sroi.blocks = blocks;
|
|
|
|
|
2018-07-20 02:29:11 +07:00
|
|
|
return xfs_rmap_query_all(cur, xchk_count_rmap_ownedby_irec,
|
2018-01-17 09:53:08 +07:00
|
|
|
&sroi);
|
|
|
|
}
|
|
|
|
|
2017-10-18 11:37:38 +07:00
|
|
|
/*
|
|
|
|
* AG scrubbing
|
|
|
|
*
|
|
|
|
* These helpers facilitate locking an allocation group's header
|
|
|
|
* buffers, setting up cursors for all btrees that are present, and
|
|
|
|
* cleaning everything up once we're through.
|
|
|
|
*/
|
|
|
|
|
2017-10-18 11:37:39 +07:00
|
|
|
/* Decide if we want to return an AG header read failure. */
|
|
|
|
static inline bool
|
|
|
|
want_ag_read_header_failure(
|
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
unsigned int type)
|
|
|
|
{
|
|
|
|
/* Return all AG header read failures when scanning btrees. */
|
|
|
|
if (sc->sm->sm_type != XFS_SCRUB_TYPE_AGF &&
|
2017-10-18 11:37:39 +07:00
|
|
|
sc->sm->sm_type != XFS_SCRUB_TYPE_AGFL &&
|
|
|
|
sc->sm->sm_type != XFS_SCRUB_TYPE_AGI)
|
2017-10-18 11:37:39 +07:00
|
|
|
return true;
|
|
|
|
/*
|
|
|
|
* If we're scanning a given type of AG header, we only want to
|
|
|
|
* see read failures from that specific header. We'd like the
|
|
|
|
* other headers to cross-check them, but this isn't required.
|
|
|
|
*/
|
|
|
|
if (sc->sm->sm_type == type)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-18 11:37:38 +07:00
|
|
|
/*
|
|
|
|
* Grab all the headers for an AG.
|
|
|
|
*
|
2018-07-20 02:29:11 +07:00
|
|
|
* The headers should be released by xchk_ag_free, but as a fail
|
2017-10-18 11:37:38 +07:00
|
|
|
* safe we attach all the buffers we grab to the scrub transaction so
|
|
|
|
* they'll all be freed when we cancel it.
|
|
|
|
*/
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ag_read_headers(
|
2017-10-18 11:37:38 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
xfs_agnumber_t agno,
|
|
|
|
struct xfs_buf **agi,
|
|
|
|
struct xfs_buf **agf,
|
|
|
|
struct xfs_buf **agfl)
|
|
|
|
{
|
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
error = xfs_ialloc_read_agi(mp, sc->tp, agno, agi);
|
2017-10-18 11:37:39 +07:00
|
|
|
if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGI))
|
2017-10-18 11:37:38 +07:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
error = xfs_alloc_read_agf(mp, sc->tp, agno, 0, agf);
|
2017-10-18 11:37:39 +07:00
|
|
|
if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGF))
|
2017-10-18 11:37:38 +07:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
error = xfs_alloc_read_agfl(mp, sc->tp, agno, agfl);
|
2017-10-18 11:37:39 +07:00
|
|
|
if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGFL))
|
2017-10-18 11:37:38 +07:00
|
|
|
goto out;
|
2018-01-09 01:49:02 +07:00
|
|
|
error = 0;
|
2017-10-18 11:37:38 +07:00
|
|
|
out:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release all the AG btree cursors. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ag_btcur_free(
|
|
|
|
struct xchk_ag *sa)
|
2017-10-18 11:37:38 +07:00
|
|
|
{
|
|
|
|
if (sa->refc_cur)
|
|
|
|
xfs_btree_del_cursor(sa->refc_cur, XFS_BTREE_ERROR);
|
|
|
|
if (sa->rmap_cur)
|
|
|
|
xfs_btree_del_cursor(sa->rmap_cur, XFS_BTREE_ERROR);
|
|
|
|
if (sa->fino_cur)
|
|
|
|
xfs_btree_del_cursor(sa->fino_cur, XFS_BTREE_ERROR);
|
|
|
|
if (sa->ino_cur)
|
|
|
|
xfs_btree_del_cursor(sa->ino_cur, XFS_BTREE_ERROR);
|
|
|
|
if (sa->cnt_cur)
|
|
|
|
xfs_btree_del_cursor(sa->cnt_cur, XFS_BTREE_ERROR);
|
|
|
|
if (sa->bno_cur)
|
|
|
|
xfs_btree_del_cursor(sa->bno_cur, XFS_BTREE_ERROR);
|
|
|
|
|
|
|
|
sa->refc_cur = NULL;
|
|
|
|
sa->rmap_cur = NULL;
|
|
|
|
sa->fino_cur = NULL;
|
|
|
|
sa->ino_cur = NULL;
|
|
|
|
sa->bno_cur = NULL;
|
|
|
|
sa->cnt_cur = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize all the btree cursors for an AG. */
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ag_btcur_init(
|
2017-10-18 11:37:38 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
2018-07-20 02:29:11 +07:00
|
|
|
struct xchk_ag *sa)
|
2017-10-18 11:37:38 +07:00
|
|
|
{
|
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
xfs_agnumber_t agno = sa->agno;
|
|
|
|
|
|
|
|
if (sa->agf_bp) {
|
|
|
|
/* Set up a bnobt cursor for cross-referencing. */
|
|
|
|
sa->bno_cur = xfs_allocbt_init_cursor(mp, sc->tp, sa->agf_bp,
|
|
|
|
agno, XFS_BTNUM_BNO);
|
|
|
|
if (!sa->bno_cur)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Set up a cntbt cursor for cross-referencing. */
|
|
|
|
sa->cnt_cur = xfs_allocbt_init_cursor(mp, sc->tp, sa->agf_bp,
|
|
|
|
agno, XFS_BTNUM_CNT);
|
|
|
|
if (!sa->cnt_cur)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up a inobt cursor for cross-referencing. */
|
|
|
|
if (sa->agi_bp) {
|
|
|
|
sa->ino_cur = xfs_inobt_init_cursor(mp, sc->tp, sa->agi_bp,
|
|
|
|
agno, XFS_BTNUM_INO);
|
|
|
|
if (!sa->ino_cur)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up a finobt cursor for cross-referencing. */
|
|
|
|
if (sa->agi_bp && xfs_sb_version_hasfinobt(&mp->m_sb)) {
|
|
|
|
sa->fino_cur = xfs_inobt_init_cursor(mp, sc->tp, sa->agi_bp,
|
|
|
|
agno, XFS_BTNUM_FINO);
|
|
|
|
if (!sa->fino_cur)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up a rmapbt cursor for cross-referencing. */
|
|
|
|
if (sa->agf_bp && xfs_sb_version_hasrmapbt(&mp->m_sb)) {
|
|
|
|
sa->rmap_cur = xfs_rmapbt_init_cursor(mp, sc->tp, sa->agf_bp,
|
|
|
|
agno);
|
|
|
|
if (!sa->rmap_cur)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up a refcountbt cursor for cross-referencing. */
|
|
|
|
if (sa->agf_bp && xfs_sb_version_hasreflink(&mp->m_sb)) {
|
|
|
|
sa->refc_cur = xfs_refcountbt_init_cursor(mp, sc->tp,
|
2018-07-12 12:26:17 +07:00
|
|
|
sa->agf_bp, agno);
|
2017-10-18 11:37:38 +07:00
|
|
|
if (!sa->refc_cur)
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the AG header context and btree cursors. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ag_free(
|
2017-10-18 11:37:38 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
2018-07-20 02:29:11 +07:00
|
|
|
struct xchk_ag *sa)
|
2017-10-18 11:37:38 +07:00
|
|
|
{
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ag_btcur_free(sa);
|
2017-10-18 11:37:38 +07:00
|
|
|
if (sa->agfl_bp) {
|
|
|
|
xfs_trans_brelse(sc->tp, sa->agfl_bp);
|
|
|
|
sa->agfl_bp = NULL;
|
|
|
|
}
|
|
|
|
if (sa->agf_bp) {
|
|
|
|
xfs_trans_brelse(sc->tp, sa->agf_bp);
|
|
|
|
sa->agf_bp = NULL;
|
|
|
|
}
|
|
|
|
if (sa->agi_bp) {
|
|
|
|
xfs_trans_brelse(sc->tp, sa->agi_bp);
|
|
|
|
sa->agi_bp = NULL;
|
|
|
|
}
|
2018-05-30 12:24:44 +07:00
|
|
|
if (sa->pag) {
|
|
|
|
xfs_perag_put(sa->pag);
|
|
|
|
sa->pag = NULL;
|
|
|
|
}
|
2017-10-18 11:37:38 +07:00
|
|
|
sa->agno = NULLAGNUMBER;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For scrub, grab the AGI and the AGF headers, in that order. Locking
|
|
|
|
* order requires us to get the AGI before the AGF. We use the
|
|
|
|
* transaction to avoid deadlocking on crosslinked metadata buffers;
|
|
|
|
* either the caller passes one in (bmap scrub) or we have to create a
|
|
|
|
* transaction ourselves.
|
|
|
|
*/
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ag_init(
|
2017-10-18 11:37:38 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
xfs_agnumber_t agno,
|
2018-07-20 02:29:11 +07:00
|
|
|
struct xchk_ag *sa)
|
2017-10-18 11:37:38 +07:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
sa->agno = agno;
|
2018-07-20 02:29:11 +07:00
|
|
|
error = xchk_ag_read_headers(sc, agno, &sa->agi_bp,
|
2017-10-18 11:37:38 +07:00
|
|
|
&sa->agf_bp, &sa->agfl_bp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2018-07-20 02:29:11 +07:00
|
|
|
return xchk_ag_btcur_init(sc, sa);
|
2017-10-18 11:37:38 +07:00
|
|
|
}
|
|
|
|
|
2018-05-30 12:24:44 +07:00
|
|
|
/*
|
|
|
|
* Grab the per-ag structure if we haven't already gotten it. Teardown of the
|
2018-07-20 02:29:11 +07:00
|
|
|
* xchk_ag will release it for us.
|
2018-05-30 12:24:44 +07:00
|
|
|
*/
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_perag_get(
|
2018-05-30 12:24:44 +07:00
|
|
|
struct xfs_mount *mp,
|
2018-07-20 02:29:11 +07:00
|
|
|
struct xchk_ag *sa)
|
2018-05-30 12:24:44 +07:00
|
|
|
{
|
|
|
|
if (!sa->pag)
|
|
|
|
sa->pag = xfs_perag_get(mp, sa->agno);
|
|
|
|
}
|
|
|
|
|
2017-10-18 11:37:36 +07:00
|
|
|
/* Per-scrubber setup functions */
|
|
|
|
|
2018-05-10 00:02:01 +07:00
|
|
|
/*
|
|
|
|
* Grab an empty transaction so that we can re-grab locked buffers if
|
|
|
|
* one of our btrees turns out to be cyclic.
|
2018-05-30 12:18:08 +07:00
|
|
|
*
|
|
|
|
* If we're going to repair something, we need to ask for the largest possible
|
|
|
|
* log reservation so that we can handle the worst case scenario for metadata
|
|
|
|
* updates while rebuilding a metadata item. We also need to reserve as many
|
|
|
|
* blocks in the head transaction as we think we're going to need to rebuild
|
|
|
|
* the metadata object.
|
2018-05-10 00:02:01 +07:00
|
|
|
*/
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_trans_alloc(
|
2018-05-30 12:18:08 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
uint resblks)
|
2018-05-10 00:02:01 +07:00
|
|
|
{
|
2018-05-30 12:18:08 +07:00
|
|
|
if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR)
|
|
|
|
return xfs_trans_alloc(sc->mp, &M_RES(sc->mp)->tr_itruncate,
|
|
|
|
resblks, 0, 0, &sc->tp);
|
|
|
|
|
2018-05-10 00:02:01 +07:00
|
|
|
return xfs_trans_alloc_empty(sc->mp, &sc->tp);
|
|
|
|
}
|
|
|
|
|
2017-10-18 11:37:36 +07:00
|
|
|
/* Set us up with a transaction and an empty context. */
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_setup_fs(
|
2017-10-18 11:37:36 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
struct xfs_inode *ip)
|
|
|
|
{
|
2018-05-30 12:18:08 +07:00
|
|
|
uint resblks;
|
|
|
|
|
|
|
|
resblks = xfs_repair_calc_ag_resblks(sc);
|
2018-07-20 02:29:11 +07:00
|
|
|
return xchk_trans_alloc(sc, resblks);
|
2017-10-18 11:37:36 +07:00
|
|
|
}
|
2017-10-18 11:37:40 +07:00
|
|
|
|
|
|
|
/* Set us up with AG headers and btree cursors. */
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_setup_ag_btree(
|
2017-10-18 11:37:40 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
struct xfs_inode *ip,
|
|
|
|
bool force_log)
|
|
|
|
{
|
2017-10-18 11:37:40 +07:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
2017-10-18 11:37:40 +07:00
|
|
|
int error;
|
|
|
|
|
2017-10-18 11:37:40 +07:00
|
|
|
/*
|
|
|
|
* If the caller asks us to checkpont the log, do so. This
|
|
|
|
* expensive operation should be performed infrequently and only
|
|
|
|
* as a last resort. Any caller that sets force_log should
|
|
|
|
* document why they need to do so.
|
|
|
|
*/
|
|
|
|
if (force_log) {
|
2018-07-20 02:29:11 +07:00
|
|
|
error = xchk_checkpoint_log(mp);
|
2017-10-18 11:37:40 +07:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-07-20 02:29:11 +07:00
|
|
|
error = xchk_setup_fs(sc, ip);
|
2017-10-18 11:37:40 +07:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2018-07-20 02:29:11 +07:00
|
|
|
return xchk_ag_init(sc, sc->sm->sm_agno, &sc->sa);
|
2017-10-18 11:37:40 +07:00
|
|
|
}
|
2017-10-18 11:37:40 +07:00
|
|
|
|
|
|
|
/* Push everything out of the log onto disk. */
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_checkpoint_log(
|
2017-10-18 11:37:40 +07:00
|
|
|
struct xfs_mount *mp)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2018-03-14 13:15:28 +07:00
|
|
|
error = xfs_log_force(mp, XFS_LOG_SYNC);
|
2017-10-18 11:37:40 +07:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
xfs_ail_push_all_sync(mp->m_ail);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-18 11:37:42 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Given an inode and the scrub control structure, grab either the
|
|
|
|
* inode referenced in the control structure or the inode passed in.
|
|
|
|
* The inode is not locked.
|
|
|
|
*/
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_get_inode(
|
2017-10-18 11:37:42 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
struct xfs_inode *ip_in)
|
|
|
|
{
|
2018-01-09 01:49:04 +07:00
|
|
|
struct xfs_imap imap;
|
2017-10-18 11:37:42 +07:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
struct xfs_inode *ip = NULL;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* We want to scan the inode we already had opened. */
|
|
|
|
if (sc->sm->sm_ino == 0 || sc->sm->sm_ino == ip_in->i_ino) {
|
|
|
|
sc->ip = ip_in;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Look up the inode, see if the generation number matches. */
|
|
|
|
if (xfs_internal_inum(mp, sc->sm->sm_ino))
|
|
|
|
return -ENOENT;
|
|
|
|
error = xfs_iget(mp, NULL, sc->sm->sm_ino,
|
|
|
|
XFS_IGET_UNTRUSTED | XFS_IGET_DONTCACHE, 0, &ip);
|
2018-01-09 01:49:04 +07:00
|
|
|
switch (error) {
|
|
|
|
case -ENOENT:
|
|
|
|
/* Inode doesn't exist, just bail out. */
|
|
|
|
return error;
|
|
|
|
case 0:
|
|
|
|
/* Got an inode, continue. */
|
|
|
|
break;
|
|
|
|
case -EINVAL:
|
|
|
|
/*
|
|
|
|
* -EINVAL with IGET_UNTRUSTED could mean one of several
|
|
|
|
* things: userspace gave us an inode number that doesn't
|
|
|
|
* correspond to fs space, or doesn't have an inobt entry;
|
|
|
|
* or it could simply mean that the inode buffer failed the
|
|
|
|
* read verifiers.
|
|
|
|
*
|
|
|
|
* Try just the inode mapping lookup -- if it succeeds, then
|
|
|
|
* the inode buffer verifier failed and something needs fixing.
|
|
|
|
* Otherwise, we really couldn't find it so tell userspace
|
|
|
|
* that it no longer exists.
|
|
|
|
*/
|
|
|
|
error = xfs_imap(sc->mp, sc->tp, sc->sm->sm_ino, &imap,
|
|
|
|
XFS_IGET_UNTRUSTED | XFS_IGET_DONTCACHE);
|
|
|
|
if (error)
|
|
|
|
return -ENOENT;
|
|
|
|
error = -EFSCORRUPTED;
|
|
|
|
/* fall through */
|
|
|
|
default:
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_op_error(sc,
|
2017-10-18 11:37:42 +07:00
|
|
|
XFS_INO_TO_AGNO(mp, sc->sm->sm_ino),
|
|
|
|
XFS_INO_TO_AGBNO(mp, sc->sm->sm_ino),
|
|
|
|
error, __return_address);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (VFS_I(ip)->i_generation != sc->sm->sm_gen) {
|
|
|
|
iput(VFS_I(ip));
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->ip = ip;
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-18 11:37:44 +07:00
|
|
|
|
|
|
|
/* Set us up to scrub a file's contents. */
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_setup_inode_contents(
|
2017-10-18 11:37:44 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
struct xfs_inode *ip,
|
|
|
|
unsigned int resblks)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2018-07-20 02:29:11 +07:00
|
|
|
error = xchk_get_inode(sc, ip);
|
2017-10-18 11:37:44 +07:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Got the inode, lock it and we're ready to go. */
|
|
|
|
sc->ilock_flags = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
|
|
|
|
xfs_ilock(sc->ip, sc->ilock_flags);
|
2018-07-20 02:29:11 +07:00
|
|
|
error = xchk_trans_alloc(sc, resblks);
|
2017-10-18 11:37:44 +07:00
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
sc->ilock_flags |= XFS_ILOCK_EXCL;
|
|
|
|
xfs_ilock(sc->ip, XFS_ILOCK_EXCL);
|
|
|
|
|
|
|
|
out:
|
|
|
|
/* scrub teardown will unlock and release the inode for us */
|
|
|
|
return error;
|
|
|
|
}
|
2018-01-17 09:52:14 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Predicate that decides if we need to evaluate the cross-reference check.
|
|
|
|
* If there was an error accessing the cross-reference btree, just delete
|
|
|
|
* the cursor and skip the check.
|
|
|
|
*/
|
|
|
|
bool
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_should_check_xref(
|
2018-01-17 09:52:14 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
int *error,
|
|
|
|
struct xfs_btree_cur **curpp)
|
|
|
|
{
|
2018-05-14 20:34:31 +07:00
|
|
|
/* No point in xref if we already know we're corrupt. */
|
2018-07-20 02:29:11 +07:00
|
|
|
if (xchk_skip_xref(sc->sm))
|
2018-05-14 20:34:31 +07:00
|
|
|
return false;
|
|
|
|
|
2018-01-17 09:52:14 +07:00
|
|
|
if (*error == 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (curpp) {
|
|
|
|
/* If we've already given up on xref, just bail out. */
|
|
|
|
if (!*curpp)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* xref error, delete cursor and bail out. */
|
|
|
|
xfs_btree_del_cursor(*curpp, XFS_BTREE_ERROR);
|
|
|
|
*curpp = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XFAIL;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_xref_error(sc, *error, __return_address);
|
2018-01-17 09:52:14 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Errors encountered during cross-referencing with another
|
|
|
|
* data structure should not cause this scrubber to abort.
|
|
|
|
*/
|
|
|
|
*error = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-17 09:53:11 +07:00
|
|
|
|
|
|
|
/* Run the structure verifiers on in-memory buffers to detect bad memory. */
|
|
|
|
void
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_buffer_recheck(
|
2018-01-17 09:53:11 +07:00
|
|
|
struct xfs_scrub_context *sc,
|
|
|
|
struct xfs_buf *bp)
|
|
|
|
{
|
|
|
|
xfs_failaddr_t fa;
|
|
|
|
|
|
|
|
if (bp->b_ops == NULL) {
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2018-01-17 09:53:11 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (bp->b_ops->verify_struct == NULL) {
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_set_incomplete(sc);
|
2018-01-17 09:53:11 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
fa = bp->b_ops->verify_struct(bp);
|
|
|
|
if (!fa)
|
|
|
|
return;
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
|
2018-07-20 02:29:11 +07:00
|
|
|
trace_xchk_block_error(sc, bp->b_bn, fa);
|
2018-01-17 09:53:11 +07:00
|
|
|
}
|
2018-05-14 20:34:33 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scrub the attr/data forks of a metadata inode. The metadata inode must be
|
|
|
|
* pointed to by sc->ip and the ILOCK must be held.
|
|
|
|
*/
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_metadata_inode_forks(
|
2018-05-14 20:34:33 +07:00
|
|
|
struct xfs_scrub_context *sc)
|
|
|
|
{
|
|
|
|
__u32 smtype;
|
|
|
|
bool shared;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Metadata inodes don't live on the rt device. */
|
|
|
|
if (sc->ip->i_d.di_flags & XFS_DIFLAG_REALTIME) {
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ino_set_corrupt(sc, sc->ip->i_ino);
|
2018-05-14 20:34:33 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* They should never participate in reflink. */
|
|
|
|
if (xfs_is_reflink_inode(sc->ip)) {
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ino_set_corrupt(sc, sc->ip->i_ino);
|
2018-05-14 20:34:33 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* They also should never have extended attributes. */
|
|
|
|
if (xfs_inode_hasattr(sc->ip)) {
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ino_set_corrupt(sc, sc->ip->i_ino);
|
2018-05-14 20:34:33 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invoke the data fork scrubber. */
|
|
|
|
smtype = sc->sm->sm_type;
|
|
|
|
sc->sm->sm_type = XFS_SCRUB_TYPE_BMBTD;
|
2018-07-20 02:29:11 +07:00
|
|
|
error = xchk_bmap_data(sc);
|
2018-05-14 20:34:33 +07:00
|
|
|
sc->sm->sm_type = smtype;
|
|
|
|
if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Look for incorrect shared blocks. */
|
|
|
|
if (xfs_sb_version_hasreflink(&sc->mp->m_sb)) {
|
|
|
|
error = xfs_reflink_inode_has_shared_extents(sc->tp, sc->ip,
|
|
|
|
&shared);
|
2018-07-20 02:29:11 +07:00
|
|
|
if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, 0,
|
2018-05-14 20:34:33 +07:00
|
|
|
&error))
|
|
|
|
return error;
|
|
|
|
if (shared)
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ino_set_corrupt(sc, sc->ip->i_ino);
|
2018-05-14 20:34:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
2018-05-14 20:34:34 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to lock an inode in violation of the usual locking order rules. For
|
|
|
|
* example, trying to get the IOLOCK while in transaction context, or just
|
|
|
|
* plain breaking AG-order or inode-order inode locking rules. Either way,
|
|
|
|
* the only way to avoid an ABBA deadlock is to use trylock and back off if
|
|
|
|
* we can't.
|
|
|
|
*/
|
|
|
|
int
|
2018-07-20 02:29:11 +07:00
|
|
|
xchk_ilock_inverted(
|
2018-05-14 20:34:34 +07:00
|
|
|
struct xfs_inode *ip,
|
|
|
|
uint lock_mode)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 20; i++) {
|
|
|
|
if (xfs_ilock_nowait(ip, lock_mode))
|
|
|
|
return 0;
|
|
|
|
delay(1);
|
|
|
|
}
|
|
|
|
return -EDEADLOCK;
|
|
|
|
}
|