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