xref: /freebsd/tests/sys/geom/class/mirror/9_test.sh (revision 10ff414c)
1#!/bin/sh
2# $FreeBSD$
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)[pid $(gmirror_worker_pid)]" || 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
36syncwait
37gmirror stop $name || exit 1
38
39# Restart the gmirror on the original two mirrors. One of them is broken,
40# so we should end up with a degraded gmirror.
41gmirror activate $name /dev/$us0 /dev/$us1 || exit 1
42devwait
43dd if=/dev/random of=/dev/mirror/$name bs=$ddbs count=1 >/dev/null 2>&1
44
45# Re-add the replacement mirror and verify the two mirrors are synchronized.
46# Destroy the gmirror first so that the mirror metadata is wiped; otherwise
47# the metadata blocks will fail the comparison. It would be nice to do this
48# with a "gmirror verify" command instead.
49gmirror activate $name /dev/$us2 || exit 1
50syncwait
51gmirror destroy $name || exit 1
52if cmp -s $m1 $m3; then
53	echo "ok 1"
54else
55	echo "not ok 1"
56fi
57
58rm -f $m1 $m2 $m3
59