xref: /freebsd/tools/test/stress2/misc/crossmp11.sh (revision c1d255d3)
1#!/bin/sh
2
3#
4# Copyright (c) 2017 Dell EMC Isilon
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# Copy of crossmp3.sh + elements from dfull.sh
30
31# Live lock seen:
32# https://people.freebsd.org/~pho/stress/log/crossmp11.txt
33
34# umount stuck in mnt_ref seen:
35# https://people.freebsd.org/~pho/stress/log/kostik1002.txt
36
37# Fixed by r319518, r319519 and r319539.
38
39[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
40
41. ../default.cfg
42
43g3=$((3 * 1024 * 1024 * 1024))
44CONT=/tmp/crossmp11.continue
45N=`sysctl -n hw.ncpu`
46[ $N -gt 4 ] && N=4
47usermem=`sysctl -n hw.usermem`
48[ $usermem -gt $g3 ] && usermem=$g3
49[ `sysctl -n vm.swap_total` -eq 0 ] && usermem=$((usermem/100*80))
50size=$((usermem / 1024 / 1024 / N))
51
52mounts=$N		# Number of parallel scripts
53
54if [ $# -eq 0 ]; then
55	echo "Expect:
56    /mnt6: write failed, filesystem is full
57    /mnt6: create/symlink failed, no inodes free"
58
59	for i in `jot $mounts`; do
60		m=$(( i + mdstart - 1 ))
61		[ ! -d ${mntpoint}$m ] &&
62		    { mkdir ${mntpoint}$m;  chmod 755 ${mntpoint}$m; }
63		mount | grep "${mntpoint}$m " | grep -q md$m && umount ${mntpoint}$m
64		mdconfig -l | grep -q md$m && mdconfig -d -u $m
65
66		mdconfig -a -t swap -s ${size}m -u $m
67		bsdlabel -w md$m auto
68		newfs $newfs_flags md${m}$part > /dev/null 2>&1
69	done
70
71	# start the parallel tests
72	touch $CONT
73	for i in `jot $mounts`; do
74		m=$(( i + mdstart - 1 ))
75		./$0 $m &
76		./$0 find &
77	done
78
79	wait
80
81	for i in `jot $mounts`; do
82		m=$(( i + mdstart - 1 ))
83		while mount | grep -q "on ${mntpoint}$m "; do
84		    umount ${mntpoint}$m && break
85		    sleep 1
86		done
87		mdconfig -d -u $m
88	done
89	exit 0
90else
91	if [ $1 = find ]; then
92		while [ -f $CONT ]; do
93			find ${mntpoint}* -type f > /dev/null 2>&1
94		done
95	else
96		m=$1
97		export runRUNTIME=20s
98		# The test: Parallel mount and unmounts
99		for i in `jot 3`; do
100			mount /dev/md${m}$part ${mntpoint}$m &&
101			   chmod 777 ${mntpoint}$m
102			export RUNDIR=${mntpoint}$m/stressX
103			export CTRLDIR=${mntpoint}$m/stressX.control
104			(cd ${mntpoint}$m && find . -delete)
105			if [ -z "$KBLOCKS" ]; then
106				r=`df -ik ${mntpoint}$m | tail -1 | awk '{print $4,$7}'`
107				export KBLOCKS=`echo $r | awk '{print $1 * 10}'`
108				export INODES=`echo  $r | awk '{print $2 * 10}'`
109			fi
110			su $testuser -c 'cd ..; ./run.sh disk.cfg' > \
111			    /dev/null 2>&1
112
113			while mount | grep -q "on ${mntpoint}$m "; do
114				opt=$([ $((`date '+%s'` % 2)) -eq 0 ] && echo "-f")
115				umount $opt ${mntpoint}$m > /dev/null 2>&1
116				[ -f $CONT ] || break 2
117			done
118		done
119		rm -f $CONT
120	fi
121fi
122