xfs: wait for direct I/O before swapping extents
Subsystems (2)
PATCH 1/1 xfs: wait for direct I/O before swapping extents
An AIO direct write drops the iolock before its bios complete. XFS_IOC_SWAPEXT does not wait for it. The write can land in blocks that the swap moved to the temporary file. Once xfs_fsr frees them, the write corrupts whatever reuses them.
Wait for direct I/O first, as exchange-range does.
---
Tested with an AIO direct write held back by cgroup io.max. Before, the write reached files that reused the freed blocks in 7 of 7 runs. After, those files were intact. The new fstests case "xfs: test that swapext waits for in-flight direct I/O" fails before and passes after. Running fstests -g fsr shows no change.
Applies with or without "xfs: break layouts before swapping extents".
--- fs/xfs/xfs_bmap_util.c | 1 + 1 file changed, 1 insertion(+)
fs/xfs/xfs_bmap_util.c +1 -0
@@ -1257,6 +1257,7 @@ xfs_swap_extent_flush( {int error; +inode_dio_wait (VFS_I (ip)); error =filemap_write_and_wait (VFS_I (ip)->i_mapping);if (error)return error;
---
base-commit: 1e17fc56469d62d1c1ac45c137a2456d14456f1d
change-id: 20261109-xfs-swapext-dio-wait-6b700c2a981e
Best regards,
Signature · 1 line
Daejun Park <[email protected]>
Looks good:
Quoted 8 lines · Daejun Park
An AIO direct write drops the iolock before its bios complete.
XFS_IOC_SWAPEXTdoes not wait for it. The write can land in blocks that the swap moved to the temporary file. Oncexfs_fsrfrees them, the write corrupts whatever reuses them.Wait for direct I/O first, as exchange-range does.
[...]
Applied to for-next, thanks!
[1/1] xfs: wait for direct I/O before swapping extents
commit: 844bc1167f1b2d19d9495a556599af24dc4468bd
Best regards,
Signature · 1 line
Carlos Maiolino <[email protected]>