mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
BACKPORT: f2fs: introduce update_sit_entry_for_release/alloc()
No logical changes, just for cleanliness. Bug: 394006856 Change-Id: I4dddab6be974476879af46cda814dee2223ed21d Signed-off-by: Yi Sun <yi.sun@unisoc.com> Reviewed-by: Chao Yu <chao@kernel.org> [Dylan: Resolved minor conflict in fs/f2fs/segment.c ] Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org> (cherry picked from commit 66baee2b886d72ab6be11a08d4c7897f9612e25b)
This commit is contained in:
@@ -2304,15 +2304,102 @@ static void update_segment_mtime(struct f2fs_sb_info *sbi, block_t blkaddr,
|
|||||||
SIT_I(sbi)->max_mtime = ctime;
|
SIT_I(sbi)->max_mtime = ctime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int update_sit_entry_for_release(struct f2fs_sb_info *sbi, struct seg_entry *se,
|
||||||
|
block_t blkaddr, unsigned int offset, int del)
|
||||||
|
{
|
||||||
|
bool exist;
|
||||||
|
#ifdef CONFIG_F2FS_CHECK_FS
|
||||||
|
bool mir_exist;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
exist = f2fs_test_and_clear_bit(offset, se->cur_valid_map);
|
||||||
|
#ifdef CONFIG_F2FS_CHECK_FS
|
||||||
|
mir_exist = f2fs_test_and_clear_bit(offset,
|
||||||
|
se->cur_valid_map_mir);
|
||||||
|
if (unlikely(exist != mir_exist)) {
|
||||||
|
f2fs_err(sbi, "Inconsistent error when clearing bitmap, blk:%u, old bit:%d",
|
||||||
|
blkaddr, exist);
|
||||||
|
f2fs_bug_on(sbi, 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (unlikely(!exist)) {
|
||||||
|
f2fs_err(sbi, "Bitmap was wrongly cleared, blk:%u", blkaddr);
|
||||||
|
f2fs_bug_on(sbi, 1);
|
||||||
|
se->valid_blocks++;
|
||||||
|
del = 0;
|
||||||
|
} else if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
|
||||||
|
/*
|
||||||
|
* If checkpoints are off, we must not reuse data that
|
||||||
|
* was used in the previous checkpoint. If it was used
|
||||||
|
* before, we must track that to know how much space we
|
||||||
|
* really have.
|
||||||
|
*/
|
||||||
|
if (f2fs_test_bit(offset, se->ckpt_valid_map)) {
|
||||||
|
spin_lock(&sbi->stat_lock);
|
||||||
|
sbi->unusable_block_count++;
|
||||||
|
spin_unlock(&sbi->stat_lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f2fs_block_unit_discard(sbi) &&
|
||||||
|
f2fs_test_and_clear_bit(offset, se->discard_map))
|
||||||
|
sbi->discard_blks++;
|
||||||
|
|
||||||
|
if (!f2fs_test_bit(offset, se->ckpt_valid_map))
|
||||||
|
se->ckpt_valid_blocks += del;
|
||||||
|
|
||||||
|
return del;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int update_sit_entry_for_alloc(struct f2fs_sb_info *sbi, struct seg_entry *se,
|
||||||
|
block_t blkaddr, unsigned int offset, int del)
|
||||||
|
{
|
||||||
|
bool exist;
|
||||||
|
#ifdef CONFIG_F2FS_CHECK_FS
|
||||||
|
bool mir_exist;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
exist = f2fs_test_and_set_bit(offset, se->cur_valid_map);
|
||||||
|
#ifdef CONFIG_F2FS_CHECK_FS
|
||||||
|
mir_exist = f2fs_test_and_set_bit(offset,
|
||||||
|
se->cur_valid_map_mir);
|
||||||
|
if (unlikely(exist != mir_exist)) {
|
||||||
|
f2fs_err(sbi, "Inconsistent error when setting bitmap, blk:%u, old bit:%d",
|
||||||
|
blkaddr, exist);
|
||||||
|
f2fs_bug_on(sbi, 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (unlikely(exist)) {
|
||||||
|
f2fs_err(sbi, "Bitmap was wrongly set, blk:%u", blkaddr);
|
||||||
|
f2fs_bug_on(sbi, 1);
|
||||||
|
se->valid_blocks--;
|
||||||
|
del = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f2fs_block_unit_discard(sbi) &&
|
||||||
|
!f2fs_test_and_set_bit(offset, se->discard_map))
|
||||||
|
sbi->discard_blks--;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* SSR should never reuse block which is checkpointed
|
||||||
|
* or newly invalidated.
|
||||||
|
*/
|
||||||
|
if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) {
|
||||||
|
if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map))
|
||||||
|
se->ckpt_valid_blocks++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!f2fs_test_bit(offset, se->ckpt_valid_map))
|
||||||
|
se->ckpt_valid_blocks += del;
|
||||||
|
|
||||||
|
return del;
|
||||||
|
}
|
||||||
|
|
||||||
static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
|
static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
|
||||||
{
|
{
|
||||||
struct seg_entry *se;
|
struct seg_entry *se;
|
||||||
unsigned int segno, offset;
|
unsigned int segno, offset;
|
||||||
long int new_vblocks;
|
long int new_vblocks;
|
||||||
bool exist;
|
|
||||||
#ifdef CONFIG_F2FS_CHECK_FS
|
|
||||||
bool mir_exist;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
segno = GET_SEGNO(sbi, blkaddr);
|
segno = GET_SEGNO(sbi, blkaddr);
|
||||||
if (segno == NULL_SEGNO)
|
if (segno == NULL_SEGNO)
|
||||||
@@ -2329,73 +2416,10 @@ static void update_sit_entry(struct f2fs_sb_info *sbi, block_t blkaddr, int del)
|
|||||||
|
|
||||||
/* Update valid block bitmap */
|
/* Update valid block bitmap */
|
||||||
if (del > 0) {
|
if (del > 0) {
|
||||||
exist = f2fs_test_and_set_bit(offset, se->cur_valid_map);
|
del = update_sit_entry_for_alloc(sbi, se, blkaddr, offset, del);
|
||||||
#ifdef CONFIG_F2FS_CHECK_FS
|
|
||||||
mir_exist = f2fs_test_and_set_bit(offset,
|
|
||||||
se->cur_valid_map_mir);
|
|
||||||
if (unlikely(exist != mir_exist)) {
|
|
||||||
f2fs_err(sbi, "Inconsistent error when setting bitmap, blk:%u, old bit:%d",
|
|
||||||
blkaddr, exist);
|
|
||||||
f2fs_bug_on(sbi, 1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (unlikely(exist)) {
|
|
||||||
f2fs_err(sbi, "Bitmap was wrongly set, blk:%u",
|
|
||||||
blkaddr);
|
|
||||||
f2fs_bug_on(sbi, 1);
|
|
||||||
se->valid_blocks--;
|
|
||||||
del = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f2fs_block_unit_discard(sbi) &&
|
|
||||||
!f2fs_test_and_set_bit(offset, se->discard_map))
|
|
||||||
sbi->discard_blks--;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* SSR should never reuse block which is checkpointed
|
|
||||||
* or newly invalidated.
|
|
||||||
*/
|
|
||||||
if (!is_sbi_flag_set(sbi, SBI_CP_DISABLED)) {
|
|
||||||
if (!f2fs_test_and_set_bit(offset, se->ckpt_valid_map))
|
|
||||||
se->ckpt_valid_blocks++;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
exist = f2fs_test_and_clear_bit(offset, se->cur_valid_map);
|
del = update_sit_entry_for_release(sbi, se, blkaddr, offset, del);
|
||||||
#ifdef CONFIG_F2FS_CHECK_FS
|
|
||||||
mir_exist = f2fs_test_and_clear_bit(offset,
|
|
||||||
se->cur_valid_map_mir);
|
|
||||||
if (unlikely(exist != mir_exist)) {
|
|
||||||
f2fs_err(sbi, "Inconsistent error when clearing bitmap, blk:%u, old bit:%d",
|
|
||||||
blkaddr, exist);
|
|
||||||
f2fs_bug_on(sbi, 1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if (unlikely(!exist)) {
|
|
||||||
f2fs_err(sbi, "Bitmap was wrongly cleared, blk:%u",
|
|
||||||
blkaddr);
|
|
||||||
f2fs_bug_on(sbi, 1);
|
|
||||||
se->valid_blocks++;
|
|
||||||
del = 0;
|
|
||||||
} else if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) {
|
|
||||||
/*
|
|
||||||
* If checkpoints are off, we must not reuse data that
|
|
||||||
* was used in the previous checkpoint. If it was used
|
|
||||||
* before, we must track that to know how much space we
|
|
||||||
* really have.
|
|
||||||
*/
|
|
||||||
if (f2fs_test_bit(offset, se->ckpt_valid_map)) {
|
|
||||||
spin_lock(&sbi->stat_lock);
|
|
||||||
sbi->unusable_block_count++;
|
|
||||||
spin_unlock(&sbi->stat_lock);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (f2fs_block_unit_discard(sbi) &&
|
|
||||||
f2fs_test_and_clear_bit(offset, se->discard_map))
|
|
||||||
sbi->discard_blks++;
|
|
||||||
}
|
}
|
||||||
if (!f2fs_test_bit(offset, se->ckpt_valid_map))
|
|
||||||
se->ckpt_valid_blocks += del;
|
|
||||||
|
|
||||||
__mark_sit_entry_dirty(sbi, segno);
|
__mark_sit_entry_dirty(sbi, segno);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user