xref: /freebsd/tests/sys/geom/class/mirror/12_test.sh (revision 43a5ec4eb41567cc92586503212743d89686d78f)
1#!/bin/sh
2# $FreeBSD$
3
4# Test handling of write errors.
5
6. $(dirname $0)/conf.sh
7
8echo 1..3
9
10set -e
11
12ddbs=2048
13regwritefp="debug.fail_point.g_mirror_regular_request_write"
14m1=$(mktemp $base.XXXXXX)
15m2=$(mktemp $base.XXXXXX)
16
17dd if=/dev/zero of=$m1 bs=$ddbs count=1024 >/dev/null 2>&1
18dd if=/dev/zero of=$m2 bs=$ddbs count=1024 >/dev/null 2>&1
19
20us0=$(attach_md -t vnode -f $m1)
21us1=$(attach_md -t vnode -f $m2)
22
23gmirror label $name /dev/$us0 /dev/$us1
24devwait
25
26tmp1=$(mktemp $base.XXXXXX)
27tmp2=$(mktemp $base.XXXXXX)
28dd if=/dev/random of=$tmp1 bs=$ddbs count=1 >/dev/null 2>&1
29
30EIO=5
31# gmirror should kick one of the mirrors out after hitting EIO.
32sysctl ${regwritefp}="1*return(${EIO})[pid $(gmirror_worker_pid)]"
33dd if=$tmp1 of=/dev/mirror/$name bs=$ddbs count=1 >/dev/null 2>&1
34dd if=/dev/mirror/$name of=$tmp2 bs=$ddbs count=1 >/dev/null 2>&1
35sysctl ${regwritefp}='off'
36
37if cmp -s $tmp1 $tmp2; then
38	echo "ok 1"
39else
40	echo "not ok 1"
41fi
42
43# Make sure that one of the mirrors was marked broken.
44genid1=$(gmirror dump /dev/$us0 | awk '/^[[:space:]]*genid: /{print $2}')
45genid2=$(gmirror dump /dev/$us1 | awk '/^[[:space:]]*genid: /{print $2}')
46if [ $genid1 -eq $(($genid2 + 1)) -o $genid2 -eq $(($genid1 + 1)) ]; then
47	echo "ok 2"
48else
49	echo "not ok 2"
50fi
51
52# Force a retaste of the disconnected component.
53if [ $(gmirror status -s $name | awk '{print $3}') = $us0 ]; then
54	detach_md $us1
55	us1=$(attach_md -t vnode -f $m2)
56else
57	detach_md $us0
58	us0=$(attach_md -t vnode -f $m1)
59fi
60
61# Make sure that the component wasn't re-added to the gmirror.
62if [ $(gmirror status -s $name | wc -l) -eq 1 ]; then
63	echo "ok 3"
64else
65	echo "not ok 3"
66fi
67
68rm -f $m1 $m2 $tmp1 $tmp2
69