xref: /freebsd/tools/test/stress2/misc/gnop10.sh (revision e32fecd0c2c3ee37c47ee100f169e7eb0282a873)
1#!/bin/sh
2
3#
4# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5#
6# Copyright (c) 2021 Peter Holm <pho@FreeBSD.org>
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27# SUCH DAMAGE.
28#
29
30# fsck test with forced unmount of a SU FS.
31# Variation of gnop8.sh by Kirk McKusick <mckusick@mckusick.com>
32
33# Copy of gnop9.sh. Uses SU instead of SUJ.
34
35# https://people.freebsd.org/~pho/stress/log/log0269.txt
36# https://people.freebsd.org/~pho/stress/log/log0370.txt
37# https://people.freebsd.org/~pho/stress/log/log0396.txt
38
39[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
40. ../default.cfg
41
42# Check for lingering threads from the last run
43pgrep -x mount && { pgrep -x mount | xargs ps -lp; exit 1; }
44../tools/killall.sh || exit 1
45
46fsck=/sbin/fsck_ffs
47fsck_loops=10
48log=/tmp/gnop10.log
49[ -c /dev/md$mdstart ] && mdconfig -d -u $mdstart
50mdconfig -a -t swap -s 5g -u $mdstart || exit 1
51md=md$mdstart
52newfs -U /dev/$md > /dev/null 2>&1 || exit 1
53
54export LOAD=80
55export rwLOAD=80
56export runRUNTIME=10m
57export RUNDIR=$mntpoint/stressX
58export CTRLDIR=$mntpoint/stressX.control
59export MAXSWAPPCT=80
60export TESTPROGS='
61testcases/lockf2/lockf2
62testcases/symlink/symlink
63testcases/openat/openat
64testcases/socket/socket
65testcases/rw/rw
66testcases/fts/fts
67testcases/link/link
68testcases/lockf/lockf
69testcases/creat/creat
70testcases/mkdir/mkdir
71testcases/rename/rename
72testcases/mkfifo/mkfifo
73testcases/dirnprename/dirnprename
74testcases/dirrename/dirrename
75'
76
77start=`date +%s`
78while [ $((`date +%s` - start)) -lt 600 ]; do
79	gnop create /dev/$md || exit 1
80	mount /dev/$md.nop $mntpoint || exit 1
81
82	rm -rf $RUNDIR $CTRLDIR
83	mkdir -p $RUNDIR $CTRLDIR
84	chmod 777 $RUNDIR $CTRLDIR
85	set `df -ik $mntpoint | tail -1 | awk '{print $4,$7}'`
86	export KBLOCKS=$(($1 / 10 * 7))
87	export INODES=$(($2 / 10 * 7))
88
89	# start your favorite I/O test here
90
91	su $testuser -c 'cd ..; ./testcases/run/run $TESTPROGS' > /dev/null 2>&1 &
92
93	# after some number of seconds
94	sleep `jot -r 1 20 30`
95	gnop destroy -f /dev/$md.nop
96	../tools/killall.sh || exit 1
97	while pgrep -qU $testuser; do pkill -U $testuser; done
98	wait
99
100	# Wait until forcible unmount, may be up to about 30 seconds,
101	# but typically very quick if I/O is in progress
102	s=`date +%s`
103	n=0
104	while mount | grep -q "on $mntpoint "; do
105		[ $n -eq 0 ] && /bin/echo -n "Waiting for $mntpoint to force umount ..."
106		n=$((n + 1))
107		sleep 5
108		if [ $((`date +%s` - s)) -ge 180 ]; then
109			echo "Giving up on waiting for umount of $mntpoint"
110			umount $mntpoint
111			while mount | grep -q "on $mntpoint "; do
112			    umount -f $mntpoint
113			done
114		fi
115	done
116	[ $n -ne 0 ] && echo
117
118	# The initial fsck_ffs may run for more than on hour with a 5GB MD disk
119	t=`date +%s`
120	$fsck -fy /dev/$md > /dev/null 2>&1
121	t=$((`date +%s`- t))
122	[ $t -gt 300 ] && echo "First fsck took $(((t + 30) / 60)) minutes!"
123
124	for i in `jot $fsck_loops`; do
125		sleep 10
126		$fsck -fy /dev/$md > $log 2>&1
127		# For now, do not trust fsck_ffs's "CLEAN" message
128#		grep -Eq "IS CLEAN|MARKED CLEAN" $log && break
129		grep -Eq "FILE SYSTEM WAS MODIFIED" $log || break
130		[ $i -eq $fsck_loops ] &&
131		    { echo "$fsck did not mark FS as clean"; tail -12 $log; exit 1; }
132	done
133done
134$fsck -fy /dev/$md > $log || { tail -5 $log; exit 1; }
135mdconfig -d -u ${md#md}
136rm -f $log
137exit 0
138