Skip to content

Commit a303b0a

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to avoid GC/mmap race with f2fs_truncate()
It missed to hold i_gc_rwsem and i_map_sem around f2fs_truncate() in f2fs_file_write_iter() to avoid racing with background GC and mmap, fix it. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent b5d1519 commit a303b0a

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎fs/f2fs/file.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4443,8 +4443,13 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
44434443
clear_inode_flag(inode, FI_NO_PREALLOC);
44444444

44454445
/* if we couldn't write data, we should deallocate blocks. */
4446-
if (preallocated && i_size_read(inode) < target_size)
4446+
if (preallocated && i_size_read(inode) < target_size) {
4447+
down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
4448+
down_write(&F2FS_I(inode)->i_mmap_sem);
44474449
f2fs_truncate(inode);
4450+
up_write(&F2FS_I(inode)->i_mmap_sem);
4451+
up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]);
4452+
}
44484453

44494454
if (ret > 0)
44504455
f2fs_update_iostat(F2FS_I_SB(inode), APP_WRITE_IO, ret);

0 commit comments

Comments
 (0)