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 X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1751C0650F for ; Tue, 6 Aug 2019 02:25:43 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 938A9208C3 for ; Tue, 6 Aug 2019 02:25:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sourceforge.net header.i=@sourceforge.net header.b="V5XmqD/7"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=sf.net header.i=@sf.net header.b="l2T/N/HU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 938A9208C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-f2fs-devel-bounces@lists.sourceforge.net Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1hupAV-0002Ur-5k; Tue, 06 Aug 2019 02:25:43 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1hupAU-0002Ul-Mm for linux-f2fs-devel@lists.sourceforge.net; Tue, 06 Aug 2019 02:25:42 +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: MIME-Version:Date:Message-ID:From:References:CC:To:Subject: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=H34i7KFGv2emAga55grC8Yrx/NqIEVN3b0bTzlxiNyM=; b=V5XmqD/7Zr7wTdyjyAfjTeuLcm eJ5hrRBdQwpOQSHKTJt8UmXUEF38G6bPxNy9Pp5hFhVFelfXMvr82F5wLyqroL0ZtxYcCL+SqEhtG WmXgpPS0fPX5cdzqVhb0u200AMxlV1S0+iumooeiFUOMQskMua4582F0PzAaWhry2EAM=; 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:MIME-Version:Date: Message-ID:From:References:CC:To:Subject: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=H34i7KFGv2emAga55grC8Yrx/NqIEVN3b0bTzlxiNyM=; b=l2T/N/HUfHFU95EkoJXnnjthn6 7ZNKAIIkUr853tcKRwep/xAypsoceacUwE0TcQvzL2ib+gEEmgLjo3qwNOKVn5dCH0MZPKOtQhnzp CrVeVmMpPN00PiTpdc6KGKz6ycO1av7eazEK8IK2vPhJ4SQluV54kCS4IhNB17d0HSHM=; Received: from szxga06-in.huawei.com ([45.249.212.32] helo=huawei.com) by sfi-mx-4.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) id 1hupAS-00Bnyi-Lt for linux-f2fs-devel@lists.sourceforge.net; Tue, 06 Aug 2019 02:25:42 +0000 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id EFED76CE6834A0EE249C; Tue, 6 Aug 2019 10:25:28 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.210) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 6 Aug 2019 10:25:26 +0800 To: References: <20190805094406.21614-1-yuchao0@huawei.com> From: Chao Yu Message-ID: <7b0cd2e6-7242-ae8d-7e9f-06f6a7ce7dcc@huawei.com> Date: Tue, 6 Aug 2019 10:25:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190805094406.21614-1-yuchao0@huawei.com> Content-Language: en-US X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected X-Headers-End: 1hupAS-00Bnyi-Lt Subject: Re: [f2fs-dev] [PATCH] f2fs-tools: fix stat update in sload/fsck 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-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Jaegeuk, Forgot to add this into dev-test branch? This patch is based on Lihong's one, and I've done simple fsck/slod tests on it. Thanks, On 2019/8/5 17:44, Chao Yu wrote: > Change logic as below: > - fix to account block/node/inode stats correctly in reserve_new_block() > - check overflow in reserve_new_block() > - move stat update from f2fs_alloc_nid() to reserve_new_block() > - adjust write_checkpoint() to update stat for sload/fsck > > Signed-off-by: Chao Yu > --- > fsck/dir.c | 8 ++++---- > fsck/fsck.c | 3 +++ > fsck/fsck.h | 4 ++-- > fsck/mount.c | 12 +++++++++++- > fsck/node.c | 15 ++++----------- > fsck/segment.c | 25 ++++++++++++++++++++++--- > fsck/xattr.c | 2 +- > 7 files changed, 47 insertions(+), 22 deletions(-) > > diff --git a/fsck/dir.c b/fsck/dir.c > index 0984d26..5f4f75e 100644 > --- a/fsck/dir.c > +++ b/fsck/dir.c > @@ -363,7 +363,7 @@ static void make_empty_dir(struct f2fs_sb_info *sbi, struct f2fs_node *inode) > test_and_set_bit_le(1, dent_blk->dentry_bitmap); > > set_summary(&sum, ino, 0, ni.version); > - ret = reserve_new_block(sbi, &blkaddr, &sum, CURSEG_HOT_DATA); > + ret = reserve_new_block(sbi, &blkaddr, &sum, CURSEG_HOT_DATA, 0); > ASSERT(!ret); > > ret = dev_write_block(dent_blk, blkaddr); > @@ -399,7 +399,7 @@ static void page_symlink(struct f2fs_sb_info *sbi, struct f2fs_node *inode, > memcpy(data_blk, symname, symlen); > > set_summary(&sum, ino, 0, ni.version); > - ret = reserve_new_block(sbi, &blkaddr, &sum, CURSEG_WARM_DATA); > + ret = reserve_new_block(sbi, &blkaddr, &sum, CURSEG_WARM_DATA, 1); > ASSERT(!ret); > > ret = dev_write_block(data_blk, blkaddr); > @@ -673,7 +673,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de) > child = calloc(BLOCK_SZ, 1); > ASSERT(child); > > - f2fs_alloc_nid(sbi, &de->ino, 1); > + f2fs_alloc_nid(sbi, &de->ino); > > init_inode_block(sbi, child, de); > > @@ -690,7 +690,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de) > > /* write child */ > set_summary(&sum, de->ino, 0, ni.version); > - ret = reserve_new_block(sbi, &blkaddr, &sum, CURSEG_HOT_NODE); > + ret = reserve_new_block(sbi, &blkaddr, &sum, CURSEG_HOT_NODE, 1); > ASSERT(!ret); > > /* update nat info */ > diff --git a/fsck/fsck.c b/fsck/fsck.c > index ccebad1..e835a22 100644 > --- a/fsck/fsck.c > +++ b/fsck/fsck.c > @@ -2056,6 +2056,9 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi) > int ret; > u_int32_t crc = 0; > > + /* should call from fsck */ > + ASSERT(c.func == FSCK); > + > if (is_set_ckpt_flags(cp, CP_ORPHAN_PRESENT_FLAG)) { > orphan_blks = __start_sum_addr(sbi) - 1; > flags |= CP_ORPHAN_PRESENT_FLAG; > diff --git a/fsck/fsck.h b/fsck/fsck.h > index 5733785..aabe4a3 100644 > --- a/fsck/fsck.h > +++ b/fsck/fsck.h > @@ -241,11 +241,11 @@ int f2fs_sload(struct f2fs_sb_info *); > > /* segment.c */ > int reserve_new_block(struct f2fs_sb_info *, block_t *, > - struct f2fs_summary *, int); > + struct f2fs_summary *, int, bool); > int new_data_block(struct f2fs_sb_info *, void *, > struct dnode_of_data *, int); > int f2fs_build_file(struct f2fs_sb_info *, struct dentry *); > -void f2fs_alloc_nid(struct f2fs_sb_info *, nid_t *, int); > +void f2fs_alloc_nid(struct f2fs_sb_info *, nid_t *); > void set_data_blkaddr(struct dnode_of_data *); > block_t new_node_block(struct f2fs_sb_info *, > struct dnode_of_data *, unsigned int); > diff --git a/fsck/mount.c b/fsck/mount.c > index e5f7f3b..0d378e5 100644 > --- a/fsck/mount.c > +++ b/fsck/mount.c > @@ -2548,7 +2548,17 @@ void write_checkpoint(struct f2fs_sb_info *sbi) > } > > set_cp(free_segment_count, get_free_segments(sbi)); > - set_cp(valid_block_count, sbi->total_valid_block_count); > + if (c.func == FSCK) { > + struct f2fs_fsck *fsck = F2FS_FSCK(sbi); > + > + set_cp(valid_block_count, fsck->chk.valid_blk_cnt); > + set_cp(valid_node_count, fsck->chk.valid_node_cnt); > + set_cp(valid_inode_count, fsck->chk.valid_inode_cnt); > + } else { > + set_cp(valid_block_count, sbi->total_valid_block_count); > + set_cp(valid_node_count, sbi->total_valid_node_count); > + set_cp(valid_inode_count, sbi->total_valid_inode_count); > + } > set_cp(cp_pack_total_block_count, 8 + orphan_blks + get_sb(cp_payload)); > > flags = update_nat_bits_flags(sb, cp, flags); > diff --git a/fsck/node.c b/fsck/node.c > index 882f355..6bb5484 100644 > --- a/fsck/node.c > +++ b/fsck/node.c > @@ -16,11 +16,10 @@ > #include "fsck.h" > #include "node.h" > > -void f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid, int inode) > +void f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid) > { > struct f2fs_nm_info *nm_i = NM_I(sbi); > - struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); > - nid_t i, inode_cnt, node_cnt; > + nid_t i; > > for (i = 0; i < nm_i->max_nid; i++) > if(f2fs_test_bit(i, nm_i->nid_bitmap) == 0) > @@ -29,12 +28,6 @@ void f2fs_alloc_nid(struct f2fs_sb_info *sbi, nid_t *nid, int inode) > ASSERT(i < nm_i->max_nid); > f2fs_set_bit(i, nm_i->nid_bitmap); > *nid = i; > - > - inode_cnt = get_cp(valid_inode_count); > - node_cnt = get_cp(valid_node_count); > - if (inode) > - set_cp(valid_inode_count, inode_cnt + 1); > - set_cp(valid_node_count, node_cnt + 1); > } > > void set_data_blkaddr(struct dnode_of_data *dn) > @@ -87,7 +80,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi, > > get_node_info(sbi, dn->nid, &ni); > set_summary(&sum, dn->nid, 0, ni.version); > - ret = reserve_new_block(sbi, &blkaddr, &sum, type); > + ret = reserve_new_block(sbi, &blkaddr, &sum, type, !ofs); > if (ret) { > free(node_blk); > return 0; > @@ -216,7 +209,7 @@ int get_dnode_of_data(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, > c.alloc_failed = 1; > return -EINVAL; > } > - f2fs_alloc_nid(sbi, &nids[i], 0); > + f2fs_alloc_nid(sbi, &nids[i]); > > dn->nid = nids[i]; > > diff --git a/fsck/segment.c b/fsck/segment.c > index 367865a..2d18358 100644 > --- a/fsck/segment.c > +++ b/fsck/segment.c > @@ -17,12 +17,13 @@ > #include "node.h" > > int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, > - struct f2fs_summary *sum, int type) > + struct f2fs_summary *sum, int type, bool is_inode) > { > struct f2fs_fsck *fsck = F2FS_FSCK(sbi); > struct seg_entry *se; > u64 blkaddr, offset; > u64 old_blkaddr = *to; > + bool is_node = IS_NODESEG(type); > > if (old_blkaddr == NULL_ADDR) { > if (c.func == FSCK) { > @@ -30,12 +31,22 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, > ERR_MSG("Not enough space"); > return -ENOSPC; > } > + if (is_node && fsck->chk.valid_node_cnt >= > + sbi->total_valid_node_count) { > + ERR_MSG("Not enough space for node block"); > + return -ENOSPC; > + } > } else { > if (sbi->total_valid_block_count >= > sbi->user_block_count) { > ERR_MSG("Not enough space"); > return -ENOSPC; > } > + if (is_node && sbi->total_valid_node_count >= > + sbi->total_node_count) { > + ERR_MSG("Not enough space for node block"); > + return -ENOSPC; > + } > } > } > > @@ -58,10 +69,18 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, > > if (old_blkaddr == NULL_ADDR) { > sbi->total_valid_block_count++; > + if (is_node) { > + sbi->total_valid_node_count++; > + if (is_inode) > + sbi->total_valid_inode_count++; > + } > if (c.func == FSCK) { > fsck->chk.valid_blk_cnt++; > - if (IS_NODESEG(type)) > + if (is_node) { > fsck->chk.valid_node_cnt++; > + if (is_inode) > + fsck->chk.valid_inode_cnt++; > + } > } > } > se->dirty = 1; > @@ -92,7 +111,7 @@ int new_data_block(struct f2fs_sb_info *sbi, void *block, > > get_node_info(sbi, dn->nid, &ni); > set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); > - ret = reserve_new_block(sbi, &dn->data_blkaddr, &sum, type); > + ret = reserve_new_block(sbi, &dn->data_blkaddr, &sum, type, 0); > if (ret) { > c.alloc_failed = 1; > return ret; > diff --git a/fsck/xattr.c b/fsck/xattr.c > index 98cbb0c..d51a08a 100644 > --- a/fsck/xattr.c > +++ b/fsck/xattr.c > @@ -83,7 +83,7 @@ static void write_all_xattrs(struct f2fs_sb_info *sbi, > return; > > if (!xnid) { > - f2fs_alloc_nid(sbi, &new_nid, 0); > + f2fs_alloc_nid(sbi, &new_nid); > > set_new_dnode(&dn, inode, NULL, new_nid); > /* NAT entry would be updated by new_node_page. */ > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel