148031e6cSPeter Holm#!/bin/sh 248031e6cSPeter Holm 348031e6cSPeter Holm# 4*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 548031e6cSPeter Holm# 648031e6cSPeter Holm# Copyright (c) 2022 Peter Holm <pho@FreeBSD.org> 748031e6cSPeter Holm# 848031e6cSPeter Holm# Redistribution and use in source and binary forms, with or without 948031e6cSPeter Holm# modification, are permitted provided that the following conditions 1048031e6cSPeter Holm# are met: 1148031e6cSPeter Holm# 1. Redistributions of source code must retain the above copyright 1248031e6cSPeter Holm# notice, this list of conditions and the following disclaimer. 1348031e6cSPeter Holm# 2. Redistributions in binary form must reproduce the above copyright 1448031e6cSPeter Holm# notice, this list of conditions and the following disclaimer in the 1548031e6cSPeter Holm# documentation and/or other materials provided with the distribution. 1648031e6cSPeter Holm# 1748031e6cSPeter Holm# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1848031e6cSPeter Holm# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1948031e6cSPeter Holm# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2048031e6cSPeter Holm# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2148031e6cSPeter Holm# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2248031e6cSPeter Holm# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2348031e6cSPeter Holm# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2448031e6cSPeter Holm# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2548031e6cSPeter Holm# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2648031e6cSPeter Holm# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2748031e6cSPeter Holm# SUCH DAMAGE. 2848031e6cSPeter Holm# 2948031e6cSPeter Holm 3048031e6cSPeter Holm# Scenario: mount -t nullfs /mnt /mnt 3148031e6cSPeter Holm 3248031e6cSPeter Holm# Seen: 3348031e6cSPeter Holm# [root@mercat1 /home/pho]# ps -lUroot | grep -v grep | grep -E "find|umount" 3448031e6cSPeter Holm# 0 23496 3144 0 52 0 12856 2544 ufs D+ 0 0:00.00 find /mnt -type f -maxdepth 2 -ls 3548031e6cSPeter Holm# 0 23497 3126 6 52 0 12812 2512 mount dr D+ 0 0:00.00 umount /mnt 3648031e6cSPeter Holm# [root@mercat1 /home/pho]# 3748031e6cSPeter Holm 3848031e6cSPeter Holm# Test suggestion by Jason Harmening: 3948031e6cSPeter Holm 4048031e6cSPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1 4148031e6cSPeter Holm 4248031e6cSPeter Holm. ../default.cfg 4348031e6cSPeter Holm 4448031e6cSPeter Holmnullfs_srcdir=$mntpoint 4548031e6cSPeter Holmnullfs_dstdir=$mntpoint 4648031e6cSPeter Holmruntime=300 4748031e6cSPeter Holm 4848031e6cSPeter Holmset -e 4948031e6cSPeter Holmmount | grep $mntpoint | grep -q /dev/md && umount -f $mntpoint 5048031e6cSPeter Holmmdconfig -l | grep -q md$mdstart && mdconfig -d -u $mdstart 5148031e6cSPeter Holmmdconfig -a -t swap -s 2g -u $mdstart || exit 1 5248031e6cSPeter Holmnewfs $newfs_flags md$mdstart > /dev/null 5348031e6cSPeter Holmmount /dev/md$mdstart $mntpoint 5448031e6cSPeter Holmchmod 777 $mntpoint 5548031e6cSPeter Holmset +e 5648031e6cSPeter Holm 5748031e6cSPeter Holmstart=`date '+%s'` 5848031e6cSPeter Holmwhile [ `date '+%s'` -lt $((start + $runtime)) ]; do 5948031e6cSPeter Holm find $nullfs_dstdir -type f -maxdepth 2 -ls > \ 6048031e6cSPeter Holm /dev/null 2>&1 6148031e6cSPeter Holmdone & 6248031e6cSPeter Holm 6348031e6cSPeter Holm(cd ../testcases/swap; ./swap -t ${runtime}s -i 20) & 6448031e6cSPeter Holmstart=`date '+%s'` 6548031e6cSPeter Holmwhile [ `date '+%s'` -lt $((start + $runtime)) ]; do 6648031e6cSPeter Holm mount_nullfs $nullfs_srcdir $nullfs_dstdir 6748031e6cSPeter Holm opt=$([ `jot -r 1 0 1` -eq 0 ] && echo "-f") 6848031e6cSPeter Holm while mount | grep nullfs | grep -q ${nullfs_dstdir}; do 6948031e6cSPeter Holm umount $opt $nullfs_dstdir 7048031e6cSPeter Holm done 7148031e6cSPeter Holmdone > /dev/null 2>&1 7248031e6cSPeter Holmpkill swap 7348031e6cSPeter Holmwait 7448031e6cSPeter Holmn=0 7548031e6cSPeter Holmwhile mount | grep $mntpoint | grep -q /dev/md; do 7648031e6cSPeter Holm umount $mntpoint || sleep 1 7748031e6cSPeter Holm n=$((n + 1)) 7848031e6cSPeter Holm [ $n -gt 30 ] && { echo FAIL; status=2; } 7948031e6cSPeter Holmdone 8048031e6cSPeter Holmmdconfig -d -u $mdstart 8148031e6cSPeter Holmexit 0 82