Path: blob/main/tools/test/stress2/misc/cleanup.sh
39537 views
#!/bin/sh12#3# Copyright (c) 2008-2013 Peter Holm <[email protected]>4# All rights reserved.5#6# Redistribution and use in source and binary forms, with or without7# modification, are permitted provided that the following conditions8# are met:9# 1. Redistributions of source code must retain the above copyright10# notice, this list of conditions and the following disclaimer.11# 2. Redistributions in binary form must reproduce the above copyright12# notice, this list of conditions and the following disclaimer in the13# documentation and/or other materials provided with the distribution.14#15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25# SUCH DAMAGE.26#2728[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 12930. ../default.cfg3132bname=`basename $mntpoint`33mounts=`mount | awk "/$bname/{print \\$3}"`34nmounts=`sysctl -n hw.ncpu` # Max number of mounts in use35[ $nmounts -lt 31 ] && nmounts=31 # Arbitrary value36s=037# Unmount the test mount points: /mnt, /mnt10 .. mnt3138for i in $mounts; do39u=`echo $i | sed "s/\/$bname//"`40[ -z "$u" ] && u=$mdstart41echo "$u" | grep -Eq '^[0-9]+$' || continue42# [ $u -lt $mdstart -o $u -gt $((mdstart + nmounts)) ] && continue43while mount | grep -q "on $i "; do44r=`fstat -mf $i 2>/dev/null | awk '$3 ~ /^[0-9]+$/ {print $3}'`45if [ -n "$r" ]; then46echo "cleanup.sh: kill $r"47echo $r | xargs kill; sleep 148fi49echo "cleanup.sh: umount -f $i"50umount -f $i > /dev/null 2>&1 || s=151[ -z "$r" ] && break52done53done5455# Delete the test mount points /mnt10 .. /mnt3156for i in `ls -d $mntpoint* 2>/dev/null | grep -Ev '^$mntpoint$'`; do57u=`echo $i | sed "s/\/$bname//"`58echo "$u" | grep -Eq '^[0-9]+$' || continue59# [ $u -lt $mdstart -o $u -gt $((mdstart + nmounts)) ] && continue60if ! mount | grep -q "on $i "; then61[ -d $i ] && find $i -delete \622>/dev/null63rm -rf $i > /dev/null 2>&164fi65done6667# Delete the memory disks68units=`mdconfig -l | sed 's/md//g'`69for u in $units; do70if [ $u -ge $mdstart -a $u -lt $((mdstart + nmounts)) ]; then71echo "cleanup.sh: mdconfig -d -u $u"72mdconfig -d -u $u || s=173[ -c /dev/md$u ] && sleep .174fi75done7677[ -d "$mntpoint" ] && (cd $mntpoint && find . -delete)78rm -f /tmp/.snap/stress2* /var/.snap/stress2*79rm -rf /tmp/stressX.control $RUNDIR80[ -d `dirname "$diskimage"` ] || mkdir -p `dirname "$diskimage"`81mkdir -p $RUNDIR82chmod 0777 $RUNDIR8384# Delete $testuser's ipcs85ipcs | awk "\$5 ~/$testuser/ && \$6 ~/$testuser/ {print \"-\" \$1,\$2}" | \86xargs -t ipcrm8788# Modules89#mlist=/tmp/stress2.d/mlist90#find $mlist -mtime +1 -delete 2>/dev/null91#[ -f $mlist ] && touch $mlist ||92# { kldstat | kldstat | awk '/\.ko$/ {print $NF}' > $mlist; \93# echo "Updating $mlist"; }94#for m in `kldstat | awk '/\.ko$/ {print $NF}'`; do95# grep -q $m $mlist && continue96# echo "pty.ko mqueuefs.ko ioat.ko ums.ko" | grep -q $m && continue97# echo "cleanup.sh: kldunload $m"98# kldunload $m99#done100# unloading an active dtrace causes a panic101#kldstat | grep -q dtraceall.ko && kldunload dtraceall.ko102kldstat | grep -q ext2fs.ko && kldunload ext2fs.ko103[ $s -ne 0 ] && echo "cleanup.sh: FAIL $s"104exit $s105106107