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	newfs $newfs_flags md$mdstart > /dev/null
45	export PATH_FSTAB=/var/tmp/fstab.$$
46	echo "/dev/md$mdstart $mntpoint ufs rw,userquota 2 2" > $PATH_FSTAB
47	mount /dev/md$mdstart $mntpoint
48	set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'`
49	export QK=$(($1 / 10 * 8))
50	export QI=$(($2 / 10 * 8))
51	edquota -u -f $mntpoint -e $mntpoint:$((QK - 50)):$QK:$((QI - 50 )):$QI $testuser
52	quotaon $mntpoint
53	umount $mntpoint
54
55	# start the parallel tests
56	for i in `jot $parallel`; do
57		./$0 $i &
58	done
59
60	while kill -0 $! 2> /dev/null; do
61		for i in `jot 100`; do
62			find $mntpoint > /dev/null 2>&1
63		done
64	done
65	wait
66	rm -f $PATH_FSTAB
67
68        for i in `jot 6`; do
69		mount | grep -q "on $mntpoint " || break
70                umount $mntpoint && break || sleep 10
71        done
72        [ $i -eq 6 ] && exit 1
73	mdconfig -d -u $mdstart
74	exit 0
75else
76	start=`date '+%s'`
77	while [ $((`date '+%s'` - start)) -lt 600 ]; do
78		mount /dev/md$mdstart $mntpoint
79		quotaon $mntpoint
80		umount $mntpoint
81		mount
82	done > /dev/null 2>&1
83fi
84