From: David Disseldorp <ddiss@suse.de>
To: Chao Yu <chao@kernel.org>
Cc: Zorro Lang <zlang@kernel.org>,
fstests@vger.kernel.org, jaegeuk@kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [PATCH 4/4] f2fs/009: detect and repair nlink corruption
Date: Fri, 7 Mar 2025 15:02:12 +1100 [thread overview]
Message-ID: <20250307150212.7cda01f2.ddiss@suse.de> (raw)
In-Reply-To: <20250306081809.2397527-4-chao@kernel.org>
Thanks for submitting the new test. It looks good aside from a few minor
things below...
On Thu, 6 Mar 2025 16:18:09 +0800, 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 <jaegeuk@kernel.org>
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> tests/f2fs/009 | 142 +++++++++++++++++++++++++++++++++++++++++++++
> tests/f2fs/009.out | 2 +
> 2 files changed, 144 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..8f6a3e11
> --- /dev/null
> +++ b/tests/f2fs/009
> @@ -0,0 +1,142 @@
> +#! /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
> +
> +_require_scratch
You should probably check for F2FS_INJECT_PROG and skip if not present.
Is it dependent on CONFIG_F2FS_FAULT_INJECTION? If so it'd be nice if
you could check for that too.
Flag the fix for the regression via e.g.:
_fixed_by_git_commit f2fs-tools 958cd6e
> +
> +dir=$SCRATCH_MNT
I think it'd be easier to follow if you dropped this alias and just used
$SCRATCH_MNT directly.
> +filename=$dir/foo
> +hardlink=$dir/bar
> +
> +for ((i=0;i<14;i++)) do
> + echo "round: " $i >> $seqres.full
> +
> + _scratch_mkfs "-f" >> $seqres.full
> + _scratch_mount >> $seqres.full
> +
> + if [ $i == 0 ]; then
> + touch $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
Use "stat -c '%i'" instead of piping into awk. Also, it looks like this
is called in every round, so just move it after the elifs.
> + nlink=0
> + elif [ $i == 1 ]; then
> + mkdir $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + nlink=1
> + elif [ $i == 2 ]; then
> + mknod $filename c 9 0
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + nlink=0
> + elif [ $i == 3 ]; then
> + mknod $filename b 8 0
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + nlink=0
> + elif [ $i == 4 ]; then
> + mkfifo $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + nlink=0
> + elif [ $i == 5 ]; then
> + socket -s $filename >> $seqres.full 2>&1 &
> + pid=$!
> + sleep 2
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + kill $pid >> $seqres.full 2>&1
> + nlink=0
> + elif [ $i == 6 ]; then
> + ln -s $dir/empty $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + nlink=0
> + elif [ $i == 7 ]; then
> + # orphan inode
> + touch $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + $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 $dir/ >> $seqres.full
> + sleep 6
> + nlink=1
> + elif [ $i == 8 ]; then
> + # hardlink on file
> + touch $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + ln $filename $hardlink
> + nlink=0
> + elif [ $i == 9 ]; then
> + # hardlink on charactor
> + mknod $filename c 9 0
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + ln $filename $hardlink
> + nlink=0
> + elif [ $i == 10 ]; then
> + # hardlink on blockdev
> + mknod $filename b 8 0
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + ln $filename $hardlink
> + nlink=0
> + elif [ $i == 11 ]; then
> + # hardlink on pipe
> + mkfifo $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + ln $filename $hardlink
> + nlink=0
> + elif [ $i == 12 ]; then
> + # hardlink on socket
> + socket -s $filename >> $seqres.full 2>&1 &
> + pid=$!
> + sleep 2
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + kill $pid >> $seqres.full 2>&1
> + ln $filename $hardlink
> + nlink=0
> + elif [ $i == 13 ]; then
> + # hardlink on symlink
> + ln -s $dir/empty $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + ln $filename $hardlink
> + nlink=0
> + fi
> +
> + if [ $i != 7 ]; then
> + stat $dir/* >> $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
> + if [ $? != 0 ]; then
> + exit
> + fi
xfstests failures are normally triggered via golden output mismatch
instead of explicit status checks or _fail calls... Can you filter the
inject / repair output so that it ends up in the golden output for
comparison?
> + export FSCK_OPTIONS="-f"
> + _repair_scratch_fs >> $seqres.full
> + if [ $? != 1 ]; then
> + _fail "fsck can not detect and repair zero nlink corruption "$i
> + exit
> + fi
> +
> + export FSCK_OPTIONS=""
> + _check_scratch_fs >> $seqres.full
> + if [ $? != 0 ]; then
> + _fail "fsck hasn't fixed nlink corruption "$i
> + exit
> + fi
> +
> + _scratch_mount >> $seqres.full
> + _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
WARNING: multiple messages have this Message-ID (diff)
From: David Disseldorp <ddiss@suse.de>
To: Chao Yu <chao@kernel.org>
Cc: jaegeuk@kernel.org, Zorro Lang <zlang@kernel.org>,
fstests@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH 4/4] f2fs/009: detect and repair nlink corruption
Date: Fri, 7 Mar 2025 15:02:12 +1100 [thread overview]
Message-ID: <20250307150212.7cda01f2.ddiss@suse.de> (raw)
In-Reply-To: <20250306081809.2397527-4-chao@kernel.org>
Thanks for submitting the new test. It looks good aside from a few minor
things below...
On Thu, 6 Mar 2025 16:18:09 +0800, 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 <jaegeuk@kernel.org>
> Signed-off-by: Chao Yu <chao@kernel.org>
> ---
> tests/f2fs/009 | 142 +++++++++++++++++++++++++++++++++++++++++++++
> tests/f2fs/009.out | 2 +
> 2 files changed, 144 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..8f6a3e11
> --- /dev/null
> +++ b/tests/f2fs/009
> @@ -0,0 +1,142 @@
> +#! /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
> +
> +_require_scratch
You should probably check for F2FS_INJECT_PROG and skip if not present.
Is it dependent on CONFIG_F2FS_FAULT_INJECTION? If so it'd be nice if
you could check for that too.
Flag the fix for the regression via e.g.:
_fixed_by_git_commit f2fs-tools 958cd6e
> +
> +dir=$SCRATCH_MNT
I think it'd be easier to follow if you dropped this alias and just used
$SCRATCH_MNT directly.
> +filename=$dir/foo
> +hardlink=$dir/bar
> +
> +for ((i=0;i<14;i++)) do
> + echo "round: " $i >> $seqres.full
> +
> + _scratch_mkfs "-f" >> $seqres.full
> + _scratch_mount >> $seqres.full
> +
> + if [ $i == 0 ]; then
> + touch $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
Use "stat -c '%i'" instead of piping into awk. Also, it looks like this
is called in every round, so just move it after the elifs.
> + nlink=0
> + elif [ $i == 1 ]; then
> + mkdir $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + nlink=1
> + elif [ $i == 2 ]; then
> + mknod $filename c 9 0
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + nlink=0
> + elif [ $i == 3 ]; then
> + mknod $filename b 8 0
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + nlink=0
> + elif [ $i == 4 ]; then
> + mkfifo $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + nlink=0
> + elif [ $i == 5 ]; then
> + socket -s $filename >> $seqres.full 2>&1 &
> + pid=$!
> + sleep 2
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + kill $pid >> $seqres.full 2>&1
> + nlink=0
> + elif [ $i == 6 ]; then
> + ln -s $dir/empty $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + nlink=0
> + elif [ $i == 7 ]; then
> + # orphan inode
> + touch $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + $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 $dir/ >> $seqres.full
> + sleep 6
> + nlink=1
> + elif [ $i == 8 ]; then
> + # hardlink on file
> + touch $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + ln $filename $hardlink
> + nlink=0
> + elif [ $i == 9 ]; then
> + # hardlink on charactor
> + mknod $filename c 9 0
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + ln $filename $hardlink
> + nlink=0
> + elif [ $i == 10 ]; then
> + # hardlink on blockdev
> + mknod $filename b 8 0
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + ln $filename $hardlink
> + nlink=0
> + elif [ $i == 11 ]; then
> + # hardlink on pipe
> + mkfifo $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + ln $filename $hardlink
> + nlink=0
> + elif [ $i == 12 ]; then
> + # hardlink on socket
> + socket -s $filename >> $seqres.full 2>&1 &
> + pid=$!
> + sleep 2
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + kill $pid >> $seqres.full 2>&1
> + ln $filename $hardlink
> + nlink=0
> + elif [ $i == 13 ]; then
> + # hardlink on symlink
> + ln -s $dir/empty $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + ln $filename $hardlink
> + nlink=0
> + fi
> +
> + if [ $i != 7 ]; then
> + stat $dir/* >> $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
> + if [ $? != 0 ]; then
> + exit
> + fi
xfstests failures are normally triggered via golden output mismatch
instead of explicit status checks or _fail calls... Can you filter the
inject / repair output so that it ends up in the golden output for
comparison?
> + export FSCK_OPTIONS="-f"
> + _repair_scratch_fs >> $seqres.full
> + if [ $? != 1 ]; then
> + _fail "fsck can not detect and repair zero nlink corruption "$i
> + exit
> + fi
> +
> + export FSCK_OPTIONS=""
> + _check_scratch_fs >> $seqres.full
> + if [ $? != 0 ]; then
> + _fail "fsck hasn't fixed nlink corruption "$i
> + exit
> + fi
> +
> + _scratch_mount >> $seqres.full
> + _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
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2025-03-07 4:02 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-06 8:18 [PATCH 1/4] common/config: remove redundant export of F2FS_IO_PROG Chao Yu
2025-03-06 8:18 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2025-03-06 8:18 ` [PATCH 2/4] common/config: export F2FS_INJECT_PROG Chao Yu
2025-03-06 8:18 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2025-03-07 3:57 ` David Disseldorp
2025-03-07 3:57 ` [f2fs-dev] " David Disseldorp
2025-03-06 8:18 ` [PATCH 3/4] common/rc: support f2fs in _repair_scratch_fs Chao Yu
2025-03-06 8:18 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2025-03-07 3:57 ` David Disseldorp
2025-03-07 3:57 ` [f2fs-dev] " David Disseldorp
2025-03-06 8:18 ` [PATCH 4/4] f2fs/009: detect and repair nlink corruption Chao Yu
2025-03-06 8:18 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2025-03-07 4:02 ` David Disseldorp [this message]
2025-03-07 4:02 ` David Disseldorp
2025-03-10 9:46 ` Chao Yu
2025-03-10 9:46 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2025-03-10 8:00 ` Zorro Lang
2025-03-10 8:00 ` [f2fs-dev] " Zorro Lang
2025-03-10 9:59 ` Chao Yu
2025-03-10 9:59 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2025-03-10 19:48 ` Zorro Lang
2025-03-10 19:48 ` [f2fs-dev] " Zorro Lang
2025-03-11 2:24 ` Chao Yu
2025-03-11 2:24 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
2025-03-07 3:56 ` [PATCH 1/4] common/config: remove redundant export of F2FS_IO_PROG David Disseldorp
2025-03-07 3:56 ` [f2fs-dev] " David Disseldorp
2025-03-10 7:16 ` Zorro Lang
2025-03-10 7:16 ` [f2fs-dev] " Zorro Lang
2025-03-10 8:02 ` Zorro Lang
2025-03-10 8:02 ` [f2fs-dev] " Zorro Lang
2025-03-10 10:01 ` Chao Yu
2025-03-10 10:01 ` [f2fs-dev] " Chao Yu via Linux-f2fs-devel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250307150212.7cda01f2.ddiss@suse.de \
--to=ddiss@suse.de \
--cc=chao@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=zlang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.