xref: /freebsd/tests/sys/geom/class/mirror/10_test.sh (revision 95eb4b873b6a8b527c5bd78d7191975dfca38998)
1#!/bin/sh
2
3# Test handling of read errors.
4
5. $(dirname $0)/conf.sh
6
7echo 1..3
8
9set -e
10
11ddbs=2048
12regreadfp="debug.fail_point.g_mirror_regular_request_read"
13m1=$(mktemp $base.XXXXXX)
14m2=$(mktemp $base.XXXXXX)
15
16dd if=/dev/random of=$m1 bs=$ddbs count=1024 >/dev/null 2>&1
17dd if=/dev/zero of=$m2 bs=$ddbs count=1024 >/dev/null 2>&1
18
19attach_md us0 -t vnode -f $m1
20attach_md us1 -t vnode -f $m2
21
22gmirror label $name /dev/$us0
23gmirror insert $name /dev/$us1
24devwait
25syncwait
26
27tmp1=$(mktemp $base.XXXXXX)
28tmp2=$(mktemp $base.XXXXXX)
29
30EIO=5
31# gmirror should retry a failed read from the other mirror.
32sysctl ${regreadfp}="1*return(${EIO})[pid $(gmirror_worker_pid)]"
33dd if=/dev/mirror/$name of=$tmp1 iseek=256 bs=$ddbs count=1 >/dev/null 2>&1
34dd if=/dev/$us1 of=$tmp2 iseek=256 bs=$ddbs count=1 >/dev/null 2>&1
35sysctl ${regreadfp}='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	attach_md us1 -t vnode -f $m2
56else
57	detach_md $us0
58	attach_md us0 -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