From patchwork Tue Feb 25 09:36:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 13989646 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 5ABEAC021BC for ; Tue, 25 Feb 2025 09:37:18 +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 1tmrNN-0000US-7D; Tue, 25 Feb 2025 09:37:17 +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 1tmrNL-0000UJ-5n for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 Feb 2025 09:37:15 +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=Pzulq5Oz0IIgb8ofgMOP6djALWJM+QRWWMPou6y74n0=; b=RZPIQpz8Bs2yezgG2uKFN6qi5b XxnVg5/oBFTDi7k79GmUg9H0hMBS5om6PLTGfsFTy0W+HdnCEro9OaNVq72dWxhekf6mDdjZDx/ro N6Lq8mR2xzQAeY2YfJPCDJcaz06OGc1KAYw28GyDUD+HGaAdXHhHyXBIglza5vdn6Bh0=; 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=Pzulq5Oz0IIgb8ofgMOP6djALWJM+QRWWMPou6y74n0=; b=B YvsJrgTqOE/U0VOOoxHHRz6LKaGzSnAWFD9DpHrnu28DC1iLpnC/9r2pBAZrs6KFw6rGq+y3ZIlTg dM+97CIdgw/e1HdqfFoc7/wgmk79getUDUsnC/1gnOq9DNeUrzdszJjx/wswQM6vje5U2OH1CYMny M53WjZdvlmtKpZbc=; 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 1tmrNK-0007Pf-D4 for linux-f2fs-devel@lists.sourceforge.net; Tue, 25 Feb 2025 09:37:15 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 17A955C6A9C for ; Tue, 25 Feb 2025 09:36:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D7B0C4CEDD; Tue, 25 Feb 2025 09:37:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1740476223; bh=vo/uwtoGQ8GULTwla/DNBnhPxdWOndpU+xQ7NuMvuXc=; h=From:To:Cc:Subject:Date:From; b=AYSlGitw3TujqldwOfOCPJeHkTXXRunwClVXWCFcjo8ZZ+YH0evl7uim9knKjyghL q7GQjkTu+NWL+vrDuo4G6EsbeAkRVRnygCNHEihYrDTJE3PVpdeWJxQJa9dvY5hG2F XJjkjYlo/vhnohKZlZMIgiJb19rKOfuyeG94aVgqtJRMefBtwoNQ3myxbZ+4q/Tp/d XRKaEhjaVVIDMqAnfPSKoT9Gpy8lv0mNZ7533+p5c1gSlFqhIijjs/FfdfnfHzshoJ MyPNouqmecsXpqSDiD/sFToHs4FHFGBFv2gGfNBhhGIGqWG+Ne7EvCWfjhJg2h9/3I mOi1C8rEdnTdw== To: jaegeuk@kernel.org Date: Tue, 25 Feb 2025 17:36:54 +0800 Message-ID: <20250225093654.414590-1-chao@kernel.org> X-Mailer: git-send-email 2.48.1.658.g4767266eb4-goog MIME-Version: 1.0 X-Headers-End: 1tmrNK-0007Pf-D4 Subject: [f2fs-dev] [PATCH v2] fsck.f2fs: support to repair corrupted i_links 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 fsck.f2fs missed to check and repair zeroed i_links for char, block, fifo, sock, symlink and regular inode, fix it. Tested w/ below testcase: dev=/dev/vda mp=/mnt/f2fs for ((i=0;i<14;i++)) do echo "testcase #"$i mkfs.f2fs -f $dev >/dev/null 2>&1 if [ $? != 0 ]; then exit fi mount $dev $mp cd $mp if [ $i == 0 ]; then touch file nlink=0 elif [ $i == 1 ]; then mkdir dir nlink=1 elif [ $i == 2 ]; then mknod charactor c 9 0 nlink=0 elif [ $i == 3 ]; then mknod blockdev b 8 0 nlink=0 elif [ $i == 4 ]; then mkfifo pipe nlink=0 elif [ $i == 5 ]; then socket -s $mp/sock & sleep 2 fuser -k $mp/sock nlink=0 elif [ $i == 6 ]; then ln -s file symlink nlink=0 elif [ $i == 7 ]; then # orphan inode touch atomic f2fs_io write 1 0 1 zero atomic_commit ./atomic 2000 & rm atomic sync f2fs_io shutdown 2 ./ nlink=1 sleep 2 elif [ $i == 8 ]; then # hardlink on file touch file ln file hardlink nlink=0 elif [ $i == 9 ]; then # hardlink on charactor mknod charactor c 9 0 ln charactor hardlink nlink=0 elif [ $i == 10 ]; then # hardlink on blockdev mknod blockdev b 8 0 ln blockdev hardlink nlink=0 elif [ $i == 11 ]; then # hardlink on pipe mkfifo pipe ln pipe hardlink nlink=0 elif [ $i == 12 ]; then # hardlink on socket socket -s $mp/sock & sleep 2 fuser -k $mp/sock ln sock hardlink nlink=0 elif [ $i == 13 ]; then # hardlink on symlink ln -s file symlink ln symlink hardlink nlink=0 fi cd ~/ umount $mp inject.f2fs --node --mb i_links --nid 4 --val $nlink $dev if [ $? != 0 ]; then exit fi fsck.f2fs -f $dev if [ $? != 1 ]; then exit fi fsck.f2fs $dev if [ $? != 0 ]; then exit fi mount $dev $mp stat $mp/* umount $mp done Signed-off-by: Chao Yu --- v2: - update testcase to cover hardlink of non-dir inode - fix zeroed i_links only fsck/fsck.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fsck/fsck.c b/fsck/fsck.c index aa3fb97..8155cbd 100644 --- a/fsck/fsck.c +++ b/fsck/fsck.c @@ -942,6 +942,22 @@ check_next: if (f2fs_test_main_bitmap(sbi, ni->blk_addr) == 0) { f2fs_set_main_bitmap(sbi, ni->blk_addr, CURSEG_WARM_NODE); + + if (i_links == 0 && (ftype == F2FS_FT_CHRDEV || + ftype == F2FS_FT_BLKDEV || + ftype == F2FS_FT_FIFO || + ftype == F2FS_FT_SOCK || + ftype == F2FS_FT_SYMLINK || + ftype == F2FS_FT_REG_FILE)) { + ASSERT_MSG("ino: 0x%x ftype: %d has i_links: %u", + nid, ftype, i_links); + if (c.fix_on) { + node_blk->i.i_links = cpu_to_le32(1); + need_fix = 1; + FIX_MSG("ino: 0x%x ftype: %d fix i_links: %u -> 1", + nid, ftype, i_links); + } + } if (i_links > 1 && ftype != F2FS_FT_ORPHAN && !is_qf_ino(F2FS_RAW_SUPER(sbi), nid)) { /* First time. Create new hard link node */