Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp674910rdb; Fri, 17 Nov 2023 09:25:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IGOY2KSpxiG5le0Y9FMK5LjoUfOBlug0E59GUvLaQw+YgdrrB6hBCdjnVUH6kYqlTzW/zUE X-Received: by 2002:a17:902:f541:b0:1ce:5bc8:4734 with SMTP id h1-20020a170902f54100b001ce5bc84734mr4736940plf.30.1700241906357; Fri, 17 Nov 2023 09:25:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700241906; cv=none; d=google.com; s=arc-20160816; b=VkkjwsXjzL5uMKEj/lq1NXInA1fBpO2CUG/W9e9KByQ0RBcmcw9m5IpQGGJtAJfSLx etVKMR0Oc+aUX1uw5j8nopAr1qBd4J5pVynkHfzil98W14NTHgRC4hjtHA6AL8q3VUaQ u/F2kiGQhrjPqaGFVpMZ+QwWNr92qzAHrJBeqCZvE+muL4XHFekXumHovTfMnXE73Nql KMf/cc4h7zpgtnQ+KohMpdgviktgr5DwlgRMSp5dyTqHgQNOm3HpEbgCouA7mHghBCeK DUirPcMO736qqox0jBEGtoL+qEtQJCJbLMw3BMihX1xzihWbYtvF8snu43LtopQ5BSlU ih5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hZ0dernX1mjzZEua7dpzISsijAUC+xDiOXveKYozVjY=; fh=StCp4x7toPjJ7Hl1l6kR6a7AIPaInJevDOxGpZfmXso=; b=cTee7gDwoOQYutuKUpnEBaQdq2ifEt+NMGRV1Br0vJK8SnLKlhp7R8lU752WueMoyX qD2JR4wV60V3+aBWShNGQ8G4hPIJ0bfcjHmcYWjlZ1aHEWxBIb03fC+8ZwnmloGRtJ+2 ahT5Mpj/2ZpGzgKFEgO2kE8LNH2Uf/V8jLd+3rtJfvsL50utVgjwZ2yUDBn0CB3izKd9 qzciwfE6gCjhwkLnW8YW57mmCTWu1i9nbXYVI6T6dOXe/IZwSt39m+jRWIJebKvM+O/2 PB3gsEeqG15TXKy/5BcNoOznt4tkkzKcsNByv9t5kF1m+YTMJsK0vaUfnmCnWUsyPmet pPWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ItTF4IXx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id o1-20020a170903210100b001bdd58f685fsi2117677ple.85.2023.11.17.09.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 09:25:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ItTF4IXx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 117E68208AEF; Fri, 17 Nov 2023 09:25:03 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346147AbjKQRYt (ORCPT + 99 others); Fri, 17 Nov 2023 12:24:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230186AbjKQRYs (ORCPT ); Fri, 17 Nov 2023 12:24:48 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A94ECAD for ; Fri, 17 Nov 2023 09:24:44 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 242D3C433C8; Fri, 17 Nov 2023 17:24:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700241884; bh=26MRHWylt0nXrukBmgnOlVNwwDicHj9Fjs4MTZhPT1o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ItTF4IXxx5vwEDN29iFnozgfWUQ6cWEkSzmh2g4PNwK+wIdgfgS40KI9xbcPSPzMi MzRl1t5U9WaMKNaEssVcNkrmlixJGB22SN2GdoGRlKvSbWbQ/dSqpiuGryrjxrUEh8 oVWZoga/00jwqqHFguQR2P/0r1W0vVYXz6cgpwJhviJl/ijzxVVQ5zB6jZt88aQ0De jvWhQYpBDl5pTGoXgvNRvqHbo12RKOXU5B8k75A0qVsipFzkNkte/Ytgk6Tl7kw8l5 IDslvubfAm+CcmnOgcmmYeSyfnwoiRq075ylCUNAoxClXEuyR5eHBLFkXFUVPta7YA 68O1gUYkmaTOw== Date: Fri, 17 Nov 2023 09:24:42 -0800 From: Jaegeuk Kim To: Chao Yu Cc: Daeho Jeong , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com, Daeho Jeong Subject: Re: [f2fs-dev] [PATCH v2] f2fs-tools: do not reuse corrupted quota inodes Message-ID: References: <20231027002123.1195780-1-daeho43@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 17 Nov 2023 09:25:03 -0800 (PST) On 11/15, Chao Yu wrote: > On 2023/10/27 8:21, Daeho Jeong wrote: > > From: Daeho Jeong > > > > When we detect quota inode corruption, we better deallocate the current > > space and allocate new ones for a clean start. > > > > Signed-off-by: Daeho Jeong > > > > --- > > v2: change node count check when creating a new node block > > --- > > fsck/fsck.c | 148 +++++++++++++++++++++++++++++++++++-------------- > > fsck/segment.c | 5 +- > > 2 files changed, 109 insertions(+), 44 deletions(-) > > > > diff --git a/fsck/fsck.c b/fsck/fsck.c > > index 99cface..dc8e282 100644 > > --- a/fsck/fsck.c > > +++ b/fsck/fsck.c > > @@ -67,6 +67,14 @@ int f2fs_set_sit_bitmap(struct f2fs_sb_info *sbi, u32 blk) > > return f2fs_set_bit(BLKOFF_FROM_MAIN(sbi, blk), fsck->sit_area_bitmap); > > } > > +static inline int f2fs_clear_sit_bitmap(struct f2fs_sb_info *sbi, u32 blk) > > +{ > > + struct f2fs_fsck *fsck = F2FS_FSCK(sbi); > > + > > + return f2fs_clear_bit(BLKOFF_FROM_MAIN(sbi, blk), > > + fsck->sit_area_bitmap); > > +} > > + > > static int add_into_hard_link_list(struct f2fs_sb_info *sbi, > > u32 nid, u32 link_cnt) > > { > > @@ -2150,6 +2158,9 @@ int fsck_chk_quota_node(struct f2fs_sb_info *sbi) > > return ret; > > } > > +static void fsck_disconnect_file(struct f2fs_sb_info *sbi, nid_t ino, > > + bool dealloc); > > + > > int fsck_chk_quota_files(struct f2fs_sb_info *sbi) > > { > > struct f2fs_fsck *fsck = F2FS_FSCK(sbi); > > @@ -2181,6 +2192,8 @@ int fsck_chk_quota_files(struct f2fs_sb_info *sbi) > > if (c.fix_on) { > > DBG(0, "Fixing Quota file ([%3d] ino [0x%x])\n", > > qtype, ino); > > + fsck_disconnect_file(sbi, ino, true); > > + f2fs_rebuild_qf_inode(sbi, qtype); > > f2fs_filesize_update(sbi, ino, 0); > > ret = quota_write_inode(sbi, qtype); > > if (!ret) { > > @@ -2874,10 +2887,53 @@ static int fsck_do_reconnect_file(struct f2fs_sb_info *sbi, > > return 0; > > } > > -static void fsck_failed_reconnect_file_dnode(struct f2fs_sb_info *sbi, > > - struct f2fs_inode *inode, nid_t nid) > > +static inline void release_inode_cnt(struct f2fs_sb_info *sbi, bool dealloc) > > +{ > > + F2FS_FSCK(sbi)->chk.valid_inode_cnt--; > > + if (dealloc) > > + sbi->total_valid_inode_count--; > > +} > > + > > +static inline void release_node_cnt(struct f2fs_sb_info *sbi, bool dealloc) > > +{ > > + F2FS_FSCK(sbi)->chk.valid_node_cnt--; > > + if (dealloc) > > + sbi->total_valid_node_count--; > > +} > > + > > +static inline void release_block_cnt(struct f2fs_sb_info *sbi, bool dealloc) > > +{ > > + F2FS_FSCK(sbi)->chk.valid_blk_cnt--; > > + if (dealloc) > > + sbi->total_valid_block_count--; > > +} > > + > > +static inline void release_block(struct f2fs_sb_info *sbi, u64 blkaddr, > > + bool dealloc) > > +{ > > + f2fs_clear_main_bitmap(sbi, blkaddr); > > + if (dealloc) { > > + struct seg_entry *se; > > + u64 offset; > > + > > + se = get_seg_entry(sbi, GET_SEGNO(sbi, blkaddr)); > > + offset = OFFSET_IN_SEG(sbi, blkaddr); > > + se->valid_blocks--; > > + f2fs_clear_bit(offset, (char *)se->cur_valid_map); > > + se->dirty = 1; > > + f2fs_clear_sit_bitmap(sbi, blkaddr); > > + } > > +} > > + > > +static inline void release_nat_entry(struct f2fs_sb_info *sbi, u32 nid) > > +{ > > + nullify_nat_entry(sbi, nid); > > + F2FS_FSCK(sbi)->chk.valid_nat_entry_cnt--; > > +} > > + > > +static void fsck_disconnect_file_dnode(struct f2fs_sb_info *sbi, > > + struct f2fs_inode *inode, nid_t nid, bool dealloc) > > { > > - struct f2fs_fsck *fsck = F2FS_FSCK(sbi); > > struct f2fs_node *node; > > struct node_info ni; > > u32 addr; > > @@ -2890,27 +2946,29 @@ static void fsck_failed_reconnect_file_dnode(struct f2fs_sb_info *sbi, > > err = dev_read_block(node, ni.blk_addr); > > ASSERT(err >= 0); > > - fsck->chk.valid_node_cnt--; > > - fsck->chk.valid_blk_cnt--; > > - f2fs_clear_main_bitmap(sbi, ni.blk_addr); > > + release_node_cnt(sbi, dealloc); > > + release_block_cnt(sbi, dealloc); > > + release_block(sbi, ni.blk_addr, dealloc); > > for (i = 0; i < ADDRS_PER_BLOCK(inode); i++) { > > addr = le32_to_cpu(node->dn.addr[i]); > > if (!addr) > > continue; > > - fsck->chk.valid_blk_cnt--; > > + release_block_cnt(sbi, dealloc); > > if (addr == NEW_ADDR || addr == COMPRESS_ADDR) > > continue; > > - f2fs_clear_main_bitmap(sbi, addr); > > + release_block(sbi, addr, dealloc); > > } > > + if (dealloc) > > + release_nat_entry(sbi, nid); > > + > > free(node); > > } > > -static void fsck_failed_reconnect_file_idnode(struct f2fs_sb_info *sbi, > > - struct f2fs_inode *inode, nid_t nid) > > +static void fsck_disconnect_file_idnode(struct f2fs_sb_info *sbi, > > + struct f2fs_inode *inode, nid_t nid, bool dealloc) > > { > > - struct f2fs_fsck *fsck = F2FS_FSCK(sbi); > > struct f2fs_node *node; > > struct node_info ni; > > nid_t tmp; > > @@ -2923,24 +2981,26 @@ static void fsck_failed_reconnect_file_idnode(struct f2fs_sb_info *sbi, > > err = dev_read_block(node, ni.blk_addr); > > ASSERT(err >= 0); > > - fsck->chk.valid_node_cnt--; > > - fsck->chk.valid_blk_cnt--; > > - f2fs_clear_main_bitmap(sbi, ni.blk_addr); > > + release_node_cnt(sbi, dealloc); > > + release_block_cnt(sbi, dealloc); > > + release_block(sbi, ni.blk_addr, dealloc); > > for (i = 0; i < NIDS_PER_BLOCK; i++) { > > tmp = le32_to_cpu(node->in.nid[i]); > > if (!tmp) > > continue; > > - fsck_failed_reconnect_file_dnode(sbi, inode, tmp); > > + fsck_disconnect_file_dnode(sbi, inode, tmp, dealloc); > > } > > + if (dealloc) > > + release_nat_entry(sbi, nid); > > + > > free(node); > > } > > -static void fsck_failed_reconnect_file_didnode(struct f2fs_sb_info *sbi, > > - struct f2fs_inode *inode, nid_t nid) > > +static void fsck_disconnect_file_didnode(struct f2fs_sb_info *sbi, > > + struct f2fs_inode *inode, nid_t nid, bool dealloc) > > { > > - struct f2fs_fsck *fsck = F2FS_FSCK(sbi); > > struct f2fs_node *node; > > struct node_info ni; > > nid_t tmp; > > @@ -2953,28 +3013,26 @@ static void fsck_failed_reconnect_file_didnode(struct f2fs_sb_info *sbi, > > err = dev_read_block(node, ni.blk_addr); > > ASSERT(err >= 0); > > - fsck->chk.valid_node_cnt--; > > - fsck->chk.valid_blk_cnt--; > > - f2fs_clear_main_bitmap(sbi, ni.blk_addr); > > + release_node_cnt(sbi, dealloc); > > + release_block_cnt(sbi, dealloc); > > + release_block(sbi, ni.blk_addr, dealloc); > > for (i = 0; i < NIDS_PER_BLOCK; i++) { > > tmp = le32_to_cpu(node->in.nid[i]); > > if (!tmp) > > continue; > > - fsck_failed_reconnect_file_idnode(sbi, inode, tmp); > > + fsck_disconnect_file_idnode(sbi, inode, tmp, dealloc); > > } > > + if (dealloc) > > + release_nat_entry(sbi, nid); > > + > > free(node); > > } > > -/* > > - * Counters and main_area_bitmap are already changed during checking > > - * inode block, so clear them. There is no need to clear new blocks > > - * allocted to lost+found. > > - */ > > -static void fsck_failed_reconnect_file(struct f2fs_sb_info *sbi, nid_t ino) > > +static void fsck_disconnect_file(struct f2fs_sb_info *sbi, nid_t ino, > > + bool dealloc) > > { > > - struct f2fs_fsck *fsck = F2FS_FSCK(sbi); > > struct f2fs_node *node; > > struct node_info ni; > > nid_t nid; > > @@ -2988,18 +3046,18 @@ static void fsck_failed_reconnect_file(struct f2fs_sb_info *sbi, nid_t ino) > > ASSERT(err >= 0); > > /* clear inode counters */ > > - fsck->chk.valid_inode_cnt--; > > - fsck->chk.valid_node_cnt--; > > - fsck->chk.valid_blk_cnt--; > > - f2fs_clear_main_bitmap(sbi, ni.blk_addr); > > + release_inode_cnt(sbi, dealloc); > > + release_node_cnt(sbi, dealloc); > > + release_block_cnt(sbi, dealloc); > > + release_block(sbi, ni.blk_addr, dealloc); > > /* clear xnid counters */ > > if (node->i.i_xattr_nid) { > > nid = le32_to_cpu(node->i.i_xattr_nid); > > - fsck->chk.valid_node_cnt--; > > - fsck->chk.valid_blk_cnt--; > > + release_node_cnt(sbi, dealloc); > > + release_block_cnt(sbi, dealloc); > > get_node_info(sbi, nid, &ni); > > - f2fs_clear_main_bitmap(sbi, ni.blk_addr); > > + release_block(sbi, ni.blk_addr, dealloc); > > Needs to release xattr node's nat entry, right? > > if (dealloc) > release_nat_entry(sbi, nid); Daeho? > > Thanks, > > > } > > /* clear data counters */ > > @@ -3009,10 +3067,10 @@ static void fsck_failed_reconnect_file(struct f2fs_sb_info *sbi, nid_t ino) > > block_t addr = le32_to_cpu(node->i.i_addr[ofs + i]); > > if (!addr) > > continue; > > - fsck->chk.valid_blk_cnt--; > > + release_block_cnt(sbi, dealloc); > > if (addr == NEW_ADDR || addr == COMPRESS_ADDR) > > continue; > > - f2fs_clear_main_bitmap(sbi, addr); > > + release_block(sbi, addr, dealloc); > > } > > } > > @@ -3024,18 +3082,24 @@ static void fsck_failed_reconnect_file(struct f2fs_sb_info *sbi, nid_t ino) > > switch (i) { > > case 0: /* direct node */ > > case 1: > > - fsck_failed_reconnect_file_dnode(sbi, &node->i, nid); > > + fsck_disconnect_file_dnode(sbi, &node->i, nid, > > + dealloc); > > break; > > case 2: /* indirect node */ > > case 3: > > - fsck_failed_reconnect_file_idnode(sbi, &node->i, nid); > > + fsck_disconnect_file_idnode(sbi, &node->i, nid, > > + dealloc); > > break; > > case 4: /* double indirect node */ > > - fsck_failed_reconnect_file_didnode(sbi, &node->i, nid); > > + fsck_disconnect_file_didnode(sbi, &node->i, nid, > > + dealloc); > > break; > > } > > } > > + if (dealloc) > > + release_nat_entry(sbi, ino); > > + > > free(node); > > } > > @@ -3121,7 +3185,7 @@ static int fsck_reconnect_file(struct f2fs_sb_info *sbi) > > if (fsck_do_reconnect_file(sbi, lpf_node, node)) { > > DBG(1, "Failed to reconnect inode [0x%x]\n", > > nid); > > - fsck_failed_reconnect_file(sbi, nid); > > + fsck_disconnect_file(sbi, nid, false); > > continue; > > } > > diff --git a/fsck/segment.c b/fsck/segment.c > > index 3a9500f..4e326c4 100644 > > --- a/fsck/segment.c > > +++ b/fsck/segment.c > > @@ -37,7 +37,7 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, > > return -ENOSPC; > > } > > if (is_node && fsck->chk.valid_node_cnt >= > > - sbi->total_valid_node_count) { > > + sbi->total_node_count) { > > ERR_MSG("Not enough space for node block\n"); > > return -ENOSPC; > > } > > @@ -76,7 +76,7 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, > > se = get_seg_entry(sbi, GET_SEGNO(sbi, blkaddr)); > > offset = OFFSET_IN_SEG(sbi, blkaddr); > > - se->type = type; > > + se->type = se->orig_type = type; > > if (se->valid_blocks == 0) > > SM_I(sbi)->free_segments--; > > se->valid_blocks++; > > @@ -101,6 +101,7 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, > > if (c.func == FSCK) { > > fsck->chk.valid_blk_cnt++; > > if (is_node) { > > + fsck->chk.valid_nat_entry_cnt++; > > fsck->chk.valid_node_cnt++; > > if (is_inode) > > fsck->chk.valid_inode_cnt++;