2023-04-11 18:59:56 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2017-10-17 21:37:36 -07:00
|
|
|
/*
|
2023-04-11 18:59:57 -07:00
|
|
|
* Copyright (C) 2017-2023 Oracle. All Rights Reserved.
|
2023-04-11 18:59:56 -07:00
|
|
|
* Author: Darrick J. Wong <djwong@kernel.org>
|
2017-10-17 21:37:36 -07:00
|
|
|
*/
|
|
|
|
#include "xfs.h"
|
|
|
|
#include "xfs_fs.h"
|
|
|
|
#include "xfs_shared.h"
|
|
|
|
#include "xfs_format.h"
|
|
|
|
#include "xfs_trans_resv.h"
|
|
|
|
#include "xfs_mount.h"
|
|
|
|
#include "xfs_btree.h"
|
|
|
|
#include "xfs_log_format.h"
|
|
|
|
#include "xfs_trans.h"
|
|
|
|
#include "xfs_inode.h"
|
2017-10-17 21:37:42 -07:00
|
|
|
#include "xfs_icache.h"
|
2017-10-17 21:37:36 -07:00
|
|
|
#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"
|
2017-10-17 21:37:40 -07:00
|
|
|
#include "xfs_log.h"
|
|
|
|
#include "xfs_trans_priv.h"
|
2022-05-04 12:41:02 +10:00
|
|
|
#include "xfs_da_format.h"
|
|
|
|
#include "xfs_da_btree.h"
|
2023-12-15 10:03:37 -08:00
|
|
|
#include "xfs_dir2_priv.h"
|
2018-05-14 06:34:33 -07:00
|
|
|
#include "xfs_attr.h"
|
|
|
|
#include "xfs_reflink.h"
|
2021-06-02 10:48:24 +10:00
|
|
|
#include "xfs_ag.h"
|
2024-02-22 12:30:54 -08:00
|
|
|
#include "xfs_error.h"
|
2024-02-22 12:30:55 -08:00
|
|
|
#include "xfs_quota.h"
|
2024-04-15 14:54:33 -07:00
|
|
|
#include "xfs_exchmaps.h"
|
2024-04-22 13:20:08 +02:00
|
|
|
#include "xfs_rtbitmap.h"
|
2017-10-17 21:37:36 -07:00
|
|
|
#include "scrub/scrub.h"
|
|
|
|
#include "scrub/common.h"
|
|
|
|
#include "scrub/trace.h"
|
2018-05-29 22:18:08 -07:00
|
|
|
#include "scrub/repair.h"
|
2019-04-16 08:22:01 -07:00
|
|
|
#include "scrub/health.h"
|
2017-10-17 21:37:36 -07:00
|
|
|
|
|
|
|
/* Common code for the metadata scrubbers. */
|
|
|
|
|
2017-10-17 21: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-16 18:52:14 -08:00
|
|
|
static bool
|
2018-07-19 12:29:11 -07:00
|
|
|
__xchk_process_error(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
xfs_agnumber_t agno,
|
|
|
|
xfs_agblock_t bno,
|
|
|
|
int *error,
|
|
|
|
__u32 errflag,
|
|
|
|
void *ret_ip)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
|
|
|
switch (*error) {
|
|
|
|
case 0:
|
|
|
|
return true;
|
|
|
|
case -EDEADLOCK:
|
2023-04-11 19:00:00 -07:00
|
|
|
case -ECHRNG:
|
2017-10-17 21:37:36 -07:00
|
|
|
/* Used to restart an op with deadlock avoidance. */
|
2021-05-12 16:41:13 -07:00
|
|
|
trace_xchk_deadlock_retry(
|
|
|
|
sc->ip ? sc->ip : XFS_I(file_inode(sc->file)),
|
|
|
|
sc->sm, *error);
|
2017-10-17 21:37:36 -07:00
|
|
|
break;
|
2024-02-22 12:30:54 -08:00
|
|
|
case -ECANCELED:
|
|
|
|
/*
|
|
|
|
* ECANCELED here means that the caller set one of the scrub
|
|
|
|
* outcome flags (corrupt, xfail, xcorrupt) and wants to exit
|
|
|
|
* quickly. Set error to zero and do not continue.
|
|
|
|
*/
|
|
|
|
trace_xchk_op_error(sc, agno, bno, *error, ret_ip);
|
|
|
|
*error = 0;
|
|
|
|
break;
|
2017-10-17 21:37:36 -07:00
|
|
|
case -EFSBADCRC:
|
|
|
|
case -EFSCORRUPTED:
|
|
|
|
/* Note the badness but don't abort. */
|
2018-01-16 18:52:14 -08:00
|
|
|
sc->sm->sm_flags |= errflag;
|
2017-10-17 21:37:36 -07:00
|
|
|
*error = 0;
|
2021-04-20 17:54:36 -05:00
|
|
|
fallthrough;
|
2017-10-17 21:37:36 -07:00
|
|
|
default:
|
2024-02-22 12:30:54 -08:00
|
|
|
trace_xchk_op_error(sc, agno, bno, *error, ret_ip);
|
2017-10-17 21:37:36 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_process_error(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
xfs_agnumber_t agno,
|
|
|
|
xfs_agblock_t bno,
|
|
|
|
int *error)
|
2018-01-16 18:52:14 -08:00
|
|
|
{
|
2018-07-19 12:29:11 -07:00
|
|
|
return __xchk_process_error(sc, agno, bno, error,
|
2018-01-16 18:52:14 -08:00
|
|
|
XFS_SCRUB_OFLAG_CORRUPT, __return_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_xref_process_error(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
xfs_agnumber_t agno,
|
|
|
|
xfs_agblock_t bno,
|
|
|
|
int *error)
|
2018-01-16 18:52:14 -08:00
|
|
|
{
|
2018-07-19 12:29:11 -07:00
|
|
|
return __xchk_process_error(sc, agno, bno, error,
|
2018-01-16 18:52:14 -08:00
|
|
|
XFS_SCRUB_OFLAG_XFAIL, __return_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for operational errors for a file offset. */
|
|
|
|
static bool
|
2018-07-19 12:29:11 -07:00
|
|
|
__xchk_fblock_process_error(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset,
|
|
|
|
int *error,
|
|
|
|
__u32 errflag,
|
|
|
|
void *ret_ip)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
|
|
|
switch (*error) {
|
|
|
|
case 0:
|
|
|
|
return true;
|
|
|
|
case -EDEADLOCK:
|
2023-04-11 19:00:00 -07:00
|
|
|
case -ECHRNG:
|
2017-10-17 21:37:36 -07:00
|
|
|
/* Used to restart an op with deadlock avoidance. */
|
2018-07-19 12:29:11 -07:00
|
|
|
trace_xchk_deadlock_retry(sc->ip, sc->sm, *error);
|
2017-10-17 21:37:36 -07:00
|
|
|
break;
|
2024-02-22 12:30:54 -08:00
|
|
|
case -ECANCELED:
|
|
|
|
/*
|
|
|
|
* ECANCELED here means that the caller set one of the scrub
|
|
|
|
* outcome flags (corrupt, xfail, xcorrupt) and wants to exit
|
|
|
|
* quickly. Set error to zero and do not continue.
|
|
|
|
*/
|
|
|
|
trace_xchk_file_op_error(sc, whichfork, offset, *error,
|
|
|
|
ret_ip);
|
|
|
|
*error = 0;
|
|
|
|
break;
|
2017-10-17 21:37:36 -07:00
|
|
|
case -EFSBADCRC:
|
|
|
|
case -EFSCORRUPTED:
|
|
|
|
/* Note the badness but don't abort. */
|
2018-01-16 18:52:14 -08:00
|
|
|
sc->sm->sm_flags |= errflag;
|
2017-10-17 21:37:36 -07:00
|
|
|
*error = 0;
|
2021-04-20 17:54:36 -05:00
|
|
|
fallthrough;
|
2017-10-17 21:37:36 -07:00
|
|
|
default:
|
2018-07-19 12:29:11 -07:00
|
|
|
trace_xchk_file_op_error(sc, whichfork, offset, *error,
|
2018-01-16 18:52:14 -08:00
|
|
|
ret_ip);
|
2017-10-17 21:37:36 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-16 18:52:14 -08:00
|
|
|
bool
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_fblock_process_error(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset,
|
|
|
|
int *error)
|
2018-01-16 18:52:14 -08:00
|
|
|
{
|
2018-07-19 12:29:11 -07:00
|
|
|
return __xchk_fblock_process_error(sc, whichfork, offset, error,
|
2018-01-16 18:52:14 -08:00
|
|
|
XFS_SCRUB_OFLAG_CORRUPT, __return_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_fblock_xref_process_error(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset,
|
|
|
|
int *error)
|
2018-01-16 18:52:14 -08:00
|
|
|
{
|
2018-07-19 12:29:11 -07:00
|
|
|
return __xchk_fblock_process_error(sc, whichfork, offset, error,
|
2018-01-16 18:52:14 -08:00
|
|
|
XFS_SCRUB_OFLAG_XFAIL, __return_address);
|
|
|
|
}
|
|
|
|
|
2017-10-17 21: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-19 12:29:11 -07:00
|
|
|
xchk_block_set_preen(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_buf *bp)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_PREEN;
|
2021-08-18 18:47:05 -07:00
|
|
|
trace_xchk_block_preen(sc, xfs_buf_daddr(bp), __return_address);
|
2017-10-17 21: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-19 12:29:11 -07:00
|
|
|
xchk_ino_set_preen(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
xfs_ino_t ino)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_PREEN;
|
2018-07-19 12:29:11 -07:00
|
|
|
trace_xchk_ino_preen(sc, ino, __return_address);
|
2017-10-17 21:37:36 -07:00
|
|
|
}
|
|
|
|
|
2019-04-25 18:26:24 -07:00
|
|
|
/* Record something being wrong with the filesystem primary superblock. */
|
|
|
|
void
|
|
|
|
xchk_set_corrupt(
|
|
|
|
struct xfs_scrub *sc)
|
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
|
|
|
|
trace_xchk_fs_error(sc, 0, __return_address);
|
|
|
|
}
|
|
|
|
|
2017-10-17 21:37:36 -07:00
|
|
|
/* Record a corrupt block. */
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_block_set_corrupt(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_buf *bp)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
|
2021-08-18 18:47:05 -07:00
|
|
|
trace_xchk_block_error(sc, xfs_buf_daddr(bp), __return_address);
|
2017-10-17 21:37:36 -07:00
|
|
|
}
|
|
|
|
|
2024-02-22 12:30:54 -08:00
|
|
|
#ifdef CONFIG_XFS_QUOTA
|
|
|
|
/* Record a corrupt quota counter. */
|
|
|
|
void
|
|
|
|
xchk_qcheck_set_corrupt(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
unsigned int dqtype,
|
|
|
|
xfs_dqid_t id)
|
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
|
|
|
|
trace_xchk_qcheck_error(sc, dqtype, id, __return_address);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-01-16 18:52:14 -08:00
|
|
|
/* Record a corruption while cross-referencing. */
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_block_xref_set_corrupt(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_buf *bp)
|
2018-01-16 18:52:14 -08:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT;
|
2021-08-18 18:47:05 -07:00
|
|
|
trace_xchk_block_error(sc, xfs_buf_daddr(bp), __return_address);
|
2018-01-16 18:52:14 -08:00
|
|
|
}
|
|
|
|
|
2017-10-17 21: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-19 12:29:11 -07:00
|
|
|
xchk_ino_set_corrupt(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
xfs_ino_t ino)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
|
2018-07-19 12:29:11 -07:00
|
|
|
trace_xchk_ino_error(sc, ino, __return_address);
|
2017-10-17 21:37:36 -07:00
|
|
|
}
|
|
|
|
|
2018-01-16 18:52:14 -08:00
|
|
|
/* Record a corruption while cross-referencing with an inode. */
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ino_xref_set_corrupt(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
xfs_ino_t ino)
|
2018-01-16 18:52:14 -08:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT;
|
2018-07-19 12:29:11 -07:00
|
|
|
trace_xchk_ino_error(sc, ino, __return_address);
|
2018-01-16 18:52:14 -08:00
|
|
|
}
|
|
|
|
|
2017-10-17 21:37:36 -07:00
|
|
|
/* Record corruption in a block indexed by a file fork. */
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_fblock_set_corrupt(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
|
2018-07-19 12:29:11 -07:00
|
|
|
trace_xchk_fblock_error(sc, whichfork, offset, __return_address);
|
2017-10-17 21:37:36 -07:00
|
|
|
}
|
|
|
|
|
2018-01-16 18:52:14 -08:00
|
|
|
/* Record a corruption while cross-referencing a fork block. */
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_fblock_xref_set_corrupt(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset)
|
2018-01-16 18:52:14 -08:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_XCORRUPT;
|
2018-07-19 12:29:11 -07:00
|
|
|
trace_xchk_fblock_error(sc, whichfork, offset, __return_address);
|
2018-01-16 18:52:14 -08:00
|
|
|
}
|
|
|
|
|
2017-10-17 21:37:36 -07:00
|
|
|
/*
|
|
|
|
* Warn about inodes that need administrative review but is not
|
|
|
|
* incorrect.
|
|
|
|
*/
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ino_set_warning(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
xfs_ino_t ino)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_WARNING;
|
2018-07-19 12:29:11 -07:00
|
|
|
trace_xchk_ino_warning(sc, ino, __return_address);
|
2017-10-17 21:37:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Warn about a block indexed by a file fork that needs review. */
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_fblock_set_warning(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
int whichfork,
|
|
|
|
xfs_fileoff_t offset)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_WARNING;
|
2018-07-19 12:29:11 -07:00
|
|
|
trace_xchk_fblock_warning(sc, whichfork, offset, __return_address);
|
2017-10-17 21:37:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Signal an incomplete scrub. */
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_set_incomplete(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_INCOMPLETE;
|
2018-07-19 12:29:11 -07:00
|
|
|
trace_xchk_incomplete(sc, __return_address);
|
2017-10-17 21:37:36 -07:00
|
|
|
}
|
|
|
|
|
2018-01-16 18:53:08 -08:00
|
|
|
/*
|
|
|
|
* rmap scrubbing -- compute the number of blocks with a given owner,
|
|
|
|
* at least according to the reverse mapping data.
|
|
|
|
*/
|
|
|
|
|
2018-07-19 12:29:11 -07:00
|
|
|
struct xchk_rmap_ownedby_info {
|
2018-12-12 08:46:23 -08:00
|
|
|
const struct xfs_owner_info *oinfo;
|
|
|
|
xfs_filblks_t *blocks;
|
2018-01-16 18:53:08 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
STATIC int
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_count_rmap_ownedby_irec(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_btree_cur *cur,
|
2021-08-10 17:02:16 -07:00
|
|
|
const struct xfs_rmap_irec *rec,
|
2018-07-19 12:29:12 -07:00
|
|
|
void *priv)
|
2018-01-16 18:53:08 -08:00
|
|
|
{
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xchk_rmap_ownedby_info *sroi = priv;
|
|
|
|
bool irec_attr;
|
|
|
|
bool oinfo_attr;
|
2018-01-16 18:53:08 -08:00
|
|
|
|
|
|
|
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-19 12:29:11 -07:00
|
|
|
xchk_count_rmap_ownedby_ag(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_btree_cur *cur,
|
2018-12-12 08:46:23 -08:00
|
|
|
const struct xfs_owner_info *oinfo,
|
2018-07-19 12:29:12 -07:00
|
|
|
xfs_filblks_t *blocks)
|
2018-01-16 18:53:08 -08:00
|
|
|
{
|
2018-12-12 08:46:23 -08:00
|
|
|
struct xchk_rmap_ownedby_info sroi = {
|
|
|
|
.oinfo = oinfo,
|
|
|
|
.blocks = blocks,
|
|
|
|
};
|
2018-01-16 18:53:08 -08:00
|
|
|
|
|
|
|
*blocks = 0;
|
2018-07-19 12:29:11 -07:00
|
|
|
return xfs_rmap_query_all(cur, xchk_count_rmap_ownedby_irec,
|
2018-01-16 18:53:08 -08:00
|
|
|
&sroi);
|
|
|
|
}
|
|
|
|
|
2017-10-17 21: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-17 21:37:39 -07:00
|
|
|
/* Decide if we want to return an AG header read failure. */
|
|
|
|
static inline bool
|
|
|
|
want_ag_read_header_failure(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
unsigned int type)
|
2017-10-17 21:37:39 -07:00
|
|
|
{
|
|
|
|
/* Return all AG header read failures when scanning btrees. */
|
|
|
|
if (sc->sm->sm_type != XFS_SCRUB_TYPE_AGF &&
|
2017-10-17 21:37:39 -07:00
|
|
|
sc->sm->sm_type != XFS_SCRUB_TYPE_AGFL &&
|
|
|
|
sc->sm->sm_type != XFS_SCRUB_TYPE_AGI)
|
2017-10-17 21: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-17 21:37:38 -07:00
|
|
|
/*
|
xfs: allow queued AG intents to drain before scrubbing
When a writer thread executes a chain of log intent items, the AG header
buffer locks will cycle during a transaction roll to get from one intent
item to the next in a chain. Although scrub takes all AG header buffer
locks, this isn't sufficient to guard against scrub checking an AG while
that writer thread is in the middle of finishing a chain because there's
no higher level locking primitive guarding allocation groups.
When there's a collision, cross-referencing between data structures
(e.g. rmapbt and refcountbt) yields false corruption events; if repair
is running, this results in incorrect repairs, which is catastrophic.
Fix this by adding to the perag structure the count of active intents
and make scrub wait until it has both AG header buffer locks and the
intent counter reaches zero.
One quirk of the drain code is that deferred bmap updates also bump and
drop the intent counter. A fundamental decision made during the design
phase of the reverse mapping feature is that updates to the rmapbt
records are always made by the same code that updates the primary
metadata. In other words, callers of bmapi functions expect that the
bmapi functions will queue deferred rmap updates.
Some parts of the reflink code queue deferred refcount (CUI) and bmap
(BUI) updates in the same head transaction, but the deferred work
manager completely finishes the CUI before the BUI work is started. As
a result, the CUI drops the intent count long before the deferred rmap
(RUI) update even has a chance to bump the intent count. The only way
to keep the intent count elevated between the CUI and RUI is for the BUI
to bump the counter until the RUI has been created.
A second quirk of the intent drain code is that deferred work items must
increment the intent counter as soon as the work item is added to the
transaction. When a BUI completes and queues an RUI, the RUI must
increment the counter before the BUI decrements it. The only way to
accomplish this is to require that the counter be bumped as soon as the
deferred work item is created in memory.
In the next patches we'll improve on this facility, but this patch
provides the basic functionality.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 18:59:58 -07:00
|
|
|
* Grab the AG header buffers for the attached perag structure.
|
2017-10-17 21:37:38 -07:00
|
|
|
*
|
2021-08-06 11:06:35 -07:00
|
|
|
* The headers should be released by xchk_ag_free, but as a fail safe we attach
|
|
|
|
* all the buffers we grab to the scrub transaction so they'll all be freed
|
xfs: allow queued AG intents to drain before scrubbing
When a writer thread executes a chain of log intent items, the AG header
buffer locks will cycle during a transaction roll to get from one intent
item to the next in a chain. Although scrub takes all AG header buffer
locks, this isn't sufficient to guard against scrub checking an AG while
that writer thread is in the middle of finishing a chain because there's
no higher level locking primitive guarding allocation groups.
When there's a collision, cross-referencing between data structures
(e.g. rmapbt and refcountbt) yields false corruption events; if repair
is running, this results in incorrect repairs, which is catastrophic.
Fix this by adding to the perag structure the count of active intents
and make scrub wait until it has both AG header buffer locks and the
intent counter reaches zero.
One quirk of the drain code is that deferred bmap updates also bump and
drop the intent counter. A fundamental decision made during the design
phase of the reverse mapping feature is that updates to the rmapbt
records are always made by the same code that updates the primary
metadata. In other words, callers of bmapi functions expect that the
bmapi functions will queue deferred rmap updates.
Some parts of the reflink code queue deferred refcount (CUI) and bmap
(BUI) updates in the same head transaction, but the deferred work
manager completely finishes the CUI before the BUI work is started. As
a result, the CUI drops the intent count long before the deferred rmap
(RUI) update even has a chance to bump the intent count. The only way
to keep the intent count elevated between the CUI and RUI is for the BUI
to bump the counter until the RUI has been created.
A second quirk of the intent drain code is that deferred work items must
increment the intent counter as soon as the work item is added to the
transaction. When a BUI completes and queues an RUI, the RUI must
increment the counter before the BUI decrements it. The only way to
accomplish this is to require that the counter be bumped as soon as the
deferred work item is created in memory.
In the next patches we'll improve on this facility, but this patch
provides the basic functionality.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 18:59:58 -07:00
|
|
|
* when we cancel it.
|
2017-10-17 21:37:38 -07:00
|
|
|
*/
|
xfs: allow queued AG intents to drain before scrubbing
When a writer thread executes a chain of log intent items, the AG header
buffer locks will cycle during a transaction roll to get from one intent
item to the next in a chain. Although scrub takes all AG header buffer
locks, this isn't sufficient to guard against scrub checking an AG while
that writer thread is in the middle of finishing a chain because there's
no higher level locking primitive guarding allocation groups.
When there's a collision, cross-referencing between data structures
(e.g. rmapbt and refcountbt) yields false corruption events; if repair
is running, this results in incorrect repairs, which is catastrophic.
Fix this by adding to the perag structure the count of active intents
and make scrub wait until it has both AG header buffer locks and the
intent counter reaches zero.
One quirk of the drain code is that deferred bmap updates also bump and
drop the intent counter. A fundamental decision made during the design
phase of the reverse mapping feature is that updates to the rmapbt
records are always made by the same code that updates the primary
metadata. In other words, callers of bmapi functions expect that the
bmapi functions will queue deferred rmap updates.
Some parts of the reflink code queue deferred refcount (CUI) and bmap
(BUI) updates in the same head transaction, but the deferred work
manager completely finishes the CUI before the BUI work is started. As
a result, the CUI drops the intent count long before the deferred rmap
(RUI) update even has a chance to bump the intent count. The only way
to keep the intent count elevated between the CUI and RUI is for the BUI
to bump the counter until the RUI has been created.
A second quirk of the intent drain code is that deferred work items must
increment the intent counter as soon as the work item is added to the
transaction. When a BUI completes and queues an RUI, the RUI must
increment the counter before the BUI decrements it. The only way to
accomplish this is to require that the counter be bumped as soon as the
deferred work item is created in memory.
In the next patches we'll improve on this facility, but this patch
provides the basic functionality.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 18:59:58 -07:00
|
|
|
static inline int
|
|
|
|
xchk_perag_read_headers(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2021-03-22 09:51:53 -07:00
|
|
|
struct xchk_ag *sa)
|
2017-10-17 21:37:38 -07:00
|
|
|
{
|
2018-07-19 12:29:12 -07:00
|
|
|
int error;
|
2017-10-17 21:37:38 -07:00
|
|
|
|
2024-04-15 14:54:03 -07:00
|
|
|
error = xfs_ialloc_read_agi(sa->pag, sc->tp, 0, &sa->agi_bp);
|
2017-10-17 21:37:39 -07:00
|
|
|
if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGI))
|
2021-08-06 11:06:35 -07:00
|
|
|
return error;
|
2017-10-17 21:37:38 -07:00
|
|
|
|
2022-07-07 19:07:40 +10:00
|
|
|
error = xfs_alloc_read_agf(sa->pag, sc->tp, 0, &sa->agf_bp);
|
2017-10-17 21:37:39 -07:00
|
|
|
if (error && want_ag_read_header_failure(sc, XFS_SCRUB_TYPE_AGF))
|
2021-08-06 11:06:35 -07:00
|
|
|
return error;
|
2017-10-17 21:37:38 -07:00
|
|
|
|
2021-08-06 11:06:35 -07:00
|
|
|
return 0;
|
2017-10-17 21:37:38 -07:00
|
|
|
}
|
|
|
|
|
xfs: allow queued AG intents to drain before scrubbing
When a writer thread executes a chain of log intent items, the AG header
buffer locks will cycle during a transaction roll to get from one intent
item to the next in a chain. Although scrub takes all AG header buffer
locks, this isn't sufficient to guard against scrub checking an AG while
that writer thread is in the middle of finishing a chain because there's
no higher level locking primitive guarding allocation groups.
When there's a collision, cross-referencing between data structures
(e.g. rmapbt and refcountbt) yields false corruption events; if repair
is running, this results in incorrect repairs, which is catastrophic.
Fix this by adding to the perag structure the count of active intents
and make scrub wait until it has both AG header buffer locks and the
intent counter reaches zero.
One quirk of the drain code is that deferred bmap updates also bump and
drop the intent counter. A fundamental decision made during the design
phase of the reverse mapping feature is that updates to the rmapbt
records are always made by the same code that updates the primary
metadata. In other words, callers of bmapi functions expect that the
bmapi functions will queue deferred rmap updates.
Some parts of the reflink code queue deferred refcount (CUI) and bmap
(BUI) updates in the same head transaction, but the deferred work
manager completely finishes the CUI before the BUI work is started. As
a result, the CUI drops the intent count long before the deferred rmap
(RUI) update even has a chance to bump the intent count. The only way
to keep the intent count elevated between the CUI and RUI is for the BUI
to bump the counter until the RUI has been created.
A second quirk of the intent drain code is that deferred work items must
increment the intent counter as soon as the work item is added to the
transaction. When a BUI completes and queues an RUI, the RUI must
increment the counter before the BUI decrements it. The only way to
accomplish this is to require that the counter be bumped as soon as the
deferred work item is created in memory.
In the next patches we'll improve on this facility, but this patch
provides the basic functionality.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 18:59:58 -07:00
|
|
|
/*
|
|
|
|
* Grab the AG headers for the attached perag structure and wait for pending
|
|
|
|
* intents to drain.
|
|
|
|
*/
|
2024-02-22 12:43:38 -08:00
|
|
|
int
|
xfs: allow queued AG intents to drain before scrubbing
When a writer thread executes a chain of log intent items, the AG header
buffer locks will cycle during a transaction roll to get from one intent
item to the next in a chain. Although scrub takes all AG header buffer
locks, this isn't sufficient to guard against scrub checking an AG while
that writer thread is in the middle of finishing a chain because there's
no higher level locking primitive guarding allocation groups.
When there's a collision, cross-referencing between data structures
(e.g. rmapbt and refcountbt) yields false corruption events; if repair
is running, this results in incorrect repairs, which is catastrophic.
Fix this by adding to the perag structure the count of active intents
and make scrub wait until it has both AG header buffer locks and the
intent counter reaches zero.
One quirk of the drain code is that deferred bmap updates also bump and
drop the intent counter. A fundamental decision made during the design
phase of the reverse mapping feature is that updates to the rmapbt
records are always made by the same code that updates the primary
metadata. In other words, callers of bmapi functions expect that the
bmapi functions will queue deferred rmap updates.
Some parts of the reflink code queue deferred refcount (CUI) and bmap
(BUI) updates in the same head transaction, but the deferred work
manager completely finishes the CUI before the BUI work is started. As
a result, the CUI drops the intent count long before the deferred rmap
(RUI) update even has a chance to bump the intent count. The only way
to keep the intent count elevated between the CUI and RUI is for the BUI
to bump the counter until the RUI has been created.
A second quirk of the intent drain code is that deferred work items must
increment the intent counter as soon as the work item is added to the
transaction. When a BUI completes and queues an RUI, the RUI must
increment the counter before the BUI decrements it. The only way to
accomplish this is to require that the counter be bumped as soon as the
deferred work item is created in memory.
In the next patches we'll improve on this facility, but this patch
provides the basic functionality.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 18:59:58 -07:00
|
|
|
xchk_perag_drain_and_lock(
|
|
|
|
struct xfs_scrub *sc)
|
|
|
|
{
|
|
|
|
struct xchk_ag *sa = &sc->sa;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
ASSERT(sa->pag != NULL);
|
|
|
|
ASSERT(sa->agi_bp == NULL);
|
|
|
|
ASSERT(sa->agf_bp == NULL);
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (xchk_should_terminate(sc, &error))
|
|
|
|
return error;
|
|
|
|
|
|
|
|
error = xchk_perag_read_headers(sc, sa);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we've grabbed an inode for scrubbing then we assume that
|
|
|
|
* holding its ILOCK will suffice to coordinate with any intent
|
|
|
|
* chains involving this inode.
|
|
|
|
*/
|
|
|
|
if (sc->ip)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decide if this AG is quiet enough for all metadata to be
|
|
|
|
* consistent with each other. XFS allows the AG header buffer
|
|
|
|
* locks to cycle across transaction rolls while processing
|
|
|
|
* chains of deferred ops, which means that there could be
|
|
|
|
* other threads in the middle of processing a chain of
|
|
|
|
* deferred ops. For regular operations we are careful about
|
|
|
|
* ordering operations to prevent collisions between threads
|
|
|
|
* (which is why we don't need a per-AG lock), but scrub and
|
|
|
|
* repair have to serialize against chained operations.
|
|
|
|
*
|
|
|
|
* We just locked all the AG headers buffers; now take a look
|
|
|
|
* to see if there are any intents in progress. If there are,
|
|
|
|
* drop the AG headers and wait for the intents to drain.
|
|
|
|
* Since we hold all the AG header locks for the duration of
|
|
|
|
* the scrub, this is the only time we have to sample the
|
|
|
|
* intents counter; any threads increasing it after this point
|
|
|
|
* can't possibly be in the middle of a chain of AG metadata
|
|
|
|
* updates.
|
|
|
|
*
|
|
|
|
* Obviously, this should be slanted against scrub and in favor
|
|
|
|
* of runtime threads.
|
|
|
|
*/
|
|
|
|
if (!xfs_perag_intent_busy(sa->pag))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-04-11 18:59:59 -07:00
|
|
|
if (!(sc->flags & XCHK_FSGATES_DRAIN))
|
2023-04-11 19:00:00 -07:00
|
|
|
return -ECHRNG;
|
xfs: allow queued AG intents to drain before scrubbing
When a writer thread executes a chain of log intent items, the AG header
buffer locks will cycle during a transaction roll to get from one intent
item to the next in a chain. Although scrub takes all AG header buffer
locks, this isn't sufficient to guard against scrub checking an AG while
that writer thread is in the middle of finishing a chain because there's
no higher level locking primitive guarding allocation groups.
When there's a collision, cross-referencing between data structures
(e.g. rmapbt and refcountbt) yields false corruption events; if repair
is running, this results in incorrect repairs, which is catastrophic.
Fix this by adding to the perag structure the count of active intents
and make scrub wait until it has both AG header buffer locks and the
intent counter reaches zero.
One quirk of the drain code is that deferred bmap updates also bump and
drop the intent counter. A fundamental decision made during the design
phase of the reverse mapping feature is that updates to the rmapbt
records are always made by the same code that updates the primary
metadata. In other words, callers of bmapi functions expect that the
bmapi functions will queue deferred rmap updates.
Some parts of the reflink code queue deferred refcount (CUI) and bmap
(BUI) updates in the same head transaction, but the deferred work
manager completely finishes the CUI before the BUI work is started. As
a result, the CUI drops the intent count long before the deferred rmap
(RUI) update even has a chance to bump the intent count. The only way
to keep the intent count elevated between the CUI and RUI is for the BUI
to bump the counter until the RUI has been created.
A second quirk of the intent drain code is that deferred work items must
increment the intent counter as soon as the work item is added to the
transaction. When a BUI completes and queues an RUI, the RUI must
increment the counter before the BUI decrements it. The only way to
accomplish this is to require that the counter be bumped as soon as the
deferred work item is created in memory.
In the next patches we'll improve on this facility, but this patch
provides the basic functionality.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 18:59:58 -07:00
|
|
|
error = xfs_perag_intent_drain(sa->pag);
|
|
|
|
if (error == -ERESTARTSYS)
|
|
|
|
error = -EINTR;
|
|
|
|
} while (!error);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab the per-AG structure, grab all AG header buffers, and wait until there
|
|
|
|
* aren't any pending intents. Returns -ENOENT if we can't grab the perag
|
|
|
|
* structure.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xchk_ag_read_headers(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
xfs_agnumber_t agno,
|
|
|
|
struct xchk_ag *sa)
|
|
|
|
{
|
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
|
|
|
|
ASSERT(!sa->pag);
|
|
|
|
sa->pag = xfs_perag_get(mp, agno);
|
|
|
|
if (!sa->pag)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
return xchk_perag_drain_and_lock(sc);
|
|
|
|
}
|
|
|
|
|
2017-10-17 21:37:38 -07:00
|
|
|
/* Release all the AG btree cursors. */
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ag_btcur_free(
|
|
|
|
struct xchk_ag *sa)
|
2017-10-17 21: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. */
|
2021-03-22 09:51:53 -07:00
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ag_btcur_init(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:11 -07:00
|
|
|
struct xchk_ag *sa)
|
2017-10-17 21:37:38 -07:00
|
|
|
{
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
2017-10-17 21:37:38 -07:00
|
|
|
|
2024-02-22 12:39:48 -08:00
|
|
|
if (sa->agf_bp) {
|
2017-10-17 21:37:38 -07:00
|
|
|
/* Set up a bnobt cursor for cross-referencing. */
|
2024-02-22 12:40:12 -08:00
|
|
|
sa->bno_cur = xfs_bnobt_init_cursor(mp, sc->tp, sa->agf_bp,
|
|
|
|
sa->pag);
|
2024-02-22 12:39:48 -08:00
|
|
|
xchk_ag_btree_del_cursor_if_sick(sc, &sa->bno_cur,
|
|
|
|
XFS_SCRUB_TYPE_BNOBT);
|
2017-10-17 21:37:38 -07:00
|
|
|
|
|
|
|
/* Set up a cntbt cursor for cross-referencing. */
|
2024-02-22 12:40:12 -08:00
|
|
|
sa->cnt_cur = xfs_cntbt_init_cursor(mp, sc->tp, sa->agf_bp,
|
|
|
|
sa->pag);
|
2024-02-22 12:39:48 -08:00
|
|
|
xchk_ag_btree_del_cursor_if_sick(sc, &sa->cnt_cur,
|
|
|
|
XFS_SCRUB_TYPE_CNTBT);
|
|
|
|
|
|
|
|
/* Set up a rmapbt cursor for cross-referencing. */
|
|
|
|
if (xfs_has_rmapbt(mp)) {
|
|
|
|
sa->rmap_cur = xfs_rmapbt_init_cursor(mp, sc->tp,
|
|
|
|
sa->agf_bp, sa->pag);
|
|
|
|
xchk_ag_btree_del_cursor_if_sick(sc, &sa->rmap_cur,
|
|
|
|
XFS_SCRUB_TYPE_RMAPBT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up a refcountbt cursor for cross-referencing. */
|
|
|
|
if (xfs_has_reflink(mp)) {
|
|
|
|
sa->refc_cur = xfs_refcountbt_init_cursor(mp, sc->tp,
|
|
|
|
sa->agf_bp, sa->pag);
|
|
|
|
xchk_ag_btree_del_cursor_if_sick(sc, &sa->refc_cur,
|
|
|
|
XFS_SCRUB_TYPE_REFCNTBT);
|
|
|
|
}
|
2017-10-17 21:37:38 -07:00
|
|
|
}
|
|
|
|
|
2024-02-22 12:39:48 -08:00
|
|
|
if (sa->agi_bp) {
|
|
|
|
/* Set up a inobt cursor for cross-referencing. */
|
2024-02-22 12:40:49 -08:00
|
|
|
sa->ino_cur = xfs_inobt_init_cursor(sa->pag, sc->tp,
|
|
|
|
sa->agi_bp);
|
2024-02-22 12:39:48 -08:00
|
|
|
xchk_ag_btree_del_cursor_if_sick(sc, &sa->ino_cur,
|
|
|
|
XFS_SCRUB_TYPE_INOBT);
|
|
|
|
|
|
|
|
/* Set up a finobt cursor for cross-referencing. */
|
|
|
|
if (xfs_has_finobt(mp)) {
|
2024-02-22 12:40:49 -08:00
|
|
|
sa->fino_cur = xfs_finobt_init_cursor(sa->pag, sc->tp,
|
|
|
|
sa->agi_bp);
|
2024-02-22 12:39:48 -08:00
|
|
|
xchk_ag_btree_del_cursor_if_sick(sc, &sa->fino_cur,
|
|
|
|
XFS_SCRUB_TYPE_FINOBT);
|
|
|
|
}
|
2017-10-17 21:37:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the AG header context and btree cursors. */
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ag_free(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:11 -07:00
|
|
|
struct xchk_ag *sa)
|
2017-10-17 21:37:38 -07:00
|
|
|
{
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ag_btcur_free(sa);
|
2023-12-15 10:03:32 -08:00
|
|
|
xrep_reset_perag_resv(sc);
|
2017-10-17 21:37:38 -07:00
|
|
|
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-29 22:24:44 -07:00
|
|
|
if (sa->pag) {
|
|
|
|
xfs_perag_put(sa->pag);
|
|
|
|
sa->pag = NULL;
|
|
|
|
}
|
2017-10-17 21:37:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-08-06 11:06:35 -07:00
|
|
|
* For scrub, grab the perag structure, 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. Returns ENOENT if the perag struct cannot be grabbed.
|
2017-10-17 21:37:38 -07:00
|
|
|
*/
|
|
|
|
int
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ag_init(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
xfs_agnumber_t agno,
|
2018-07-19 12:29:11 -07:00
|
|
|
struct xchk_ag *sa)
|
2017-10-17 21:37:38 -07:00
|
|
|
{
|
2018-07-19 12:29:12 -07:00
|
|
|
int error;
|
2017-10-17 21:37:38 -07:00
|
|
|
|
2021-03-22 09:51:53 -07:00
|
|
|
error = xchk_ag_read_headers(sc, agno, sa);
|
2017-10-17 21:37:38 -07:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2021-03-22 09:51:53 -07:00
|
|
|
xchk_ag_btcur_init(sc, sa);
|
|
|
|
return 0;
|
2017-10-17 21:37:38 -07:00
|
|
|
}
|
|
|
|
|
2017-10-17 21:37:36 -07:00
|
|
|
/* Per-scrubber setup functions */
|
|
|
|
|
2023-04-11 19:00:21 -07:00
|
|
|
void
|
|
|
|
xchk_trans_cancel(
|
|
|
|
struct xfs_scrub *sc)
|
|
|
|
{
|
|
|
|
xfs_trans_cancel(sc->tp);
|
|
|
|
sc->tp = NULL;
|
|
|
|
}
|
|
|
|
|
2024-02-22 12:30:52 -08:00
|
|
|
int
|
|
|
|
xchk_trans_alloc_empty(
|
|
|
|
struct xfs_scrub *sc)
|
|
|
|
{
|
|
|
|
return xfs_trans_alloc_empty(sc->mp, &sc->tp);
|
|
|
|
}
|
|
|
|
|
2018-05-09 10: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-29 22: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-09 10:02:01 -07:00
|
|
|
*/
|
|
|
|
int
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_trans_alloc(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
uint resblks)
|
2018-05-09 10:02:01 -07:00
|
|
|
{
|
2018-05-29 22: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);
|
|
|
|
|
2024-02-22 12:30:52 -08:00
|
|
|
return xchk_trans_alloc_empty(sc);
|
2018-05-09 10:02:01 -07:00
|
|
|
}
|
|
|
|
|
2017-10-17 21:37:36 -07:00
|
|
|
/* Set us up with a transaction and an empty context. */
|
|
|
|
int
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_setup_fs(
|
2021-04-07 17:59:39 -07:00
|
|
|
struct xfs_scrub *sc)
|
2017-10-17 21:37:36 -07:00
|
|
|
{
|
2018-07-19 12:29:12 -07:00
|
|
|
uint resblks;
|
2018-05-29 22:18:08 -07:00
|
|
|
|
2018-07-19 12:29:11 -07:00
|
|
|
resblks = xrep_calc_ag_resblks(sc);
|
2018-07-19 12:29:11 -07:00
|
|
|
return xchk_trans_alloc(sc, resblks);
|
2017-10-17 21:37:36 -07:00
|
|
|
}
|
2017-10-17 21:37:40 -07:00
|
|
|
|
|
|
|
/* Set us up with AG headers and btree cursors. */
|
|
|
|
int
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_setup_ag_btree(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
bool force_log)
|
2017-10-17 21:37:40 -07:00
|
|
|
{
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
int error;
|
2017-10-17 21:37:40 -07:00
|
|
|
|
2017-10-17 21: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-19 12:29:11 -07:00
|
|
|
error = xchk_checkpoint_log(mp);
|
2017-10-17 21:37:40 -07:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2021-04-07 17:59:39 -07:00
|
|
|
error = xchk_setup_fs(sc);
|
2017-10-17 21:37:40 -07:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2018-07-19 12:29:11 -07:00
|
|
|
return xchk_ag_init(sc, sc->sm->sm_agno, &sc->sa);
|
2017-10-17 21:37:40 -07:00
|
|
|
}
|
2017-10-17 21:37:40 -07:00
|
|
|
|
|
|
|
/* Push everything out of the log onto disk. */
|
|
|
|
int
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_checkpoint_log(
|
2017-10-17 21:37:40 -07:00
|
|
|
struct xfs_mount *mp)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
2018-03-13 23:15:28 -07:00
|
|
|
error = xfs_log_force(mp, XFS_LOG_SYNC);
|
2017-10-17 21:37:40 -07:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
xfs_ail_push_all_sync(mp->m_ail);
|
|
|
|
return 0;
|
|
|
|
}
|
2017-10-17 21:37:42 -07:00
|
|
|
|
xfs: manage inode DONTCACHE status at irele time
Right now, there are statements scattered all over the online fsck
codebase about how we can't use XFS_IGET_DONTCACHE because of concerns
about scrub's unusual practice of releasing inodes with transactions
held.
However, iget is the wrong place to handle this -- the DONTCACHE state
doesn't matter at all until we try to *release* the inode, and here we
get things wrong in multiple ways:
First, if we /do/ have a transaction, we must NOT drop the inode,
because the inode could have dirty pages, dropping the inode will
trigger writeback, and writeback can trigger a nested transaction.
Second, if the inode already had an active reference and the DONTCACHE
flag set, the icache hit when scrub grabs another ref will not clear
DONTCACHE. This is sort of by design, since DONTCACHE is now used to
initiate cache drops so that sysadmins can change a file's access mode
between pagecache and DAX.
Third, if we do actually have the last active reference to the inode, we
can set DONTCACHE to avoid polluting the cache. This is the /one/ case
where we actually want that flag.
Create an xchk_irele helper to encode all that logic and switch the
online fsck code to use it. Since this now means that nearly all
scrubbers use the same xfs_iget flags, we can wrap them too.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 19:00:20 -07:00
|
|
|
/* Verify that an inode is allocated ondisk, then return its cached inode. */
|
|
|
|
int
|
|
|
|
xchk_iget(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
xfs_ino_t inum,
|
|
|
|
struct xfs_inode **ipp)
|
|
|
|
{
|
2023-12-06 18:40:54 -08:00
|
|
|
ASSERT(sc->tp != NULL);
|
|
|
|
|
xfs: use dontcache for grabbing inodes during scrub
Back when I wrote commit a03297a0ca9f2, I had thought that we'd be doing
users a favor by only marking inodes dontcache at the end of a scrub
operation, and only if there's only one reference to that inode. This
was more or less true back when I_DONTCACHE was an XFS iflag and the
only thing it did was change the outcome of xfs_fs_drop_inode to 1.
Note: If there are dentries pointing to the inode when scrub finishes,
the inode will have positive i_count and stay around in cache until
dentry reclaim.
But now we have d_mark_dontcache, which cause the inode *and* the
dentries attached to it all to be marked I_DONTCACHE, which means that
we drop the dentries ASAP, which drops the inode ASAP.
This is bad if scrub found problems with the inode, because now they can
be scheduled for inactivation, which can cause inodegc to trip on it and
shut down the filesystem.
Even if the inode isn't bad, this is still suboptimal because phases 3-7
each initiate inode scans. Dropping the inode immediately during phase
3 is silly because phase 5 will reload it and drop it immediately, etc.
It's fine to mark the inodes dontcache, but if there have been accesses
to the file that set up dentries, we should keep them.
I validated this by setting up ftrace to capture xfs_iget_recycle*
tracepoints and ran xfs/285 for 30 seconds. With current djwong-wtf I
saw ~30,000 recycle events. I then dropped the d_mark_dontcache calls
and set XFS_IGET_DONTCACHE, and the recycle events dropped to ~5,000 per
30 seconds.
Therefore, grab the inode with XFS_IGET_DONTCACHE, which only has the
effect of setting I_DONTCACHE for cache misses. Remove the
d_mark_dontcache call that can happen in xchk_irele.
Fixes: a03297a0ca9f2 ("xfs: manage inode DONTCACHE status at irele time")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
2024-04-22 09:48:26 -07:00
|
|
|
return xfs_iget(sc->mp, sc->tp, inum, XCHK_IGET_FLAGS, 0, ipp);
|
xfs: manage inode DONTCACHE status at irele time
Right now, there are statements scattered all over the online fsck
codebase about how we can't use XFS_IGET_DONTCACHE because of concerns
about scrub's unusual practice of releasing inodes with transactions
held.
However, iget is the wrong place to handle this -- the DONTCACHE state
doesn't matter at all until we try to *release* the inode, and here we
get things wrong in multiple ways:
First, if we /do/ have a transaction, we must NOT drop the inode,
because the inode could have dirty pages, dropping the inode will
trigger writeback, and writeback can trigger a nested transaction.
Second, if the inode already had an active reference and the DONTCACHE
flag set, the icache hit when scrub grabs another ref will not clear
DONTCACHE. This is sort of by design, since DONTCACHE is now used to
initiate cache drops so that sysadmins can change a file's access mode
between pagecache and DAX.
Third, if we do actually have the last active reference to the inode, we
can set DONTCACHE to avoid polluting the cache. This is the /one/ case
where we actually want that flag.
Create an xchk_irele helper to encode all that logic and switch the
online fsck code to use it. Since this now means that nearly all
scrubbers use the same xfs_iget flags, we can wrap them too.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 19:00:20 -07:00
|
|
|
}
|
|
|
|
|
2023-04-11 19:00:21 -07:00
|
|
|
/*
|
|
|
|
* Try to grab an inode in a manner that avoids races with physical inode
|
|
|
|
* allocation. If we can't, return the locked AGI buffer so that the caller
|
|
|
|
* can single-step the loading process to see where things went wrong.
|
|
|
|
* Callers must have a valid scrub transaction.
|
|
|
|
*
|
|
|
|
* If the iget succeeds, return 0, a NULL AGI, and the inode.
|
|
|
|
*
|
|
|
|
* If the iget fails, return the error, the locked AGI, and a NULL inode. This
|
|
|
|
* can include -EINVAL and -ENOENT for invalid inode numbers or inodes that are
|
|
|
|
* no longer allocated; or any other corruption or runtime error.
|
|
|
|
*
|
|
|
|
* If the AGI read fails, return the error, a NULL AGI, and NULL inode.
|
|
|
|
*
|
|
|
|
* If a fatal signal is pending, return -EINTR, a NULL AGI, and a NULL inode.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xchk_iget_agi(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
xfs_ino_t inum,
|
|
|
|
struct xfs_buf **agi_bpp,
|
|
|
|
struct xfs_inode **ipp)
|
|
|
|
{
|
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
struct xfs_trans *tp = sc->tp;
|
|
|
|
struct xfs_perag *pag;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
ASSERT(sc->tp != NULL);
|
|
|
|
|
|
|
|
again:
|
|
|
|
*agi_bpp = NULL;
|
|
|
|
*ipp = NULL;
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
if (xchk_should_terminate(sc, &error))
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach the AGI buffer to the scrub transaction to avoid deadlocks
|
|
|
|
* in the iget cache miss path.
|
|
|
|
*/
|
|
|
|
pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, inum));
|
2024-04-15 14:54:03 -07:00
|
|
|
error = xfs_ialloc_read_agi(pag, tp, 0, agi_bpp);
|
2023-04-11 19:00:21 -07:00
|
|
|
xfs_perag_put(pag);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
xfs: use dontcache for grabbing inodes during scrub
Back when I wrote commit a03297a0ca9f2, I had thought that we'd be doing
users a favor by only marking inodes dontcache at the end of a scrub
operation, and only if there's only one reference to that inode. This
was more or less true back when I_DONTCACHE was an XFS iflag and the
only thing it did was change the outcome of xfs_fs_drop_inode to 1.
Note: If there are dentries pointing to the inode when scrub finishes,
the inode will have positive i_count and stay around in cache until
dentry reclaim.
But now we have d_mark_dontcache, which cause the inode *and* the
dentries attached to it all to be marked I_DONTCACHE, which means that
we drop the dentries ASAP, which drops the inode ASAP.
This is bad if scrub found problems with the inode, because now they can
be scheduled for inactivation, which can cause inodegc to trip on it and
shut down the filesystem.
Even if the inode isn't bad, this is still suboptimal because phases 3-7
each initiate inode scans. Dropping the inode immediately during phase
3 is silly because phase 5 will reload it and drop it immediately, etc.
It's fine to mark the inodes dontcache, but if there have been accesses
to the file that set up dentries, we should keep them.
I validated this by setting up ftrace to capture xfs_iget_recycle*
tracepoints and ran xfs/285 for 30 seconds. With current djwong-wtf I
saw ~30,000 recycle events. I then dropped the d_mark_dontcache calls
and set XFS_IGET_DONTCACHE, and the recycle events dropped to ~5,000 per
30 seconds.
Therefore, grab the inode with XFS_IGET_DONTCACHE, which only has the
effect of setting I_DONTCACHE for cache misses. Remove the
d_mark_dontcache call that can happen in xchk_irele.
Fixes: a03297a0ca9f2 ("xfs: manage inode DONTCACHE status at irele time")
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
2024-04-22 09:48:26 -07:00
|
|
|
error = xfs_iget(mp, tp, inum, XFS_IGET_NORETRY | XCHK_IGET_FLAGS, 0,
|
|
|
|
ipp);
|
2023-04-11 19:00:21 -07:00
|
|
|
if (error == -EAGAIN) {
|
|
|
|
/*
|
|
|
|
* The inode may be in core but temporarily unavailable and may
|
|
|
|
* require the AGI buffer before it can be returned. Drop the
|
|
|
|
* AGI buffer and retry the lookup.
|
|
|
|
*
|
|
|
|
* Incore lookup will fail with EAGAIN on a cache hit if the
|
|
|
|
* inode is queued to the inactivation list. The inactivation
|
|
|
|
* worker may remove the inode from the unlinked list and hence
|
|
|
|
* needs the AGI.
|
|
|
|
*
|
|
|
|
* Hence xchk_iget_agi() needs to drop the AGI lock on EAGAIN
|
|
|
|
* to allow inodegc to make progress and move the inode to
|
|
|
|
* IRECLAIMABLE state where xfs_iget will be able to return it
|
|
|
|
* again if it can lock the inode.
|
|
|
|
*/
|
|
|
|
xfs_trans_brelse(tp, *agi_bpp);
|
|
|
|
delay(1);
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* We got the inode, so we can release the AGI. */
|
|
|
|
ASSERT(*ipp != NULL);
|
|
|
|
xfs_trans_brelse(tp, *agi_bpp);
|
|
|
|
*agi_bpp = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-12-15 10:03:34 -08:00
|
|
|
#ifdef CONFIG_XFS_QUOTA
|
|
|
|
/*
|
|
|
|
* Try to attach dquots to this inode if we think we might want to repair it.
|
|
|
|
* Callers must not hold any ILOCKs. If the dquots are broken and cannot be
|
|
|
|
* attached, a quotacheck will be scheduled.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xchk_ino_dqattach(
|
|
|
|
struct xfs_scrub *sc)
|
|
|
|
{
|
|
|
|
ASSERT(sc->tp != NULL);
|
|
|
|
ASSERT(sc->ip != NULL);
|
|
|
|
|
|
|
|
if (!xchk_could_repair(sc))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return xrep_ino_dqattach(sc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-04-11 19:00:21 -07:00
|
|
|
/* Install an inode that we opened by handle for scrubbing. */
|
xfs: retain the AGI when we can't iget an inode to scrub the core
xchk_get_inode is not quite the right function to be calling from the
inode scrubber setup function. The common get_inode function either
gets an inode and installs it in the scrub context, or it returns an
error code explaining what happened. This is acceptable for most file
scrubbers because it is not in their scope to fix corruptions in the
inode core and fork areas that cause iget to fail.
Dealing with these problems is within the scope of the inode scrubber,
however. If iget fails with EFSCORRUPTED, we need to xchk_inode to flag
that as corruption. Since we can't get our hands on an incore inode, we
need to hold the AGI to prevent inode allocation activity so that
nothing changes in the inode metadata.
Looking ahead to the inode core repair patches, we will also need to
hold the AGI buffer into xrep_inode so that we can make modifications to
the xfs_dinode structure without any other thread swooping in to
allocate or free the inode.
Adapt the xchk_get_inode into xchk_setup_inode since this is a one-off
use case where the error codes we check for are a little different, and
the return state is much different from the common function.
xchk_setup_inode prepares to check or repair an inode record, so it must
continue the scrub operation even if the inode/inobt verifiers cause
xfs_iget to return EFSCORRUPTED. This is done by attaching the locked
AGI buffer to the scrub transaction and returning 0 to move on to the
actual scrub. (Later, the online inode repair code will also want the
xfs_imap structure so that it can reset the ondisk xfs_dinode
structure.)
xchk_get_inode retrieves an inode on behalf of a scrubber that operates
on an incore inode -- data/attr/cow forks, directories, xattrs,
symlinks, parent pointers, etc. If the inode/inobt verifiers fail and
xfs_iget returns EFSCORRUPTED, we want to exit to userspace (because the
caller should be fix the inode first) and drop everything we acquired
along the way.
A behavior common to both functions is that it's possible that xfs_scrub
asked for a scrub-by-handle concurrent with the inode being freed or the
passed-in inumber is invalid. In this case, we call xfs_imap to see if
the inobt index thinks the inode is allocated, and return ENOENT
("nothing to check here") to userspace if this is not the case. The
imap lookup is why both functions call xchk_iget_agi.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 19:00:22 -07:00
|
|
|
int
|
2023-04-11 19:00:21 -07:00
|
|
|
xchk_install_handle_inode(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
if (VFS_I(ip)->i_generation != sc->sm->sm_gen) {
|
|
|
|
xchk_irele(sc, ip);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->ip = ip;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-08-10 07:48:08 -07:00
|
|
|
/*
|
|
|
|
* Install an already-referenced inode for scrubbing. Get our own reference to
|
|
|
|
* the inode to make disposal simpler. The inode must not be in I_FREEING or
|
|
|
|
* I_WILL_FREE state!
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
xchk_install_live_inode(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
struct xfs_inode *ip)
|
|
|
|
{
|
|
|
|
if (!igrab(VFS_I(ip))) {
|
|
|
|
xchk_ino_set_corrupt(sc, ip->i_ino);
|
|
|
|
return -EFSCORRUPTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->ip = ip;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-17 21:37:42 -07:00
|
|
|
/*
|
2023-04-11 19:00:21 -07:00
|
|
|
* In preparation to scrub metadata structures that hang off of an inode,
|
|
|
|
* grab either the inode referenced in the scrub control structure or the
|
|
|
|
* inode passed in. If the inumber does not reference an allocated inode
|
|
|
|
* record, the function returns ENOENT to end the scrub early. The inode
|
|
|
|
* is not locked.
|
2017-10-17 21:37:42 -07:00
|
|
|
*/
|
|
|
|
int
|
2023-04-11 19:00:21 -07:00
|
|
|
xchk_iget_for_scrubbing(
|
2021-04-07 17:59:39 -07:00
|
|
|
struct xfs_scrub *sc)
|
2017-10-17 21:37:42 -07:00
|
|
|
{
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_imap imap;
|
|
|
|
struct xfs_mount *mp = sc->mp;
|
2023-02-13 09:14:52 +11:00
|
|
|
struct xfs_perag *pag;
|
2023-04-11 19:00:21 -07:00
|
|
|
struct xfs_buf *agi_bp;
|
2021-04-07 17:59:39 -07:00
|
|
|
struct xfs_inode *ip_in = XFS_I(file_inode(sc->file));
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_inode *ip = NULL;
|
2023-04-11 19:00:21 -07:00
|
|
|
xfs_agnumber_t agno = XFS_INO_TO_AGNO(mp, sc->sm->sm_ino);
|
2018-07-19 12:29:12 -07:00
|
|
|
int error;
|
2017-10-17 21:37:42 -07:00
|
|
|
|
2023-04-11 19:00:21 -07:00
|
|
|
ASSERT(sc->tp == NULL);
|
|
|
|
|
2017-10-17 21:37:42 -07:00
|
|
|
/* We want to scan the inode we already had opened. */
|
2023-08-10 07:48:08 -07:00
|
|
|
if (sc->sm->sm_ino == 0 || sc->sm->sm_ino == ip_in->i_ino)
|
|
|
|
return xchk_install_live_inode(sc, ip_in);
|
2017-10-17 21:37:42 -07:00
|
|
|
|
2023-04-11 19:00:21 -07:00
|
|
|
/* Reject internal metadata files and obviously bad inode numbers. */
|
2017-10-17 21:37:42 -07:00
|
|
|
if (xfs_internal_inum(mp, sc->sm->sm_ino))
|
|
|
|
return -ENOENT;
|
2023-04-11 19:00:21 -07:00
|
|
|
if (!xfs_verify_ino(sc->mp, sc->sm->sm_ino))
|
|
|
|
return -ENOENT;
|
|
|
|
|
2023-12-06 18:40:54 -08:00
|
|
|
/* Try a safe untrusted iget. */
|
|
|
|
error = xchk_iget_safe(sc, sc->sm->sm_ino, &ip);
|
2023-04-11 19:00:21 -07:00
|
|
|
if (!error)
|
|
|
|
return xchk_install_handle_inode(sc, ip);
|
|
|
|
if (error == -ENOENT)
|
2017-10-17 21:37:42 -07:00
|
|
|
return error;
|
2023-04-11 19:00:21 -07:00
|
|
|
if (error != -EINVAL)
|
|
|
|
goto out_error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* EINVAL with IGET_UNTRUSTED probably means one of several things:
|
|
|
|
* userspace gave us an inode number that doesn't correspond to fs
|
|
|
|
* space; the inode btree lacks a record for this inode; or there is a
|
|
|
|
* record, and it says this inode is free.
|
|
|
|
*
|
|
|
|
* We want to look up this inode in the inobt to distinguish two
|
|
|
|
* scenarios: (1) the inobt says the inode is free, in which case
|
|
|
|
* there's nothing to do; and (2) the inobt says the inode is
|
|
|
|
* allocated, but loading it failed due to corruption.
|
|
|
|
*
|
|
|
|
* Allocate a transaction and grab the AGI to prevent inobt activity
|
|
|
|
* in this AG. Retry the iget in case someone allocated a new inode
|
|
|
|
* after the first iget failed.
|
|
|
|
*/
|
|
|
|
error = xchk_trans_alloc(sc, 0);
|
|
|
|
if (error)
|
|
|
|
goto out_error;
|
|
|
|
|
|
|
|
error = xchk_iget_agi(sc, sc->sm->sm_ino, &agi_bp, &ip);
|
|
|
|
if (error == 0) {
|
|
|
|
/* Actually got the inode, so install it. */
|
|
|
|
xchk_trans_cancel(sc);
|
|
|
|
return xchk_install_handle_inode(sc, ip);
|
2017-10-17 21:37:42 -07:00
|
|
|
}
|
2023-04-11 19:00:21 -07:00
|
|
|
if (error == -ENOENT)
|
|
|
|
goto out_gone;
|
|
|
|
if (error != -EINVAL)
|
|
|
|
goto out_cancel;
|
|
|
|
|
|
|
|
/* Ensure that we have protected against inode allocation/freeing. */
|
|
|
|
if (agi_bp == NULL) {
|
|
|
|
ASSERT(agi_bp != NULL);
|
|
|
|
error = -ECANCELED;
|
|
|
|
goto out_cancel;
|
2017-10-17 21:37:42 -07:00
|
|
|
}
|
|
|
|
|
2023-04-11 19:00:21 -07:00
|
|
|
/*
|
|
|
|
* Untrusted iget failed a second time. Let's try an inobt lookup.
|
|
|
|
* If the inobt thinks this the inode neither can exist inside the
|
|
|
|
* filesystem nor is allocated, return ENOENT to signal that the check
|
|
|
|
* can be skipped.
|
|
|
|
*
|
|
|
|
* If the lookup returns corruption, we'll mark this inode corrupt and
|
|
|
|
* exit to userspace. There's little chance of fixing anything until
|
|
|
|
* the inobt is straightened out, but there's nothing we can do here.
|
|
|
|
*
|
|
|
|
* If the lookup encounters any other error, exit to userspace.
|
|
|
|
*
|
|
|
|
* If the lookup succeeds, something else must be very wrong in the fs
|
|
|
|
* such that setting up the incore inode failed in some strange way.
|
|
|
|
* Treat those as corruptions.
|
|
|
|
*/
|
|
|
|
pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, sc->sm->sm_ino));
|
|
|
|
if (!pag) {
|
|
|
|
error = -EFSCORRUPTED;
|
|
|
|
goto out_cancel;
|
|
|
|
}
|
|
|
|
|
|
|
|
error = xfs_imap(pag, sc->tp, sc->sm->sm_ino, &imap,
|
|
|
|
XFS_IGET_UNTRUSTED);
|
|
|
|
xfs_perag_put(pag);
|
|
|
|
if (error == -EINVAL || error == -ENOENT)
|
|
|
|
goto out_gone;
|
|
|
|
if (!error)
|
|
|
|
error = -EFSCORRUPTED;
|
|
|
|
|
|
|
|
out_cancel:
|
|
|
|
xchk_trans_cancel(sc);
|
|
|
|
out_error:
|
|
|
|
trace_xchk_op_error(sc, agno, XFS_INO_TO_AGBNO(mp, sc->sm->sm_ino),
|
|
|
|
error, __return_address);
|
|
|
|
return error;
|
|
|
|
out_gone:
|
|
|
|
/* The file is gone, so there's nothing to check. */
|
|
|
|
xchk_trans_cancel(sc);
|
|
|
|
return -ENOENT;
|
2017-10-17 21:37:42 -07:00
|
|
|
}
|
2017-10-17 21:37:44 -07:00
|
|
|
|
xfs: manage inode DONTCACHE status at irele time
Right now, there are statements scattered all over the online fsck
codebase about how we can't use XFS_IGET_DONTCACHE because of concerns
about scrub's unusual practice of releasing inodes with transactions
held.
However, iget is the wrong place to handle this -- the DONTCACHE state
doesn't matter at all until we try to *release* the inode, and here we
get things wrong in multiple ways:
First, if we /do/ have a transaction, we must NOT drop the inode,
because the inode could have dirty pages, dropping the inode will
trigger writeback, and writeback can trigger a nested transaction.
Second, if the inode already had an active reference and the DONTCACHE
flag set, the icache hit when scrub grabs another ref will not clear
DONTCACHE. This is sort of by design, since DONTCACHE is now used to
initiate cache drops so that sysadmins can change a file's access mode
between pagecache and DAX.
Third, if we do actually have the last active reference to the inode, we
can set DONTCACHE to avoid polluting the cache. This is the /one/ case
where we actually want that flag.
Create an xchk_irele helper to encode all that logic and switch the
online fsck code to use it. Since this now means that nearly all
scrubbers use the same xfs_iget flags, we can wrap them too.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 19:00:20 -07:00
|
|
|
/* Release an inode, possibly dropping it in the process. */
|
|
|
|
void
|
|
|
|
xchk_irele(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
struct xfs_inode *ip)
|
|
|
|
{
|
xfs: don't use current->journal_info
syzbot reported an ext4 panic during a page fault where found a
journal handle when it didn't expect to find one. The structure
it tripped over had a value of 'TRAN' in the first entry in the
structure, and that indicates it tripped over a struct xfs_trans
instead of a jbd2 handle.
The reason for this is that the page fault was taken during a
copy-out to a user buffer from an xfs bulkstat operation. XFS uses
an "empty" transaction context for bulkstat to do automated metadata
buffer cleanup, and so the transaction context is valid across the
copyout of the bulkstat info into the user buffer.
We are using empty transaction contexts like this in XFS to reduce
the risk of failing to release objects we reference during the
operation, especially during error handling. Hence we really need to
ensure that we can take page faults from these contexts without
leaving landmines for the code processing the page fault to trip
over.
However, this same behaviour could happen from any other filesystem
that triggers a page fault or any other exception that is handled
on-stack from within a task context that has current->journal_info
set. Having a page fault from some other filesystem bounce into XFS
where we have to run a transaction isn't a bug at all, but the usage
of current->journal_info means that this could result corruption of
the outer task's journal_info structure.
The problem is purely that we now have two different contexts that
now think they own current->journal_info. IOWs, no filesystem can
allow page faults or on-stack exceptions while current->journal_info
is set by the filesystem because the exception processing might use
current->journal_info itself.
If we end up with nested XFS transactions whilst holding an empty
transaction, then it isn't an issue as the outer transaction does
not hold a log reservation. If we ignore the current->journal_info
usage, then the only problem that might occur is a deadlock if the
exception tries to take the same locks the upper context holds.
That, however, is not a problem that setting current->journal_info
would solve, so it's largely an irrelevant concern here.
IOWs, we really only use current->journal_info for a warning check
in xfs_vm_writepages() to ensure we aren't doing writeback from a
transaction context. Writeback might need to do allocation, so it
can need to run transactions itself. Hence it's a debug check to
warn us that we've done something silly, and largely it is not all
that useful.
So let's just remove all the use of current->journal_info in XFS and
get rid of all the potential issues from nested contexts where
current->journal_info might get misused by another filesystem
context.
Reported-by: syzbot+cdee56dbcdf0096ef605@syzkaller.appspotmail.com
Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: "Darrick J. Wong" <djwong@kernel.org>
Reviewed-by: Mark Tinguely <mark.tinguely@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Chandan Babu R <chandanbabu@kernel.org>
2024-03-19 09:36:28 +11:00
|
|
|
if (sc->tp) {
|
xfs: manage inode DONTCACHE status at irele time
Right now, there are statements scattered all over the online fsck
codebase about how we can't use XFS_IGET_DONTCACHE because of concerns
about scrub's unusual practice of releasing inodes with transactions
held.
However, iget is the wrong place to handle this -- the DONTCACHE state
doesn't matter at all until we try to *release* the inode, and here we
get things wrong in multiple ways:
First, if we /do/ have a transaction, we must NOT drop the inode,
because the inode could have dirty pages, dropping the inode will
trigger writeback, and writeback can trigger a nested transaction.
Second, if the inode already had an active reference and the DONTCACHE
flag set, the icache hit when scrub grabs another ref will not clear
DONTCACHE. This is sort of by design, since DONTCACHE is now used to
initiate cache drops so that sysadmins can change a file's access mode
between pagecache and DAX.
Third, if we do actually have the last active reference to the inode, we
can set DONTCACHE to avoid polluting the cache. This is the /one/ case
where we actually want that flag.
Create an xchk_irele helper to encode all that logic and switch the
online fsck code to use it. Since this now means that nearly all
scrubbers use the same xfs_iget flags, we can wrap them too.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-04-11 19:00:20 -07:00
|
|
|
/*
|
|
|
|
* If we are in a transaction, we /cannot/ drop the inode
|
|
|
|
* ourselves, because the VFS will trigger writeback, which
|
|
|
|
* can require a transaction. Clear DONTCACHE to force the
|
|
|
|
* inode to the LRU, where someone else can take care of
|
|
|
|
* dropping it.
|
|
|
|
*
|
|
|
|
* Note that when we grabbed our reference to the inode, it
|
|
|
|
* could have had an active ref and DONTCACHE set if a sysadmin
|
|
|
|
* is trying to coerce a change in file access mode. icache
|
|
|
|
* hits do not clear DONTCACHE, so we must do it here.
|
|
|
|
*/
|
|
|
|
spin_lock(&VFS_I(ip)->i_lock);
|
|
|
|
VFS_I(ip)->i_state &= ~I_DONTCACHE;
|
|
|
|
spin_unlock(&VFS_I(ip)->i_lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
xfs_irele(ip);
|
|
|
|
}
|
|
|
|
|
2023-04-11 19:00:22 -07:00
|
|
|
/*
|
|
|
|
* Set us up to scrub metadata mapped by a file's fork. Callers must not use
|
|
|
|
* this to operate on user-accessible regular file data because the MMAPLOCK is
|
|
|
|
* not taken.
|
|
|
|
*/
|
2017-10-17 21:37:44 -07:00
|
|
|
int
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_setup_inode_contents(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
unsigned int resblks)
|
2017-10-17 21:37:44 -07:00
|
|
|
{
|
2018-07-19 12:29:12 -07:00
|
|
|
int error;
|
2017-10-17 21:37:44 -07:00
|
|
|
|
2023-04-11 19:00:21 -07:00
|
|
|
error = xchk_iget_for_scrubbing(sc);
|
2017-10-17 21:37:44 -07:00
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
2023-04-11 19:00:22 -07:00
|
|
|
/* Lock the inode so the VFS cannot touch this file. */
|
2023-08-10 07:48:08 -07:00
|
|
|
xchk_ilock(sc, XFS_IOLOCK_EXCL);
|
2023-04-11 19:00:22 -07:00
|
|
|
|
2018-07-19 12:29:11 -07:00
|
|
|
error = xchk_trans_alloc(sc, resblks);
|
2017-10-17 21:37:44 -07:00
|
|
|
if (error)
|
|
|
|
goto out;
|
2023-12-15 10:03:34 -08:00
|
|
|
|
|
|
|
error = xchk_ino_dqattach(sc);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
|
2023-08-10 07:48:08 -07:00
|
|
|
xchk_ilock(sc, XFS_ILOCK_EXCL);
|
2017-10-17 21:37:44 -07:00
|
|
|
out:
|
|
|
|
/* scrub teardown will unlock and release the inode for us */
|
|
|
|
return error;
|
|
|
|
}
|
2018-01-16 18:52:14 -08:00
|
|
|
|
2023-08-10 07:48:08 -07:00
|
|
|
void
|
|
|
|
xchk_ilock(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
unsigned int ilock_flags)
|
|
|
|
{
|
|
|
|
xfs_ilock(sc->ip, ilock_flags);
|
|
|
|
sc->ilock_flags |= ilock_flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
xchk_ilock_nowait(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
unsigned int ilock_flags)
|
|
|
|
{
|
|
|
|
if (xfs_ilock_nowait(sc->ip, ilock_flags)) {
|
|
|
|
sc->ilock_flags |= ilock_flags;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xchk_iunlock(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
unsigned int ilock_flags)
|
|
|
|
{
|
|
|
|
sc->ilock_flags &= ~ilock_flags;
|
|
|
|
xfs_iunlock(sc->ip, ilock_flags);
|
|
|
|
}
|
|
|
|
|
2018-01-16 18:52:14 -08: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-19 12:29:11 -07:00
|
|
|
xchk_should_check_xref(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
int *error,
|
|
|
|
struct xfs_btree_cur **curpp)
|
2018-01-16 18:52:14 -08:00
|
|
|
{
|
2018-05-14 06:34:31 -07:00
|
|
|
/* No point in xref if we already know we're corrupt. */
|
2018-07-19 12:29:11 -07:00
|
|
|
if (xchk_skip_xref(sc->sm))
|
2018-05-14 06:34:31 -07:00
|
|
|
return false;
|
|
|
|
|
2018-01-16 18:52:14 -08: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-19 12:29:11 -07:00
|
|
|
trace_xchk_xref_error(sc, *error, __return_address);
|
2018-01-16 18:52:14 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Errors encountered during cross-referencing with another
|
|
|
|
* data structure should not cause this scrubber to abort.
|
|
|
|
*/
|
|
|
|
*error = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2018-01-16 18:53:11 -08:00
|
|
|
|
|
|
|
/* Run the structure verifiers on in-memory buffers to detect bad memory. */
|
|
|
|
void
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_buffer_recheck(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc,
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_buf *bp)
|
2018-01-16 18:53:11 -08:00
|
|
|
{
|
2018-07-19 12:29:12 -07:00
|
|
|
xfs_failaddr_t fa;
|
2018-01-16 18:53:11 -08:00
|
|
|
|
|
|
|
if (bp->b_ops == NULL) {
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_block_set_corrupt(sc, bp);
|
2018-01-16 18:53:11 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (bp->b_ops->verify_struct == NULL) {
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_set_incomplete(sc);
|
2018-01-16 18:53:11 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
fa = bp->b_ops->verify_struct(bp);
|
|
|
|
if (!fa)
|
|
|
|
return;
|
|
|
|
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
|
2021-08-18 18:47:05 -07:00
|
|
|
trace_xchk_block_error(sc, xfs_buf_daddr(bp), fa);
|
2018-01-16 18:53:11 -08:00
|
|
|
}
|
2018-05-14 06:34:33 -07:00
|
|
|
|
2022-11-16 16:08:03 -08:00
|
|
|
static inline int
|
|
|
|
xchk_metadata_inode_subtype(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
unsigned int scrub_type)
|
|
|
|
{
|
2024-04-15 14:55:06 -07:00
|
|
|
struct xfs_scrub_subord *sub;
|
2022-11-16 16:08:03 -08:00
|
|
|
int error;
|
|
|
|
|
2024-04-15 14:55:06 -07:00
|
|
|
sub = xchk_scrub_create_subord(sc, scrub_type);
|
|
|
|
error = sub->sc.ops->scrub(&sub->sc);
|
|
|
|
xchk_scrub_free_subord(sub);
|
2022-11-16 16:08:03 -08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2018-05-14 06: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-19 12:29:11 -07:00
|
|
|
xchk_metadata_inode_forks(
|
2018-07-19 12:29:12 -07:00
|
|
|
struct xfs_scrub *sc)
|
2018-05-14 06:34:33 -07:00
|
|
|
{
|
2018-07-19 12:29:12 -07:00
|
|
|
bool shared;
|
|
|
|
int error;
|
2018-05-14 06:34:33 -07:00
|
|
|
|
|
|
|
if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
|
|
|
|
return 0;
|
|
|
|
|
2022-11-16 16:08:03 -08:00
|
|
|
/* Check the inode record. */
|
|
|
|
error = xchk_metadata_inode_subtype(sc, XFS_SCRUB_TYPE_INODE);
|
|
|
|
if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
|
|
|
|
return error;
|
|
|
|
|
2018-05-14 06:34:33 -07:00
|
|
|
/* Metadata inodes don't live on the rt device. */
|
2021-03-29 11:11:44 -07:00
|
|
|
if (sc->ip->i_diflags & XFS_DIFLAG_REALTIME) {
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ino_set_corrupt(sc, sc->ip->i_ino);
|
2018-05-14 06:34:33 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* They should never participate in reflink. */
|
|
|
|
if (xfs_is_reflink_inode(sc->ip)) {
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ino_set_corrupt(sc, sc->ip->i_ino);
|
2018-05-14 06:34:33 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* They also should never have extended attributes. */
|
|
|
|
if (xfs_inode_hasattr(sc->ip)) {
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ino_set_corrupt(sc, sc->ip->i_ino);
|
2018-05-14 06:34:33 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Invoke the data fork scrubber. */
|
2022-11-16 16:08:03 -08:00
|
|
|
error = xchk_metadata_inode_subtype(sc, XFS_SCRUB_TYPE_BMBTD);
|
2018-05-14 06:34:33 -07:00
|
|
|
if (error || (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT))
|
|
|
|
return error;
|
|
|
|
|
|
|
|
/* Look for incorrect shared blocks. */
|
2021-08-18 18:46:37 -07:00
|
|
|
if (xfs_has_reflink(sc->mp)) {
|
2018-05-14 06:34:33 -07:00
|
|
|
error = xfs_reflink_inode_has_shared_extents(sc->tp, sc->ip,
|
|
|
|
&shared);
|
2018-07-19 12:29:11 -07:00
|
|
|
if (!xchk_fblock_process_error(sc, XFS_DATA_FORK, 0,
|
2018-05-14 06:34:33 -07:00
|
|
|
&error))
|
|
|
|
return error;
|
|
|
|
if (shared)
|
2018-07-19 12:29:11 -07:00
|
|
|
xchk_ino_set_corrupt(sc, sc->ip->i_ino);
|
2018-05-14 06:34:33 -07:00
|
|
|
}
|
|
|
|
|
2022-11-16 16:08:03 -08:00
|
|
|
return 0;
|
2018-05-14 06:34:33 -07:00
|
|
|
}
|
2018-05-14 06:34:34 -07:00
|
|
|
|
2023-04-11 18:59:59 -07:00
|
|
|
/*
|
|
|
|
* Enable filesystem hooks (i.e. runtime code patching) before starting a scrub
|
|
|
|
* operation. Callers must not hold any locks that intersect with the CPU
|
|
|
|
* hotplug lock (e.g. writeback locks) because code patching must halt the CPUs
|
|
|
|
* to change kernel code.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
xchk_fsgates_enable(
|
|
|
|
struct xfs_scrub *sc,
|
|
|
|
unsigned int scrub_fsgates)
|
|
|
|
{
|
|
|
|
ASSERT(!(scrub_fsgates & ~XCHK_FSGATES_ALL));
|
|
|
|
ASSERT(!(sc->flags & scrub_fsgates));
|
|
|
|
|
|
|
|
trace_xchk_fsgates_enable(sc, scrub_fsgates);
|
|
|
|
|
|
|
|
if (scrub_fsgates & XCHK_FSGATES_DRAIN)
|
|
|
|
xfs_drain_wait_enable();
|
|
|
|
|
2024-02-22 12:30:55 -08:00
|
|
|
if (scrub_fsgates & XCHK_FSGATES_QUOTA)
|
|
|
|
xfs_dqtrx_hook_enable();
|
|
|
|
|
2024-02-22 12:30:59 -08:00
|
|
|
if (scrub_fsgates & XCHK_FSGATES_DIRENTS)
|
|
|
|
xfs_dir_hook_enable();
|
|
|
|
|
2024-02-22 12:43:40 -08:00
|
|
|
if (scrub_fsgates & XCHK_FSGATES_RMAP)
|
|
|
|
xfs_rmap_hook_enable();
|
|
|
|
|
2023-04-11 18:59:59 -07:00
|
|
|
sc->flags |= scrub_fsgates;
|
|
|
|
}
|
2023-08-10 07:48:12 -07:00
|
|
|
|
|
|
|
/*
|
xfs: rewrite xchk_inode_is_allocated to work properly
Back in the mists of time[1], I proposed this function to assist the
inode btree scrubbers in checking the inode btree contents against the
allocation state of the inode records. The original version performed a
direct lookup in the inode cache and returned the allocation status if
the cached inode hadn't been reused and wasn't in an intermediate state.
Brian thought it would be better to use the usual iget/irele mechanisms,
so that was changed for the final version.
Unfortunately, this hasn't aged well -- the IGET_INCORE flag only has
one user and clutters up the regular iget path, which makes it hard to
reason about how it actually works. Worse yet, the inode inactivation
series silently broke it because iget won't return inodes that are
anywhere in the inactivation machinery, even though the caller is
already required to prevent inode allocation and freeing. Inodes in the
inactivation machinery are still allocated, but the current code's
interactions with the iget code prevent us from being able to say that.
Now that I understand the inode lifecycle better than I did in early
2017, I now realize that as long as the cached inode hasn't been reused
and isn't actively being reclaimed, it's safe to access the i_mode field
(with the AGI, rcu, and i_flags locks held), and we don't need to worry
about the inode being freed out from under us.
Therefore, port the original version to modern code structure, which
fixes the brokennes w.r.t. inactivation. In the next patch we'll remove
IGET_INCORE since it's no longer necessary.
[1] https://lore.kernel.org/linux-xfs/149643868294.23065.8094890990886436794.stgit@birch.djwong.org/
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-08-10 07:48:12 -07:00
|
|
|
* Decide if this is this a cached inode that's also allocated. The caller
|
|
|
|
* must hold a reference to an AG and the AGI buffer lock to prevent inodes
|
|
|
|
* from being allocated or freed.
|
2023-08-10 07:48:12 -07:00
|
|
|
*
|
xfs: rewrite xchk_inode_is_allocated to work properly
Back in the mists of time[1], I proposed this function to assist the
inode btree scrubbers in checking the inode btree contents against the
allocation state of the inode records. The original version performed a
direct lookup in the inode cache and returned the allocation status if
the cached inode hadn't been reused and wasn't in an intermediate state.
Brian thought it would be better to use the usual iget/irele mechanisms,
so that was changed for the final version.
Unfortunately, this hasn't aged well -- the IGET_INCORE flag only has
one user and clutters up the regular iget path, which makes it hard to
reason about how it actually works. Worse yet, the inode inactivation
series silently broke it because iget won't return inodes that are
anywhere in the inactivation machinery, even though the caller is
already required to prevent inode allocation and freeing. Inodes in the
inactivation machinery are still allocated, but the current code's
interactions with the iget code prevent us from being able to say that.
Now that I understand the inode lifecycle better than I did in early
2017, I now realize that as long as the cached inode hasn't been reused
and isn't actively being reclaimed, it's safe to access the i_mode field
(with the AGI, rcu, and i_flags locks held), and we don't need to worry
about the inode being freed out from under us.
Therefore, port the original version to modern code structure, which
fixes the brokennes w.r.t. inactivation. In the next patch we'll remove
IGET_INCORE since it's no longer necessary.
[1] https://lore.kernel.org/linux-xfs/149643868294.23065.8094890990886436794.stgit@birch.djwong.org/
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-08-10 07:48:12 -07:00
|
|
|
* Look up an inode by number in the given file system. If the inode number
|
|
|
|
* is invalid, return -EINVAL. If the inode is not in cache, return -ENODATA.
|
|
|
|
* If the inode is being reclaimed, return -ENODATA because we know the inode
|
|
|
|
* cache cannot be updating the ondisk metadata.
|
2023-08-10 07:48:12 -07:00
|
|
|
*
|
xfs: rewrite xchk_inode_is_allocated to work properly
Back in the mists of time[1], I proposed this function to assist the
inode btree scrubbers in checking the inode btree contents against the
allocation state of the inode records. The original version performed a
direct lookup in the inode cache and returned the allocation status if
the cached inode hadn't been reused and wasn't in an intermediate state.
Brian thought it would be better to use the usual iget/irele mechanisms,
so that was changed for the final version.
Unfortunately, this hasn't aged well -- the IGET_INCORE flag only has
one user and clutters up the regular iget path, which makes it hard to
reason about how it actually works. Worse yet, the inode inactivation
series silently broke it because iget won't return inodes that are
anywhere in the inactivation machinery, even though the caller is
already required to prevent inode allocation and freeing. Inodes in the
inactivation machinery are still allocated, but the current code's
interactions with the iget code prevent us from being able to say that.
Now that I understand the inode lifecycle better than I did in early
2017, I now realize that as long as the cached inode hasn't been reused
and isn't actively being reclaimed, it's safe to access the i_mode field
(with the AGI, rcu, and i_flags locks held), and we don't need to worry
about the inode being freed out from under us.
Therefore, port the original version to modern code structure, which
fixes the brokennes w.r.t. inactivation. In the next patch we'll remove
IGET_INCORE since it's no longer necessary.
[1] https://lore.kernel.org/linux-xfs/149643868294.23065.8094890990886436794.stgit@birch.djwong.org/
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-08-10 07:48:12 -07:00
|
|
|
* Otherwise, the incore inode is the one we want, and it is either live,
|
|
|
|
* somewhere in the inactivation machinery, or reclaimable. The inode is
|
|
|
|
* allocated if i_mode is nonzero. In all three cases, the cached inode will
|
|
|
|
* be more up to date than the ondisk inode buffer, so we must use the incore
|
|
|
|
* i_mode.
|
2023-08-10 07:48:12 -07:00
|
|
|
*/
|
|
|
|
int
|
|
|
|
xchk_inode_is_allocated(
|
|
|
|
struct xfs_scrub *sc,
|
xfs: rewrite xchk_inode_is_allocated to work properly
Back in the mists of time[1], I proposed this function to assist the
inode btree scrubbers in checking the inode btree contents against the
allocation state of the inode records. The original version performed a
direct lookup in the inode cache and returned the allocation status if
the cached inode hadn't been reused and wasn't in an intermediate state.
Brian thought it would be better to use the usual iget/irele mechanisms,
so that was changed for the final version.
Unfortunately, this hasn't aged well -- the IGET_INCORE flag only has
one user and clutters up the regular iget path, which makes it hard to
reason about how it actually works. Worse yet, the inode inactivation
series silently broke it because iget won't return inodes that are
anywhere in the inactivation machinery, even though the caller is
already required to prevent inode allocation and freeing. Inodes in the
inactivation machinery are still allocated, but the current code's
interactions with the iget code prevent us from being able to say that.
Now that I understand the inode lifecycle better than I did in early
2017, I now realize that as long as the cached inode hasn't been reused
and isn't actively being reclaimed, it's safe to access the i_mode field
(with the AGI, rcu, and i_flags locks held), and we don't need to worry
about the inode being freed out from under us.
Therefore, port the original version to modern code structure, which
fixes the brokennes w.r.t. inactivation. In the next patch we'll remove
IGET_INCORE since it's no longer necessary.
[1] https://lore.kernel.org/linux-xfs/149643868294.23065.8094890990886436794.stgit@birch.djwong.org/
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-08-10 07:48:12 -07:00
|
|
|
xfs_agino_t agino,
|
2023-08-10 07:48:12 -07:00
|
|
|
bool *inuse)
|
|
|
|
{
|
xfs: rewrite xchk_inode_is_allocated to work properly
Back in the mists of time[1], I proposed this function to assist the
inode btree scrubbers in checking the inode btree contents against the
allocation state of the inode records. The original version performed a
direct lookup in the inode cache and returned the allocation status if
the cached inode hadn't been reused and wasn't in an intermediate state.
Brian thought it would be better to use the usual iget/irele mechanisms,
so that was changed for the final version.
Unfortunately, this hasn't aged well -- the IGET_INCORE flag only has
one user and clutters up the regular iget path, which makes it hard to
reason about how it actually works. Worse yet, the inode inactivation
series silently broke it because iget won't return inodes that are
anywhere in the inactivation machinery, even though the caller is
already required to prevent inode allocation and freeing. Inodes in the
inactivation machinery are still allocated, but the current code's
interactions with the iget code prevent us from being able to say that.
Now that I understand the inode lifecycle better than I did in early
2017, I now realize that as long as the cached inode hasn't been reused
and isn't actively being reclaimed, it's safe to access the i_mode field
(with the AGI, rcu, and i_flags locks held), and we don't need to worry
about the inode being freed out from under us.
Therefore, port the original version to modern code structure, which
fixes the brokennes w.r.t. inactivation. In the next patch we'll remove
IGET_INCORE since it's no longer necessary.
[1] https://lore.kernel.org/linux-xfs/149643868294.23065.8094890990886436794.stgit@birch.djwong.org/
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-08-10 07:48:12 -07:00
|
|
|
struct xfs_mount *mp = sc->mp;
|
|
|
|
struct xfs_perag *pag = sc->sa.pag;
|
|
|
|
xfs_ino_t ino;
|
2023-08-10 07:48:12 -07:00
|
|
|
struct xfs_inode *ip;
|
|
|
|
int error;
|
|
|
|
|
xfs: rewrite xchk_inode_is_allocated to work properly
Back in the mists of time[1], I proposed this function to assist the
inode btree scrubbers in checking the inode btree contents against the
allocation state of the inode records. The original version performed a
direct lookup in the inode cache and returned the allocation status if
the cached inode hadn't been reused and wasn't in an intermediate state.
Brian thought it would be better to use the usual iget/irele mechanisms,
so that was changed for the final version.
Unfortunately, this hasn't aged well -- the IGET_INCORE flag only has
one user and clutters up the regular iget path, which makes it hard to
reason about how it actually works. Worse yet, the inode inactivation
series silently broke it because iget won't return inodes that are
anywhere in the inactivation machinery, even though the caller is
already required to prevent inode allocation and freeing. Inodes in the
inactivation machinery are still allocated, but the current code's
interactions with the iget code prevent us from being able to say that.
Now that I understand the inode lifecycle better than I did in early
2017, I now realize that as long as the cached inode hasn't been reused
and isn't actively being reclaimed, it's safe to access the i_mode field
(with the AGI, rcu, and i_flags locks held), and we don't need to worry
about the inode being freed out from under us.
Therefore, port the original version to modern code structure, which
fixes the brokennes w.r.t. inactivation. In the next patch we'll remove
IGET_INCORE since it's no longer necessary.
[1] https://lore.kernel.org/linux-xfs/149643868294.23065.8094890990886436794.stgit@birch.djwong.org/
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-08-10 07:48:12 -07:00
|
|
|
/* caller must hold perag reference */
|
|
|
|
if (pag == NULL) {
|
|
|
|
ASSERT(pag != NULL);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2023-08-10 07:48:12 -07:00
|
|
|
|
xfs: rewrite xchk_inode_is_allocated to work properly
Back in the mists of time[1], I proposed this function to assist the
inode btree scrubbers in checking the inode btree contents against the
allocation state of the inode records. The original version performed a
direct lookup in the inode cache and returned the allocation status if
the cached inode hadn't been reused and wasn't in an intermediate state.
Brian thought it would be better to use the usual iget/irele mechanisms,
so that was changed for the final version.
Unfortunately, this hasn't aged well -- the IGET_INCORE flag only has
one user and clutters up the regular iget path, which makes it hard to
reason about how it actually works. Worse yet, the inode inactivation
series silently broke it because iget won't return inodes that are
anywhere in the inactivation machinery, even though the caller is
already required to prevent inode allocation and freeing. Inodes in the
inactivation machinery are still allocated, but the current code's
interactions with the iget code prevent us from being able to say that.
Now that I understand the inode lifecycle better than I did in early
2017, I now realize that as long as the cached inode hasn't been reused
and isn't actively being reclaimed, it's safe to access the i_mode field
(with the AGI, rcu, and i_flags locks held), and we don't need to worry
about the inode being freed out from under us.
Therefore, port the original version to modern code structure, which
fixes the brokennes w.r.t. inactivation. In the next patch we'll remove
IGET_INCORE since it's no longer necessary.
[1] https://lore.kernel.org/linux-xfs/149643868294.23065.8094890990886436794.stgit@birch.djwong.org/
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2023-08-10 07:48:12 -07:00
|
|
|
/* caller must have AGI buffer */
|
|
|
|
if (sc->sa.agi_bp == NULL) {
|
|
|
|
ASSERT(sc->sa.agi_bp != NULL);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* reject inode numbers outside existing AGs */
|
|
|
|
ino = XFS_AGINO_TO_INO(sc->mp, pag->pag_agno, agino);
|
|
|
|
if (!xfs_verify_ino(mp, ino))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
error = -ENODATA;
|
|
|
|
rcu_read_lock();
|
|
|
|
ip = radix_tree_lookup(&pag->pag_ici_root, agino);
|
|
|
|
if (!ip) {
|
|
|
|
/* cache miss */
|
|
|
|
goto out_rcu;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the inode number doesn't match, the incore inode got reused
|
|
|
|
* during an RCU grace period and the radix tree hasn't been updated.
|
|
|
|
* This isn't the inode we want.
|
|
|
|
*/
|
|
|
|
spin_lock(&ip->i_flags_lock);
|
|
|
|
if (ip->i_ino != ino)
|
|
|
|
goto out_skip;
|
|
|
|
|
|
|
|
trace_xchk_inode_is_allocated(ip);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have an incore inode that matches the inode we want, and the
|
|
|
|
* caller holds the perag structure and the AGI buffer. Let's check
|
|
|
|
* our assumptions below:
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/*
|
|
|
|
* (1) If the incore inode is live (i.e. referenced from the dcache),
|
|
|
|
* it will not be INEW, nor will it be in the inactivation or reclaim
|
|
|
|
* machinery. The ondisk inode had better be allocated. This is the
|
|
|
|
* most trivial case.
|
|
|
|
*/
|
|
|
|
if (!(ip->i_flags & (XFS_NEED_INACTIVE | XFS_INEW | XFS_IRECLAIMABLE |
|
|
|
|
XFS_INACTIVATING))) {
|
|
|
|
/* live inode */
|
|
|
|
ASSERT(VFS_I(ip)->i_mode != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the incore inode is INEW, there are several possibilities:
|
|
|
|
*
|
|
|
|
* (2) For a file that is being created, note that we allocate the
|
|
|
|
* ondisk inode before allocating, initializing, and adding the incore
|
|
|
|
* inode to the radix tree.
|
|
|
|
*
|
|
|
|
* (3) If the incore inode is being recycled, the inode has to be
|
|
|
|
* allocated because we don't allow freed inodes to be recycled.
|
|
|
|
* Recycling doesn't touch i_mode.
|
|
|
|
*/
|
|
|
|
if (ip->i_flags & XFS_INEW) {
|
|
|
|
/* created on disk already or recycling */
|
|
|
|
ASSERT(VFS_I(ip)->i_mode != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (4) If the inode is queued for inactivation (NEED_INACTIVE) but
|
|
|
|
* inactivation has not started (!INACTIVATING), it is still allocated.
|
|
|
|
*/
|
|
|
|
if ((ip->i_flags & XFS_NEED_INACTIVE) &&
|
|
|
|
!(ip->i_flags & XFS_INACTIVATING)) {
|
|
|
|
/* definitely before difree */
|
|
|
|
ASSERT(VFS_I(ip)->i_mode != 0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the incore inode is undergoing inactivation (INACTIVATING), there
|
|
|
|
* are two possibilities:
|
|
|
|
*
|
|
|
|
* (5) It is before the point where it would get freed ondisk, in which
|
|
|
|
* case i_mode is still nonzero.
|
|
|
|
*
|
|
|
|
* (6) It has already been freed, in which case i_mode is zero.
|
|
|
|
*
|
|
|
|
* We don't take the ILOCK here, but difree and dialloc update the AGI,
|
|
|
|
* and we've taken the AGI buffer lock, which prevents that from
|
|
|
|
* happening.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (7) Inodes undergoing inactivation (INACTIVATING) or queued for
|
|
|
|
* reclaim (IRECLAIMABLE) could be allocated or free. i_mode still
|
|
|
|
* reflects the ondisk state.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (8) If the inode is in IFLUSHING, it's safe to query i_mode because
|
|
|
|
* the flush code uses i_mode to format the ondisk inode.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* (9) If the inode is in IRECLAIM and was reachable via the radix
|
|
|
|
* tree, it still has the same i_mode as it did before it entered
|
|
|
|
* reclaim. The inode object is still alive because we hold the RCU
|
|
|
|
* read lock.
|
|
|
|
*/
|
|
|
|
|
|
|
|
*inuse = VFS_I(ip)->i_mode != 0;
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
out_skip:
|
|
|
|
spin_unlock(&ip->i_flags_lock);
|
|
|
|
out_rcu:
|
|
|
|
rcu_read_unlock();
|
|
|
|
return error;
|
2023-08-10 07:48:12 -07:00
|
|
|
}
|