f2fs: fix wrong discard space
authorChao Yu <yuchao0@huawei.com>
Fri, 29 May 2020 09:29:47 +0000 (17:29 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Sat, 30 May 2020 15:17:52 +0000 (08:17 -0700)
commitca7f76e680745d3b8a386638045f85dac1c4b2f4
treec6889db95486ee70e3bee573a9dd4bff7136dc09
parentdc35d73a42291b2a68f5b9a12b2b095b82194c1f
f2fs: fix wrong discard space

Under heavy fsstress, we may triggle panic while issuing discard,
because __check_sit_bitmap() detects that discard command may earse
valid data blocks, the root cause is as below race stack described,
since we removed lock when flushing quota data, quota data writeback
may race with write_checkpoint(), so that it causes inconsistency in
between cached discard entry and segment bitmap.

- f2fs_write_checkpoint
 - block_operations
  - set_sbi_flag(sbi, SBI_QUOTA_SKIP_FLUSH)
 - f2fs_flush_sit_entries
  - add_discard_addrs
   - __set_bit_le(i, (void *)de->discard_map);
- f2fs_write_data_pages
 - f2fs_write_single_data_page
   : inode is quota one, cp_rwsem won't be locked
  - f2fs_do_write_data_page
   - f2fs_allocate_data_block
    - f2fs_wait_discard_bio
      : discard entry has not been added yet.
    - update_sit_entry
 - f2fs_clear_prefree_segments
  - f2fs_issue_discard
  : add discard entry

In order to fix this, this patch uses node_write to serialize
f2fs_allocate_data_block and checkpoint.

Fixes: 435cbab95e39 ("f2fs: fix quota_sync failure due to f2fs_lock_op")
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/segment.c