xref: /freebsd/tools/test/stress2/misc/graid1_9.sh (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1#!/bin/sh
2
3#
4# Copyright (c) 2018 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 graid1.sh with fail points added.
30# https://people.freebsd.org/~pho/stress/log/mark015.txt
31# Fixed by r327779
32
33# Problem also seen with non SU:
34# https://people.freebsd.org/~pho/stress/log/numa027.txt
35
36[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
37
38. ../default.cfg
39
40md1=$mdstart
41md2=$((mdstart + 1))
42md3=$((mdstart + 2))
43
44s=0
45size=1g
46[ $((`sysctl -n hw.usermem` / 1024 / 1024 / 1024)) -le 4 ] &&
47    size=512m
48
49for u in $md1 $md2 $md3; do
50	mdconfig -l | grep -q md$u && mdconfig -d -u $u
51	mdconfig -a -t swap -s $size -u $u
52done
53
54gmirror load > /dev/null 2>&1 && unload=1
55old=`sysctl -n kern.geom.mirror.debug`
56sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 ||
57    sysctl kern.geom.mirror.debug=$old > /dev/null
58gmirror label -v -b split -s 2048 test /dev/md$md1 /dev/md$md2 \
59    /dev/md$md3 > /dev/null || exit 1
60[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] &&
61    sleep $((`sysctl -n kern.geom.mirror.timeout` + 1))
62[ -c /dev/mirror/test ] || exit 1
63# Do not use SU as it is more intolerant to FS corruption
64newfs /dev/mirror/test > /dev/null
65mount /dev/mirror/test $mntpoint
66chmod 777 $mntpoint
67
68export runRUNTIME=10m
69export RUNDIR=$mntpoint/stressX
70
71woid=debug.fail_point.g_mirror_regular_request_write
72roid=debug.fail_point.g_mirror_regular_request_read
73gpid=`pgrep -fS "g_mirror test"`
74sysctl $woid="0.0005%return(5)[pid $gpid]" > /dev/null
75sysctl $roid="0.0005%return(5)[pid $gpid]" > /dev/null
76
77su $testuser -c 'cd ..; ./run.sh marcus.cfg' > /dev/null &
78
79while kill -0 $! 2>/dev/null; do
80	if gmirror status test | grep -q DEGRADED; then
81		for i in $md1 $md2 $md3; do
82			if ! gmirror status test | grep -q md$i; then
83				gmirror forget test md$i 2>/dev/null
84				gmirror remove test md$i 2>/dev/null
85				gmirror insert test md$i
86			fi
87		done
88	else
89		sleep 5
90	fi
91done
92wait
93
94sysctl $woid=off > /dev/null
95sysctl $roid=off > /dev/null
96
97for i in `jot 12`; do
98	gmirror status test | grep -q SYNCHRONIZING || break
99	sleep 10
100done
101gmirror status test | grep -q SYNCHRONIZING &&
102    { s=1; gmirror status test; }
103while mount | grep $mntpoint | grep -q /mirror/; do
104	umount $mntpoint || sleep 1
105done
106# The FS is most likely corrupted at this point, so do not run fsck(8).
107gmirror stop test || s=2
108gmirror destroy test 2>/dev/null
109[ $unload ] && gmirror unload
110
111for u in $md3 $md2 $md1; do
112	mdconfig -d -u $u || s=3
113done
114exit $s
115