]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/test/stress2/misc/graid1_8.sh
contrib/bc: update to version 5.1.1
[FreeBSD/FreeBSD.git] / tools / test / stress2 / misc / graid1_8.sh
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 # Mirror test where the third disk is partially wiped:
30 # Silent Data Corruption.
31 # fsck() will trash your FS in this scenario.
32
33 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
34
35 . ../default.cfg
36
37 gmirror load > /dev/null 2>&1 && unload=1
38 mount | grep -q "on $mntpoint " && umount $mntpoint
39 [ -c /dev/mirror/test ] && { gmirror stop test; gmirror destroy test; }
40 old=`sysctl -n kern.geom.mirror.debug`
41 sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 ||
42         sysctl kern.geom.mirror.debug=$old > /dev/null
43
44 u1=$mdstart
45 u2=$((mdstart + 1))
46 u3=$((mdstart + 2))
47
48 for u in $u1 $u2 $u3; do
49         [ -c /dev/md$u ] && mdconfig -d -u $u
50         dd if=/dev/zero of=$diskimage.$u bs=1m count=100 status=none
51         mdconfig -a -t vnode -f $diskimage.$u -u $u
52 done > /dev/null
53
54 gmirror label test md$u1 md$u2 md$u3 || exit 1
55 [ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] &&
56     sleep 5
57 (
58 gpart create -s BSD mirror/test
59 gpart add -t freebsd-ufs -s 99m mirror/test
60 ) > /dev/null
61 [ -c /dev/mirror/testa ] || exit 1
62
63 newfs -n /dev/mirror/testa > /dev/null
64 mount /dev/mirror/testa $mntpoint
65 jot 10 | xargs -P0 -I% cp /etc/passwd $mntpoint/%
66
67 # The test: zap part of the third disk
68 dd if=/dev/random of=$diskimage.$u3 bs=1m count=80 conv=notrunc status=none
69 umount $mntpoint
70 log=/tmp/graid1_8.sh.log
71
72 if [ $# -eq 1 ]; then # This will fix the mirror
73         gmirror remove test md$u3
74         gmirror insert test md$u3
75         while gmirror status test | grep -q SYNCHRONIZING; do
76                 sleep 2
77         done
78 fi
79
80 fsck -fy /dev/mirror/testa > $log 2>&1
81 grep -q RERUN $log && fsck -fy /dev/mirror/testa > /dev/null 2>&1
82 grep -Eq "MODIFIED|BAD" $log &&
83     { s=1; head -5 $log; } ||
84     s=0
85 rm $log
86 mount /dev/mirror/testa $mntpoint
87 [ `ls $mntpoint | wc -l` -lt 10 ] && ls -l $mntpoint
88 umount $mntpoint
89
90 while gmirror status test | grep -q SYNCHRONIZING; do sleep 10; done
91 for i in `jot 10`; do
92         gmirror stop test && break || sleep 30
93 done
94 [ $i -eq 10 ] && s=1
95 gmirror destroy test 2>/dev/null
96 [ $unload ] && gmirror unload
97
98 for u in $u1 $u2 $u3; do
99         mdconfig -d -u $u || s=3
100         rm $diskimage.$u
101 done
102 exit $s