Skip to content

Commit 66baee2

Browse files
Yi SunJaegeuk Kim
authored andcommitted
f2fs: introduce update_sit_entry_for_release/alloc()
No logical changes, just for cleanliness. Signed-off-by: Yi Sun <[email protected]> Reviewed-by: Chao Yu <[email protected]> Signed-off-by: Jaegeuk Kim <[email protected]>
1 parent cf5817c commit 66baee2

File tree

1 file changed

+93
-69
lines changed

1 file changed

+93
-69
lines changed

fs/f2fs/segment.c

Lines changed: 93 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,16 +2426,103 @@ static void update_segment_mtime(struct f2fs_sb_info *sbi, block_t blkaddr,
24262426
SIT_I(sbi)->max_mtime = ctime;
24272427
}
24282428

2429-
static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
2429+
static int update_sit_entry_for_release(struct f2fs_sb_info *sbi, struct seg_entry *se,
2430+
block_t blkaddr, unsigned int offset, int del)
2431+
{
2432+
bool exist;
2433+
#ifdef CONFIG_F2FS_CHECK_FS
2434+
bool mir_exist;
2435+
#endif
2436+
2437+
exist = f2fs_test_and_clear_bit(offset, se->cur_valid_map);
2438+
#ifdef CONFIG_F2FS_CHECK_FS
2439+
mir_exist = f2fs_test_and_clear_bit(offset,
2440+
se->cur_valid_map_mir);
2441+
if (unlikely(exist != mir_exist)) {
2442+
f2fs_err(sbi, "Inconsistent error when clearing bitmap, blk:%u, old bit:%d",
2443+
blkaddr, exist);
2444+
f2fs_bug_on(sbi, 1);
2445+
}
2446+
#endif
2447+
if (unlikely(!exist)) {
2448+
f2fs_err(sbi, "Bitmap was wrongly cleared, blk:%u", blkaddr);
2449+
f2fs_bug_on(sbi, 1);
2450+
se->valid_blocks++;
2451+
del = 0;
2452+
} else if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
2453+
/*
2454+
* If checkpoints are off, we must not reuse data that
2455+
* was used in the previous checkpoint. If it was used
2456+
* before, we must track that to know how much space we
2457+
* really have.
2458+
*/
2459+
if (f2fs_test_bit(offset, se->ckpt_valid_map)) {
2460+
spin_lock(&sbi->stat_lock);
2461+
sbi->unusable_block_count++;
2462+
spin_unlock(&sbi->stat_lock);
2463+
}
2464+
}
2465+
2466+
if (f2fs_block_unit_discard(sbi) &&
2467+
f2fs_test_and_clear_bit(offset, se->discard_map))
2468+
sbi->discard_blks++;
2469+
2470+
if (!f2fs_test_bit(offset, se->ckpt_valid_map))
2471+
se->ckpt_valid_blocks += del;
2472+
2473+
return del;
2474+
}
2475+
2476+
static int update_sit_entry_for_alloc(struct f2fs_sb_info *sbi, struct seg_entry *se,
2477+
block_t blkaddr, unsigned int offset, int del)
24302478
{
2431-
struct seg_entry *se;
2432-
unsigned int segno, offset;
2433-
long int new_vblocks;
24342479
bool exist;
24352480
#ifdef CONFIG_F2FS_CHECK_FS
24362481
bool mir_exist;
24372482
#endif
24382483

2484+
exist = f2fs_test_and_set_bit(offset, se->cur_valid_map);
2485+
#ifdef CONFIG_F2FS_CHECK_FS
2486+
mir_exist = f2fs_test_and_set_bit(offset,
2487+
se->cur_valid_map_mir);
2488+
if (unlikely(exist != mir_exist)) {
2489+
f2fs_err(sbi, "Inconsistent error when setting bitmap, blk:%u, old bit:%d",
2490+
blkaddr, exist);
2491+
f2fs_bug_on(sbi, 1);
2492+
}
2493+
#endif
2494+
if (unlikely(exist)) {
2495+
f2fs_err(sbi, "Bitmap was wrongly set, blk:%u", blkaddr);
2496+
f2fs_bug_on(sbi, 1);
2497+
se->valid_blocks--;
2498+
del = 0;
2499+
}
2500+
2501+
if (f2fs_block_unit_discard(sbi) &&
2502+
!f2fs_test_and_set_bit(offset, se->discard_map))
2503+
sbi->discard_blks--;
2504+
2505+
/*
2506+
* SSR should never reuse block which is checkpointed
2507+
* or newly invalidated.
2508+
*/
2509+
if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) {
2510+
if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map))
2511+
se->ckpt_valid_blocks++;
2512+
}
2513+
2514+
if (!f2fs_test_bit(offset, se->ckpt_valid_map))
2515+
se->ckpt_valid_blocks += del;
2516+
2517+
return del;
2518+
}
2519+
2520+
static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
2521+
{
2522+
struct seg_entry *se;
2523+
unsigned int segno, offset;
2524+
long int new_vblocks;
2525+
24392526
segno = GET_SEGNO(sbi, blkaddr);
24402527
if (segno == NULL_SEGNO)
24412528
return;
@@ -2451,73 +2538,10 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
24512538

24522539
/* Update valid block bitmap */
24532540
if (del > 0) {
2454-
exist = f2fs_test_and_set_bit(offset, se->cur_valid_map);
2455-
#ifdef CONFIG_F2FS_CHECK_FS
2456-
mir_exist = f2fs_test_and_set_bit(offset,
2457-
se->cur_valid_map_mir);
2458-
if (unlikely(exist != mir_exist)) {
2459-
f2fs_err(sbi, "Inconsistent error when setting bitmap, blk:%u, old bit:%d",
2460-
blkaddr, exist);
2461-
f2fs_bug_on(sbi, 1);
2462-
}
2463-
#endif
2464-
if (unlikely(exist)) {
2465-
f2fs_err(sbi, "Bitmap was wrongly set, blk:%u",
2466-
blkaddr);
2467-
f2fs_bug_on(sbi, 1);
2468-
se->valid_blocks--;
2469-
del = 0;
2470-
}
2471-
2472-
if (f2fs_block_unit_discard(sbi) &&
2473-
!f2fs_test_and_set_bit(offset, se->discard_map))
2474-
sbi->discard_blks--;
2475-
2476-
/*
2477-
* SSR should never reuse block which is checkpointed
2478-
* or newly invalidated.
2479-
*/
2480-
if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) {
2481-
if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map))
2482-
se->ckpt_valid_blocks++;
2483-
}
2541+
del = update_sit_entry_for_alloc(sbi, se, blkaddr, offset, del);
24842542
} else {
2485-
exist = f2fs_test_and_clear_bit(offset, se->cur_valid_map);
2486-
#ifdef CONFIG_F2FS_CHECK_FS
2487-
mir_exist = f2fs_test_and_clear_bit(offset,
2488-
se->cur_valid_map_mir);
2489-
if (unlikely(exist != mir_exist)) {
2490-
f2fs_err(sbi, "Inconsistent error when clearing bitmap, blk:%u, old bit:%d",
2491-
blkaddr, exist);
2492-
f2fs_bug_on(sbi, 1);
2493-
}
2494-
#endif
2495-
if (unlikely(!exist)) {
2496-
f2fs_err(sbi, "Bitmap was wrongly cleared, blk:%u",
2497-
blkaddr);
2498-
f2fs_bug_on(sbi, 1);
2499-
se->valid_blocks++;
2500-
del = 0;
2501-
} else if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
2502-
/*
2503-
* If checkpoints are off, we must not reuse data that
2504-
* was used in the previous checkpoint. If it was used
2505-
* before, we must track that to know how much space we
2506-
* really have.
2507-
*/
2508-
if (f2fs_test_bit(offset, se->ckpt_valid_map)) {
2509-
spin_lock(&sbi->stat_lock);
2510-
sbi->unusable_block_count++;
2511-
spin_unlock(&sbi->stat_lock);
2512-
}
2513-
}
2514-
2515-
if (f2fs_block_unit_discard(sbi) &&
2516-
f2fs_test_and_clear_bit(offset, se->discard_map))
2517-
sbi->discard_blks++;
2543+
del = update_sit_entry_for_release(sbi, se, blkaddr, offset, del);
25182544
}
2519-
if (!f2fs_test_bit(offset, se->ckpt_valid_map))
2520-
se->ckpt_valid_blocks += del;
25212545

25222546
__mark_sit_entry_dirty(sbi, segno);
25232547

0 commit comments

Comments
 (0)