xfs: use atomic extent swapping to fix user file fork data
authorDarrick J. Wong <djwong@kernel.org>
Mon, 15 Apr 2024 21:54:44 +0000 (14:54 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Mon, 15 Apr 2024 21:58:53 +0000 (14:58 -0700)
commit629fdaf5f5b1b7f7107ed4de04e0991a99501ced
tree65c5a2307471871d83aae2ffeafbdac60c638fc6
parentd2bd7eef4f217fc3e1ddf18b4f4eac848886bfa0
xfs: use atomic extent swapping to fix user file fork data

Build on the code that was recently added to the temporary repair file
code so that we can atomically switch the contents of any file fork,
even if the fork is in local format.  The upcoming functions to repair
xattrs, directories, and symlinks will need that capability.

Repair can lock out access to these user files by holding IOLOCK_EXCL on
these user files.  Therefore, it is safe to drop the ILOCK of both the
file being repaired and the tempfile being used for staging, and cancel
the scrub transaction.  We do this so that we can reuse the resource
estimation and transaction allocation functions used by a regular file
exchange operation.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/libxfs/xfs_exchmaps.c
fs/xfs/libxfs/xfs_exchmaps.h
fs/xfs/scrub/tempexch.h
fs/xfs/scrub/tempfile.c
fs/xfs/scrub/tempfile.h