On Thu, Mar 06, 2025 at 04:18:09PM +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 <[email protected]>
> Signed-off-by: Chao Yu <[email protected]>
> ---
Hi Chao,
I planned to merge patch 1~3 at first. But as you need to change this
patch more, and might need to change other patches, so how about you
send v2 with all this patchset. I'll wait your v2 :)
Some review points as below...
> 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
> +
> +dir=$SCRATCH_MNT
> +filename=$dir/foo
> +hardlink=$dir/bar
> +
> +for ((i=0;i<14;i++)) do
> + echo "round: " $i >> $seqres.full
> +
> + _scratch_mkfs "-f" >> $seqres.full
Can we give "-f" to _scratch_mkfs "f2fs" part? Likes:
diff --git a/common/rc b/common/rc
index bf24da4eb..cafe2f3dd 100644
--- a/common/rc
+++ b/common/rc
@@ -993,7 +993,7 @@ _scratch_mkfs()
mkfs_filter="grep -v -e ^Warning: -e \"^mke2fs \""
;;
f2fs)
- mkfs_cmd="$MKFS_F2FS_PROG"
+ mkfs_cmd="$MKFS_F2FS_PROG -f"
mkfs_filter="cat"
;;
> + _scratch_mount >> $seqres.full
> +
> + if [ $i == 0 ]; then
> + touch $filename
> + ino=`stat $filename | awk '/Inode:/ {print $4}'`
> + 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
> +
> + export FSCK_OPTIONS="-f"
You've set below code in _repair_scratch_fs():
f2fs)
fsck -t $FSTYP -f $SCRATCH_DEV
;;
The FSCK_OPTIONS="-f" is useless.
> + _repair_scratch_fs >> $seqres.full
> + if [ $? != 1 ]; then
What does $?=1 mean? Does $?=1 mean finding corruption and fixed, $?=0 mean no
corruption?
If you want to detect there's a corruption, then fix it, then check if it's
fixed. How about
calling _check_scratch_fs at first to get the corruption error you expect, then
call
_repair_scratch_fs to fix it. Then call _check_scratch_fs to make sure the
corruption is
fixed?
Something likes (just a rough example)
_check_scratch_fs >>$seqres.full 2>&1 && _fail "can't find corruption"
_repair_scratch_fs >> $seqres.full
_check_scratch_fs
> + _fail "fsck can not detect and repair zero nlink corruption "$i
> + exit
> + fi
> +
> + export FSCK_OPTIONS=""
> + _check_scratch_fs >> $seqres.full
I think _check_scratch_fs outputs nothing if run passed, right?
_check_scratch_fs calls _check_generic_filesystem for f2fs, the FSCK_OPTIONS
is "null" by default, so above FSCK_OPTIONS="" is useless too.
> + if [ $? != 0 ]; then
> + _fail "fsck hasn't fixed nlink corruption "$i
> + exit
> + fi
> +
> + _scratch_mount >> $seqres.full
">> $seqres.full" isn't necessary.
> + _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
> --
> 2.48.1
>
>
_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel