All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jaegeuk Kim <jaegeuk@kernel.org>
To: Chao Yu <chao@kernel.org>
Cc: linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH 3/4] mkfs.f2fs: cleanup w/ alloc_next_free_block()
Date: Tue, 23 May 2023 18:40:17 -0700	[thread overview]
Message-ID: <ZG1rAWuHP+46AiEE@google.com> (raw)
In-Reply-To: <a54081b2-ae51-6331-28df-f292a8009862@kernel.org>

On 05/18, Chao Yu wrote:
> On 2023/5/18 9:36, Jaegeuk Kim wrote:
> > On 05/17, Chao Yu wrote:
> > > Introduce alloc_next_free_block() to wrap below openned codes:
> > > 
> > > 	blkaddr = get_sb(main_blkaddr) +
> > > 			c.cur_seg[curseg_type] * c.blks_per_seg +
> > > 			c.curseg_offset[curseg_type];
> > > 
> > > Meanwhile add curseg_offset field in f2fs_configuration to record
> > > last blkaddr in each log.
> > > 
> > > Signed-off-by: Chao Yu <chao@kernel.org>
> > > ---
> > >   include/f2fs_fs.h  |   2 +
> > >   mkfs/f2fs_format.c | 101 +++++++++++++++++++--------------------------
> > >   2 files changed, 45 insertions(+), 58 deletions(-)
> > > 
> > > diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
> > > index 8475645..05d27ba 100644
> > > --- a/include/f2fs_fs.h
> > > +++ b/include/f2fs_fs.h
> > > @@ -603,6 +603,8 @@ struct f2fs_configuration {
> > >   	/* compression support for sload.f2fs */
> > >   	compress_config_t compress;
> > > +
> > > +	block_t curseg_offset[6];
> > 
> > NR_CURSEG_TYPE?
> 
> The macro is defined after struct f2fs_configuration...
> 
> How about updating all value w/ macro in below patch, as the patch
> relocates struct f2fs_configuration?

Could you please post patches?

> 
> [PATCH 4/4]mkfs.f2fs: refactor format flow for cleanup
> 
> Thanks,
> 
> > 
> > >   };
> > >   #ifdef CONFIG_64BIT
> > > diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
> > > index 620f779..2ca5f48 100644
> > > --- a/mkfs/f2fs_format.c
> > > +++ b/mkfs/f2fs_format.c
> > > @@ -1230,11 +1230,24 @@ static int f2fs_discard_obsolete_dnode(void)
> > >   }
> > >   #endif
> > > +static block_t alloc_next_free_block(int curseg_type, int blkcnt)
> > > +{
> > > +	block_t blkaddr;
> > > +
> > > +	blkaddr = get_sb(main_blkaddr) +
> > > +		c.cur_seg[curseg_type] * c.blks_per_seg +
> > > +		c.curseg_offset[curseg_type];
> > > +
> > > +	c.curseg_offset[curseg_type] += blkcnt;
> > > +
> > > +	return blkaddr;
> > > +}
> > > +
> > >   static int f2fs_write_root_inode(void)
> > >   {
> > >   	struct f2fs_node *raw_node = NULL;
> > > -	uint64_t data_blk_nor;
> > > -	uint64_t main_area_node_seg_blk_offset = 0;
> > > +	block_t data_blkaddr;
> > > +	block_t node_blkaddr;
> > >   	raw_node = calloc(F2FS_BLKSIZE, 1);
> > >   	if (raw_node == NULL) {
> > > @@ -1248,24 +1261,15 @@ static int f2fs_write_root_inode(void)
> > >   	if (c.lpf_ino)
> > >   		raw_node->i.i_links = cpu_to_le32(3);
> > > -	raw_node->footer.next_blkaddr = cpu_to_le32(
> > > -			get_sb(main_blkaddr) +
> > > -			c.cur_seg[CURSEG_HOT_NODE] *
> > > -			c.blks_per_seg + 1);
> > > -
> > > -	data_blk_nor = get_sb(main_blkaddr) +
> > > -		c.cur_seg[CURSEG_HOT_DATA] * c.blks_per_seg;
> > > -	raw_node->i.i_addr[get_extra_isize(raw_node)] = cpu_to_le32(data_blk_nor);
> > > -
> > > -	main_area_node_seg_blk_offset = get_sb(main_blkaddr);
> > > -	main_area_node_seg_blk_offset += c.cur_seg[CURSEG_HOT_NODE] *
> > > -					c.blks_per_seg;
> > > -
> > > -	DBG(1, "\tWriting root inode (hot node), %x %x %x at offset 0x%08"PRIu64"\n",
> > > -			get_sb(main_blkaddr),
> > > -			c.cur_seg[CURSEG_HOT_NODE],
> > > -			c.blks_per_seg, main_area_node_seg_blk_offset);
> > > -	if (write_inode(raw_node, main_area_node_seg_blk_offset) < 0) {
> > > +	data_blkaddr = alloc_next_free_block(CURSEG_HOT_DATA, 1);
> > > +	raw_node->i.i_addr[get_extra_isize(raw_node)] =
> > > +				cpu_to_le32(data_blkaddr);
> > > +
> > > +	node_blkaddr = alloc_next_free_block(CURSEG_HOT_NODE, 1);
> > > +	raw_node->footer.next_blkaddr = cpu_to_le32(node_blkaddr + 1);
> > > +
> > > +	DBG(1, "\tWriting root inode (hot node), offset 0x%x\n", node_blkaddr);
> > > +	if (write_inode(raw_node, node_blkaddr) < 0) {
> > >   		MSG(1, "\tError: While writing the raw_node to disk!!!\n");
> > >   		free(raw_node);
> > >   		return -1;
> > > @@ -1349,8 +1353,8 @@ static int f2fs_write_default_quota(int qtype, unsigned int blkaddr,
> > >   static int f2fs_write_qf_inode(int qtype, int offset)
> > >   {
> > >   	struct f2fs_node *raw_node = NULL;
> > > -	uint64_t data_blk_nor;
> > > -	uint64_t main_area_node_seg_blk_offset = 0;
> > > +	block_t data_blkaddr;
> > > +	block_t node_blkaddr;
> > >   	__le32 raw_id;
> > >   	int i;
> > > @@ -1366,14 +1370,10 @@ static int f2fs_write_qf_inode(int qtype, int offset)
> > >   	raw_node->i.i_blocks = cpu_to_le64(1 + QUOTA_DATA(qtype));
> > >   	raw_node->i.i_flags = F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL;
> > > -	raw_node->footer.next_blkaddr = cpu_to_le32(
> > > -			get_sb(main_blkaddr) +
> > > -			c.cur_seg[CURSEG_HOT_NODE] *
> > > -			c.blks_per_seg + 1 + qtype + 1);
> > > +	node_blkaddr = alloc_next_free_block(CURSEG_HOT_NODE, 1);
> > > +	raw_node->footer.next_blkaddr = cpu_to_le32(node_blkaddr + 1);
> > > -	data_blk_nor = get_sb(main_blkaddr) +
> > > -		c.cur_seg[CURSEG_HOT_DATA] * c.blks_per_seg + 1
> > > -		+ offset * QUOTA_DATA(i);
> > > +	data_blkaddr = alloc_next_free_block(CURSEG_HOT_DATA, QUOTA_DATA(i));
> > >   	if (qtype == 0)
> > >   		raw_id = raw_node->i.i_uid;
> > > @@ -1385,24 +1385,17 @@ static int f2fs_write_qf_inode(int qtype, int offset)
> > >   		ASSERT(0);
> > >   	/* write two blocks */
> > > -	if (f2fs_write_default_quota(qtype, data_blk_nor, raw_id)) {
> > > +	if (f2fs_write_default_quota(qtype, data_blkaddr, raw_id)) {
> > >   		free(raw_node);
> > >   		return -1;
> > >   	}
> > >   	for (i = 0; i < QUOTA_DATA(qtype); i++)
> > >   		raw_node->i.i_addr[get_extra_isize(raw_node) + i] =
> > > -					cpu_to_le32(data_blk_nor + i);
> > > +					cpu_to_le32(data_blkaddr + i);
> > > -	main_area_node_seg_blk_offset = get_sb(main_blkaddr);
> > > -	main_area_node_seg_blk_offset += c.cur_seg[CURSEG_HOT_NODE] *
> > > -					c.blks_per_seg + offset + 1;
> > > -
> > > -	DBG(1, "\tWriting quota inode (hot node), %x %x %x at offset 0x%08"PRIu64"\n",
> > > -			get_sb(main_blkaddr),
> > > -			c.cur_seg[CURSEG_HOT_NODE],
> > > -			c.blks_per_seg, main_area_node_seg_blk_offset);
> > > -	if (write_inode(raw_node, main_area_node_seg_blk_offset) < 0) {
> > > +	DBG(1, "\tWriting quota inode (hot node), offset 0x%x\n", node_blkaddr);
> > > +	if (write_inode(raw_node, node_blkaddr) < 0) {
> > >   		MSG(1, "\tError: While writing the raw_node to disk!!!\n");
> > >   		free(raw_node);
> > >   		return -1;
> > > @@ -1492,8 +1485,8 @@ static block_t f2fs_add_default_dentry_lpf(void)
> > >   static int f2fs_write_lpf_inode(void)
> > >   {
> > >   	struct f2fs_node *raw_node;
> > > -	uint64_t main_area_node_seg_blk_offset;
> > > -	block_t data_blk_nor;
> > > +	block_t data_blkaddr;
> > > +	block_t node_blkaddr;
> > >   	int err = 0;
> > >   	ASSERT(c.lpf_ino);
> > > @@ -1510,28 +1503,20 @@ static int f2fs_write_lpf_inode(void)
> > >   	raw_node->i.i_namelen = le32_to_cpu(strlen(LPF));
> > >   	memcpy(raw_node->i.i_name, LPF, strlen(LPF));
> > > -	raw_node->footer.next_blkaddr = cpu_to_le32(
> > > -			get_sb(main_blkaddr) +
> > > -			c.cur_seg[CURSEG_HOT_NODE] * c.blks_per_seg +
> > > -			1 + c.quota_inum + 1);
> > > +	node_blkaddr = alloc_next_free_block(CURSEG_HOT_NODE, 1);
> > > +	raw_node->footer.next_blkaddr = cpu_to_le32(node_blkaddr + 1);
> > > -	data_blk_nor = f2fs_add_default_dentry_lpf();
> > > -	if (data_blk_nor == 0) {
> > > +	data_blkaddr = f2fs_add_default_dentry_lpf();
> > > +	if (data_blkaddr == 0) {
> > >   		MSG(1, "\tError: Failed to add default dentries for lost+found!!!\n");
> > >   		err = -1;
> > >   		goto exit;
> > >   	}
> > > -	raw_node->i.i_addr[get_extra_isize(raw_node)] = cpu_to_le32(data_blk_nor);
> > > -
> > > -	main_area_node_seg_blk_offset = get_sb(main_blkaddr);
> > > -	main_area_node_seg_blk_offset += c.cur_seg[CURSEG_HOT_NODE] *
> > > -		c.blks_per_seg + c.quota_inum + 1;
> > > +	raw_node->i.i_addr[get_extra_isize(raw_node)] = cpu_to_le32(data_blkaddr);
> > > -	DBG(1, "\tWriting lost+found inode (hot node), %x %x %x at offset 0x%08"PRIu64"\n",
> > > -			get_sb(main_blkaddr),
> > > -			c.cur_seg[CURSEG_HOT_NODE],
> > > -			c.blks_per_seg, main_area_node_seg_blk_offset);
> > > -	if (write_inode(raw_node, main_area_node_seg_blk_offset) < 0) {
> > > +	DBG(1, "\tWriting lost+found inode (hot node), offset 0x%x\n",
> > > +								node_blkaddr);
> > > +	if (write_inode(raw_node, node_blkaddr) < 0) {
> > >   		MSG(1, "\tError: While writing the raw_node to disk!!!\n");
> > >   		err = -1;
> > >   		goto exit;
> > > -- 
> > > 2.40.1


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

  reply	other threads:[~2023-05-24  1:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17  8:26 [f2fs-dev] [PATCH 1/4] f2fs-tools: add noatime for quota file Chao Yu
2023-05-17  8:26 ` [f2fs-dev] [PATCH 2/4] mkfs.f2fs: remove unneeded nat initialization in f2fs_update_nat_root() Chao Yu
2023-05-17  8:26 ` [f2fs-dev] [PATCH 3/4] mkfs.f2fs: cleanup w/ alloc_next_free_block() Chao Yu
2023-05-18  1:36   ` Jaegeuk Kim
2023-05-18  1:59     ` Chao Yu
2023-05-24  1:40       ` Jaegeuk Kim [this message]
2023-05-25  1:22         ` Chao Yu
2023-05-26  3:25         ` Chao Yu
2023-05-17  8:26 ` [f2fs-dev] [PATCH 4/4] mkfs.f2fs: refactor format flow for cleanup Chao Yu

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=ZG1rAWuHP+46AiEE@google.com \
    --to=jaegeuk@kernel.org \
    --cc=chao@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /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.