When fsck needs to assign a new area to a curreng segment, it calls find_next_free_block() function to find a new block to assign. For zoned block devices, fsck checks write pointer consistency with current segments' positions. In case a curseg is inconsistent with the write pointer of the zone it points to, fsck should assign not a new free block but a new free zone/section with write pointer at the zone start, so that next write to the current segment succeeds without error.
To extend find_next_free_block() function's capability to find not only a block but also a zone/section, add new_sec flag to find_next_free_block() function. When new_sec flag is true, skip check for each block's availability so that the check is done with unit of section. Note that it is ensured that one zone has one section for f2fs on zoned block devices. Then the logic to find a new free section is good to find a new free zone. When fsck target devices have ZONED_HM model, set new_sec flag true to call find_next_free_block() from move_curseg_info(). Set curseg's alloc_type not SSR but LFS for the devices with ZONED_HM model, because SSR block allocation is not allowed for zoned block devices. Also skip relocate_curseg_offset() for the devices with ZONED_HM model for the same reason. Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawas...@wdc.com> --- fsck/defrag.c | 2 +- fsck/fsck.h | 2 +- fsck/mount.c | 12 ++++++++---- fsck/segment.c | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fsck/defrag.c b/fsck/defrag.c index fc6b7cf..3473637 100644 --- a/fsck/defrag.c +++ b/fsck/defrag.c @@ -77,7 +77,7 @@ int f2fs_defragment(struct f2fs_sb_info *sbi, u64 from, u64 len, u64 to, int lef if (!f2fs_test_bit(offset, (const char *)se->cur_valid_map)) continue; - if (find_next_free_block(sbi, &target, left, se->type)) { + if (find_next_free_block(sbi, &target, left, se->type, false)) { MSG(0, "Not enough space to migrate blocks"); return -1; } diff --git a/fsck/fsck.h b/fsck/fsck.h index ccf4a39..8da0ebb 100644 --- a/fsck/fsck.h +++ b/fsck/fsck.h @@ -191,7 +191,7 @@ extern void zero_journal_entries(struct f2fs_sb_info *); extern void flush_sit_entries(struct f2fs_sb_info *); extern void move_curseg_info(struct f2fs_sb_info *, u64, int); extern void write_curseg_info(struct f2fs_sb_info *); -extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int); +extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int, bool); extern void duplicate_checkpoint(struct f2fs_sb_info *); extern void write_checkpoint(struct f2fs_sb_info *); extern void write_checkpoints(struct f2fs_sb_info *); diff --git a/fsck/mount.c b/fsck/mount.c index 4814dfe..8d2ba55 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -2430,6 +2430,9 @@ int relocate_curseg_offset(struct f2fs_sb_info *sbi, int type) struct seg_entry *se = get_seg_entry(sbi, curseg->segno); unsigned int i; + if (c.zoned_model == F2FS_ZONED_HM) + return -EINVAL; + for (i = 0; i < sbi->blocks_per_seg; i++) { if (!f2fs_test_bit(i, (const char *)se->cur_valid_map)) break; @@ -2462,7 +2465,7 @@ void set_section_type(struct f2fs_sb_info *sbi, unsigned int segno, int type) } } -int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int want_type) +int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int want_type, bool new_sec) { struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); struct seg_entry *se; @@ -2520,7 +2523,7 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int want_t } } - if (type == want_type && + if (type == want_type && !new_sec && !f2fs_test_bit(offset, (const char *)bitmap)) return 0; @@ -2546,13 +2549,14 @@ void move_curseg_info(struct f2fs_sb_info *sbi, u64 from, int left) ASSERT(ret >= 0); to = from; - ret = find_next_free_block(sbi, &to, left, i); + ret = find_next_free_block(sbi, &to, left, i, + c.zoned_model == F2FS_ZONED_HM); ASSERT(ret == 0); old_segno = curseg->segno; curseg->segno = GET_SEGNO(sbi, to); curseg->next_blkoff = OFFSET_IN_SEG(sbi, to); - curseg->alloc_type = SSR; + curseg->alloc_type = c.zoned_model == F2FS_ZONED_HM ? LFS : SSR; /* update new segno */ ssa_blk = GET_SUM_BLKADDR(sbi, curseg->segno); diff --git a/fsck/segment.c b/fsck/segment.c index e3a90da..ccde05f 100644 --- a/fsck/segment.c +++ b/fsck/segment.c @@ -52,7 +52,7 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, blkaddr = SM_I(sbi)->main_blkaddr; - if (find_next_free_block(sbi, &blkaddr, 0, type)) { + if (find_next_free_block(sbi, &blkaddr, 0, type, false)) { ERR_MSG("Can't find free block"); ASSERT(0); } -- 2.21.0 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel