Skip to contentSkip to conversation

common/config: remove redundant export of F2FS_IO_PROG

PATCH Superseded Chao Yu 3 participants 16 messages Mar 6, 2025 – Mar 11, 2025

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/4 common/config: remove redundant export of F2FS_IO_PROG

F2FS_IO_PROG was been exported twice, remove the redudant one.

Cc Jaegeuk Kim <[email protected]>
---
 common/config | 1 -
 1 file changed, 1 deletion(-)
common/config +0 -1
index 2afbda14..8d3047a5 100644
@@ -191,7 +191,6 @@ export XFS_COPY_PROG="$(type -P xfs_copy)"
 export FSTRIM_PROG="$(type -P fstrim)"
 export DUMPE2FS_PROG="$(type -P dumpe2fs)"
 export RESIZE2FS_PROG="$(type -P resize2fs)"
-export F2FS_IO_PROG="$(type -P f2fs_io)"
 export FIO_PROG="$(type -P fio)"
 export FILEFRAG_PROG="$(type -P filefrag)"
 export E4DEFRAG_PROG="$(type -P e4defrag)"
Signature · 1 line
2.48.1
author
#1 lore raw

PATCH 2/4 common/config: export F2FS_INJECT_PROG

export F2FS_INJECT_PROG w/ inject.f2fs, it can be used for fault injection.

Cc Jaegeuk Kim <[email protected]>
---
 common/config | 1 +
 1 file changed, 1 insertion(+)
common/config +1 -0
index 8d3047a5..05f192ea 100644
@@ -317,6 +317,7 @@ export MKFS_BTRFS_PROG=$(set_mkfs_prog_path_with_opts btrfs)
 export MKFS_F2FS_PROG=$(set_mkfs_prog_path_with_opts f2fs)
 export DUMP_F2FS_PROG=$(type -P dump.f2fs)
 export F2FS_IO_PROG=$(type -P f2fs_io)
+export F2FS_INJECT_PROG=$(type -P inject.f2fs)
 export BTRFS_UTIL_PROG=$(type -P btrfs)
 export BTRFS_SHOW_SUPER_PROG=$(type -P btrfs-show-super)
 export BTRFS_CONVERT_PROG=$(type -P btrfs-convert)
Signature · 1 line
2.48.1
Reviewed-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] common/config: export F2FS_INJECT_PROG

Quoted 13 lines · Chao Yu

export F2FS_INJECT_PROG w/ inject.f2fs, it can be used for fault injection.

Cc Jaegeuk Kim <[email protected]>
---
 common/config | 1 +
 1 file changed, 1 insertion(+)
common/config +0 -0
index 8d3047a5..05f192ea 100644

common/config export MKFS_BTRFS_PROG=$(set_mkfs_prog_path_with_opts btrfs) · line 323

Quoted 7 lines
common/config +1 -0
@@ -317,6 +317,7 @@ export MKFS_BTRFS_PROG=$(set_mkfs_prog_path_with_opts btrfs)
 export MKFS_F2FS_PROG=$(set_mkfs_prog_path_with_opts f2fs)
 export DUMP_F2FS_PROG=$(type -P dump.f2fs)
 export F2FS_IO_PROG=$(type -P f2fs_io)
+export F2FS_INJECT_PROG=$(type -P inject.f2fs)
 export BTRFS_UTIL_PROG=$(type -P btrfs)
 export BTRFS_SHOW_SUPER_PROG=$(type -P btrfs-show-super)
 export BTRFS_CONVERT_PROG=$(type -P btrfs-convert)
author
#3 lore raw

PATCH 3/4 common/rc: support f2fs in _repair_scratch_fs

In reply to Chao Yu

Support f2fs in _repair_scratch_fs(), and use -f to repair the image forcely.

Cc Jaegeuk Kim <[email protected]>
---
 common/rc | 3 +++
 1 file changed, 3 insertions(+)
common/rc +3 -0
index ca755055..bf24da4e 100644
@@ -1500,6 +1500,9 @@ _repair_scratch_fs()
 	# want the test to fail:
 	_check_scratch_fs
 	;;
+    f2fs)
+	fsck -t $FSTYP -f $SCRATCH_DEV
+	;;
     *)
 	local dev=$SCRATCH_DEV
 	local fstyp=$FSTYP
Signature · 1 line
2.48.1
Reviewed-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] common/rc: support f2fs in _repair_scratch_fs

Quoted 14 lines · Chao Yu

Support f2fs in _repair_scratch_fs(), and use -f to repair the image forcely.

Cc Jaegeuk Kim <[email protected]>
---
 common/rc | 3 +++
 1 file changed, 3 insertions(+)
common/rc +0 -0
index ca755055..bf24da4e 100644

common/rc _repair_scratch_fs() · line 1508

Quoted 9 lines
common/rc +3 -0
@@ -1500,6 +1500,9 @@ _repair_scratch_fs()
 	# want the test to fail:
 	_check_scratch_fs
 	;;
+    f2fs)
+	fsck -t $FSTYP -f $SCRATCH_DEV
+	;;
     *)
 	local dev=$SCRATCH_DEV
 	local fstyp=$FSTYP
author
#5 lore raw

PATCH 4/4 f2fs/009: detect and repair nlink corruption

In reply to Chao Yu

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]>
---
 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
tests/f2fs/009 new file +142 -0
new file mode 100755
index 00000000..8f6a3e11
@@ -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
+	_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"
+	_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
tests/f2fs/009.out new file +2 -0
new file mode 100644
index 00000000..7e977155
@@ -0,0 +1,2 @@
+QA output created by 009
+Silence is golden
Signature · 1 line
2.48.1
#6 lore raw

Re: [PATCH 4/4] f2fs/009: detect and repair nlink corruption

Thanks for submitting the new test. It looks good aside from a few minor things below...

Quoted 23 lines · Chao Yu

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]>
---
 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
tests/f2fs/009 new file +4 -0
new file mode 100755
index 00000000..8f6a3e11
@@ -0,0 +1,142 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2025 Chao Yu.  All Rights Reserved.
+#

tests/f2fs/009 line 14

Quoted 10 lines
tests/f2fs/009 new file +10 -0
+# 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

tests/f2fs/009 line 16

Quoted 2 lines
tests/f2fs/009 new file +2 -0
+
+dir=$SCRATCH_MNT

I think it'd be easier to follow if you dropped this alias and just used $SCRATCH_MNT directly.

tests/f2fs/009 line 28

Quoted 12 lines
tests/f2fs/009 new file +12 -0
+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.

Quoted 81 lines
tests/f2fs/009 new file +81 -0
+		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

tests/f2fs/009 line 119

Quoted 10 lines
tests/f2fs/009 new file +10 -0
+	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?

Quoted 30 lines
tests/f2fs/009 new file +22 -0
+	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
tests/f2fs/009.out new file +2 -0
new file mode 100644
index 00000000..7e977155
@@ -0,0 +1,2 @@
+QA output created by 009
+Silence is golden
author
#7 lore raw

Re: [PATCH 4/4] f2fs/009: detect and repair nlink corruption

Quoted 33 lines · David Disseldorp

Thanks for submitting the new test. It looks good aside from a few minor things below...

Quoted 28 lines · Chao Yu

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]>
---
 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
tests/f2fs/009 new file +9 -0
new file mode 100755
index 00000000..8f6a3e11
@@ -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.
Quoted 8 lines

tests/f2fs/009 line 14

Quoted 5 lines
tests/f2fs/009 new file +5 -0
+#
+. ./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

It isn't dependent on CONFIG_F2FS_FAULT_INJECTION.

Quoted 115 lines

you could check for that too.

Flag the fix for the regression via e.g.:
_fixed_by_git_commit f2fs-tools 958cd6e

tests/f2fs/009 line 16

Quoted 2 lines
tests/f2fs/009 new file +2 -0
+
+dir=$SCRATCH_MNT

I think it'd be easier to follow if you dropped this alias and just used $SCRATCH_MNT directly.

tests/f2fs/009 line 28

Quoted 12 lines
tests/f2fs/009 new file +12 -0
+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.

Quoted 88 lines
tests/f2fs/009 new file +88 -0
+		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
Quoted 8 lines

tests/f2fs/009 line 119

Quoted 3 lines
tests/f2fs/009 new file +3 -0
+	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?

I tried to avoid filting inject/repair outputs and compare the output w/ golden output in 009.out, since I'm not sure whether the output will change or not later in f2fs-tools...

Will fix all others according to your comments, thanks a lot for the comments.

Thanks,

Quoted 32 lines
Quoted 31 lines
tests/f2fs/009 new file +22 -0
+	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
tests/f2fs/009.out new file +2 -0
new file mode 100644
index 00000000..7e977155
@@ -0,0 +1,2 @@
+QA output created by 009
+Silence is golden
#8 lore raw

Re: [PATCH 4/4] f2fs/009: detect and repair nlink corruption

In reply to Chao Yu
Quoted 7 lines · Chao Yu

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]>

---

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...

Quoted 25 lines
 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
tests/f2fs/009 new file +13 -0
new file mode 100755
index 00000000..8f6a3e11
@@ -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
+

tests/f2fs/009 line 23

Quoted 10 lines
tests/f2fs/009 new file +10 -0
+_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"
                  ;;
Quoted 88 lines
tests/f2fs/009 new file +88 -0
+	_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

tests/f2fs/009 line 121

Quoted 10 lines
tests/f2fs/009 new file +10 -0
+	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.

tests/f2fs/009 line 123

Quoted 2 lines
tests/f2fs/009 new file +2 -0
+	_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

tests/f2fs/009 line 129

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+		_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.

tests/f2fs/009 line 135

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+	if [ $? != 0 ]; then
+		_fail "fsck hasn't fixed nlink corruption "$i
+		exit
+	fi
+
+	_scratch_mount >> $seqres.full

">> $seqres.full" isn't necessary.

Quoted 19 lines
tests/f2fs/009 new file +7 -0
+	_scratch_unmount
+done
+
+echo "Silence is golden"
+
+status=0
+exit
tests/f2fs/009.out new file +2 -0
new file mode 100644
index 00000000..7e977155
@@ -0,0 +1,2 @@
+QA output created by 009
+Silence is golden
Signature · 1 line
2.48.1
author
#9 lore raw

Re: [PATCH 4/4] f2fs/009: detect and repair nlink corruption

Quoted 46 lines · Zorro Lang
Quoted 7 lines · Chao Yu

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]>

---

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...

Quoted 29 lines
 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
tests/f2fs/009 new file +17 -0
new file mode 100755
index 00000000..8f6a3e11
@@ -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
Quoted 8 lines

tests/f2fs/009 line 23

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+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:

Looks better,

Quoted 121 lines

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"
                  ;;
Quoted 88 lines
tests/f2fs/009 new file +88 -0
+	_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

tests/f2fs/009 line 121

Quoted 10 lines
tests/f2fs/009 new file +10 -0
+	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
        ;;
Quoted 6 lines

The FSCK_OPTIONS="-f" is useless.

tests/f2fs/009 line 123

Quoted 2 lines
tests/f2fs/009 new file +2 -0
+	_repair_scratch_fs >> $seqres.full
+	if [ $? != 1 ]; then

What does $?=1 mean? Does $?=1 mean finding corruption and fixed, $?=0 mean no corruption?

That's correct.

Quoted 9 lines

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"

You mean this?

export FSCK_OPTIONS="--dry-run"
_check_scratch_fs >>$seqres.full 2>&1 || _fail "can't find corruption"

We need to export FSCK_OPTIONS w/ "--dry-run", otherwise _check_scratch_fs will be stuck once it detects corruption.

Quoted 15 lines

_repair_scratch_fs >> $seqres.full
_check_scratch_fs

tests/f2fs/009 line 129

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+		_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.

Quoted 8 lines

tests/f2fs/009 line 135

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+	if [ $? != 0 ]; then
+		_fail "fsck hasn't fixed nlink corruption "$i
+		exit
+	fi
+
+	_scratch_mount >> $seqres.full

">> $seqres.full" isn't necessary.

Will update according to you comments, thanks a lot.

Thanks,

Quoted 21 lines
Quoted 20 lines
tests/f2fs/009 new file +7 -0
+	_scratch_unmount
+done
+
+echo "Silence is golden"
+
+status=0
+exit
tests/f2fs/009.out new file +2 -0
new file mode 100644
index 00000000..7e977155
@@ -0,0 +1,2 @@
+QA output created by 009
+Silence is golden
Signature · 1 line
2.48.1
#10 lore raw

Re: [PATCH 4/4] f2fs/009: detect and repair nlink corruption

Quoted 10 lines · Chao Yu
Quoted 9 lines · Zorro Lang
Quoted 7 lines · Chao Yu

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]>

---

[snip]

Quoted 28 lines
Quoted 13 lines

tests/f2fs/009 line 121

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+	$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
        ;;
Quoted 6 lines

The FSCK_OPTIONS="-f" is useless.

tests/f2fs/009 line 123

Quoted 2 lines
tests/f2fs/009 new file +2 -0
+	_repair_scratch_fs >> $seqres.full
+	if [ $? != 1 ]; then

What does $?=1 mean? Does $?=1 mean finding corruption and fixed, $?=0 mean no corruption?

That's correct.

Quoted 6 lines

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?

Quoted 8 lines
Quoted 3 lines

Something likes (just a rough example)

_check_scratch_fs >>$seqres.full 2>&1 && _fail "can't find corruption"

You mean this?

export FSCK_OPTIONS="--dry-run"
_check_scratch_fs >>$seqres.full 2>&1 || _fail "can't find corruption"

No,

Quoted 3 lines

We need to export FSCK_OPTIONS w/ "--dry-run", otherwise _check_scratch_fs will be stuck once it detects corruption.

If so, you might need to give _check_scratch_fs (and _check_test_fs) a f2fs specific handling. Due to _check_scratch_fs aims to do "check" only, _repair_scratch_fs aims to do "repair", they have different target. When we call _check_scratch_fs, we hope it reports pass or corruption then return, neither "repair" nor "stuck". So if I understand correct, you might need:

_check_scratch_fs()

{
	case $FSTYP in
	...
	f2fs)
		FSCK_OPTIONS="--dry-run" _check_generic_filesystem $device
		;;
	...
}

Or you have any better way to do f2fs check :)

Thanks,
Zorro

Quoted 51 lines
Quoted 16 lines

_repair_scratch_fs >> $seqres.full
_check_scratch_fs

tests/f2fs/009 line 129

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+		_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.

Quoted 8 lines

tests/f2fs/009 line 135

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+	if [ $? != 0 ]; then
+		_fail "fsck hasn't fixed nlink corruption "$i
+		exit
+	fi
+
+	_scratch_mount >> $seqres.full

">> $seqres.full" isn't necessary.

Will update according to you comments, thanks a lot.

Thanks,

Quoted 21 lines
Quoted 20 lines
tests/f2fs/009 new file +7 -0
+	_scratch_unmount
+done
+
+echo "Silence is golden"
+
+status=0
+exit
tests/f2fs/009.out new file +2 -0
new file mode 100644
index 00000000..7e977155
@@ -0,0 +1,2 @@
+QA output created by 009
+Silence is golden
Signature · 1 line
2.48.1
author
#11 lore raw

Re: [PATCH 4/4] f2fs/009: detect and repair nlink corruption

Quoted 54 lines · Zorro Lang
Quoted 10 lines · Chao Yu
Quoted 9 lines · Zorro Lang
Quoted 7 lines · Chao Yu

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]>

---

[snip]

Quoted 28 lines
Quoted 13 lines

tests/f2fs/009 line 121

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+	$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
        ;;
Quoted 6 lines

The FSCK_OPTIONS="-f" is useless.

tests/f2fs/009 line 123

Quoted 2 lines
tests/f2fs/009 new file +2 -0
+	_repair_scratch_fs >> $seqres.full
+	if [ $? != 1 ]; then

What does $?=1 mean? Does $?=1 mean finding corruption and fixed, $?=0 mean no corruption?

That's correct.

Quoted 6 lines

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?

Quoted 8 lines
Quoted 3 lines

Something likes (just a rough example)

_check_scratch_fs >>$seqres.full 2>&1 && _fail "can't find corruption"

You mean this?

export FSCK_OPTIONS="--dry-run"
_check_scratch_fs >>$seqres.full 2>&1 || _fail "can't find corruption"

No,

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

We need to export FSCK_OPTIONS w/ "--dry-run", otherwise _check_scratch_fs will be stuck once it detects corruption.

If so, you might need to give _check_scratch_fs (and _check_test_fs) a f2fs specific handling. Due to _check_scratch_fs aims to do "check" only, _repair_scratch_fs aims to do "repair", they have different target. When we call _check_scratch_fs, we hope it reports pass or corruption then return, neither "repair" nor "stuck". So if I understand correct, you might need:

Thank you for the explanation, now it's clear to me for use of those functions.

Quoted 7 lines

_check_scratch_fs()

{
	case $FSTYP in
	...
	f2fs)
		FSCK_OPTIONS="--dry-run" _check_generic_filesystem $device

It seems not work for me, due to fsck can not accept long parameter started w/ --? I didn't dig into this now.

fsck -t f2fs --dry-run /dev/vdb
fsck from util-linux 2.40.2

fsck -t f2fs /dev/vdb -- --dry-run
fsck from util-linux 2.40.2
Info: Dry run
Info: MKFS version
...
Done: 0.071639 secs

So I used this in v2:

+ f2fs)
+ if [ "$FSCK_OPTIONS" == "--dry-run" ]; then
+ fsck -t $FSTYP $device -- $FSCK_OPTIONS >> $seqres.full 2>&1
+ else
+ _check_generic_filesystem $device
+ fi
+ ;;

Any suggestion? What about introducing _check_f2fs_filesystem and reuse codes in _check_generic_filesystem as much as possible, then replace fsck w/ $F2FS_FSCK_PROG in order to use --dry-run.

Thanks,

Quoted 61 lines
		;;
	...
}

Or you have any better way to do f2fs check :)

Thanks,
Zorro

Quoted 51 lines
Quoted 16 lines

_repair_scratch_fs >> $seqres.full
_check_scratch_fs

tests/f2fs/009 line 129

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+		_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.

Quoted 8 lines

tests/f2fs/009 line 135

Quoted 6 lines
tests/f2fs/009 new file +6 -0
+	if [ $? != 0 ]; then
+		_fail "fsck hasn't fixed nlink corruption "$i
+		exit
+	fi
+
+	_scratch_mount >> $seqres.full

">> $seqres.full" isn't necessary.

Will update according to you comments, thanks a lot.

Thanks,

Quoted 21 lines
Quoted 20 lines
tests/f2fs/009 new file +7 -0
+	_scratch_unmount
+done
+
+echo "Silence is golden"
+
+status=0
+exit
tests/f2fs/009.out new file +2 -0
new file mode 100644
index 00000000..7e977155
@@ -0,0 +1,2 @@
+QA output created by 009
+Silence is golden
Signature · 1 line
2.48.1
Reviewed-by on v1 1/4
#12 lore raw
In reply to Chao Yu
Quoted 13 lines · Chao Yu

F2FS_IO_PROG was been exported twice, remove the redudant one.

Cc Jaegeuk Kim <[email protected]>
---
 common/config | 1 -
 1 file changed, 1 deletion(-)
common/config +0 -0
index 2afbda14..8d3047a5 100644

common/config export XFS_COPY_PROG="$(type -P xfs_copy)" · line 196

Quoted 7 lines
common/config +0 -1
@@ -191,7 +191,6 @@ export XFS_COPY_PROG="$(type -P xfs_copy)"
 export FSTRIM_PROG="$(type -P fstrim)"
 export DUMPE2FS_PROG="$(type -P dumpe2fs)"
 export RESIZE2FS_PROG="$(type -P resize2fs)"
-export F2FS_IO_PROG="$(type -P f2fs_io)"
 export FIO_PROG="$(type -P fio)"
 export FILEFRAG_PROG="$(type -P filefrag)"
 export E4DEFRAG_PROG="$(type -P e4defrag)"

Looks good. @Zorro, might as well squash in removal of the duplicate TIMEOUT_PROG export too.

#13 lore raw
Quoted 10 lines · David Disseldorp
Quoted 8 lines · Chao Yu

F2FS_IO_PROG was been exported twice, remove the redudant one.

Cc Jaegeuk Kim <[email protected]>
---
 common/config | 1 -
 1 file changed, 1 deletion(-)
Quoted 15 lines

common/config export XFS_COPY_PROG="$(type -P xfs_copy)" · line 196

Quoted 12 lines
common/config +0 -1
index 2afbda14..8d3047a5 100644
@@ -191,7 +191,6 @@ export XFS_COPY_PROG="$(type -P xfs_copy)"
 export FSTRIM_PROG="$(type -P fstrim)"
 export DUMPE2FS_PROG="$(type -P dumpe2fs)"
 export RESIZE2FS_PROG="$(type -P resize2fs)"
-export F2FS_IO_PROG="$(type -P f2fs_io)"
 export FIO_PROG="$(type -P fio)"
 export FILEFRAG_PROG="$(type -P filefrag)"
 export E4DEFRAG_PROG="$(type -P e4defrag)"

Looks good. @Zorro, might as well squash in removal of the duplicate TIMEOUT_PROG export too.

Sure, I roughly tried to find all duplication by:

  $ for prog in `sed -n "/export/s/export \(.*_PROG\)=.*/\1/p" common/config `;do n=`grep -E "\b$prog=" common/config|wc -l`;if [ $n -gt 1 ];then grep "\b$prog=" common/config;fi;done

Currently only found F2FS_IO_PROG and TIMEOUT_PROG. So I'll change this patch commit to:

common/config: remove redundant export variables

F2FS_IO_PROG and TIMEOUT_PROG are exported twice, remove the redundant one.

Thanks,
Zorro

Quoted 3 lines
Reviewed-by David Disseldorp
#14 lore raw
Quoted 31 lines · Zorro Lang
Quoted 10 lines · David Disseldorp
Quoted 8 lines · Chao Yu

F2FS_IO_PROG was been exported twice, remove the redudant one.

Cc Jaegeuk Kim <[email protected]>
---
 common/config | 1 -
 1 file changed, 1 deletion(-)
Quoted 15 lines

common/config export XFS_COPY_PROG="$(type -P xfs_copy)" · line 196

Quoted 12 lines
common/config +0 -1
index 2afbda14..8d3047a5 100644
@@ -191,7 +191,6 @@ export XFS_COPY_PROG="$(type -P xfs_copy)"
 export FSTRIM_PROG="$(type -P fstrim)"
 export DUMPE2FS_PROG="$(type -P dumpe2fs)"
 export RESIZE2FS_PROG="$(type -P resize2fs)"
-export F2FS_IO_PROG="$(type -P f2fs_io)"
 export FIO_PROG="$(type -P fio)"
 export FILEFRAG_PROG="$(type -P filefrag)"
 export E4DEFRAG_PROG="$(type -P e4defrag)"

Looks good. @Zorro, might as well squash in removal of the duplicate TIMEOUT_PROG export too.

Sure, I roughly tried to find all duplication by:

  $ for prog in `sed -n "/export/s/export \(.*_PROG\)=.*/\1/p" common/config `;do n=`grep -E "\b$prog=" common/config|wc -l`;if [ $n -gt 1 ];then grep "\b$prog=" common/config;fi;done
Quoted 7 lines

Currently only found F2FS_IO_PROG and TIMEOUT_PROG. So I'll change this patch commit to:

common/config: remove redundant export variables

F2FS_IO_PROG and TIMEOUT_PROG are exported twice, remove the redundant one.

Hi Chao,

As you need to change patch 4/4 more. I thought you might change others, so please change this patch refer to below:)

Thanks,
Zorro

Author: Chao Yu <[email protected]>
Date:   Thu Mar 6 16:18:06 2025 +0800

common/config: remove redundant export variables

F2FS_IO_PROG and TIMEOUT_PROG are exported twice, remove the redudant one.

common/config +0 -2
index 2afbda141..aa5258250 100644
@@ -191,7 +191,6 @@ export XFS_COPY_PROG="$(type -P xfs_copy)"
 export FSTRIM_PROG="$(type -P fstrim)"
 export DUMPE2FS_PROG="$(type -P dumpe2fs)"
 export RESIZE2FS_PROG="$(type -P resize2fs)"
-export F2FS_IO_PROG="$(type -P f2fs_io)"
 export FIO_PROG="$(type -P fio)"
 export FILEFRAG_PROG="$(type -P filefrag)"
 export E4DEFRAG_PROG="$(type -P e4defrag)"
@@ -220,7 +219,6 @@ export UBIUPDATEVOL_PROG="$(type -P ubiupdatevol)"
 export THIN_CHECK_PROG="$(type -P thin_check)"
 export PYTHON3_PROG="$(type -P python3)"
 export SQLITE3_PROG="$(type -P sqlite3)"
-export TIMEOUT_PROG="$(type -P timeout)"
 export SETCAP_PROG="$(type -P setcap)"
 export GETCAP_PROG="$(type -P getcap)"
 export CAPSH_PROG="$(type -P capsh)"
Quoted 7 lines

Thanks,
Zorro

Quoted 3 lines
author
#15 lore raw
Quoted 37 lines · Zorro Lang
Quoted 36 lines · Zorro Lang
Quoted 10 lines · David Disseldorp
Quoted 8 lines · Chao Yu

F2FS_IO_PROG was been exported twice, remove the redudant one.

Cc Jaegeuk Kim <[email protected]>
---
 common/config | 1 -
 1 file changed, 1 deletion(-)
Quoted 15 lines

common/config export XFS_COPY_PROG="$(type -P xfs_copy)" · line 196

Quoted 12 lines
common/config +0 -1
index 2afbda14..8d3047a5 100644
@@ -191,7 +191,6 @@ export XFS_COPY_PROG="$(type -P xfs_copy)"
 export FSTRIM_PROG="$(type -P fstrim)"
 export DUMPE2FS_PROG="$(type -P dumpe2fs)"
 export RESIZE2FS_PROG="$(type -P resize2fs)"
-export F2FS_IO_PROG="$(type -P f2fs_io)"
 export FIO_PROG="$(type -P fio)"
 export FILEFRAG_PROG="$(type -P filefrag)"
 export E4DEFRAG_PROG="$(type -P e4defrag)"

Looks good. @Zorro, might as well squash in removal of the duplicate TIMEOUT_PROG export too.

Sure, I roughly tried to find all duplication by:

  $ for prog in `sed -n "/export/s/export \(.*_PROG\)=.*/\1/p" common/config `;do n=`grep -E "\b$prog=" common/config|wc -l`;if [ $n -gt 1 ];then grep "\b$prog=" common/config;fi;done

Currently only found F2FS_IO_PROG and TIMEOUT_PROG. So I'll change this patch commit to:

common/config: remove redundant export variables

Quoted 7 lines
Quoted 2 lines

F2FS_IO_PROG and TIMEOUT_PROG are exported twice, remove the redundant one.

Hi Chao,

As you need to change patch 4/4 more. I thought you might change others, so please change this patch refer to below:)

Zorro, yes, let me update all in v2, thank you!

Thanks,

Quoted 46 lines

Thanks,
Zorro

Author: Chao Yu <[email protected]>
Date:   Thu Mar 6 16:18:06 2025 +0800

common/config: remove redundant export variables

F2FS_IO_PROG and TIMEOUT_PROG are exported twice, remove the redudant one.

common/config +0 -2
index 2afbda141..aa5258250 100644
@@ -191,7 +191,6 @@ export XFS_COPY_PROG="$(type -P xfs_copy)"
 export FSTRIM_PROG="$(type -P fstrim)"
 export DUMPE2FS_PROG="$(type -P dumpe2fs)"
 export RESIZE2FS_PROG="$(type -P resize2fs)"
-export F2FS_IO_PROG="$(type -P f2fs_io)"
 export FIO_PROG="$(type -P fio)"
 export FILEFRAG_PROG="$(type -P filefrag)"
 export E4DEFRAG_PROG="$(type -P e4defrag)"
@@ -220,7 +219,6 @@ export UBIUPDATEVOL_PROG="$(type -P ubiupdatevol)"
 export THIN_CHECK_PROG="$(type -P thin_check)"
 export PYTHON3_PROG="$(type -P python3)"
 export SQLITE3_PROG="$(type -P sqlite3)"
-export TIMEOUT_PROG="$(type -P timeout)"
 export SETCAP_PROG="$(type -P setcap)"
 export GETCAP_PROG="$(type -P getcap)"
 export CAPSH_PROG="$(type -P capsh)"
Quoted 8 lines

Thanks,
Zorro

Quoted 3 lines