1#!/bin/sh 2 3# 4# SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5# 6# Copyright (c) 2020 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 SUJ FS. 31# Variation of gnop8.sh by Kirk McKusick <mckusick@mckusick.com> 32 33# https://people.freebsd.org/~pho/stress/log/gnop9.txt 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 44exp=/sbin/fsck_ffs.exp # Experimental version 45log=/tmp/gnop9.log 46[ -f $exp ] && { echo "Using $exp"; fsck=$exp; } 47[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart 48mdconfig -a -t swap -s 5g -u $mdstart || exit 1 49md=md$mdstart 50newfs -j /dev/$md > /dev/null 2>&1 || exit 1 51 52export LOAD=80 53export rwLOAD=80 54export runRUNTIME=10m 55export RUNDIR=$mntpoint/stressX 56export CTRLDIR=$mntpoint/stressX.control 57export MAXSWAPPCT=80 58export TESTPROGS=' 59testcases/lockf2/lockf2 60testcases/symlink/symlink 61testcases/openat/openat 62testcases/socket/socket 63testcases/rw/rw 64testcases/fts/fts 65testcases/link/link 66testcases/lockf/lockf 67testcases/creat/creat 68testcases/mkdir/mkdir 69testcases/rename/rename 70testcases/mkfifo/mkfifo 71testcases/dirnprename/dirnprename 72testcases/dirrename/dirrename 73' 74 75set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'` 76export KBLOCKS=$(($1 / 10 * 7)) 77export INODES=$(($2 / 10 * 7)) 78 79start=`date +%s` 80while [ $((`date +%s` - start)) -lt 600 ]; do 81 gnop create /dev/$md || exit 1 82 mount /dev/$md.nop $mntpoint || exit 1 83 mkdir -p $RUNDIR $CTRLDIR 84 chmod 777 $RUNDIR $CTRLDIR 85 86 # start your favorite I/O test here 87 rm -rf /tmp/stressX.control 88 (cd $RUNDIR && find . -delete) 89 90 su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' & 91 92 # after some number of seconds 93 sleep `jot -r 1 30 90` 94 gnop destroy -f /dev/$md.nop 95 ../tools/killall.sh || exit 1 96 wait 97 98 # Wait until forcible unmount, may be up to about 30 seconds, 99 # but typically very quick if I/O is in progress 100 s=`date +%s` 101 n=0 102 while mount | grep -q "on $mntpoint "; do 103 [ $n -eq 0 ] && /bin/echo -n "Waiting for $mntpoint to force umount ..." 104 n=$((n + 1)) 105 sleep 2 106 if [ $((`date +%s` - s)) -ge 180 ]; then 107 echo "Giving up on waiting for umount of $mntpoint" 108 umount $mntpoint || umount -f $mntpoint 109 break 110 fi 111 done 112 [ $n -ne 0 ] && echo 113 114 # first fsck will attempt journal recovery 115 $fsck -fy /dev/$md > $log 2>&1 116 117 # The second fsck will do traditional check for any errors 118 # from journal recovery 119 120 # There seems to be a gnop cache issue, which resolves by adding 121 # delays between each fsck run 122 for i in `jot $fsck_loops`; do 123 sleep $((i * i)) # gnop workaround 124 [ $i -ne 1 ] && 125 echo "`date +%T` $fsck loop #$((i + 1))" 126 $fsck -fy /dev/$md > $log 2>&1 127 grep -Eq "IS CLEAN|MARKED CLEAN" $log && break 128 [ $i -eq $fsck_loops ] && 129 { echo "$fsck did not mark FS as clean"; exit 1; } 130 [ $i -ne 1 ] && tail -3 $log 131 sync; sleep 5; sync; sleep 5 132 done 133done 134echo "Final $fsck" 135sleep 3; # gnop workaround 136$fsck -fy /dev/$md > $log || { tail -5 $log; exit 1; } 137mdconfig -d -u ${md#md} 138rm -f $log 139exit 0 140