Skip to content

Commit

Permalink
f2fs: fix to cover __allocate_new_section() with curseg_lock
Browse files Browse the repository at this point in the history
In order to avoid race with f2fs_do_replace_block().

Fixes: f5a53ed ("f2fs: support aligned pinned file")
Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
  • Loading branch information
Chao Yu authored and Jaegeuk Kim committed Mar 26, 2021
1 parent 753a8ed commit 823d13e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions fs/f2fs/segment.c
Original file line number Diff line number Diff line change
Expand Up @@ -2945,19 +2945,23 @@ static void __allocate_new_section(struct f2fs_sb_info *sbi, int type)

void f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type)
{
down_read(&SM_I(sbi)->curseg_lock);
down_write(&SIT_I(sbi)->sentry_lock);
__allocate_new_section(sbi, type);
up_write(&SIT_I(sbi)->sentry_lock);
up_read(&SM_I(sbi)->curseg_lock);
}

void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi)
{
int i;

down_read(&SM_I(sbi)->curseg_lock);
down_write(&SIT_I(sbi)->sentry_lock);
for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++)
__allocate_new_segment(sbi, i, false);
up_write(&SIT_I(sbi)->sentry_lock);
up_read(&SM_I(sbi)->curseg_lock);
}

static const struct segment_allocation default_salloc_ops = {
Expand Down

0 comments on commit 823d13e

Please sign in to comment.