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);