Skip to content

Commit 5221002

Browse files
author
Chandan Babu R
committed
Merge tag 'repair-force-rebuild-6.6_2023-08-10' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux into xfs-6.6-mergeA
xfs: force rebuilding of metadata This patchset adds a new IFLAG to the scrub ioctl so that userspace can force a rebuild of an otherwise consistent piece of metadata. This will eventually enable the use of online repair to relocate metadata during a filesystem reorganization (e.g. shrink). For now, it facilitates stress testing of online repair without needing the debugging knobs to be enabled. Signed-off-by: Darrick J. Wong <[email protected]> Signed-off-by: Chandan Babu R <[email protected]> * tag 'repair-force-rebuild-6.6_2023-08-10' of https://git.kernel.org/pub/scm/linux/kernel/git/djwong/xfs-linux: xfs: allow userspace to rebuild metadata structures xfs: don't complain about unfixed metadata when repairs were injected
2 parents 7857acd + 5c83df2 commit 5221002

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

fs/xfs/libxfs/xfs_fs.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,11 @@ struct xfs_scrub_metadata {
743743
*/
744744
#define XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED (1u << 7)
745745

746-
#define XFS_SCRUB_FLAGS_IN (XFS_SCRUB_IFLAG_REPAIR)
746+
/* i: Rebuild the data structure. */
747+
#define XFS_SCRUB_IFLAG_FORCE_REBUILD (1u << 8)
748+
749+
#define XFS_SCRUB_FLAGS_IN (XFS_SCRUB_IFLAG_REPAIR | \
750+
XFS_SCRUB_IFLAG_FORCE_REBUILD)
747751
#define XFS_SCRUB_FLAGS_OUT (XFS_SCRUB_OFLAG_CORRUPT | \
748752
XFS_SCRUB_OFLAG_PREEN | \
749753
XFS_SCRUB_OFLAG_XFAIL | \

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: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ xchk_validate_inputs(
409409
goto out;
410410
}
411411

412+
/* No rebuild without repair. */
413+
if ((sm->sm_flags & XFS_SCRUB_IFLAG_FORCE_REBUILD) &&
414+
!(sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR))
415+
return -EINVAL;
416+
412417
/*
413418
* We only want to repair read-write v5+ filesystems. Defer the check
414419
* for ops->repair until after our scrub confirms that we need to
@@ -535,15 +540,16 @@ xfs_scrub_metadata(
535540

536541
if ((sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR) &&
537542
!(sc->flags & XREP_ALREADY_FIXED)) {
538-
bool needs_fix;
543+
bool needs_fix = xchk_needs_repair(sc->sm);
544+
545+
/* Userspace asked us to rebuild the structure regardless. */
546+
if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_FORCE_REBUILD)
547+
needs_fix = true;
539548

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

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

fs/xfs/scrub/trace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ TRACE_DEFINE_ENUM(XFS_SCRUB_TYPE_FSCOUNTERS);
9898
{ XFS_SCRUB_OFLAG_XCORRUPT, "xcorrupt" }, \
9999
{ XFS_SCRUB_OFLAG_INCOMPLETE, "incomplete" }, \
100100
{ XFS_SCRUB_OFLAG_WARNING, "warning" }, \
101-
{ XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED, "norepair" }
101+
{ XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED, "norepair" }, \
102+
{ XFS_SCRUB_IFLAG_FORCE_REBUILD, "rebuild" }
102103

103104
#define XFS_SCRUB_STATE_STRINGS \
104105
{ XCHK_TRY_HARDER, "try_harder" }, \

0 commit comments

Comments
 (0)