Skip to contentSkip to conversation

xfs: wait for direct I/O before swapping extents

PATCH Applied Daejun Park 3 participants 3 messages Nov 10 – Nov 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")

---
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
index 865aec3ae5a..4d214708f9c 100644
@@ -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]>
maintainer Applied
#2 lore raw
In reply to Daejun Park
Quoted 8 lines · Daejun Park

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.

[...]

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]>