xfs: break layouts before swapping extents
Subsystems (2)
PATCH 1/1 xfs: break layouts before swapping extents
XFS_IOC_SWAPEXT does not break pNFS layouts. A client can keep writing to blocks that the swap moved to the temporary file. xfs_fsr frees those blocks when it closes that file. The writes then land in whatever reuses them.
Lock with xfs_ilock2_io_mmap(), as the exchange-range ioctls do.
---xfs_fsr uses SWAPEXT on kernels without XFS_IOC_COMMIT_RANGE, on filesystems without exchange-range, and in all xfsprogs before 6.12.
When both files are DAX, xfs_ilock2_io_mmap() also breaks DAX layouts. With two DAX files whose pages had been faulted in, SWAPEXT hit the WARN_ON_ONCE in truncate_folio_batch_exceptionals() in 3 of 3 boots before this patch and in 0 of 3 after it. A DAX file swapped with a non-DAX file still hits it.
Tested with a pynfs client holding an RW block layout while the MDS ran "xfs_io -c swapext". Before, the client's writes overwrote other files' data and a directory block. After, the swap recalls the layout first. The fstests fsr and swapext tests pass with and without the patch.
--- fs/xfs/xfs_bmap_util.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/xfs/xfs_bmap_util.c +4 -6
@@ -1554,9 +1554,9 @@ xfs_swap_extents(* page cache safely. Once we have done this we can take the ilocks and * do the rest of the checks. */ -lock_two_nondirectories (VFS_I (ip),VFS_I (tip)); -filemap_invalidate_lock_two (VFS_I (ip)->i_mapping, -VFS_I (tip)->i_mapping); + error =xfs_ilock2_io_mmap (ip, tip); +if (error) +return error;/* Verify that both files have the same format */ if ((VFS_I (ip)->i_mode &S_IFMT ) != (VFS_I (tip)->i_mode &S_IFMT )) {
@@ -1762,9 +1762,7 @@ xfs_swap_extents(xfs_iunlock (ip,XFS_ILOCK_EXCL );xfs_iunlock (tip,XFS_ILOCK_EXCL ); out_unlock: -filemap_invalidate_unlock_two (VFS_I (ip)->i_mapping, -VFS_I (tip)->i_mapping); -unlock_two_nondirectories (VFS_I (ip),VFS_I (tip)); +xfs_iunlock2_io_mmap (ip, tip);return error; out_trans_cancel:
---
base-commit: 1e17fc56469d62d1c1ac45c137a2456d14456f1d
change-id: 20261109-xfs-swapext-break-layout-89fc24f5be8f
Best regards,
Signature · 1 line
Daejun Park <[email protected]>
Looks good:
Quoted 8 lines · Daejun Park
XFS_IOC_SWAPEXTdoes not break pNFS layouts. A client can keep writing to blocks that the swap moved to the temporary file.xfs_fsrfrees those blocks when it closes that file. The writes then land in whatever reuses them.Lock with
xfs_ilock2_io_mmap(), as the exchange-range ioctls do.[...]
Applied to for-next, thanks!
[1/1] xfs: break layouts before swapping extents
commit: 0d8026c7ac0c79a8ebe2942a3c3114c06aced734
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>