From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CDC0CC77B7A for ; Fri, 26 May 2023 03:25:23 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1q2O4s-00023d-W4; Fri, 26 May 2023 03:25:19 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1q2O4r-00023X-5M for linux-f2fs-devel@lists.sourceforge.net; Fri, 26 May 2023 03:25:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: From:References:Cc:To:Subject:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=h8S0q6P2YCbq4EfVbeoQy7rv0xDNo2b4SGfDbmUPPvs=; b=mvMvweNsxiibSCzbIBiSlrr0yN CSkFphaLeiznY3zTfZEqg/FoA12Wg0SSej4Fx7MVX8JyUwHHGwDGR3wO/9U33kaJEC02MKFJ7scsW Id8k+9fwkrmlQ3h1P71qW6P5oE9GAGyk7NIGWHdehHJmw5Fgg2KnHM9qHh9AzOSva22A=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:Cc:To: Subject:MIME-Version:Date:Message-ID:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=h8S0q6P2YCbq4EfVbeoQy7rv0xDNo2b4SGfDbmUPPvs=; b=cZ/F/cWBaq3rczf/qIesgkn94B 1/RmCuj2h1sxsdzOoanHCP1HtnwMMo70CDZAlC2LvorVmZcRp8zZYm5LgdlqIgGvNaZhC3l8ixdl/ Snd5DtuOzKKEx5TArEEKQ1KqVygWaXTyewUJImVsapzVCWC/KtswUH0+EjKUbWvqx3sc=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1q2O4q-002reG-Q3 for linux-f2fs-devel@lists.sourceforge.net; Fri, 26 May 2023 03:25:17 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5D3C2646D8 for ; Fri, 26 May 2023 03:25:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3197BC433D2; Fri, 26 May 2023 03:25:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685071510; bh=Bm4Dxs55HedgmIwSVMIWw3KdNzyuSGhL6iGT2Ux63Jg=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=LYG91t20TQh0MYXHr9BgSCpR8/Gu5vutRQnKKuvrb4MEjfjorURFb95D5hJG5pin5 cnasnbXYg6L0OMXmwFz77mDdRH7PG8r8UCVYFOuj7JFsLu9BKiIiME+wxObYxEFOjO Pc8QRf65ve2/4rrAWMzN97v6IqE58QiEdx8EKhIBpyYeE2C9iSdayRXnUXjFHID2No aTFa4+QKf6gIPhyjDlO/5UaRYGJ1/5HZhel3sNdYtrgQI70UHQ6bRVdh0J9aWuCTnm pN0sR9JCnMCB72JeML5NfuNBxLgtPI+tvkB8YCtZ9e49kA25noQP3TeTMBLdzgIJGu LLIwr6K2ydpvQ== Message-ID: Date: Fri, 26 May 2023 11:25:08 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Content-Language: en-US To: Jaegeuk Kim References: <20230517082632.748914-1-chao@kernel.org> <20230517082632.748914-3-chao@kernel.org> From: Chao Yu In-Reply-To: X-Headers-End: 1q2O4q-002reG-Q3 Subject: Re: [f2fs-dev] [PATCH 3/4] mkfs.f2fs: cleanup w/ alloc_next_free_block() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-f2fs-devel@lists.sourceforge.net Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net On 2023/5/24 9:40, Jaegeuk Kim wrote: > 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 >>>> --- >>>> 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? Could you please check below patch? [PATCH v2 4/4] mkfs.f2fs: refactor format flow for cleanup Thanks, > >> >> [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