9_test.sh revision 324404
1#!/bin/sh
2# $FreeBSD: stable/11/tests/sys/geom/class/mirror/9_test.sh 324404 2017-10-07 23:10:16Z ngie $
3
4# Regression test for r306743.
5
6. `dirname $0`/conf.sh
7
8echo 1..1
9
10ddbs=2048
11m1=`mktemp $base.XXXXXX` || exit 1
12m2=`mktemp $base.XXXXXX` || exit 1
13m3=`mktemp $base.XXXXXX` || exit 1
14
15dd if=/dev/zero of=$m1 bs=$ddbs count=1024 >/dev/null 2>&1
16dd if=/dev/zero of=$m2 bs=$ddbs count=1024 >/dev/null 2>&1
17dd if=/dev/zero of=$m3 bs=$ddbs count=1024 >/dev/null 2>&1
18
19us0=$(attach_md -t vnode -f $m1) || exit 1
20us1=$(attach_md -t vnode -f $m2) || exit 1
21us2=$(attach_md -t vnode -f $m3) || exit 1
22
23gmirror label $name /dev/$us0 /dev/$us1 || exit 1
24devwait
25
26# Break one of the mirrors by forcing a single metadata write error.
27# When dd closes the mirror provider, gmirror will attempt to mark the mirrors
28# clean, and will kick one of the mirrors out upon hitting the error.
29sysctl debug.fail_point.g_mirror_metadata_write='1*return(5)' || exit 1
30dd if=/dev/random of=/dev/mirror/$name bs=$ddbs count=1 >/dev/null 2>&1
31sysctl debug.fail_point.g_mirror_metadata_write='off' || exit 1
32
33# Replace the broken mirror, and then stop the gmirror.
34gmirror forget $name || exit 1
35gmirror insert $name /dev/$us2 || exit 1
36while [ $(gmirror status $name | grep ACTIVE | wc -l) -ne 2 ]; do
37    sleep 1
38done
39gmirror stop $name || exit 1
40
41# Restart the gmirror on the original two mirrors. One of them is broken,
42# so we should end up with a degraded gmirror.
43gmirror activate $name /dev/$us0 /dev/$us1 || exit 1
44devwait
45dd if=/dev/random of=/dev/mirror/$name bs=$ddbs count=1 >/dev/null 2>&1
46
47# Re-add the replacement mirror and verify the two mirrors are synchronized.
48# Destroy the gmirror first so that the mirror metadata is wiped; otherwise
49# the metadata blocks will fail the comparison. It would be nice to do this
50# with a "gmirror verify" command instead.
51gmirror activate $name /dev/$us2 || exit 1
52while [ $(gmirror status $name | grep ACTIVE | wc -l) -ne 2 ]; do
53    sleep 1
54done
55gmirror destroy $name || exit 1
56if cmp -s $m1 $m3; then
57    echo "ok 1"
58else
59    echo "not ok 1"
60fi
61
62rm -f $m1 $m2 $m3
63