Skip to content

Commit 57a0da2

Browse files
Lukas Czernertytso
authored andcommitted
ext4: fix data corruption caused by overlapping unaligned and aligned IO
Unaligned AIO must be serialized because the zeroing of partial blocks of unaligned AIO can result in data corruption in case it's overlapping another in flight IO. Currently we wait for all unwritten extents before we submit unaligned AIO which protects data in case of unaligned AIO is following overlapping IO. However if a unaligned AIO is followed by overlapping aligned AIO we can still end up corrupting data. To fix this, we must make sure that the unaligned AIO is the only IO in flight by waiting for unwritten extents conversion not just before the IO submission, but right after it as well. This problem can be reproduced by xfstest generic/538 Signed-off-by: Lukas Czerner <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Cc: [email protected]
1 parent 0d52154 commit 57a0da2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/ext4/file.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ ext4_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
264264
}
265265

266266
ret = __generic_file_write_iter(iocb, from);
267+
/*
268+
* Unaligned direct AIO must be the only IO in flight. Otherwise
269+
* overlapping aligned IO after unaligned might result in data
270+
* corruption.
271+
*/
272+
if (ret == -EIOCBQUEUED && unaligned_aio)
273+
ext4_unwritten_wait(inode);
267274
inode_unlock(inode);
268275

269276
if (ret > 0)

0 commit comments

Comments
 (0)