1#!/bin/sh 2 3# 4# SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5# 6# Copyright (c) 2021 Peter Holm <pho@FreeBSD.org> 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 test with forced unmount of a SU FS. 31# Variation of gnop8.sh by Kirk McKusick <mckusick@mckusick.com> 32 33# Copy of gnop9.sh. Uses SU instead of SUJ. 34 35[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 36. ../default.cfg 37 38# Check for lingering threads from the last run 39pgrep -x mount && { pgrep -x mount | xargs ps -lp; exit 1; } 40../tools/killall.sh || exit 1 41 42fsck=/sbin/fsck_ffs 43fsck_loops=10 44log=/tmp/gnop10.log 45[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart 46mdconfig -a -t swap -s 5g -u $mdstart || exit 1 47md=md$mdstart 48newfs -U /dev/$md > /dev/null 2>&1 || exit 1 49 50export LOAD=80 51export rwLOAD=80 52export runRUNTIME=10m 53export RUNDIR=$mntpoint/stressX 54export CTRLDIR=$mntpoint/stressX.control 55export MAXSWAPPCT=80 56export TESTPROGS=' 57testcases/lockf2/lockf2 58testcases/symlink/symlink 59testcases/openat/openat 60testcases/socket/socket 61testcases/rw/rw 62testcases/fts/fts 63testcases/link/link 64testcases/lockf/lockf 65testcases/creat/creat 66testcases/mkdir/mkdir 67testcases/rename/rename 68testcases/mkfifo/mkfifo 69testcases/dirnprename/dirnprename 70testcases/dirrename/dirrename 71' 72 73start=`date +%s` 74while [ $((`date +%s` - start)) -lt 600 ]; do 75 gnop create /dev/$md || exit 1 76 mount /dev/$md.nop $mntpoint || exit 1 77 78 rm -rf $RUNDIR $CTRLDIR 79 mkdir -p $RUNDIR $CTRLDIR 80 chmod 777 $RUNDIR $CTRLDIR 81 set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` 82 export KBLOCKS=$(($1 / 10 * 7)) 83 export INODES=$(($2 / 10 * 7)) 84 85 # start your favorite I/O test here 86 87 su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > /dev/null 2>&1 & 88 89 # after some number of seconds 90 sleep `jot -r 1 20 30` 91 gnop destroy -f /dev/$md.nop 92 ../tools/killall.sh || exit 1 93 while pgrep -qU $testuser; do pkill -U $testuser; done 94 wait 95 96 # Wait until forcible unmount, may be up to about 30 seconds, 97 # but typically very quick if I/O is in progress 98 s=`date +%s` 99 n=0 100 while mount | grep -q "on $mntpoint "; do 101 [ $n -eq 0 ] && /bin/echo -n "Waiting for $mntpoint to force umount ..." 102 n=$((n + 1)) 103 sleep 5 104 if [ $((`date +%s` - s)) -ge 180 ]; then 105 echo "Giving up on waiting for umount of $mntpoint" 106 umount $mntpoint 107 while mount | grep -q "on $mntpoint "; do 108 umount -f $mntpoint 109 done 110 fi 111 done 112 [ $n -ne 0 ] && echo 113 114 # The initial fsck_ffs may run for more than on hour with a 5GB MD disk 115 t=`date +%s` 116 $fsck -fy /dev/$md > /dev/null 2>&1 117 t=$((`date +%s`- t)) 118 [ $t -gt 300 ] && echo "First fsck took $(((t + 30) / 60)) minutes!" 119 120 for i in `jot $fsck_loops`; do 121 sleep 10 122 $fsck -fy /dev/$md > $log 2>&1 123 # For now, do not trust fsck_ffs's "CLEAN" message 124# grep -Eq "IS CLEAN|MARKED CLEAN" $log && break 125 grep -Eq "FILE SYSTEM WAS MODIFIED" $log || break 126 [ $i -eq $fsck_loops ] && 127 { echo "$fsck did not mark FS as clean"; tail -12 $log; exit 1; } 128 done 129done 130$fsck -fy /dev/$md > $log || { tail -5 $log; exit 1; } 131mdconfig -d -u ${md#md} 132rm -f $log 133exit 0 134