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