All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Aravind Ramesh <aravind.ramesh@wdc.com>
Cc: matias.bjorling@wdc.com, linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH 2/2] fsck.f2fs: validate free seg count on zns device
Date: Mon, 13 Jul 2020 12:07:36 -0700	[thread overview]
Message-ID: <20200713190736.GA3131494@google.com> (raw)
In-Reply-To: <20200702155427.13372-3-aravind.ramesh@wdc.com>

Hi Aravind,

On 07/02, Aravind Ramesh wrote:
> 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.ramesh@wdc.com>
> Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@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)

I've applied the below small change to avoid Android build error.

--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -88,7 +88,7 @@ unsigned int get_usable_seg_count(struct f2fs_sb_info *sbi)

 #else

-bool is_usable_seg(struct f2fs_sb_info *sbi, unsigned int segno)
+bool is_usable_seg(struct f2fs_sb_info *UNUSED(sbi), unsigned int UNUSED(segno))
 {
        return true;
 }

Thanks,

> +{
> +	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

  reply	other threads:[~2020-07-13 19:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-02 15:54 [f2fs-dev] [PATCH 0/2] f2fs-tools: add zone-capacity support Aravind Ramesh
2020-07-02 15:54 ` [f2fs-dev] [PATCH 1/2] mkfs.f2fs: zns " Aravind Ramesh
2020-07-17  7:28   ` Chao Yu
2020-07-17  8:36     ` Aravind Ramesh
2020-07-02 15:54 ` [f2fs-dev] [PATCH 2/2] fsck.f2fs: validate free seg count on zns device Aravind Ramesh
2020-07-13 19:07   ` Jaegeuk Kim [this message]
2020-07-15 19:25     ` Aravind Ramesh
2020-07-17  7:37   ` Chao Yu
2020-07-17  8:36     ` Aravind Ramesh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200713190736.GA3131494@google.com \
    --to=jaegeuk@kernel.org \
    --cc=aravind.ramesh@wdc.com \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=matias.bjorling@wdc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.