Skip to content

Commit 0cac511

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to avoid racing in between read and OPU dio write
If lfs mode is on, buffered read may race w/ OPU dio write as below, it may cause buffered read hits unwritten data unexpectly, and for dio read, the race condition exists as well. Thread A Thread B - f2fs_file_write_iter - f2fs_dio_write_iter - __iomap_dio_rw - f2fs_iomap_begin - f2fs_map_blocks - __allocate_data_block - allocated blkaddr #x - iomap_dio_submit_bio - f2fs_file_read_iter - filemap_read - f2fs_read_data_folio - f2fs_mpage_readpages - f2fs_map_blocks : get blkaddr #x - f2fs_submit_read_bio IRQ - f2fs_read_end_io : read IO on blkaddr #x complete IRQ - iomap_dio_bio_end_io : direct write IO on blkaddr #x complete In LFS mode, if there is inflight dio, let's wait for its completion, this policy won't cover all race cases, however it is a tradeoff which avoids abusing lock around IO paths. Fixes: f847c69 ("f2fs: allow out-place-update for direct IO in LFS mode") Signed-off-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent 96cfeb0 commit 0cac511

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/f2fs/file.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4613,6 +4613,10 @@ static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
46134613
f2fs_trace_rw_file_path(iocb->ki_filp, iocb->ki_pos,
46144614
iov_iter_count(to), READ);
46154615

4616+
/* In LFS mode, if there is inflight dio, wait for its completion */
4617+
if (f2fs_lfs_mode(F2FS_I_SB(inode)))
4618+
inode_dio_wait(inode);
4619+
46164620
if (f2fs_should_use_dio(inode, iocb, to)) {
46174621
ret = f2fs_dio_read_iter(iocb, to);
46184622
} else {

0 commit comments

Comments
 (0)