4 # Copyright (c) 2017 Dell EMC Isilon
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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
29 # Mirror test where the third disk is partially wiped:
30 # Silent Data Corruption.
31 # fsck() will trash your FS in this scenario.
33 [ `id -u ` -ne 0 ] && echo "Must be root!" && exit 1
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
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
54 gmirror label test md$u1 md$u2 md$u3 || exit 1
55 [ "`sysctl -in kern.geom.mirror.launch_mirror_before_timeout`" = "0" ] &&
58 gpart create -s BSD mirror/test
59 gpart add -t freebsd-ufs -s 99m mirror/test
61 [ -c /dev/mirror/testa ] || exit 1
63 newfs -n /dev/mirror/testa > /dev/null
64 mount /dev/mirror/testa $mntpoint
65 jot 10 | xargs -P0 -I% cp /etc/passwd $mntpoint/%
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
70 log=/tmp/graid1_8.sh.log
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
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; } ||
86 mount /dev/mirror/testa $mntpoint
87 [ `ls $mntpoint | wc -l` -lt 10 ] && ls -l $mntpoint
90 while gmirror status test | grep -q SYNCHRONIZING; do sleep 10; done
92 gmirror stop test && break || sleep 30
95 gmirror destroy test 2>/dev/null
96 [ $unload ] && gmirror unload
98 for u in $u1 $u2 $u3; do
99 mdconfig -d -u $u || s=3