xref: /freebsd/tools/test/stress2/misc/parallelmount2.sh (revision 8b959dd6a3921c35395bef4a6d7ad2426a3bd88e)
1#!/bin/sh
2
3#
4# Copyright (c) 2016 Dell EMC
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28
29# Quota version of parallelmount.sh
30# "umount busy seen:
31# https://people.freebsd.org/~pho/stress/log/parallelmount2.txt
32
33[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
34[ -z "$DEBUG" ] && exit 0 # Waiting for fix
35[ "`sysctl -in kern.features.ufs_quota`" != "1" ] && exit 0
36
37. ../default.cfg
38
39parallel=40
40
41if [ $# -eq 0 ]; then
42	[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart
43	mdconfig -a -t swap -s 10m -u $mdstart || exit 1
44	bsdlabel -w md$mdstart auto
45	newfs $newfs_flags md${mdstart}$part > /dev/null
46	export PATH_FSTAB=/var/tmp/fstab.$$
47	echo "/dev/md${mdstart}$part $mntpoint ufs rw,userquota 2 2" > $PATH_FSTAB
48	mount /dev/md${mdstart}$part $mntpoint
49	set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'`
50	export QK=$(($1 / 10 * 8))
51	export QI=$(($2 / 10 * 8))
52	edquota -u -f $mntpoint -e $mntpoint:$((QK - 50)):$QK:$((QI - 50 )):$QI $testuser
53	quotaon $mntpoint
54	umount $mntpoint
55
56	# start the parallel tests
57	for i in `jot $parallel`; do
58		./$0 $i &
59	done
60
61	while kill -0 $! 2> /dev/null; do
62		for i in `jot 100`; do
63			find $mntpoint > /dev/null 2>&1
64		done
65	done
66	wait
67	rm -f $PATH_FSTAB
68
69        for i in `jot 6`; do
70		mount | grep -q "on $mntpoint " || break
71                umount $mntpoint && break || sleep 10
72        done
73        [ $i -eq 6 ] && exit 1
74	mdconfig -d -u $mdstart
75	exit 0
76else
77	start=`date '+%s'`
78	while [ $((`date '+%s'` - start)) -lt 600 ]; do
79		mount /dev/md${mdstart}$part $mntpoint
80		quotaon $mntpoint
81		umount $mntpoint
82		mount
83	done > /dev/null 2>&1
84fi
85