diff options
author | Chao Yu <yuchao0@huawei.com> | 2021-04-01 11:01:53 +0800 |
---|---|---|
committer | Jaegeuk Kim <jaegeuk@kernel.org> | 2021-04-06 07:16:22 -0700 |
commit | a303b0ac920d807cb7da4f1cd85759fbe44fa654 (patch) | |
tree | 4af917ef5aa1e70ca53676c898860bbd3e8ac6ee /fs/f2fs | |
parent | b5d15199a26f6dce624b43c82764cdb3827e7c89 (diff) | |
download | linux-a303b0ac920d807cb7da4f1cd85759fbe44fa654.tar.gz linux-a303b0ac920d807cb7da4f1cd85759fbe44fa654.tar.bz2 linux-a303b0ac920d807cb7da4f1cd85759fbe44fa654.zip |
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>
Diffstat (limited to 'fs/f2fs')
-rw-r--r-- | fs/f2fs/file.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index dc79694e512c..f3ca63b55843 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4443,8 +4443,13 @@ write: clear_inode_flag(inode, FI_NO_PREALLOC); /* if we couldn't write data, we should deallocate blocks. */ - if (preallocated && i_size_read(inode) < target_size) + if (preallocated && i_size_read(inode) < target_size) { + down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); + down_write(&F2FS_I(inode)->i_mmap_sem); f2fs_truncate(inode); + up_write(&F2FS_I(inode)->i_mmap_sem); + up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); + } if (ret > 0) f2fs_update_iostat(F2FS_I_SB(inode), APP_WRITE_IO, ret); |