xref: /freebsd/tools/test/stress2/misc/graid1_8.sh (revision 43a5ec4eb41567cc92586503212743d89686d78f)
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
37gmirror load > /dev/null 2>&1 && unload=1
38mount | grep -q "on $mntpoint " && umount $mntpoint
39[ -c /dev/mirror/test ] && { gmirror stop test; gmirror destroy test; }
40old=`sysctl -n kern.geom.mirror.debug`
41sysctl kern.geom.mirror.debug=-1 | grep -q -- -1 ||
42	sysctl kern.geom.mirror.debug=$old > /dev/null
43
44u1=$mdstart
45u2=$((mdstart + 1))
46u3=$((mdstart + 2))
47
48for 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
52done > /dev/null
53
54gmirror 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(
58gpart create -s BSD mirror/test
59gpart add -t freebsd-ufs -s 99m mirror/test
60) > /dev/null
61[ -c /dev/mirror/testa ] || exit 1
62
63newfs -n /dev/mirror/testa > /dev/null
64mount /dev/mirror/testa $mntpoint
65jot 10 | xargs -P0 -I% cp /etc/passwd $mntpoint/%
66
67# The test: zap part of the third disk
68dd if=/dev/random of=$diskimage.$u3 bs=1m count=80 conv=notrunc status=none
69umount $mntpoint
70log=/tmp/graid1_8.sh.log
71
72if [ $# -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
78fi
79
80fsck -fy /dev/mirror/testa > $log 2>&1
81grep -q RERUN $log && fsck -fy /dev/mirror/testa > /dev/null 2>&1
82grep -Eq "MODIFIED|BAD" $log &&
83    { s=1; head -5 $log; } ||
84    s=0
85rm $log
86mount /dev/mirror/testa $mntpoint
87[ `ls $mntpoint | wc -l` -lt 10 ] && ls -l $mntpoint
88umount $mntpoint
89
90while gmirror status test | grep -q SYNCHRONIZING; do sleep 10; done
91for i in `jot 10`; do
92	gmirror stop test && break || sleep 30
93done
94[ $i -eq 10 ] && s=1
95gmirror destroy test 2>/dev/null
96[ $unload ] && gmirror unload
97
98for u in $u1 $u2 $u3; do
99	mdconfig -d -u $u || s=3
100	rm $diskimage.$u
101done
102exit $s
103