xref: /freebsd/tools/test/stress2/misc/unionfs14.sh (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
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# Parallel mount and umount test.
3148031e6cSPeter Holm# Copy of unionfs9.sh, with a subdirectory mount point.
3248031e6cSPeter Holm
3348031e6cSPeter Holm[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
3448031e6cSPeter Holm. ../default.cfg
3548031e6cSPeter Holm
3648031e6cSPeter Holmmounts=3	# Number of parallel scripts
3748031e6cSPeter HolmCONT=/tmp/unionfs9.continue
3848031e6cSPeter Holm
3948031e6cSPeter Holmset -e
4048031e6cSPeter Holmmdconfig -a -t swap -s 256m -u $mdstart
4148031e6cSPeter Holmnewfs $newfs_flags -n md$mdstart > /dev/null
4248031e6cSPeter Holmmount /dev/md$mdstart $mntpoint
4348031e6cSPeter Holm
4448031e6cSPeter Holmfor i in `jot $mounts $((mdstart + 2))`; do
4548031e6cSPeter Holm	mdconfig -a -t swap -s 512m -u $((mdstart + i))
4648031e6cSPeter Holm	newfs $newfs_flags -n md$((mdstart + i)) > /dev/null
4748031e6cSPeter Holm	mkdir -p ${mntpoint}$i
4848031e6cSPeter Holm	mount /dev/md$((mdstart + i)) ${mntpoint}$i
4948031e6cSPeter Holm	mkdir -p ${mntpoint}$i/dir
5048031e6cSPeter Holmdone
5148031e6cSPeter Holmset +e
5248031e6cSPeter Holmecho Pre:
5348031e6cSPeter Holmmount | grep mnt
5448031e6cSPeter Holm
5548031e6cSPeter Holm(cd $mntpoint; jot 500 | xargs touch)
5648031e6cSPeter Holm(cd ../testcases/swap; ./swap -t 5m -i 20 > /dev/null) &
5748031e6cSPeter Holm
5848031e6cSPeter Holm# Start the parallel tests
5948031e6cSPeter Holmtouch $CONT
6048031e6cSPeter Holmfor i in `jot $mounts $((mdstart + 2))`; do
6148031e6cSPeter Holm	while [ -f $CONT ]; do
6248031e6cSPeter Holm		find ${mntpoint}$i -type f -maxdepth 2 -ls > \
6348031e6cSPeter Holm		    /dev/null 2>&1
6448031e6cSPeter Holm	done &
6548031e6cSPeter Holm	# The test: Parallel mount and unmounts
6648031e6cSPeter Holm	start=`date +%s`
6748031e6cSPeter Holm	(
6848031e6cSPeter Holm		while [ $((`date +%s` - start))  -lt 300 ]; do
6948031e6cSPeter Holm			mount_unionfs $mntpoint ${mntpoint}$i/dir
7048031e6cSPeter Holm			opt=$([ `jot -r 1 0 1` -eq 0 ] && echo "-f")
7148031e6cSPeter Holm			while mount | grep -q ${mntpoint}$i/dir; do
7248031e6cSPeter Holm				umount $opt ${mntpoint}$i/dir
7348031e6cSPeter Holm			done
7448031e6cSPeter Holm		done > /dev/null 2>&1
7548031e6cSPeter Holm		rm -f $CONT
7648031e6cSPeter Holm	) &
7748031e6cSPeter Holmdone
7848031e6cSPeter Holmwhile [ -f $CONT ] ; do sleep 1; done
7948031e6cSPeter Holmwhile pgrep -q swap; do pkill swap; done
8048031e6cSPeter Holmwait
8148031e6cSPeter Holmecho Post:
8248031e6cSPeter Holmmount | grep mnt
8348031e6cSPeter Holm
8448031e6cSPeter Holmfor i in `jot $mounts $((mdstart + 2))`; do
8548031e6cSPeter Holm	umount ${mntpoint}$i > /dev/null 2>&1
8648031e6cSPeter Holm	mdconfig -d -u $((mdstart + i))
8748031e6cSPeter Holm	rmdir ${mntpoint}$i
8848031e6cSPeter Holmdone
8948031e6cSPeter Holmwhile mount | grep $mntpoint | grep -q /dev/md; do
9048031e6cSPeter Holm	umount $mntpoint || sleep 1
9148031e6cSPeter Holm	[ $((n += 1)) -gt 300 ] && { echo FAIL; exit 1; }
9248031e6cSPeter Holmdone
9348031e6cSPeter Holmmdconfig -d -u $mdstart
9448031e6cSPeter Holmexit 0
95