xref: /freebsd/tools/test/stress2/misc/crossmp3.sh (revision 10ff414c)
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		bsdlabel -w md$m auto
61		newfs $newfs_flags md${m}$part > /dev/null 2>&1
62	done
63
64	# start the parallel tests
65	touch $CONT
66	for i in `jot $mounts`; do
67		m=$(( i + mdstart - 1 ))
68		./$0 $m &
69		./$0 find &
70	done
71	wait
72
73	for i in `jot $mounts`; do
74		m=$(( i + mdstart - 1 ))
75		while mount | grep -q "on ${mntpoint}$m "; do
76		    umount ${mntpoint}$m && break
77		    sleep 1
78		done
79		mdconfig -d -u $m
80	done
81	exit 0
82else
83	if [ $1 = find ]; then
84		while [ -f $CONT ]; do
85			find ${mntpoint}* -type f > /dev/null 2>&1
86		done
87	else
88		export runRUNTIME=20s
89		# The test: Parallel mount and unmounts
90		for i in `jot 3`; do
91			m=$1
92			mount /dev/md${m}$part ${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		done
106		rm -f $CONT
107	fi
108fi
109