1#!/bin/sh 2 3# 4# SPDX-License-Identifier: BSD-2-Clause 5# 6# Copyright (c) 2018 Dell EMC Isilon 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions 10# are met: 11# 1. Redistributions of source code must retain the above copyright 12# notice, this list of conditions and the following disclaimer. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27# SUCH DAMAGE. 28# 29 30# fsck_ffs(8) disk image fuzz test. 31 32# "UFS /dev/md11 (/mnt11) cylinder checksum failed" seen. 33# Fixed by r341510. 34 35# 'panic: invalid counts on struct mount' seen: 36# https://people.freebsd.org/~pho/stress/log/fsck-4.txt 37 38# "panic: softdep_load_inodeblock: negative i_effnlink" seen. 39 40. ../default.cfg 41 42[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 43 44cc -o /tmp/flip -Wall -Wextra -O2 ../tools/flip.c || exit 1 45 46set -e 47u1=$mdstart 48u2=$((mdstart + 1)) 49mp1=${mntpoint}$u1 50mp2=${mntpoint}$u2 51mkdir -p $mp1 $mp2 52 53backup=/tmp/fsck.sh.diskimage.`date +%Y%m%dT%H%M%S`.gz 54core=/tmp/fsck.sh.core.`date +%Y%m%dT%H%M%S` 55diskimage=$mp1/fsck.sh.diskimage 56log=$mp1/fsck.sh.log 57 58asbs=0 59cleans=0 60reruns=0 61waccess=0 62 63max=$((10 * 1024 * 1024)) 64[ "$newfs_flags" = "-j" ] && 65 max=$((20 * 1024 * 1024)) 66 67set +e 68mount | grep "on $mp1 " | grep -q /dev/md && umount -f $mp1 69[ -c /dev/md$u1 ] && mdconfig -d -u $u1 70mdconfig -a -t swap -s 1g -u $u1 71newfs $newfs_flags -n /dev/md$u1 > /dev/null 72mount /dev/md$u1 $mp1 73 74[ -c /dev/md$u2 ] && mdconfig -d -u $u2 75dd if=/dev/zero of=$diskimage bs=$max count=1 status=none 76mdconfig -a -t vnode -f $diskimage -u $u2 77[ "$newfs_flags" = "-U" ] && [ `jot -r 1 0 1` -eq 1 ] && newfs_flags="-j" 78backups=`newfs -N $newfs_flags md$u2 | grep -A1 "super-block backups" | \ 79 tail -1 | sed 's/,//g'` 80newfs $newfs_flags md$u2 > /dev/null 81mount /dev/md$u2 $mp2 82[ -d /usr/include/sys ] && cp -r /usr/include/sys $mp2 83umount $mp2 84 85chk() { 86 local i 87 88 clean=0 89 rerun=0 90 waccess=0 91 fsck_ffs -fy $1 > $log 2>&1 92 r=$? 93 if grep -qiE "super-?block.*failed" $log; then 94 for b in $backups; do 95 echo "Using alternate SB $b" 96 asbs=$((asbs + 1)) 97 fsck_ffs -b $b -fy $1 > $log 2>&1 98 r=$? 99 grep -qiE "super-?block.*failed" $log || 100 break 101 done 102 usedasb=1 103 else 104 usedasb=0 105 fi 106 LANG=C egrep -q "[A-Z][A-Z]" $log && clean=0 107 grep -Eq "IS CLEAN|MARKED CLEAN" $log && clean=1 108 # For now regard a "was modified" as a cause for a rerun, 109 # disregarding "clean" claim. 110 grep -Eq "WAS MODIFIED" $log && rerun=1 111 grep -q RERUN $log && rerun=1 112 grep -q "NO WRITE ACCESS" $log && waccess=1 113 [ $r -ne 0 -a $clean -eq 1 ] && echo "Exit code $r w/ clean == 1" 114} 115 116cd $mp1 117s=0 118start=`date +%s` 119while [ $((`date +%s` - start)) -lt 60 ]; do 120 mount /dev/md$u2 $mp2 || { s=101; break; } 121 ls -lR $mp2 > /dev/null || { s=102; echo "ls failed"; break; } 122 touch $mp2/`jot -rc 8 a z | tr -d '\n'` 123 while mount | grep -q "on $mp2 "; do umount $mp2; done 124 echo * | grep -q core && break 125 sync 126 mdconfig -d -u $u2 127 /tmp/flip -n 10 $diskimage 128 129 sync 130 gzip < $diskimage > $backup 131 fsync $backup 132 133 for i in `jot 3`; do 134 chk $diskimage 135 [ $rerun -eq 1 ] && { reruns=$((reruns + 1)); continue; } 136 [ $clean -eq 1 ] && { cleans=$((cleans + 1)); break; } 137 [ -f fsck_ffs.core ] && 138 { cp $diskimage \ 139 /tmp/fsck_ffs.core.diskimage.`date +%Y%m%dT%H%M%S`; break 2; } 140 done 141 [ $clean -ne 1 ] && break 142 mdconfig -a -t vnode -f $diskimage -u $u2 143 [ $r -ne 0 -a $clean -eq 1 ] && 144 { echo "CLEAN && non zero exit code"; break; } 145 [ $clean -eq 1 ] && continue 146 [ $usedasb -eq 1 ] && { echo "Alt. SB failed"; s=104; } 147 [ $waccess -eq 1 ] && { echo "No write access"; s=105; } 148 break 149done 150mount | grep -q "on $mp2 " && umount $mp2 151mdconfig -l | grep -q "md$u2" && 152 mdconfig -d -u $u2 153 154echo "$cleans cleans, $reruns reruns, $asbs alternate SBs." 155if [ $clean -ne 1 ]; then 156 echo "FS still not clean. Last fsck_ffs exit code was $r." 157 cat $log 158 cp -v $log /tmp 159 [ $s -eq 0 ] && s=106 160fi 161[ -f fsck_ffs.core ] && 162 mv fsck_ffs.core $core 163[ $s -eq 0 ] && rm -f $backup 164cd /tmp 165umount $mp1 166mdconfig -d -u $u1 167rm -f /tmp/flip 168exit $s 169