* [PATCH] xfs: break layouts before swapping extents
@ 2026-11-09 8:26 Daejun Park via B4 Relay
2026-11-11 15:10 ` Christoph Hellwig
0 siblings, 1 reply; 2+ messages in thread
From: Daejun Park via B4 Relay @ 2026-11-09 8:26 UTC (permalink / raw)
To: Carlos Maiolino, linux-xfs
Cc: Christoph Hellwig, Dave Chinner, Darrick J. Wong, linux-kernel,
stable, Daejun Park
From: Daejun Park <daejun7.park@samsung.com>
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.
Fixes: 781355c6e5ae ("xfs: recall pNFS layouts on conflicting access")
Cc: stable@vger.kernel.org
Signed-off-by: Daejun Park <daejun7.park@samsung.com>
---
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(-)
diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
index 865aec3ae5a..595b7ea3ac9 100644
--- a/fs/xfs/xfs_bmap_util.c
+++ b/fs/xfs/xfs_bmap_util.c
@@ -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,
--
Daejun Park <daejun7.park@samsung.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-11 15:10 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-09 8:26 [PATCH] xfs: break layouts before swapping extents Daejun Park via B4 Relay
2026-11-11 15:10 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®