xref: /freebsd/tools/test/stress2/misc/fsck.sh (revision 7184e8c211074db57865adabf41a08a50d155582)
18a272653SPeter Holm#!/bin/sh
28a272653SPeter Holm
38a272653SPeter Holm#
48a272653SPeter Holm# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
58a272653SPeter Holm#
68a272653SPeter Holm# Copyright (c) 2018 Dell EMC Isilon
78a272653SPeter Holm#
88a272653SPeter Holm# Redistribution and use in source and binary forms, with or without
98a272653SPeter Holm# modification, are permitted provided that the following conditions
108a272653SPeter Holm# are met:
118a272653SPeter Holm# 1. Redistributions of source code must retain the above copyright
128a272653SPeter Holm#    notice, this list of conditions and the following disclaimer.
138a272653SPeter Holm# 2. Redistributions in binary form must reproduce the above copyright
148a272653SPeter Holm#    notice, this list of conditions and the following disclaimer in the
158a272653SPeter Holm#    documentation and/or other materials provided with the distribution.
168a272653SPeter Holm#
178a272653SPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
188a272653SPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
198a272653SPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
208a272653SPeter Holm# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
218a272653SPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
228a272653SPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
238a272653SPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
248a272653SPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
258a272653SPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
268a272653SPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
278a272653SPeter Holm# SUCH DAMAGE.
288a272653SPeter Holm#
298a272653SPeter Holm
30*7184e8c2SPeter Holm# fsck_ffs(8) disk image fuzz test.
31*7184e8c2SPeter Holm
328a272653SPeter Holm# "UFS /dev/md11 (/mnt11) cylinder checksum failed" seen.
338a272653SPeter Holm# Fixed by r341510.
348a272653SPeter Holm
358a272653SPeter Holm# 'panic: invalid counts on struct mount' seen:
368a272653SPeter Holm# https://people.freebsd.org/~pho/stress/log/fsck-4.txt
378a272653SPeter Holm
38*7184e8c2SPeter Holm# "panic: softdep_load_inodeblock: negative i_effnlink" seen.
398a272653SPeter Holm
408a272653SPeter Holm. ../default.cfg
418a272653SPeter Holm
428a272653SPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
438a272653SPeter Holm
448a272653SPeter Holmcc -o /tmp/flip -Wall -Wextra -O2 ../tools/flip.c || exit 1
458a272653SPeter Holm
468a272653SPeter Holmset -e
478a272653SPeter Holmu1=$mdstart
488a272653SPeter Holmu2=$((mdstart + 1))
498a272653SPeter Holmmp1=${mntpoint}$u1
508a272653SPeter Holmmp2=${mntpoint}$u2
518a272653SPeter Holmmkdir -p $mp1 $mp2
528a272653SPeter Holmlog=$mp1/fsck.sh.log
538a272653SPeter Holmdiskimage=$mp1/fsck.sh.diskimage
548a272653SPeter Holmbackup=/tmp/fsck.sh.diskimage.`date +%Y%m%dT%H%M%S`.gz
558a272653SPeter Holmasbs=0
568a272653SPeter Holmcleans=0
578a272653SPeter Holmreruns=0
588a272653SPeter Holmwaccess=0
598a272653SPeter Holm
608a272653SPeter Holmmax=$((10 * 1024 * 1024))
618a272653SPeter Holm[ "$newfs_flags" = "-j" ] &&
628a272653SPeter Holm    max=$((20 * 1024 * 1024))
638a272653SPeter Holm
648a272653SPeter Holmset +e
658a272653SPeter Holmmount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1
668a272653SPeter Holm[ -c /dev/md$u1 ] && mdconfig -d -u $u1
678a272653SPeter Holmmdconfig -a -t swap -s 1g -u $u1
68*7184e8c2SPeter Holmnewfs $newfs_flags -n /dev/md$u1 > /dev/null
698a272653SPeter Holmmount /dev/md$u1 $mp1
708a272653SPeter Holm
718a272653SPeter Holm[ -c /dev/md$u2 ] && mdconfig -d -u $u2
728a272653SPeter Holmdd if=/dev/zero of=$diskimage bs=$max count=1 status=none
738a272653SPeter Holmmdconfig -a -t vnode -f $diskimage -u $u2
748a272653SPeter Holmbackups=`newfs -N $newfs_flags md$u2 | grep -A1 "super-block backups" | \
758a272653SPeter Holm    tail -1 | sed 's/,//g'`
768a272653SPeter Holmnewfs $newfs_flags md$u2 > /dev/null
778a272653SPeter Holmmount /dev/md$u2 $mp2
788a272653SPeter Holm[ -d /usr/include/sys ] && cp -r /usr/include/sys $mp2
798a272653SPeter Holmumount $mp2
808a272653SPeter Holm
818a272653SPeter Holmchk() {
828a272653SPeter Holm	local i
838a272653SPeter Holm
84*7184e8c2SPeter Holm	clean=0
85*7184e8c2SPeter Holm	rerun=0
86*7184e8c2SPeter Holm	waccess=0
878a272653SPeter Holm	fsck_ffs -fy $1 > $log 2>&1
888a272653SPeter Holm	r=$?
898a272653SPeter Holm	if grep -qE "Cannot find file system superblock|Superblock check-hash failed" $log; then
908a272653SPeter Holm		for b in $backups; do
918a272653SPeter Holm			echo "Using alternate SB $b"
928a272653SPeter Holm			asbs=$((asbs + 1))
938a272653SPeter Holm			fsck_ffs -b $b -fy $1 > $log 2>&1
948a272653SPeter Holm			r=$?
958a272653SPeter Holm			grep -qE "Cannot find file system superblock|Superblock check-hash failed" $log ||
968a272653SPeter Holm			   break
978a272653SPeter Holm		done
988a272653SPeter Holm		usedasb=1
998a272653SPeter Holm	else
1008a272653SPeter Holm		usedasb=0
1018a272653SPeter Holm	fi
1028a272653SPeter Holm	LANG=C egrep -q "[A-Z][A-Z]" $log && clean=0
103*7184e8c2SPeter Holm	grep -Eq "IS CLEAN|MARKED CLEAN" $log && clean=1
104*7184e8c2SPeter Holm	# For now regard a "was modified" as a cause for a rerun,
105*7184e8c2SPeter Holm	# disregarding "clean" claim.
106*7184e8c2SPeter Holm	grep -Eq "WAS MODIFIED" $log && rerun=1
107*7184e8c2SPeter Holm	grep -q RERUN $log && rerun=1
108*7184e8c2SPeter Holm	grep -q "NO WRITE ACCESS" $log && waccess=1
1098a272653SPeter Holm	[ $r -ne 0 -a $clean -eq 1 ] && echo "Exit code $r w/ clean == 1"
1108a272653SPeter Holm}
1118a272653SPeter Holm
112*7184e8c2SPeter Holmcd $mp1
1138a272653SPeter Holms=0
1148a272653SPeter Holmstart=`date +%s`
1158a272653SPeter Holmwhile [ $((`date +%s` - start)) -lt 60 ]; do
1168a272653SPeter Holm	mount /dev/md$u2 $mp2 || { s=101; break; }
117*7184e8c2SPeter Holm	ls -lR $mp2 > /dev/null || { s=102; echo "ls failed"; break; }
1188a272653SPeter Holm	touch $mp2/`jot -rc 8 a z | tr -d '\n'`
119*7184e8c2SPeter Holm	while mount | grep -q "on $mp2 "; do umount $mp2; done
120*7184e8c2SPeter Holm	echo * | grep -q core && break
121*7184e8c2SPeter Holm	sync
122*7184e8c2SPeter Holm	mdconfig -d -u $u2
123*7184e8c2SPeter Holm	/tmp/flip -n 10 $diskimage
124*7184e8c2SPeter Holm
125*7184e8c2SPeter Holm	sync
126*7184e8c2SPeter Holm	gzip < $diskimage > $backup
127*7184e8c2SPeter Holm	fsync $backup
128*7184e8c2SPeter Holm
1298a272653SPeter Holm	for i in `jot 3`; do
130*7184e8c2SPeter Holm		chk $diskimage
1318a272653SPeter Holm		[ $rerun -eq 1 ] && { reruns=$((reruns + 1)); continue; }
132*7184e8c2SPeter Holm		[ $clean -eq 1 ] && { cleans=$((cleans + 1)); break; }
133*7184e8c2SPeter Holm		[ -f fsck_ffs.core ] &&
134*7184e8c2SPeter Holm		    { cp $diskimage \
135*7184e8c2SPeter Holm		        /tmp/fsck_ffs.core.diskimage.`date +%Y%m%dT%H%M%S`; break 2; }
1368a272653SPeter Holm	done
137*7184e8c2SPeter Holm	[ $clean -ne 1 ] && break
138*7184e8c2SPeter Holm	mdconfig -a -t vnode -f $diskimage -u $u2
1398a272653SPeter Holm	[ $r -ne 0 -a $clean -eq 1 ] &&
1408a272653SPeter Holm	    { echo "CLEAN && non zero exit code"; break; }
1418a272653SPeter Holm	[ $clean -eq 1 ] && continue
142*7184e8c2SPeter Holm	[ $usedasb -eq 1 ] && { echo "Alt. SB failed"; s=104; }
143*7184e8c2SPeter Holm	[ $waccess -eq 1 ] && { echo "No write access"; s=105; }
1448a272653SPeter Holm	break
1458a272653SPeter Holmdone
146*7184e8c2SPeter Holmmount | grep -q "on $mp2 " && umount $mp2
147*7184e8c2SPeter Holmmdconfig -d -u $u2 || exit 1
148*7184e8c2SPeter Holm
149*7184e8c2SPeter Holmecho "$cleans cleans, $reruns reruns, $asbs alternate SBs."
1508a272653SPeter Holmif [ $clean -ne 1 ]; then
1518a272653SPeter Holm	echo "FS still not clean. Last fsck_ffs exit code was $r."
1528a272653SPeter Holm	cat $log
153*7184e8c2SPeter Holm	cp -v $log /tmp
154*7184e8c2SPeter Holm	[ $s -eq 0 ] && s=106
1558a272653SPeter Holmfi
156*7184e8c2SPeter Holmecho * | grep -q core && { ls -l *.core; cp $log /tmp; exit 106; } ||
157*7184e8c2SPeter Holm    rm -f $backup
158*7184e8c2SPeter Holmcd /tmp
1598a272653SPeter Holmumount $mp1
1608a272653SPeter Holmmdconfig -d -u $u1
161*7184e8c2SPeter Holmrm -f /tmp/flip
1628a272653SPeter Holmexit $s
163