From patchwork Wed Sep 4 03:17:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13789657 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 DF2D0CD4846 for ; Wed, 4 Sep 2024 03:18:12 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1slgX5-0006Tv-Px; Wed, 04 Sep 2024 03:18:12 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1slgX4-0006Tn-2V for linux-f2fs-devel@lists.sourceforge.net; Wed, 04 Sep 2024 03:18:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=8bdvZIDpCjZTahtq1pwemrlYIoukz8ubMheMWb3aQ5g=; b=JtWMtayY1Ogb7fjJHhGXWPxYAb WqX4nBFZgMuW2+ZPeF2L+HIQxNw1NMfZhHOPgLBHT2OfEfrXIidCOZxJxfN+5/UeONWjSy8wuIKDM ILLdUH4UrSkMXJsRXjZSYRDVTWfsQZduaGVEmI47sbcdpz2MIvkBswt03dW5O2BYb7zA=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=8bdvZIDpCjZTahtq1pwemrlYIoukz8ubMheMWb3aQ5g=; b=B krs05CRlBxui/cSuFXesQ6azwuinwSnO+69qRKAL94q8tP12WaX/MmIWzBuUv1yetRkfIHAdBfdOq lGwQ6QJbqiINgMVQogrPEPp7YlnQMkWaJVRDXDdg29nJaQQlmH9C7kaLAfb8yKRqRkIhGq+I4KJq7 8h0guDoF0WaGnacE=; Received: from dfw.source.kernel.org ([139.178.84.217]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1slgX4-0005Ib-35 for linux-f2fs-devel@lists.sourceforge.net; Wed, 04 Sep 2024 03:18:10 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 514005C0FAE; Wed, 4 Sep 2024 03:17:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 554F0C4CEC4; Wed, 4 Sep 2024 03:17:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725419879; bh=qRbiznnrsRgEA3Web+4SIwc4T8tzRKG87HpRd1ZIWME=; h=From:To:Cc:Subject:Date:From; b=O81kw72NwaHlj0dW1QoCyxOPnKdYYhLaOMECqwNdxiyyg4r5xriSiBezA4bqsTR3A NYfFREvdWokMj2kWmmqnOwP6eMsiayYCijf0huWJhLnKt4Imk7e23v9GRWPb/IHFh7 ogGT/wBXnqcTYaT3VoYAqwId/kkE3XjUzey5yWKqU2j1sPkgkLi7yneZv+4kwcrYuz GMp5UeuoQCiYvfQLDB+WzHRrkgCja2jAUCyRMNXSust2IP/0GwCt5iMl8heGXDMZ9b OWk738+rh+3LjQglPrZy79F3ahnyMVlsxSIMZ/NkgqU6cxdSRgH1ckZMMI8zXbitiW vZ+0EOPTYefuw== To: jaegeuk@kernel.org Date: Wed, 4 Sep 2024 11:17:45 +0800 Message-Id: <20240904031746.1262403-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-Headers-End: 1slgX4-0005Ib-35 Subject: [f2fs-dev] [PATCH 1/2] fsck.f2fs: fix to detect double '.' or '..' 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: , X-Patchwork-Original-From: Chao Yu via Linux-f2fs-devel From: Chao Yu Reply-To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net If there are double '.' or '..' dirents in directory, fsck.f2fs won't detect and repaire the issue correctly, fix it. Reviewed-by: Sheng Yong Signed-off-by: Chao Yu --- fsck/fsck.c | 55 +++++++++++++++++++++++++++++++---------------- fsck/fsck.h | 3 ++- include/f2fs_fs.h | 6 ++++++ 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/fsck/fsck.c b/fsck/fsck.c index a18bee9..54ddc11 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -1307,10 +1307,10 @@ skip_blkcnt_fix: nid, i_links, child.links); } } - if (child.dots < 2 && + if ((child.dot == 0 || child.dotdot == 0) && !(node_blk->i.i_inline & F2FS_INLINE_DOTS)) { - ASSERT_MSG("ino: 0x%x dots: %u", - nid, child.dots); + ASSERT_MSG("ino: 0x%x dot: %u, dotdot: %u", + nid, child.dot, child.dotdot); if (c.fix_on) { node_blk->i.i_inline |= F2FS_INLINE_DOTS; need_fix = 1; @@ -1862,26 +1862,45 @@ static int __chk_dentries(struct f2fs_sb_info *sbi, int casefolded, /* Becareful. 'dentry.file_type' is not imode. */ if (ftype == F2FS_FT_DIR) { - if ((name[0] == '.' && name_len == 1) || - (name[0] == '.' && name[1] == '.' && - name_len == 2)) { - ret = __chk_dots_dentries(sbi, casefolded, &dentry[i], - child, name, name_len, &filenames[i], - enc_name); - switch (ret) { - case 1: + enum dot_type dot_type = NON_DOT; + + if (name[0] == '.' && name_len == 1) + dot_type = TYPE_DOT; + else if (name[0] == '.' && name[1] == '.' && + name_len == 2) + dot_type = TYPE_DOTDOT; + + if (dot_type != NON_DOT) { + bool need_del = false; + + DBG(3, "i:%u, dot_type:%u, ino:%u, p:%u, pp:%u\n", + i, dot_type, dentry[i].ino, + child->p_ino, child->pp_ino); + + ret = __chk_dots_dentries(sbi, casefolded, + &dentry[i], child, name, name_len, + &filenames[i], enc_name); + if (ret) fixed = 1; - fallthrough; - case 0: - child->dots++; - break; + + if (dot_type == TYPE_DOT) { + if (child->dot == 0) + child->dot++; + else + need_del = true; + } else if (dot_type == TYPE_DOTDOT) { + if (child->dotdot == 0) + child->dotdot++; + else + need_del = true; } - if (child->dots > 2) { - ASSERT_MSG("More than one '.' or '..', should delete the extra one\n"); + if (need_del) { + ASSERT_MSG("More than one '%s', should delete the extra one, i: %u, ino:%u", + dot_type == TYPE_DOT ? "." : "..", + i, dentry[i].ino); nullify_dentry(&dentry[i], i, &filenames[i], &bitmap); - child->dots--; fixed = 1; } diff --git a/fsck/fsck.h b/fsck/fsck.h index a8f187e..efccfbc 100644 --- a/fsck/fsck.h +++ b/fsck/fsck.h @@ -70,7 +70,8 @@ struct child_info { u32 links; u32 files; u32 pgofs; - u8 dots; + u8 dot; + u8 dotdot; u8 dir_level; u32 p_ino; /* parent ino */ char p_name[F2FS_NAME_LEN + 1]; /* parent name */ diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h index 15a1c82..0b6777a 100644 --- a/include/f2fs_fs.h +++ b/include/f2fs_fs.h @@ -1429,6 +1429,12 @@ enum FILE_TYPE { F2FS_FT_LAST_FILE_TYPE = F2FS_FT_XATTR, }; +enum dot_type { + NON_DOT, + TYPE_DOT, + TYPE_DOTDOT +}; + #define LINUX_S_IFMT 00170000 #define LINUX_S_IFREG 0100000 #define LINUX_S_IFDIR 0040000 From patchwork Wed Sep 4 03:17:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13789656 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 31357CD4842 for ; Wed, 4 Sep 2024 03:18:10 +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 1slgX2-0002Zx-WB; Wed, 04 Sep 2024 03:18:09 +0000 Received: from [172.30.29.66] (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 1slgX1-0002Zp-QZ for linux-f2fs-devel@lists.sourceforge.net; Wed, 04 Sep 2024 03:18:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: 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=g5j/j8YNvrKpdABBXvmWtpfsKwmvOEe4TjorQx3CbeE=; b=HqnSknuYYEIiPaY/6ZNWytDdml zU5ZDjuyr1x36hAzMEk70wOPN4yG+PUL1FO6zlpWpFzZ/MjapLlnXdYdoAyHwU8buxPXOBu5XFwkr m6XLZsVEOzNMEDmsnRUW0/fSIwi5o18RSAjuFFnrh/38oJDgnUNMntNeVhnlYpGvIPrM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: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=g5j/j8YNvrKpdABBXvmWtpfsKwmvOEe4TjorQx3CbeE=; b=C8x0q6RHynM34EvM+pB0BVZ52A 9J/LFlJNqh7f4+y/0rLYdAKattciQ6Iou2hCufZRg1AI+I+jofAc0lUUrWski438oLfZ0tJECdR4d SMIn6McqoA0hVIR2HYTNQDEaaqTxipew/nsnS2au9HS/KwsOns1B40RxkdrFdYPiZemY=; Received: from nyc.source.kernel.org ([147.75.193.91]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1slgX1-0005IC-2a for linux-f2fs-devel@lists.sourceforge.net; Wed, 04 Sep 2024 03:18:07 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 320C7A404F3; Wed, 4 Sep 2024 03:17:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E967DC4CEC4; Wed, 4 Sep 2024 03:17:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725419881; bh=fVUdRNyBecMoXa7qS829IquD1OMT4h2mv+VObRRxrcM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BXw10DjQV47EhinzzOrTxt9yjbAOo/o5J9RmEOJ3xYoCvX2JFw3LCbJ/WKB/IjuU8 ILUwjNkMgwLK5cuatC38Pwkwty08VjdEMItnASla1fD7Nz/JECpZAK+WlhLrwXXmW5 Ct48Lw4eU/uK6dYUqV4YlUgyea0CeFw2lCsdx/wHqq7eS+VXx3l692L3cYSVPv5rNC lQlxkjcompOpeLvbd58rjdQt5bJdFXc4HcpJZ9Z7NQoCswZtlF87o1Ti/tla9rU/FE k9wUa4Ki3Tg7Y1ldmfeSaAtVxX3+tbwyV5sjYnECdkYy4Ph4qTJxQPJ12PykdVzGF5 4FjvRh9kbe36A== To: jaegeuk@kernel.org Date: Wed, 4 Sep 2024 11:17:46 +0800 Message-Id: <20240904031746.1262403-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240904031746.1262403-1-chao@kernel.org> References: <20240904031746.1262403-1-chao@kernel.org> MIME-Version: 1.0 X-Headers-End: 1slgX1-0005IC-2a Subject: [f2fs-dev] [PATCH 2/2] fsck.f2fs: support to add missing '.' or '..' dirent 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: , X-Patchwork-Original-From: Chao Yu via Linux-f2fs-devel From: Chao Yu Reply-To: Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net Previously, once fsck.f2fs detects that directory missed '.' or '..' dirent, it tags inode w/ F2FS_INLINE_DOTS flag, and expects f2fs kernel module can repaire it online during it runs to lookup() on target directory. This patch abandons previous implementation, and do repaires directly. Reviewed-by: Sheng Yong Signed-off-by: Chao Yu --- fsck/fsck.c | 45 ++++++++++++++++++++++++++++++++++++++++----- fsck/main.c | 4 +++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/fsck/fsck.c b/fsck/fsck.c index 54ddc11..f8ea7f0 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -1307,17 +1307,52 @@ skip_blkcnt_fix: nid, i_links, child.links); } } - if ((child.dot == 0 || child.dotdot == 0) && - !(node_blk->i.i_inline & F2FS_INLINE_DOTS)) { - ASSERT_MSG("ino: 0x%x dot: %u, dotdot: %u", + if (child.dot == 0 || child.dotdot == 0) { + ASSERT_MSG("ino: 0x%x has no '.' and/or '..' dirents, dot: %u, dotdot: %u", nid, child.dot, child.dotdot); if (c.fix_on) { - node_blk->i.i_inline |= F2FS_INLINE_DOTS; + umode_t mode = le16_to_cpu(node_blk->i.i_mode); + block_t blkaddr; + + ret = convert_inline_dentry(sbi, node_blk, + &ni->blk_addr); + FIX_MSG("convert inline dentry ino: %u, pino: %u, ret: %d", + nid, child_d->p_ino, ret); + if (ret) + goto skip_dot_fix; + + if (child.dot == 0) { + char *name = "."; + + ret = f2fs_add_link(sbi, node_blk, + (const unsigned char *)name, + 1, nid, map_de_type(mode), + &blkaddr, 0); + FIX_MSG("add missing '%s' dirent in ino: %u, pino: %u, ret:%d", + name, nid, child_d->p_ino, ret); + if (ret) + goto skip_dot_fix; + } + + if (child.dotdot == 0) { + char *name = ".."; + + ret = f2fs_add_link(sbi, node_blk, + (const unsigned char *)name, + 2, child_d->p_ino, + map_de_type(mode), + &blkaddr, 0); + FIX_MSG("add missing '%s' dirent in ino: %u, pino: %u, ret:%d", + name, nid, child_d->p_ino, ret); + if (ret) + goto skip_dot_fix; + } + need_fix = 1; - FIX_MSG("Dir: 0x%x set inline_dots", nid); } } } +skip_dot_fix: i_gc_failures = le16_to_cpu(node_blk->i.i_gc_failures); diff --git a/fsck/main.c b/fsck/main.c index 8881936..4e0254d 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -892,6 +892,7 @@ static int do_fsck(struct f2fs_sb_info *sbi) u32 flag = le32_to_cpu(ckpt->ckpt_flags); u32 blk_cnt; struct f2fs_compr_blk_cnt cbc; + struct child_info child = { 0 }; errcode_t ret; fsck_init(sbi); @@ -957,8 +958,9 @@ static int do_fsck(struct f2fs_sb_info *sbi) if (fsck_sanity_check_nat(sbi, sbi->root_ino_num)) fsck_chk_root_inode(sbi); + child.p_ino = sbi->root_ino_num; fsck_chk_node_blk(sbi, NULL, sbi->root_ino_num, - F2FS_FT_DIR, TYPE_INODE, &blk_cnt, &cbc, NULL); + F2FS_FT_DIR, TYPE_INODE, &blk_cnt, &cbc, &child); fsck_chk_quota_files(sbi); ret = fsck_verify(sbi);