f2fs: Fix the race condition of resize flag between resizefs
authorZhang Qilong <zhangqilong3@huawei.com>
Tue, 18 Oct 2022 02:45:32 +0000 (10:45 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Fri, 28 Oct 2022 03:25:59 +0000 (20:25 -0700)
commit28fc4e9077ce59ab28c89c20dc6be5154473218f
tree6620d57545df4228ead354adec4d2c21864728aa
parent14dc00a0e2dbea4b685ab9723ff511fcfd223c18
f2fs: Fix the race condition of resize flag between resizefs

Because the set/clear SBI_IS_RESIZEFS flag not between any locks,
In the following case:
  thread1 thread2
   ->ioctl(resizefs)
    ->set RESIZEFS flag  ->ioctl(resizefs)
    ...                      ->set RESIZEFS flag
    ->clear RESIZEFS flag
       ->resizefs stream
    # No RESIZEFS flag in the stream

Also before freeze_super, the resizefs not started, we should not set
the SBI_IS_RESIZEFS flag.

So move the set/clear SBI_IS_RESIZEFS flag between the cp_mutex and
gc_lock.

Fixes: b4b10061ef98 ("f2fs: refactor resize_fs to avoid meta updates in progress")
Signed-off-by: Zhang Xiaoxu <zhangxiaoxu5@huawei.com>
Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com>
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fs/f2fs/gc.c