1#!/bin/sh 2 3# 4# SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5# 6# Copyright (c) 2022 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# Long fsck_ffs runtime scenario 34 35[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 36. ../default.cfg 37 38fsck=/sbin/fsck_ffs 39fsck_loops=10 40log=/tmp/gnop12.log 41[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart 42mdconfig -a -t swap -s 5g -u $mdstart || exit 1 43md=md$mdstart 44newfs -U /dev/$md > /dev/null 2>&1 || exit 1 45 46export LOAD=80 47export rwLOAD=80 48export runRUNTIME=10m 49export RUNDIR=$mntpoint/stressX 50export CTRLDIR=$mntpoint/stressX.control 51export MAXSWAPPCT=80 52export TESTPROGS=' 53testcases/creat/creat 54' 55 56start=`date +%s` 57while [ $((`date +%s` - start)) -lt 600 ]; do 58 gnop create /dev/$md || exit 1 59 mount /dev/$md.nop $mntpoint || exit 1 60 61 rm -rf $RUNDIR $CTRLDIR 62 mkdir -p $RUNDIR $CTRLDIR 63 chmod 777 $RUNDIR $CTRLDIR 64 set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` 65 export KBLOCKS=$(($1 / 10 * 7)) 66 export INODES=$(($2 / 10 * 7)) 67 68 su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > /dev/null 2>&1 & 69 70 # after some number of seconds 71 sleep `jot -r 1 20 30` 72 gnop destroy -f /dev/$md.nop 73 ../tools/killall.sh || exit 1 74 while pgrep -qU $testuser; do pkill -U $testuser; done 75 wait 76 77 # Wait until forcible unmount, may be up to about 30 seconds, 78 # but typically very quick if I/O is in progress 79 s=`date +%s` 80 n=0 81 while mount | grep -q "on $mntpoint "; do 82 [ $n -eq 0 ] && /bin/echo -n "Waiting for $mntpoint to force umount ..." 83 n=$((n + 1)) 84 sleep 5 85 if [ $((`date +%s` - s)) -ge 180 ]; then 86 echo "Giving up on waiting for umount of $mntpoint" 87 umount $mntpoint 88 while mount | grep -q "on $mntpoint "; do 89 umount -f $mntpoint 90 done 91 fi 92 done 93 [ $n -ne 0 ] && echo 94 95 # The initial fsck_ffs may run for more than on hour with a 5GB MD disk 96 t=`date +%s` 97 $fsck -fy /dev/$md > /dev/null 2>&1 98 t=$((`date +%s`- t)) 99 [ $t -gt 300 ] && { echo "First fsck took $(((t + 30) / 60)) minutes!"; e=1; } 100 101 for i in `jot $fsck_loops`; do 102 sleep 10 103 $fsck -fy /dev/$md > $log 2>&1 104 # For now, do not trust fsck_ffs's "CLEAN" message 105# grep -Eq "IS CLEAN|MARKED CLEAN" $log && break 106 grep -Eq "FILE SYSTEM WAS MODIFIED" $log || break 107 [ $i -eq $fsck_loops ] && 108 { echo "$fsck did not mark FS as clean"; tail -12 $log; exit 1; } 109 done 110done 111$fsck -fy /dev/$md > $log || { tail -5 $log; exit 1; } 112mdconfig -d -u ${md#md} 113rm -f $log 114exit $e 115