From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A16DD17AE11 for ; Tue, 11 Mar 2025 09:20:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741684840; cv=none; b=KOnqBtknngMywKZnkBPw1oTX0bgBW8UzBwCG/rpjmkHKWmNxoz+yKI/ZPRgUT4+o1x8O4H8vbbMENkgV34xQvSrJu96L0qpIWOc5KE40UDpBcD2NRlL565PougtvU2KqAgjYYhNelpBQLzxO0D/rqiir/kAJ4MvJFUtQLBqYIN0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741684840; c=relaxed/simple; bh=dmEKhV6jS4N11wpxYhxDJnfc4IQvC8nhhPDY72s6I2w=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=fklmMf1hoq7w0Ro7Dnt33Re2b0WpC1WFb/FwtMlODXQhOftdBfAcmJS2GCnCxCTRcE8Bs/gR4gdZa4nEIgbWInr3yFOfUsH/yC34yldyZJeAzqO4L6DFGFGhLKwYGVBbgzSUEhxWbA8Tocp3r+4x5UOTPir90ge0zWuaKMjWb6g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Tbla77GA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Tbla77GA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 333D5C4CEEB; Tue, 11 Mar 2025 09:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1741684840; bh=dmEKhV6jS4N11wpxYhxDJnfc4IQvC8nhhPDY72s6I2w=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=Tbla77GAjwiv4EBf/tpgtaZCEbOTdD2pycCT0mRHOGuKwN1EOqk2m6mV/U6lsGfdo TW4Y6CqpsrhSbInKYkifPxO4HvTYjkV5v83GUsfqJ4Rx/ru+YU4K59z/i4jIKhatQG bfqR5YZ10DcUTrz93e4ZRewJOr8e+lfYM+gjhF26ZbDyJ+j4wE0n+NPKfJGOalqvyq j36LhAzJJtJJwO0giyE/0WqB1obmJQXbEURWYPREjFTxOJOwWk1oYXYWnQ25RnD+VY rHejveH2IufJ9+zujikF5OTtxJ0opnBuMi3hlmeJ0fOSkbnjhK3fSSZmjVcNyjBAi/ nr9OwmSiNBMjQ== Message-ID: <6c64922e-523b-484f-98f5-5a795fe65000@kernel.org> Date: Tue, 11 Mar 2025 17:20:37 +0800 Precedence: bulk X-Mailing-List: fstests@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, jaegeuk@kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [PATCH v3 6/6] f2fs/009: detect and repair nlink corruption To: Zorro Lang , fstests@vger.kernel.org References: <20250311080430.3696582-1-chao@kernel.org> <20250311080430.3696582-6-chao@kernel.org> Content-Language: en-US From: Chao Yu In-Reply-To: <20250311080430.3696582-6-chao@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/11/25 16:04, Chao Yu wrote: > This is a regression test to check whether fsck can handle corrupted > nlinks correctly, it uses inject.f2fs to inject nlinks w/ wrong value, > and expects fsck.f2fs can detect such corruption and do the repair. > > Cc: Jaegeuk Kim > Signed-off-by: Chao Yu > --- > v3: > - check socket command > - add _cleanup to kill & wait background thread > - add commit title in _fixed_by_git_commit line > - clean up codes > tests/f2fs/009 | 145 +++++++++++++++++++++++++++++++++++++++++++++ > tests/f2fs/009.out | 2 + > 2 files changed, 147 insertions(+) > create mode 100755 tests/f2fs/009 > create mode 100644 tests/f2fs/009.out > > diff --git a/tests/f2fs/009 b/tests/f2fs/009 > new file mode 100755 > index 00000000..4f8b2079 > --- /dev/null > +++ b/tests/f2fs/009 > @@ -0,0 +1,145 @@ > +#! /bin/bash > +# SPDX-License-Identifier: GPL-2.0 > +# Copyright (c) 2025 Chao Yu. All Rights Reserved. > +# > +# FS QA Test No. f2fs/009 > +# > +# This is a regression test to check whether fsck can handle corrupted > +# nlinks correctly, it uses inject.f2fs to inject nlinks w/ wrong value, > +# and expects fsck.f2fs can detect such corruption and do the repair. > +# > +. ./common/preamble > +_begin_fstest auto quick > + > +if [ ! -x "$(type -P socket)" ]; then > + _notrun "Couldn't find socket" > +fi > + > +_require_scratch > +_require_command "$F2FS_INJECT_PROG" inject.f2fs > +_require_command "$F2FS_FSCK_PROG" fsck.f2fs Forgot to remove this, let me fix this in v4 later. Thanks, > + > +_fixed_by_git_commit f2fs-tools 958cd6e "fsck.f2fs: support to repair corrupted i_links" > + > +filename=$SCRATCH_MNT/foo > +hardlink=$SCRATCH_MNT/bar > + > +_cleanup() > +{ > + if [ -n "$pid" ]; then > + kill $pid &> /dev/null > + wait > + fi > +} > + > +for ((i=0;i<14;i++)) do > + echo "round: " $i >> $seqres.full > + > + _scratch_mkfs >> $seqres.full > + _scratch_mount > + > + if [ $i == 0 ]; then > + touch $filename > + ino=`stat -c '%i' $filename` > + nlink=0 > + elif [ $i == 1 ]; then > + mkdir $filename > + ino=`stat -c '%i' $filename` > + nlink=1 > + elif [ $i == 2 ]; then > + mknod $filename c 9 0 > + ino=`stat -c '%i' $filename` > + nlink=0 > + elif [ $i == 3 ]; then > + mknod $filename b 8 0 > + ino=`stat -c '%i' $filename` > + nlink=0 > + elif [ $i == 4 ]; then > + mkfifo $filename > + ino=`stat -c '%i' $filename` > + nlink=0 > + elif [ $i == 5 ]; then > + socket -s $filename >> $seqres.full 2>&1 & > + pid=$! > + sleep 2 > + ino=`stat -c '%i' $filename` > + kill $pid >> $seqres.full 2>&1 > + nlink=0 > + elif [ $i == 6 ]; then > + ln -s $SCRATCH_MNT/empty $filename > + ino=`stat -c '%i' $filename` > + nlink=0 > + elif [ $i == 7 ]; then > + # orphan inode > + touch $filename > + ino=`stat -c '%i' $filename` > + $F2FS_IO_PROG write 1 0 1 zero atomic_commit $filename 5000 >> $seqres.full 2>&1 & > + stat $filename >> $seqres.full > + rm $filename > + $F2FS_IO_PROG shutdown 1 $SCRATCH_MNT/ >> $seqres.full > + sleep 6 > + nlink=1 > + elif [ $i == 8 ]; then > + # hardlink on file > + touch $filename > + ino=`stat -c '%i' $filename` > + ln $filename $hardlink > + nlink=0 > + elif [ $i == 9 ]; then > + # hardlink on charactor > + mknod $filename c 9 0 > + ino=`stat -c '%i' $filename` > + ln $filename $hardlink > + nlink=0 > + elif [ $i == 10 ]; then > + # hardlink on blockdev > + mknod $filename b 8 0 > + ino=`stat -c '%i' $filename` > + ln $filename $hardlink > + nlink=0 > + elif [ $i == 11 ]; then > + # hardlink on pipe > + mkfifo $filename > + ino=`stat -c '%i' $filename` > + ln $filename $hardlink > + nlink=0 > + elif [ $i == 12 ]; then > + # hardlink on socket > + socket -s $filename >> $seqres.full 2>&1 & > + pid=$! > + sleep 2 > + ino=`stat -c '%i' $filename` > + kill $pid >> $seqres.full 2>&1 > + ln $filename $hardlink > + nlink=0 > + elif [ $i == 13 ]; then > + # hardlink on symlink > + ln -s $SCRATCH_MNT/empty $filename > + ino=`stat -c '%i' $filename` > + ln $filename $hardlink > + nlink=0 > + fi > + > + if [ $i != 7 ]; then > + stat $SCRATCH_MNT/* >> $seqres.full > + fi > + echo "ino:"$ino >> $seqres.full > + echo "nlink:"$nlink >> $seqres.full > + > + _scratch_unmount > + > + $F2FS_INJECT_PROG --node --mb i_links --nid $ino --val $nlink $SCRATCH_DEV \ > + >> $seqres.full || _fail "fail to inject" > + > + _check_scratch_fs >> $seqres.full 2>&1 && _fail "can't find corruption" > + _repair_scratch_fs >> $seqres.full > + _check_scratch_fs >> $seqres.full 2>&1 || _fail "fsck can't fix corruption" > + > + _scratch_mount > + _scratch_unmount > +done > + > +echo "Silence is golden" > + > +status=0 > +exit > diff --git a/tests/f2fs/009.out b/tests/f2fs/009.out > new file mode 100644 > index 00000000..7e977155 > --- /dev/null > +++ b/tests/f2fs/009.out > @@ -0,0 +1,2 @@ > +QA output created by 009 > +Silence is golden