Commit 28fc4e90 authored by Zhang Qilong's avatar Zhang Qilong Committed by Jaegeuk Kim

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: b4b10061 ("f2fs: refactor resize_fs to avoid meta updates in progress")
Signed-off-by: default avatarZhang Xiaoxu <zhangxiaoxu5@huawei.com>
Signed-off-by: default avatarZhang Qilong <zhangqilong3@huawei.com>
Reviewed-by: default avatarChao Yu <chao@kernel.org>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent 14dc00a0
...@@ -2134,8 +2134,6 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count) ...@@ -2134,8 +2134,6 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
if (err) if (err)
return err; return err;
set_sbi_flag(sbi, SBI_IS_RESIZEFS);
freeze_super(sbi->sb); freeze_super(sbi->sb);
f2fs_down_write(&sbi->gc_lock); f2fs_down_write(&sbi->gc_lock);
f2fs_down_write(&sbi->cp_global_sem); f2fs_down_write(&sbi->cp_global_sem);
...@@ -2151,6 +2149,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count) ...@@ -2151,6 +2149,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
if (err) if (err)
goto out_err; goto out_err;
set_sbi_flag(sbi, SBI_IS_RESIZEFS);
err = free_segment_range(sbi, secs, false); err = free_segment_range(sbi, secs, false);
if (err) if (err)
goto recover_out; goto recover_out;
...@@ -2174,6 +2173,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count) ...@@ -2174,6 +2173,7 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
f2fs_commit_super(sbi, false); f2fs_commit_super(sbi, false);
} }
recover_out: recover_out:
clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
if (err) { if (err) {
set_sbi_flag(sbi, SBI_NEED_FSCK); set_sbi_flag(sbi, SBI_NEED_FSCK);
f2fs_err(sbi, "resize_fs failed, should run fsck to repair!"); f2fs_err(sbi, "resize_fs failed, should run fsck to repair!");
...@@ -2186,6 +2186,5 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count) ...@@ -2186,6 +2186,5 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
f2fs_up_write(&sbi->cp_global_sem); f2fs_up_write(&sbi->cp_global_sem);
f2fs_up_write(&sbi->gc_lock); f2fs_up_write(&sbi->gc_lock);
thaw_super(sbi->sb); thaw_super(sbi->sb);
clear_sbi_flag(sbi, SBI_IS_RESIZEFS);
return err; return err;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment