Skip to content

Commit 8336a64

Browse files
author
Darrick J. Wong
committed
xfs: don't complain about unfixed metadata when repairs were injected
While debugging other parts of online repair, I noticed that if someone injects FORCE_SCRUB_REPAIR, starts an IFLAG_REPAIR scrub on a piece of metadata, and the metadata repair fails, we'll log a message about uncorrected errors in the filesystem. This isn't strictly true if the scrub function didn't set OFLAG_CORRUPT and we're only doing the repair because the error injection knob is set. Repair functions are allowed to abort the entire operation at any point before committing new metadata, in which case the piece of metadata is in the same state as it was before. Therefore, the log message should be gated on the results of the scrub. Refactor the predicate and rearrange the code flow to make this happen. Note: If the repair function errors out after it commits the new metadata, the transaction cancellation will shut down the filesystem, which is an obvious sign of corrupt metadata. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent d728f4e commit 8336a64

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

fs/xfs/scrub/common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ static inline bool xchk_skip_xref(struct xfs_scrub_metadata *sm)
167167
XFS_SCRUB_OFLAG_XCORRUPT);
168168
}
169169

170+
#ifdef CONFIG_XFS_ONLINE_REPAIR
171+
/* Decide if a repair is required. */
172+
static inline bool xchk_needs_repair(const struct xfs_scrub_metadata *sm)
173+
{
174+
return sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
175+
XFS_SCRUB_OFLAG_XCORRUPT |
176+
XFS_SCRUB_OFLAG_PREEN);
177+
}
178+
#else
179+
# define xchk_needs_repair(sc) (false)
180+
#endif /* CONFIG_XFS_ONLINE_REPAIR */
181+
170182
int xchk_metadata_inode_forks(struct xfs_scrub *sc);
171183

172184
/*

fs/xfs/scrub/scrub.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,15 +535,12 @@ xfs_scrub_metadata(
535535

536536
if ((sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR) &&
537537
!(sc->flags & XREP_ALREADY_FIXED)) {
538-
bool needs_fix;
538+
bool needs_fix = xchk_needs_repair(sc->sm);
539539

540540
/* Let debug users force us into the repair routines. */
541541
if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_FORCE_SCRUB_REPAIR))
542-
sc->sm->sm_flags |= XFS_SCRUB_OFLAG_CORRUPT;
542+
needs_fix = true;
543543

544-
needs_fix = (sc->sm->sm_flags & (XFS_SCRUB_OFLAG_CORRUPT |
545-
XFS_SCRUB_OFLAG_XCORRUPT |
546-
XFS_SCRUB_OFLAG_PREEN));
547544
/*
548545
* If userspace asked for a repair but it wasn't necessary,
549546
* report that back to userspace.

0 commit comments

Comments
 (0)