xref: /freebsd/tools/test/stress2/misc/crossmp3.sh (revision 02e9120893770924227138ba49df1edb3896112a)
1#!/bin/sh
2
3#
4# Copyright (c) 2014 EMC Corp.
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# Parallel mount and umount of file systems
30# "panic: Bad link elm 0xfffff8052a20cc00 prev->next != elm" seen:
31# http://people.freebsd.org/~pho/stress/log/crossmp3.txt
32# Fixed in r269853
33
34# panic: softdep_waitidle: work added after flush:
35# http://people.freebsd.org/~pho/stress/log/crossmp3-2.txt, fixed by r273967.
36
37[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
38
39. ../default.cfg
40
41CONT=/tmp/crossmp3.continue
42if [ $# -eq 0 ]; then
43	N=`sysctl -n hw.ncpu`
44	usermem=`sysctl -n hw.usermem`
45	[ `sysctl -n vm.swap_total` -eq 0 ] && usermem=$((usermem / 2))
46	size=$((usermem / 1024 / 1024 / N))
47	echo "Using $N memory disks of size $size MB."
48
49	mounts=$N		# Number of parallel scripts
50
51	for i in `jot $mounts`; do
52		m=$(( i + mdstart - 1 ))
53		[ ! -d ${mntpoint}$m ] &&
54		    { mkdir ${mntpoint}$m; chmod 755 ${mntpoint}$m; }
55		mount | grep "${mntpoint}$m " | grep -q md$m &&
56		    umount ${mntpoint}$m
57		mdconfig -l | grep -q md$m && mdconfig -d -u $m
58
59		mdconfig -a -t swap -s ${size}m -u $m
60		newfs $newfs_flags md${m} > /dev/null 2>&1
61	done
62
63	# start the parallel tests
64	touch $CONT
65	for i in `jot $mounts`; do
66		m=$(( i + mdstart - 1 ))
67		./$0 $m &
68		./$0 find &
69	done
70	wait
71
72	for i in `jot $mounts`; do
73		m=$(( i + mdstart - 1 ))
74		while mount | grep -q "on ${mntpoint}$m "; do
75		    umount ${mntpoint}$m && break
76		    sleep 1
77		done
78		mdconfig -d -u $m
79	done
80	exit 0
81else
82	if [ $1 = find ]; then
83		while [ -f $CONT ]; do
84			find ${mntpoint}* -type f > /dev/null 2>&1
85		done
86	else
87		export runRUNTIME=20s
88		# The test: Parallel mount and unmounts
89		start=`date +%s`
90		for i in `jot 3`; do
91			m=$1
92			mount /dev/md${m} ${mntpoint}$m &&
93			   chmod 777 ${mntpoint}$m
94			export RUNDIR=${mntpoint}$m/stressX
95			export CTRLDIR=${mntpoint}$m/stressX.control
96			(cd ${mntpoint}$m && find . -delete)
97			su $testuser -c 'cd ..; ./run.sh disk.cfg' > \
98			    /dev/null 2>&1
99
100			while mount | grep -q "on ${mntpoint}$m "; do
101				opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f")
102				umount $opt ${mntpoint}$m > /dev/null 2>&1
103				[ -f $CONT ] || break 2
104			done
105			[ $((`date +%s` - start)) -gt 600 ] &&
106			    { echo "Timed out"; s=1; }
107		done
108		rm -f $CONT
109	fi
110	exit $s
111fi
112