f2fs: fix race in between GC and atomic open
authorChao Yu <yuchao0@huawei.com>
Tue, 17 Apr 2018 09:51:28 +0000 (17:51 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Thu, 28 Jun 2018 22:49:24 +0000 (15:49 -0700)
commit2e405acc866a9f632c0267f30730e9dde3df93d5
tree00829ffb9311977e6e762b5d957a81d751db47c1
parent408e9720d894a35851c4e8c1c3e62faf78d05ae3
f2fs: fix race in between GC and atomic open

Thread GC thread
- f2fs_ioc_start_atomic_write
 - get_dirty_pages
 - filemap_write_and_wait_range
- f2fs_gc
 - do_garbage_collect
  - gc_data_segment
   - move_data_page
    - f2fs_is_atomic_file
    - set_page_dirty
 - set_inode_flag(, FI_ATOMIC_FILE)

Dirty data page can still be generated by GC in race condition as
above call stack.

This patch adds fi->dio_rwsem[WRITE] in f2fs_ioc_start_atomic_write
to avoid such race.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/file.c