18a272653SPeter Holm#!/bin/sh 28a272653SPeter Holm 38a272653SPeter Holm# 4*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 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 307184e8c2SPeter Holm# fsck_ffs(8) disk image fuzz test. 317184e8c2SPeter 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 387184e8c2SPeter 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 52f31ca922SPeter Holm 538a272653SPeter Holmbackup=/tmp/fsck.sh.diskimage.`date +%Y%m%dT%H%M%S`.gz 54f31ca922SPeter Holmcore=/tmp/fsck.sh.core.`date +%Y%m%dT%H%M%S` 55f31ca922SPeter Holmdiskimage=$mp1/fsck.sh.diskimage 56f31ca922SPeter Holmlog=$mp1/fsck.sh.log 57f31ca922SPeter Holm 588a272653SPeter Holmasbs=0 598a272653SPeter Holmcleans=0 608a272653SPeter Holmreruns=0 618a272653SPeter Holmwaccess=0 628a272653SPeter Holm 638a272653SPeter Holmmax=$((10 * 1024 * 1024)) 648a272653SPeter Holm[ "$newfs_flags" = "-j" ] && 658a272653SPeter Holm max=$((20 * 1024 * 1024)) 668a272653SPeter Holm 678a272653SPeter Holmset +e 688a272653SPeter Holmmount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1 698a272653SPeter Holm[ -c /dev/md$u1 ] && mdconfig -d -u $u1 708a272653SPeter Holmmdconfig -a -t swap -s 1g -u $u1 717184e8c2SPeter Holmnewfs $newfs_flags -n /dev/md$u1 > /dev/null 728a272653SPeter Holmmount /dev/md$u1 $mp1 738a272653SPeter Holm 748a272653SPeter Holm[ -c /dev/md$u2 ] && mdconfig -d -u $u2 758a272653SPeter Holmdd if=/dev/zero of=$diskimage bs=$max count=1 status=none 768a272653SPeter Holmmdconfig -a -t vnode -f $diskimage -u $u2 77f31ca922SPeter Holm[ "$newfs_flags" = "-U" ] && [ `jot -r 1 0 1` -eq 1 ] && newfs_flags="-j" 788a272653SPeter Holmbackups=`newfs -N $newfs_flags md$u2 | grep -A1 "super-block backups" | \ 798a272653SPeter Holm tail -1 | sed 's/,//g'` 808a272653SPeter Holmnewfs $newfs_flags md$u2 > /dev/null 818a272653SPeter Holmmount /dev/md$u2 $mp2 828a272653SPeter Holm[ -d /usr/include/sys ] && cp -r /usr/include/sys $mp2 838a272653SPeter Holmumount $mp2 848a272653SPeter Holm 858a272653SPeter Holmchk() { 868a272653SPeter Holm local i 878a272653SPeter Holm 887184e8c2SPeter Holm clean=0 897184e8c2SPeter Holm rerun=0 907184e8c2SPeter Holm waccess=0 918a272653SPeter Holm fsck_ffs -fy $1 > $log 2>&1 928a272653SPeter Holm r=$? 9398b13e25SPeter Holm if grep -qiE "super-?block.*failed" $log; then 948a272653SPeter Holm for b in $backups; do 958a272653SPeter Holm echo "Using alternate SB $b" 968a272653SPeter Holm asbs=$((asbs + 1)) 978a272653SPeter Holm fsck_ffs -b $b -fy $1 > $log 2>&1 988a272653SPeter Holm r=$? 9998b13e25SPeter Holm grep -qiE "super-?block.*failed" $log || 1008a272653SPeter Holm break 1018a272653SPeter Holm done 1028a272653SPeter Holm usedasb=1 1038a272653SPeter Holm else 1048a272653SPeter Holm usedasb=0 1058a272653SPeter Holm fi 1068a272653SPeter Holm LANG=C egrep -q "[A-Z][A-Z]" $log && clean=0 1077184e8c2SPeter Holm grep -Eq "IS CLEAN|MARKED CLEAN" $log && clean=1 1087184e8c2SPeter Holm # For now regard a "was modified" as a cause for a rerun, 1097184e8c2SPeter Holm # disregarding "clean" claim. 1107184e8c2SPeter Holm grep -Eq "WAS MODIFIED" $log && rerun=1 1117184e8c2SPeter Holm grep -q RERUN $log && rerun=1 1127184e8c2SPeter Holm grep -q "NO WRITE ACCESS" $log && waccess=1 1138a272653SPeter Holm [ $r -ne 0 -a $clean -eq 1 ] && echo "Exit code $r w/ clean == 1" 1148a272653SPeter Holm} 1158a272653SPeter Holm 1167184e8c2SPeter Holmcd $mp1 1178a272653SPeter Holms=0 1188a272653SPeter Holmstart=`date +%s` 1198a272653SPeter Holmwhile [ $((`date +%s` - start)) -lt 60 ]; do 1208a272653SPeter Holm mount /dev/md$u2 $mp2 || { s=101; break; } 1217184e8c2SPeter Holm ls -lR $mp2 > /dev/null || { s=102; echo "ls failed"; break; } 1228a272653SPeter Holm touch $mp2/`jot -rc 8 a z | tr -d '\n'` 1237184e8c2SPeter Holm while mount | grep -q "on $mp2 "; do umount $mp2; done 1247184e8c2SPeter Holm echo * | grep -q core && break 1257184e8c2SPeter Holm sync 1267184e8c2SPeter Holm mdconfig -d -u $u2 1277184e8c2SPeter Holm /tmp/flip -n 10 $diskimage 1287184e8c2SPeter Holm 1297184e8c2SPeter Holm sync 1307184e8c2SPeter Holm gzip < $diskimage > $backup 1317184e8c2SPeter Holm fsync $backup 1327184e8c2SPeter Holm 1338a272653SPeter Holm for i in `jot 3`; do 1347184e8c2SPeter Holm chk $diskimage 1358a272653SPeter Holm [ $rerun -eq 1 ] && { reruns=$((reruns + 1)); continue; } 1367184e8c2SPeter Holm [ $clean -eq 1 ] && { cleans=$((cleans + 1)); break; } 1377184e8c2SPeter Holm [ -f fsck_ffs.core ] && 1387184e8c2SPeter Holm { cp $diskimage \ 1397184e8c2SPeter Holm /tmp/fsck_ffs.core.diskimage.`date +%Y%m%dT%H%M%S`; break 2; } 1408a272653SPeter Holm done 1417184e8c2SPeter Holm [ $clean -ne 1 ] && break 1427184e8c2SPeter Holm mdconfig -a -t vnode -f $diskimage -u $u2 1438a272653SPeter Holm [ $r -ne 0 -a $clean -eq 1 ] && 1448a272653SPeter Holm { echo "CLEAN && non zero exit code"; break; } 1458a272653SPeter Holm [ $clean -eq 1 ] && continue 1467184e8c2SPeter Holm [ $usedasb -eq 1 ] && { echo "Alt. SB failed"; s=104; } 1477184e8c2SPeter Holm [ $waccess -eq 1 ] && { echo "No write access"; s=105; } 1488a272653SPeter Holm break 1498a272653SPeter Holmdone 1507184e8c2SPeter Holmmount | grep -q "on $mp2 " && umount $mp2 151f31ca922SPeter Holmmdconfig -l | grep -q "md$u2" && 152f31ca922SPeter Holm mdconfig -d -u $u2 1537184e8c2SPeter Holm 1547184e8c2SPeter Holmecho "$cleans cleans, $reruns reruns, $asbs alternate SBs." 1558a272653SPeter Holmif [ $clean -ne 1 ]; then 1568a272653SPeter Holm echo "FS still not clean. Last fsck_ffs exit code was $r." 1578a272653SPeter Holm cat $log 1587184e8c2SPeter Holm cp -v $log /tmp 1597184e8c2SPeter Holm [ $s -eq 0 ] && s=106 1608a272653SPeter Holmfi 161f31ca922SPeter Holm[ -f fsck_ffs.core ] && 162f31ca922SPeter Holm mv fsck_ffs.core $core 163f31ca922SPeter Holm[ $s -eq 0 ] && rm -f $backup 1647184e8c2SPeter Holmcd /tmp 1658a272653SPeter Holmumount $mp1 1668a272653SPeter Holmmdconfig -d -u $u1 1677184e8c2SPeter Holmrm -f /tmp/flip 1688a272653SPeter Holmexit $s 169