mirror of
https://github.com/torvalds/linux.git
synced 2026-06-09 15:12:59 +02:00
f2fs: avoid duplicated codes for cleanup
f2fs_segment_has_free_slot() was copied and modified from __next_free_blkoff(), they are almost the same, clean up to reuse common code as much as possible. Signed-off-by: Chao Yu <yuchao0@huawei.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
parent
e882e7aeff
commit
e4947f414c
|
|
@ -2635,22 +2635,20 @@ static void new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec)
|
||||||
curseg->alloc_type = LFS;
|
curseg->alloc_type = LFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __next_free_blkoff(struct f2fs_sb_info *sbi,
|
static int __next_free_blkoff(struct f2fs_sb_info *sbi,
|
||||||
struct curseg_info *seg, block_t start)
|
int segno, block_t start)
|
||||||
{
|
{
|
||||||
struct seg_entry *se = get_seg_entry(sbi, seg->segno);
|
struct seg_entry *se = get_seg_entry(sbi, segno);
|
||||||
int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
|
int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
|
||||||
unsigned long *target_map = SIT_I(sbi)->tmp_map;
|
unsigned long *target_map = SIT_I(sbi)->tmp_map;
|
||||||
unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
|
unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
|
||||||
unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
|
unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
|
||||||
int i, pos;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < entries; i++)
|
for (i = 0; i < entries; i++)
|
||||||
target_map[i] = ckpt_map[i] | cur_map[i];
|
target_map[i] = ckpt_map[i] | cur_map[i];
|
||||||
|
|
||||||
pos = __find_rev_next_zero_bit(target_map, sbi->blocks_per_seg, start);
|
return __find_rev_next_zero_bit(target_map, sbi->blocks_per_seg, start);
|
||||||
|
|
||||||
seg->next_blkoff = pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -2662,26 +2660,16 @@ static void __refresh_next_blkoff(struct f2fs_sb_info *sbi,
|
||||||
struct curseg_info *seg)
|
struct curseg_info *seg)
|
||||||
{
|
{
|
||||||
if (seg->alloc_type == SSR)
|
if (seg->alloc_type == SSR)
|
||||||
__next_free_blkoff(sbi, seg, seg->next_blkoff + 1);
|
seg->next_blkoff =
|
||||||
|
__next_free_blkoff(sbi, seg->segno,
|
||||||
|
seg->next_blkoff + 1);
|
||||||
else
|
else
|
||||||
seg->next_blkoff++;
|
seg->next_blkoff++;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
|
bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno)
|
||||||
{
|
{
|
||||||
struct seg_entry *se = get_seg_entry(sbi, segno);
|
return __next_free_blkoff(sbi, segno, 0) < sbi->blocks_per_seg;
|
||||||
int entries = SIT_VBLOCK_MAP_SIZE / sizeof(unsigned long);
|
|
||||||
unsigned long *target_map = SIT_I(sbi)->tmp_map;
|
|
||||||
unsigned long *ckpt_map = (unsigned long *)se->ckpt_valid_map;
|
|
||||||
unsigned long *cur_map = (unsigned long *)se->cur_valid_map;
|
|
||||||
int i, pos;
|
|
||||||
|
|
||||||
for (i = 0; i < entries; i++)
|
|
||||||
target_map[i] = ckpt_map[i] | cur_map[i];
|
|
||||||
|
|
||||||
pos = __find_rev_next_zero_bit(target_map, sbi->blocks_per_seg, 0);
|
|
||||||
|
|
||||||
return pos < sbi->blocks_per_seg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -2709,7 +2697,7 @@ static void change_curseg(struct f2fs_sb_info *sbi, int type, bool flush)
|
||||||
|
|
||||||
reset_curseg(sbi, type, 1);
|
reset_curseg(sbi, type, 1);
|
||||||
curseg->alloc_type = SSR;
|
curseg->alloc_type = SSR;
|
||||||
__next_free_blkoff(sbi, curseg, 0);
|
curseg->next_blkoff = __next_free_blkoff(sbi, curseg->segno, 0);
|
||||||
|
|
||||||
sum_page = f2fs_get_sum_page(sbi, new_segno);
|
sum_page = f2fs_get_sum_page(sbi, new_segno);
|
||||||
if (IS_ERR(sum_page)) {
|
if (IS_ERR(sum_page)) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user