* [PATCH v2 1/4] common/config: remove redundant export variables
@ 2025-03-10 11:56 Chao Yu
2025-03-10 11:56 ` [PATCH v2 2/4] common/config: export F2FS_INJECT_PROG Chao Yu
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Chao Yu @ 2025-03-10 11:56 UTC (permalink / raw)
To: Zorro Lang, fstests; +Cc: jaegeuk, linux-f2fs-devel, Chao Yu, David Disseldorp
F2FS_IO_PROG and TIMEOUT_PROG are exported twice, remove the redundant
one.
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Chao Yu <chao@kernel.org>
Reviewed-by: David Disseldorp <ddiss@suse.de>
---
v2:
- remove another redundant export variable
common/config | 2 --
1 file changed, 2 deletions(-)
diff --git a/common/config b/common/config
index 2afbda14..aa525825 100644
--- a/common/config
+++ b/common/config
@@ -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)"
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 2/4] common/config: export F2FS_INJECT_PROG
2025-03-10 11:56 [PATCH v2 1/4] common/config: remove redundant export variables Chao Yu
@ 2025-03-10 11:56 ` Chao Yu
2025-03-10 11:56 ` [PATCH v2 3/4] common/rc: support f2fs in _repair_scratch_fs Chao Yu
2025-03-10 11:56 ` [PATCH v2 4/4] f2fs/009: detect and repair nlink corruption Chao Yu
2 siblings, 0 replies; 7+ messages in thread
From: Chao Yu @ 2025-03-10 11:56 UTC (permalink / raw)
To: Zorro Lang, fstests; +Cc: jaegeuk, linux-f2fs-devel, Chao Yu, David Disseldorp
export F2FS_INJECT_PROG w/ inject.f2fs, it can be used for fault injection.
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Chao Yu <chao@kernel.org>
Reviewed-by: David Disseldorp <ddiss@suse.de>
---
v2:
- no changes
common/config | 1 +
1 file changed, 1 insertion(+)
diff --git a/common/config b/common/config
index aa525825..7d017a05 100644
--- a/common/config
+++ b/common/config
@@ -316,6 +316,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)
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 3/4] common/rc: support f2fs in _repair_scratch_fs
2025-03-10 11:56 [PATCH v2 1/4] common/config: remove redundant export variables Chao Yu
2025-03-10 11:56 ` [PATCH v2 2/4] common/config: export F2FS_INJECT_PROG Chao Yu
@ 2025-03-10 11:56 ` Chao Yu
2025-03-10 11:56 ` [PATCH v2 4/4] f2fs/009: detect and repair nlink corruption Chao Yu
2 siblings, 0 replies; 7+ messages in thread
From: Chao Yu @ 2025-03-10 11:56 UTC (permalink / raw)
To: Zorro Lang, fstests; +Cc: jaegeuk, linux-f2fs-devel, Chao Yu, David Disseldorp
Support f2fs in _repair_scratch_fs(), and use -f to repair the image
forcely.
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: Chao Yu <chao@kernel.org>
Reviewed-by: David Disseldorp <ddiss@suse.de>
---
v2:
- no changes
common/rc | 3 +++
1 file changed, 3 insertions(+)
diff --git a/common/rc b/common/rc
index ca755055..bf24da4e 100644
--- a/common/rc
+++ b/common/rc
@@ -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
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v2 4/4] f2fs/009: detect and repair nlink corruption
2025-03-10 11:56 [PATCH v2 1/4] common/config: remove redundant export variables Chao Yu
2025-03-10 11:56 ` [PATCH v2 2/4] common/config: export F2FS_INJECT_PROG Chao Yu
2025-03-10 11:56 ` [PATCH v2 3/4] common/rc: support f2fs in _repair_scratch_fs Chao Yu
@ 2025-03-10 11:56 ` Chao Yu
2025-03-10 20:03 ` Zorro Lang
2025-03-10 20:25 ` Zorro Lang
2 siblings, 2 replies; 7+ messages in thread
From: Chao Yu @ 2025-03-10 11:56 UTC (permalink / raw)
To: Zorro Lang, fstests; +Cc: jaegeuk, linux-f2fs-devel, 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 <jaegeuk@kernel.org>
Signed-off-by: Chao Yu <chao@kernel.org>
---
v2:
- make _scratch_mkfs() to format f2fs image forcely
- adjust _check_scratch_fs() to allow specified parameter of f2fs
- add _fixed_by_git_commit
- add _require_command inject.f2fs
- simply return value handling
common/rc | 9 ++-
tests/f2fs/009 | 133 +++++++++++++++++++++++++++++++++++++++++++++
tests/f2fs/009.out | 2 +
3 files changed, 143 insertions(+), 1 deletion(-)
create mode 100755 tests/f2fs/009
create mode 100644 tests/f2fs/009.out
diff --git a/common/rc b/common/rc
index bf24da4e..e156f3af 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"
;;
ocfs2)
@@ -3682,6 +3682,13 @@ _check_scratch_fs()
ubifs)
# there is no fsck program for ubifs yet
;;
+ f2fs)
+ if [ "$FSCK_OPTIONS" == "--dry-run" ]; then
+ fsck -t $FSTYP $device -- $FSCK_OPTIONS >> $seqres.full 2>&1
+ else
+ _check_generic_filesystem $device
+ fi
+ ;;
*)
_check_generic_filesystem $device
;;
diff --git a/tests/f2fs/009 b/tests/f2fs/009
new file mode 100755
index 00000000..d14df968
--- /dev/null
+++ b/tests/f2fs/009
@@ -0,0 +1,133 @@
+#! /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
+_require_command "$F2FS_INJECT_PROG" inject.f2fs
+
+_fixed_by_git_commit f2fs-tools 958cd6e
+
+filename=$SCRATCH_MNT/foo
+hardlink=$SCRATCH_MNT/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 -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"
+
+ export FSCK_OPTIONS="--dry-run"
+ _check_scratch_fs >>$seqres.full 2>&1 && _fail "can't find corruption"
+ _repair_scratch_fs >> $seqres.full
+ _check_scratch_fs
+
+ _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
--
2.48.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2 4/4] f2fs/009: detect and repair nlink corruption
2025-03-10 11:56 ` [PATCH v2 4/4] f2fs/009: detect and repair nlink corruption Chao Yu
@ 2025-03-10 20:03 ` Zorro Lang
2025-03-10 20:25 ` Zorro Lang
1 sibling, 0 replies; 7+ messages in thread
From: Zorro Lang @ 2025-03-10 20:03 UTC (permalink / raw)
To: Chao Yu; +Cc: Zorro Lang, fstests, jaegeuk, linux-f2fs-devel
On Mon, Mar 10, 2025 at 07:56:21PM +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>
> ---
> v2:
> - make _scratch_mkfs() to format f2fs image forcely
> - adjust _check_scratch_fs() to allow specified parameter of f2fs
> - add _fixed_by_git_commit
> - add _require_command inject.f2fs
> - simply return value handling
> common/rc | 9 ++-
> tests/f2fs/009 | 133 +++++++++++++++++++++++++++++++++++++++++++++
> tests/f2fs/009.out | 2 +
> 3 files changed, 143 insertions(+), 1 deletion(-)
> create mode 100755 tests/f2fs/009
> create mode 100644 tests/f2fs/009.out
>
> diff --git a/common/rc b/common/rc
> index bf24da4e..e156f3af 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"
> ;;
> ocfs2)
> @@ -3682,6 +3682,13 @@ _check_scratch_fs()
> ubifs)
> # there is no fsck program for ubifs yet
> ;;
> + f2fs)
> + if [ "$FSCK_OPTIONS" == "--dry-run" ]; then
> + fsck -t $FSTYP $device -- $FSCK_OPTIONS >> $seqres.full 2>&1
> + else
> + _check_generic_filesystem $device
> + fi
If the "--dry-run" of fsck.f2fs is similar with "-n -y" of fsck.ext4. Then
you might need to change the fsck_opts() function in common/config.
_fsck_opts()
{
case $FSTYP in
ext2|ext3|ext4)
export FSCK_OPTIONS="-nf"
;;
reiser*)
export FSCK_OPTIONS="--yes"
;;
f2fs)
export FSCK_OPTIONS=""
;;
...
}
The default FSCK_OPTIONS for f2fs should be "--dry-run".
f2fs)
export FSCK_OPTIONS="--dry-run"
Then ...
[snip]
> + $F2FS_INJECT_PROG --node --mb i_links --nid $ino --val $nlink $SCRATCH_DEV \
> + >> $seqres.full || _fail "fail to inject"
> +
> + export FSCK_OPTIONS="--dry-run"
... then you can save this export FSCK_OPTIONS="--dry-run". I've explained
more in your v1 patch review, refer to:
https://lore.kernel.org/fstests/20250310194818.wki325qreuta26nc@dell-per750-06-vm-08.rhts.eng.pek2.redhat.com/T/#u
Thanks,
Zorro
> + _check_scratch_fs >>$seqres.full 2>&1 && _fail "can't find corruption"
> + _repair_scratch_fs >> $seqres.full
> + _check_scratch_fs
> +
> + _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
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 4/4] f2fs/009: detect and repair nlink corruption
2025-03-10 11:56 ` [PATCH v2 4/4] f2fs/009: detect and repair nlink corruption Chao Yu
2025-03-10 20:03 ` Zorro Lang
@ 2025-03-10 20:25 ` Zorro Lang
2025-03-11 8:06 ` Chao Yu
1 sibling, 1 reply; 7+ messages in thread
From: Zorro Lang @ 2025-03-10 20:25 UTC (permalink / raw)
To: Chao Yu; +Cc: Zorro Lang, fstests, jaegeuk, linux-f2fs-devel
On Mon, Mar 10, 2025 at 07:56:21PM +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>
> ---
> v2:
> - make _scratch_mkfs() to format f2fs image forcely
> - adjust _check_scratch_fs() to allow specified parameter of f2fs
> - add _fixed_by_git_commit
> - add _require_command inject.f2fs
> - simply return value handling
> common/rc | 9 ++-
> tests/f2fs/009 | 133 +++++++++++++++++++++++++++++++++++++++++++++
> tests/f2fs/009.out | 2 +
> 3 files changed, 143 insertions(+), 1 deletion(-)
> create mode 100755 tests/f2fs/009
> create mode 100644 tests/f2fs/009.out
>
> diff --git a/common/rc b/common/rc
> index bf24da4e..e156f3af 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"
> ;;
> ocfs2)
> @@ -3682,6 +3682,13 @@ _check_scratch_fs()
> ubifs)
> # there is no fsck program for ubifs yet
> ;;
> + f2fs)
> + if [ "$FSCK_OPTIONS" == "--dry-run" ]; then
> + fsck -t $FSTYP $device -- $FSCK_OPTIONS >> $seqres.full 2>&1
> + else
> + _check_generic_filesystem $device
> + fi
> + ;;
> *)
> _check_generic_filesystem $device
> ;;
> diff --git a/tests/f2fs/009 b/tests/f2fs/009
> new file mode 100755
> index 00000000..d14df968
> --- /dev/null
> +++ b/tests/f2fs/009
> @@ -0,0 +1,133 @@
> +#! /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
> +_require_command "$F2FS_INJECT_PROG" inject.f2fs
> +
> +_fixed_by_git_commit f2fs-tools 958cd6e
^^^^^^^^
commit subject?
> +
> +filename=$SCRATCH_MNT/foo
> +hardlink=$SCRATCH_MNT/bar
> +
> +for ((i=0;i<14;i++)) do
> + echo "round: " $i >> $seqres.full
> +
> + _scratch_mkfs "-f" >> $seqres.full
As you've add "-f" in _scratch_mkfs, so this "-f" can be removed.
> + _scratch_mount >> $seqres.full
^^^^^^
I think it's useless
> +
> + 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 &
^^^^^^
Where's the "socket" command from? I think it's not always installed on any
Linux system. fstests never use this command in any test case. If you
need this command, you might need to check that, and _notrun if it's
not installed.
> + pid=$!
As you have background processes in this test case, you need to make sure
these processes are killed properly in _cleanup, especially if the test
is killed suddently, refer to generic/019.
Thanks,
Zorro
> + 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"
> +
> + export FSCK_OPTIONS="--dry-run"
> + _check_scratch_fs >>$seqres.full 2>&1 && _fail "can't find corruption"
> + _repair_scratch_fs >> $seqres.full
> + _check_scratch_fs
> +
> + _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
> --
> 2.48.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 4/4] f2fs/009: detect and repair nlink corruption
2025-03-10 20:25 ` Zorro Lang
@ 2025-03-11 8:06 ` Chao Yu
0 siblings, 0 replies; 7+ messages in thread
From: Chao Yu @ 2025-03-11 8:06 UTC (permalink / raw)
To: Zorro Lang; +Cc: chao, Zorro Lang, fstests, jaegeuk, linux-f2fs-devel
On 3/11/25 04:25, Zorro Lang wrote:
> On Mon, Mar 10, 2025 at 07:56:21PM +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>
>> ---
>> v2:
>> - make _scratch_mkfs() to format f2fs image forcely
>> - adjust _check_scratch_fs() to allow specified parameter of f2fs
>> - add _fixed_by_git_commit
>> - add _require_command inject.f2fs
>> - simply return value handling
>> common/rc | 9 ++-
>> tests/f2fs/009 | 133 +++++++++++++++++++++++++++++++++++++++++++++
>> tests/f2fs/009.out | 2 +
>> 3 files changed, 143 insertions(+), 1 deletion(-)
>> create mode 100755 tests/f2fs/009
>> create mode 100644 tests/f2fs/009.out
>>
>> diff --git a/common/rc b/common/rc
>> index bf24da4e..e156f3af 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"
>> ;;
>> ocfs2)
>> @@ -3682,6 +3682,13 @@ _check_scratch_fs()
>> ubifs)
>> # there is no fsck program for ubifs yet
>> ;;
>> + f2fs)
>> + if [ "$FSCK_OPTIONS" == "--dry-run" ]; then
>> + fsck -t $FSTYP $device -- $FSCK_OPTIONS >> $seqres.full 2>&1
>> + else
>> + _check_generic_filesystem $device
>> + fi
>> + ;;
>> *)
>> _check_generic_filesystem $device
>> ;;
>> diff --git a/tests/f2fs/009 b/tests/f2fs/009
>> new file mode 100755
>> index 00000000..d14df968
>> --- /dev/null
>> +++ b/tests/f2fs/009
>> @@ -0,0 +1,133 @@
>> +#! /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
>> +_require_command "$F2FS_INJECT_PROG" inject.f2fs
>> +
>> +_fixed_by_git_commit f2fs-tools 958cd6e
> ^^^^^^^^
> commit subject?
>
>> +
>> +filename=$SCRATCH_MNT/foo
>> +hardlink=$SCRATCH_MNT/bar
>> +
>> +for ((i=0;i<14;i++)) do
>> + echo "round: " $i >> $seqres.full
>> +
>> + _scratch_mkfs "-f" >> $seqres.full
>
> As you've add "-f" in _scratch_mkfs, so this "-f" can be removed.
>
>> + _scratch_mount >> $seqres.full
> ^^^^^^
> I think it's useless
>
>> +
>> + 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 &
> ^^^^^^
>
> Where's the "socket" command from? I think it's not always installed on any
> Linux system. fstests never use this command in any test case. If you
> need this command, you might need to check that, and _notrun if it's
> not installed.
>
>> + pid=$!
>
> As you have background processes in this test case, you need to make sure
> these processes are killed properly in _cleanup, especially if the test
> is killed suddently, refer to generic/019.
Zorro, I've updated the patchset, could you please help to check that?
Thanks,
>
> Thanks,
> Zorro
>
>> + 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"
>> +
>> + export FSCK_OPTIONS="--dry-run"
>> + _check_scratch_fs >>$seqres.full 2>&1 && _fail "can't find corruption"
>> + _repair_scratch_fs >> $seqres.full
>> + _check_scratch_fs
>> +
>> + _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
>> --
>> 2.48.1
>>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-03-11 8:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-10 11:56 [PATCH v2 1/4] common/config: remove redundant export variables Chao Yu
2025-03-10 11:56 ` [PATCH v2 2/4] common/config: export F2FS_INJECT_PROG Chao Yu
2025-03-10 11:56 ` [PATCH v2 3/4] common/rc: support f2fs in _repair_scratch_fs Chao Yu
2025-03-10 11:56 ` [PATCH v2 4/4] f2fs/009: detect and repair nlink corruption Chao Yu
2025-03-10 20:03 ` Zorro Lang
2025-03-10 20:25 ` Zorro Lang
2025-03-11 8:06 ` Chao Yu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox