NVMe Zoned Namespace devices can have zone-capacity less than zone-size. Zone-capacity indicates the number of usable blocks in a zone, if zone-capacity is less than zone-size, then the segments which start at/after zone-capacity are considered unusable. Only those segments which start before the zone-capacity are considered as usable and added to the free_segment_count and free_segment_bitmap of the kernel.
Allow fsck to find the free_segment_count based on the zone-capacity and compare with checkpoint values. Signed-off-by: Aravind Ramesh <aravind.ram...@wdc.com> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawas...@wdc.com> --- fsck/fsck.c | 5 ++-- fsck/fsck.h | 2 ++ fsck/mount.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/fsck/fsck.c b/fsck/fsck.c index e110f3d..ba2340d 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -1905,11 +1905,12 @@ int fsck_chk_meta(struct f2fs_sb_info *sbi) if (IS_NODESEG(se->type)) sit_node_blks += se->valid_blocks; } - if (fsck->chk.sit_free_segs + sit_valid_segs != TOTAL_SEGS(sbi)) { + if (fsck->chk.sit_free_segs + sit_valid_segs != + get_usable_seg_count(sbi)) { ASSERT_MSG("SIT usage does not match: sit_free_segs %u, " "sit_valid_segs %u, total_segs %u", fsck->chk.sit_free_segs, sit_valid_segs, - TOTAL_SEGS(sbi)); + get_usable_seg_count(sbi)); return -EINVAL; } diff --git a/fsck/fsck.h b/fsck/fsck.h index bc6a435..e86730c 100644 --- a/fsck/fsck.h +++ b/fsck/fsck.h @@ -224,6 +224,8 @@ extern u32 update_nat_bits_flags(struct f2fs_super_block *, struct f2fs_checkpoint *, u32); extern void write_nat_bits(struct f2fs_sb_info *, struct f2fs_super_block *, struct f2fs_checkpoint *, int); +extern unsigned int get_usable_seg_count(struct f2fs_sb_info *); +extern bool is_usable_seg(struct f2fs_sb_info *, unsigned int); /* dump.c */ struct dump_option { diff --git a/fsck/mount.c b/fsck/mount.c index d0f2eab..72ca0cb 100644 --- a/fsck/mount.c +++ b/fsck/mount.c @@ -30,6 +30,76 @@ #define ACL_OTHER (0x20) #endif +static int get_device_idx(struct f2fs_sb_info *sbi, u_int32_t segno) +{ + block_t seg_start_blkaddr; + int i; + + seg_start_blkaddr = SM_I(sbi)->main_blkaddr + + segno * DEFAULT_BLOCKS_PER_SEGMENT; + for (i = 0; i < c.ndevs; i++) + if (c.devices[i].start_blkaddr <= seg_start_blkaddr && + c.devices[i].end_blkaddr > seg_start_blkaddr) + return i; + return 0; +} + +#ifdef HAVE_LINUX_BLKZONED_H + +static int get_zone_idx_from_dev(struct f2fs_sb_info *sbi, + u_int32_t segno, u_int32_t dev_idx) +{ + block_t seg_start_blkaddr = START_BLOCK(sbi, segno); + + return (seg_start_blkaddr - c.devices[dev_idx].start_blkaddr) >> + log_base_2(sbi->segs_per_sec * sbi->blocks_per_seg); +} + +bool is_usable_seg(struct f2fs_sb_info *sbi, unsigned int segno) +{ + unsigned int secno = segno / sbi->segs_per_sec; + block_t seg_start = START_BLOCK(sbi, segno); + block_t blocks_per_sec = sbi->blocks_per_seg * sbi->segs_per_sec; + unsigned int dev_idx = get_device_idx(sbi, segno); + unsigned int zone_idx = get_zone_idx_from_dev(sbi, segno, dev_idx); + unsigned int sec_off = SM_I(sbi)->main_blkaddr >> + log_base_2(blocks_per_sec); + + if (zone_idx < c.devices[dev_idx].nr_rnd_zones) + return true; + + if (c.devices[dev_idx].zoned_model != F2FS_ZONED_HM) + return true; + + return seg_start < ((sec_off + secno) * blocks_per_sec) + + c.devices[dev_idx].zone_cap_blocks[zone_idx]; +} + +unsigned int get_usable_seg_count(struct f2fs_sb_info *sbi) +{ + unsigned int i, usable_seg_count = 0; + + for (i = 0; i < TOTAL_SEGS(sbi); i++) + if (is_usable_seg(sbi, i)) + usable_seg_count++; + + return usable_seg_count; +} + +#else + +bool is_usable_seg(struct f2fs_sb_info *sbi, unsigned int segno) +{ + return true; +} + +unsigned int get_usable_seg_count(struct f2fs_sb_info *sbi) +{ + return TOTAL_SEGS(sbi); +} + +#endif + u32 get_free_segments(struct f2fs_sb_info *sbi) { u32 i, free_segs = 0; @@ -37,7 +107,8 @@ u32 get_free_segments(struct f2fs_sb_info *sbi) for (i = 0; i < TOTAL_SEGS(sbi); i++) { struct seg_entry *se = get_seg_entry(sbi, i); - if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, i)) + if (se->valid_blocks == 0x0 && !IS_CUR_SEGNO(sbi, i) && + is_usable_seg(sbi, i)) free_segs++; } return free_segs; @@ -2337,7 +2408,7 @@ void build_sit_area_bitmap(struct f2fs_sb_info *sbi) memcpy(ptr, se->cur_valid_map, SIT_VBLOCK_MAP_SIZE); ptr += SIT_VBLOCK_MAP_SIZE; - if (se->valid_blocks == 0x0) { + if (se->valid_blocks == 0x0 && is_usable_seg(sbi, segno)) { if (le32_to_cpu(sbi->ckpt->cur_node_segno[0]) == segno || le32_to_cpu(sbi->ckpt->cur_data_segno[0]) == segno || le32_to_cpu(sbi->ckpt->cur_node_segno[1]) == segno || -- 2.19.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel