Skip to content

Commit 5c83df2

Browse files
author
Darrick J. Wong
committed
xfs: allow userspace to rebuild metadata structures
Add a new (superuser-only) flag to the online metadata repair ioctl to force it to rebuild structures, even if they're not broken. We will use this to move metadata structures out of the way during a free space defragmentation operation. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent 8336a64 commit 5c83df2

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
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/scrub.c

Lines changed: 10 additions & 1 deletion
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
@@ -537,8 +542,12 @@ xfs_scrub_metadata(
537542
!(sc->flags & XREP_ALREADY_FIXED)) {
538543
bool needs_fix = xchk_needs_repair(sc->sm);
539544

545+
/* Userspace asked us to rebuild the structure regardless. */
546+
if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_FORCE_REBUILD)
547+
needs_fix = true;
548+
540549
/* Let debug users force us into the repair routines. */
541-
if (XFS_TEST_ERROR(false, mp, XFS_ERRTAG_FORCE_SCRUB_REPAIR))
550+
if (XFS_TEST_ERROR(needs_fix, mp, XFS_ERRTAG_FORCE_SCRUB_REPAIR))
542551
needs_fix = true;
543552

544553
/*

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)