git: 7184e8c21107 - main - Keep running fsck_ffs as long as "WAS MODIFIED" is reported

From: Peter Holm <pho_at_FreeBSD.org>
Date: Sat, 27 Nov 2021 10:57:35 UTC
The branch main has been updated by pho:

URL: https://cgit.FreeBSD.org/src/commit/?id=7184e8c211074db57865adabf41a08a50d155582

commit 7184e8c211074db57865adabf41a08a50d155582
Author:     Peter Holm <pho@FreeBSD.org>
AuthorDate: 2021-11-27 10:54:53 +0000
Commit:     Peter Holm <pho@FreeBSD.org>
CommitDate: 2021-11-27 10:54:53 +0000

    Keep running fsck_ffs as long as "WAS MODIFIED" is reported
---
 tools/test/stress2/misc/fsck.sh | 79 ++++++++++++++++++++++++-----------------
 1 file changed, 46 insertions(+), 33 deletions(-)

diff --git a/tools/test/stress2/misc/fsck.sh b/tools/test/stress2/misc/fsck.sh
index a007e722988e..826c31f733c3 100755
--- a/tools/test/stress2/misc/fsck.sh
+++ b/tools/test/stress2/misc/fsck.sh
@@ -27,14 +27,15 @@
 # SUCH DAMAGE.
 #
 
-# fsck_ffs(8) test.
+# fsck_ffs(8) disk image fuzz test.
+
 # "UFS /dev/md11 (/mnt11) cylinder checksum failed" seen.
 # Fixed by r341510.
 
 # 'panic: invalid counts on struct mount' seen:
 # https://people.freebsd.org/~pho/stress/log/fsck-4.txt
 
-[ $DEBUG ] || exit 0 # Still WiP
+# "panic: softdep_load_inodeblock: negative i_effnlink" seen.
 
 . ../default.cfg
 
@@ -42,11 +43,6 @@
 
 cc -o /tmp/flip -Wall -Wextra -O2 ../tools/flip.c || exit 1
 
-echo 'int sync(void) { return (0); }' > /tmp/fsck_preload.c
-mycc -o /tmp/fsck_preload.so -shared -fpic /tmp/fsck_preload.c || exit 1
-cc -o /tmp/fsck_preload.so -shared -fpic /tmp/fsck_preload.c || exit 1
-rm /tmp/fsck_preload.c
-
 set -e
 u1=$mdstart
 u2=$((mdstart + 1))
@@ -69,7 +65,7 @@ set +e
 mount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1
 [ -c /dev/md$u1 ] && mdconfig -d -u $u1
 mdconfig -a -t swap -s 1g -u $u1
-newfs $newfs_flags /dev/md$u1 > /dev/null
+newfs $newfs_flags -n /dev/md$u1 > /dev/null
 mount /dev/md$u1 $mp1
 
 [ -c /dev/md$u2 ] && mdconfig -d -u $u2
@@ -85,15 +81,16 @@ umount $mp2
 chk() {
 	local i
 
-	LD_PRELOAD=/tmp/fsck_preload.so  \
-	    fsck_ffs -fy $1 > $log 2>&1
+	clean=0
+	rerun=0
+	waccess=0
+	fsck_ffs -fy $1 > $log 2>&1
 	r=$?
 	if grep -qE "Cannot find file system superblock|Superblock check-hash failed" $log; then
 		for b in $backups; do
 			echo "Using alternate SB $b"
 			asbs=$((asbs + 1))
-			LD_PRELOAD=/tmp/fsck_preload.so  \
-			    fsck_ffs -b $b -fy $1 > $log 2>&1
+			fsck_ffs -b $b -fy $1 > $log 2>&1
 			r=$?
 			grep -qE "Cannot find file system superblock|Superblock check-hash failed" $log ||
 			   break
@@ -103,47 +100,63 @@ chk() {
 		usedasb=0
 	fi
 	LANG=C egrep -q "[A-Z][A-Z]" $log && clean=0
-	! grep -Eq "IS CLEAN|MARKED CLEAN" $log; clean=$?
-	! grep -q RERUN $log; rerun=$?
-	! grep -q "NO WRITE ACCESS" $log; waccess=$?
+	grep -Eq "IS CLEAN|MARKED CLEAN" $log && clean=1
+	# For now regard a "was modified" as a cause for a rerun,
+	# disregarding "clean" claim.
+	grep -Eq "WAS MODIFIED" $log && rerun=1
+	grep -q RERUN $log && rerun=1
+	grep -q "NO WRITE ACCESS" $log && waccess=1
 	[ $r -ne 0 -a $clean -eq 1 ] && echo "Exit code $r w/ clean == 1"
-
 }
 
-cd /tmp
+cd $mp1
 s=0
 start=`date +%s`
 while [ $((`date +%s` - start)) -lt 60 ]; do
-	gzip < $diskimage > $backup
-	fsync $backup; sync # ; sleep .2; sync; sleep .2; sync
 	mount /dev/md$u2 $mp2 || { s=101; break; }
+	ls -lR $mp2 > /dev/null || { s=102; echo "ls failed"; break; }
 	touch $mp2/`jot -rc 8 a z | tr -d '\n'`
-	umount $mp2
-	/tmp/flip -n 4 $diskimage
+	while mount | grep -q "on $mp2 "; do umount $mp2; done
+	echo * | grep -q core && break
+	sync
+	mdconfig -d -u $u2
+	/tmp/flip -n 10 $diskimage
+
+	sync
+	gzip < $diskimage > $backup
+	fsync $backup
+
 	for i in `jot 3`; do
-		chk /dev/md$u2
-		[ $clean -eq 1 ] && { cleans=$((cleans + 1)); break; }
+		chk $diskimage
 		[ $rerun -eq 1 ] && { reruns=$((reruns + 1)); continue; }
+		[ $clean -eq 1 ] && { cleans=$((cleans + 1)); break; }
+		[ -f fsck_ffs.core ] &&
+		    { cp $diskimage \
+		        /tmp/fsck_ffs.core.diskimage.`date +%Y%m%dT%H%M%S`; break 2; }
 	done
+	[ $clean -ne 1 ] && break
+	mdconfig -a -t vnode -f $diskimage -u $u2
 	[ $r -ne 0 -a $clean -eq 1 ] &&
 	    { echo "CLEAN && non zero exit code"; break; }
 	[ $clean -eq 1 ] && continue
-	[ $usedasb -eq 1 ] && { echo "Alt. SB failed"; s=103; }
-	[ $waccess -eq 1 ] && { echo "No write access"; s=555; }
+	[ $usedasb -eq 1 ] && { echo "Alt. SB failed"; s=104; }
+	[ $waccess -eq 1 ] && { echo "No write access"; s=105; }
 	break
 done
-[ $DEBUG ] &&
-    echo "$cleans cleans, $reruns reruns, $asbs alternate SBs." && cat $log
+mount | grep -q "on $mp2 " && umount $mp2
+mdconfig -d -u $u2 || exit 1
+
+echo "$cleans cleans, $reruns reruns, $asbs alternate SBs."
 if [ $clean -ne 1 ]; then
 	echo "FS still not clean. Last fsck_ffs exit code was $r."
 	cat $log
-	cp -v $log /tmp || rm $log
-	[ $s -eq 0 ] && s=104
+	cp -v $log /tmp
+	[ $s -eq 0 ] && s=106
 fi
-mdconfig -d -u $u2 || exit 1
-[ -f fsck_ffs.core ] && ls -l fsck_ffs.core
-
+echo * | grep -q core && { ls -l *.core; cp $log /tmp; exit 106; } ||
+    rm -f $backup
+cd /tmp
 umount $mp1
 mdconfig -d -u $u1
-rm -f /tmp/fsck_preload.so $backup /tmp/flip
+rm -f /tmp/flip
 exit $s