linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Chao Yu via Linux-f2fs-devel <linux-f2fs-devel@lists.sourceforge.net>
To: Sheng Yong <shengyong@oppo.com>, jaegeuk@kernel.org
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [RFC PATCH 04/24] inject.f2fs: add members in inject_cp
Date: Fri, 8 Nov 2024 10:09:12 +0800	[thread overview]
Message-ID: <2eb62d79-72b3-4621-a83b-eb5cfd207187@kernel.org> (raw)
In-Reply-To: <20241029120956.4186731-5-shengyong@oppo.com>

On 2024/10/29 20:09, Sheng Yong wrote:
> The following members are add to inject more fields in cp:
> 
> * next_blkaddr: inject fsync dnodes
> 
> An error is returned if no fsync dnode is found.
> 
> However, the injection is not supported on zoned device. This is because
> fsync dnodes must remains at the end of current warm node segnemt, any
> dnode change causes all previous dnodes in the chain to be updated
> out-of-place, and there may not have enough space left in the curseg.
> To simplify the injection, it returns an error on zoned device.
> 
> * alloc_type: inject curseg's alloc type
> * crc: inject cp's checksum
> * elapsed_time: inject cp's mount elapsed time
> 
> Signed-off-by: Sheng Yong <shengyong@oppo.com>
> ---
>   fsck/fsck.h       |  3 +-
>   fsck/inject.c     | 80 ++++++++++++++++++++++++++++++++++++++++++++++-
>   fsck/mount.c      | 15 ++++++---
>   man/inject.f2fs.8 |  9 ++++++
>   4 files changed, 101 insertions(+), 6 deletions(-)
> 
> diff --git a/fsck/fsck.h b/fsck/fsck.h
> index b581d3e0da9f..51061e435f5b 100644
> --- a/fsck/fsck.h
> +++ b/fsck/fsck.h
> @@ -222,6 +222,7 @@ extern int f2fs_ra_meta_pages(struct f2fs_sb_info *, block_t, int, int);
>   extern int f2fs_do_mount(struct f2fs_sb_info *);
>   extern void f2fs_do_umount(struct f2fs_sb_info *);
>   extern int f2fs_sparse_initialize_meta(struct f2fs_sb_info *);
> +extern int f2fs_find_fsync_inode(struct f2fs_sb_info *, struct list_head *);
>   
>   extern void flush_journal_entries(struct f2fs_sb_info *);
>   extern void update_curseg_info(struct f2fs_sb_info *, int);
> @@ -238,7 +239,7 @@ extern void duplicate_checkpoint(struct f2fs_sb_info *);
>   extern void write_checkpoint(struct f2fs_sb_info *);
>   extern void write_checkpoints(struct f2fs_sb_info *);
>   extern void write_raw_cp_blocks(struct f2fs_sb_info *sbi,
> -			struct f2fs_checkpoint *cp, int which);
> +			struct f2fs_checkpoint *cp, int which, bool update_crc);
>   extern void update_superblock(struct f2fs_super_block *, int);
>   extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t,
>   			struct f2fs_node *);
> diff --git a/fsck/inject.c b/fsck/inject.c
> index bd6ab8480972..c3e68eb35246 100644
> --- a/fsck/inject.c
> +++ b/fsck/inject.c
> @@ -138,6 +138,10 @@ static void inject_cp_usage(void)
>   	MSG(0, "  cur_node_blkoff: inject cur_node_blkoff array selected by --idx <index>\n");
>   	MSG(0, "  cur_data_segno: inject cur_data_segno array selected by --idx <index>\n");
>   	MSG(0, "  cur_data_blkoff: inject cur_data_blkoff array selected by --idx <index>\n");
> +	MSG(0, "  alloc_type: inject alloc_type array selected by --idx <index>\n");
> +	MSG(0, "  next_blkaddr: inject next_blkaddr of fsync dnodes selected by --idx <index>\n");
> +	MSG(0, "  crc: inject crc checksum\n");
> +	MSG(0, "  elapsed_time: inject elapsed_time\n");
>   }
>   
>   static void inject_nat_usage(void)
> @@ -440,6 +444,7 @@ out:
>   static int inject_cp(struct f2fs_sb_info *sbi, struct inject_option *opt)
>   {
>   	struct f2fs_checkpoint *cp, *cur_cp = F2FS_CKPT(sbi);
> +	bool update_crc = true;
>   	char *buf = NULL;
>   	int ret = 0;
>   
> @@ -518,6 +523,79 @@ static int inject_cp(struct f2fs_sb_info *sbi, struct inject_option *opt)
>   		    opt->idx, opt->cp, get_cp(cur_data_blkoff[opt->idx]),
>   		    (u16)opt->val);
>   		set_cp(cur_data_blkoff[opt->idx], (u16)opt->val);
> +	} else if (!strcmp(opt->mb, "alloc_type")) {
> +		if (opt->idx >= MAX_ACTIVE_LOGS) {
> +			ERR_MSG("invalid index %u of cp->alloc_type[]\n",
> +				opt->idx);
> +			ret = -EINVAL;
> +			goto out;
> +		}
> +		MSG(0, "Info: inject alloc_type[%d] of cp %d: 0x%x -> 0x%x\n",
> +		    opt->idx, opt->cp, cp->alloc_type[opt->idx],
> +		    (unsigned char)opt->val);
> +		cp->alloc_type[opt->idx] = (unsigned char)opt->val;
> +	} else if (!strcmp(opt->mb, "next_blkaddr")) {
> +		struct fsync_inode_entry *entry;
> +		struct list_head inode_list = LIST_HEAD_INIT(inode_list);
> +		struct f2fs_node *node;
> +		block_t blkaddr;
> +		int i = 0;
> +
> +		if (c.zoned_model == F2FS_ZONED_HM) {
> +			ERR_MSG("inject fsync dnodes not supported in "
> +				"zoned device\n");
> +			ret = -EOPNOTSUPP;
> +			goto out;
> +		}
> +
> +		if (!need_fsync_data_record(sbi)) {
> +			ERR_MSG("no need to recover fsync dnodes\n");
> +			ret = -EINVAL;
> +			goto out;
> +		}
> +
> +		ret = f2fs_find_fsync_inode(sbi, &inode_list);
> +		if (ret) {
> +			ERR_MSG("failed to find fsync inodes: %d\n", ret);
> +			goto out;
> +		}
> +
> +		list_for_each_entry(entry, &inode_list, list) {
> +			if (i == opt->idx)
> +				blkaddr = entry->blkaddr;
> +			DBG(0, "[%4d] blkaddr:0x%x\n", i++, entry->blkaddr);
> +		}
> +
> +		if (opt->idx == 0 || opt->idx >= i) {
> +			ERR_MSG("invalid index %u of fsync dnodes range [1, %u]\n",
> +				opt->idx, i);
> +			ret = -EINVAL;
> +			goto out;
> +		}
> +
> +		MSG(0, "Info: inject next_blkaddr[%d] of cp %d: 0x%x -> 0x%x\n",
> +		    opt->idx, opt->cp, blkaddr, (u32)opt->val);
> +
> +		node = malloc(F2FS_BLKSIZE);
> +		ASSERT(node);
> +		ret = dev_read_block(node, blkaddr);
> +		ASSERT(ret >= 0);
> +		F2FS_NODE_FOOTER(node)->next_blkaddr = cpu_to_le32((u32)opt->val);
> +		ret = update_block(sbi, node, &blkaddr, NULL);

Needs to call update_inode() to update & persist chksum fields?

Thanks,

> +		ASSERT(ret >= 0);
> +		goto out;
> +	} else if (!strcmp(opt->mb, "crc")) {
> +		__le32 *crc = (__le32 *)((unsigned char *)cp +
> +						get_cp(checksum_offset));
> +
> +		MSG(0, "Info: inject crc of cp %d: 0x%x -> 0x%x\n",
> +		    opt->cp, le32_to_cpu(*crc), (u32)opt->val);
> +		*crc = cpu_to_le32((u32)opt->val);
> +		update_crc = false;
> +	} else if (!strcmp(opt->mb, "elapsed_time")) {
> +		MSG(0, "Info: inject elapsed_time of cp %d: %llu -> %"PRIu64"\n",
> +		    opt->cp, get_cp(elapsed_time), (u64)opt->val);
> +		set_cp(elapsed_time, (u64)opt->val);
>   	} else {
>   		ERR_MSG("unknown or unsupported member \"%s\"\n", opt->mb);
>   		ret = -EINVAL;
> @@ -525,7 +603,7 @@ static int inject_cp(struct f2fs_sb_info *sbi, struct inject_option *opt)
>   	}
>   
>   	print_ckpt_info(sbi);
> -	write_raw_cp_blocks(sbi, cp, opt->cp);
> +	write_raw_cp_blocks(sbi, cp, opt->cp, update_crc);
>   
>   out:
>   	free(buf);
> diff --git a/fsck/mount.c b/fsck/mount.c
> index bbe29dba0f45..c2e0f1a3a9df 100644
> --- a/fsck/mount.c
> +++ b/fsck/mount.c
> @@ -3454,17 +3454,19 @@ void write_checkpoints(struct f2fs_sb_info *sbi)
>   	write_checkpoint(sbi);
>   }
>   
> -void write_raw_cp_blocks(struct f2fs_sb_info *sbi,
> -			 struct f2fs_checkpoint *cp, int which)
> +void write_raw_cp_blocks(struct f2fs_sb_info *sbi, struct f2fs_checkpoint *cp,
> +			 int which, bool update_crc)
>   {
>   	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
>   	uint32_t crc;
>   	block_t cp_blkaddr;
>   	int ret;
>   
> -	crc = f2fs_checkpoint_chksum(cp);
> -	*((__le32 *)((unsigned char *)cp + get_cp(checksum_offset))) =
> +	if (update_crc) {
> +		crc = f2fs_checkpoint_chksum(cp);
> +		*((__le32 *)((unsigned char *)cp + get_cp(checksum_offset))) =
>   							cpu_to_le32(crc);
> +	}
>   
>   	cp_blkaddr = get_sb(cp_blkaddr);
>   	if (which == 2)
> @@ -3864,6 +3866,11 @@ next:
>   	return err;
>   }
>   
> +int f2fs_find_fsync_inode(struct f2fs_sb_info *sbi, struct list_head *head)
> +{
> +	return find_fsync_inode(sbi, head);
> +}
> +
>   static int do_record_fsync_data(struct f2fs_sb_info *sbi,
>   					struct f2fs_node *node_blk,
>   					block_t blkaddr)
> diff --git a/man/inject.f2fs.8 b/man/inject.f2fs.8
> index 01d58effbfe4..6cf66bcbf2a3 100644
> --- a/man/inject.f2fs.8
> +++ b/man/inject.f2fs.8
> @@ -79,6 +79,15 @@ cur_data_segno array.
>   .TP
>   .BI cur_data_blkoff
>   cur_data_blkoff array.
> +.TP
> +.BI next_blkaddr
> +fsync dnodes.
> +.TP
> +.BI crc
> +crc checksum.
> +.TP
> +.BI elapsed_time
> +elapsed mount time.
>   .RE
>   .TP
>   .BI \-\-nat " 0 or 1 or 2"



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

  reply	other threads:[~2024-11-08  2:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-29 12:09 [f2fs-dev] [RFC PATCH 00/24] f2fs-tools: add testcases Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 01/24] f2fs-tools: add option N to answer no for all questions Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 02/24] dump.f2fs: print checkpoint crc Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 03/24] fsck.f2fs: fix invalidate checkpoint Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 04/24] inject.f2fs: add members in inject_cp Sheng Yong via Linux-f2fs-devel
2024-11-08  2:09   ` Chao Yu via Linux-f2fs-devel [this message]
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 05/24] inject.f2fs: add member `feature' in inject_sb Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 06/24] inject.f2fs: add members in inject_node Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 07/24] inject.f2fs: add member `filename' in inject_dentry Sheng Yong via Linux-f2fs-devel
2024-11-08  6:51   ` Chao Yu via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 08/24] tests: prepare helper scripts for testcases Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 09/24] tests: add fsck testcase of fixing bad super magic Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 10/24] tests: add fsck testcase of fixing errors recorded in sb Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 11/24] tests: add fsck testcase of fixing cp crc Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 12/24] tests: add fsck testcase of fixing nat entry with invalid ino Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 13/24] tests: add fsck testcase of fixing nat entry with invalid blkaddr Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 14/24] tests: add fsck testcase of fixing sit entry type Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 15/24] tests: add fsck testcase of fixing sit entry vblocks Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 16/24] tests: add fsck testcase of fixing sit entry valid_map Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 17/24] tests: add fsck testcase of fixing sum entry nid Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 18/24] tests: add fsck testcase of fixing sum footer type Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 19/24] tests: add fsck testcase of fixing sum entry ofs_in_node Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 20/24] tests: add fsck testcase of fixing invalid i_addr Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 21/24] tests: add fsck testcase of fixing dentry hash code Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 22/24] tests: add fsck testcase of fixing lost dots Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 23/24] tests: add fsck testcase of fixing duplicated dots Sheng Yong via Linux-f2fs-devel
2024-10-29 12:09 ` [f2fs-dev] [RFC PATCH 24/24] tests: add fsck testcase of fixing loop fsync dnodes Sheng Yong via Linux-f2fs-devel

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=2eb62d79-72b3-4621-a83b-eb5cfd207187@kernel.org \
    --to=linux-f2fs-devel@lists.sourceforge.net \
    --cc=chao@kernel.org \
    --cc=jaegeuk@kernel.org \
    --cc=shengyong@oppo.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).