xref: /freebsd/tools/test/stress2/misc/graid1_6.sh (revision fd45b686f9d92f583366c75b22c04c7ee49709c0)
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# Variation of graid1_4.sh
30
31[ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
32
33. ../default.cfg
34
35rm -f $diskimage*
36need=1024 # MB
37[ `df -k $(dirname $diskimage) | tail -1 | awk '{print int($4 / 1024)}'` -lt \
38    $need ] && printf "Need %d MB on %s.\n" $need `dirname $diskimage` && exit
39
40gmirror load > /dev/null 2>&1 && unload=1
41[ -c /dev/mirror/test ] && { gmirror stop test; gmirror destroy test; }
42old=`sysctl -n kern.geom.mirror.debug`
43sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 ||
44    sysctl kern.geom.mirror.debug=$old > /dev/null
45
46md1=$mdstart
47md2=$((mdstart + 1))
48
49s=0
50for u in $md1 $md2; do
51	disk="$diskimage.$u"
52	dd if=/dev/zero of=$disk bs=1m count=512 status=none
53	[ -c /dev/md$u ] && mdconfig -d -u $u
54	mdconfig -a -t vnode -f $disk -u $u
55done
56
57gmirror label -v -b split -s 2048 test /dev/md$md1 /dev/md$md2 \
58    > /dev/null || exit 1
59[ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] &&
60    sleep $((`sysctl -n kern.geom.mirror.timeout` + 1))
61[ -c /dev/mirror/test ] || exit 1
62newfs $newfs_flags /dev/mirror/test > /dev/null
63mount /dev/mirror/test $mntpoint
64chmod 777 $mntpoint
65
66mlog=/tmp/graid1_6.log
67tail -F -n 0 /var/log/messages > $mlog & mpid=$!
68export runRUNTIME=4m
69export RUNDIR=$mntpoint/stressX
70su $testuser -c 'cd ..; ./run.sh marcus.cfg > /dev/null' &
71
72while kill -0 $! > /dev/null 2>&1; do
73	sleep `jot -r 1 1 5`
74	gmirror remove test md$md2
75	sleep `jot -r 1 1 5`
76	gmirror insert test md$md2
77done
78wait $!
79i=0
80while ! gmirror status test | grep -q COMPLETE; do
81	sleep 10
82	if [ $((i += 1)) -gt 20 ]; then
83		echo "FAIL to COMPLETE"
84		graid status test
85		s=1
86		break
87	fi
88done
89
90while mount | grep $mntpoint | grep -q /mirror/; do
91	umount $mntpoint || sleep 1
92done
93checkfs /dev/mirror/test || s=2
94gmirror stop -f test ||s=3
95gmirror destroy test 2>/dev/null
96[ $unload ] && gmirror unload
97
98for u in $md2 $md1; do
99	mdconfig -d -u $u || s=4
100done
101rm -f $diskimage*
102grep -m 1 "check-hash" $mlog && s=5
103kill $mpid
104wait
105rm -f $mlog
106exit $s
107