Commit 1081b512 authored by Chao Yu's avatar Chao Yu Committed by Jaegeuk Kim

f2fs: clean up new_curseg()

Move f2fs_valid_pinned_area() check logic from new_curseg() to
get_new_segment(), it can avoid calling __set_free() if it fails
to find free segment in conventional zone for pinned file.
Signed-off-by: default avatarChao Yu <chao@kernel.org>
Reviewed-by: default avatarDaeho Jeong <daehojeong@google.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>
parent f1e7646a
...@@ -2722,12 +2722,19 @@ static int get_new_segment(struct f2fs_sb_info *sbi, ...@@ -2722,12 +2722,19 @@ static int get_new_segment(struct f2fs_sb_info *sbi,
got_it: got_it:
/* set it as dirty segment in free segmap */ /* set it as dirty segment in free segmap */
f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap)); f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap));
/* no free section in conventional zone */
if (new_sec && pinning &&
!f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) {
ret = -EAGAIN;
goto out_unlock;
}
__set_inuse(sbi, segno); __set_inuse(sbi, segno);
*newseg = segno; *newseg = segno;
out_unlock: out_unlock:
spin_unlock(&free_i->segmap_lock); spin_unlock(&free_i->segmap_lock);
if (ret) { if (ret == -ENOSPC) {
f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT); f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT);
f2fs_bug_on(sbi, 1); f2fs_bug_on(sbi, 1);
} }
...@@ -2803,19 +2810,17 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec) ...@@ -2803,19 +2810,17 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
struct curseg_info *curseg = CURSEG_I(sbi, type); struct curseg_info *curseg = CURSEG_I(sbi, type);
unsigned int segno = curseg->segno; unsigned int segno = curseg->segno;
bool pinning = type == CURSEG_COLD_DATA_PINNED; bool pinning = type == CURSEG_COLD_DATA_PINNED;
int ret;
if (curseg->inited) if (curseg->inited)
write_sum_page(sbi, curseg->sum_blk, GET_SUM_BLOCK(sbi, segno)); write_sum_page(sbi, curseg->sum_blk, GET_SUM_BLOCK(sbi, segno));
segno = __get_next_segno(sbi, type); segno = __get_next_segno(sbi, type);
if (get_new_segment(sbi, &segno, new_sec, pinning)) { ret = get_new_segment(sbi, &segno, new_sec, pinning);
curseg->segno = NULL_SEGNO; if (ret) {
return -ENOSPC; if (ret == -ENOSPC)
} curseg->segno = NULL_SEGNO;
if (new_sec && pinning && return ret;
!f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) {
__set_free(sbi, segno);
return -EAGAIN;
} }
curseg->next_segno = segno; curseg->next_segno = segno;
......
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