xref: /freebsd/tests/sys/geom/class/mirror/11_test.sh (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
1#!/bin/sh
2
3# Test handling of read errors.
4
5. $(dirname $0)/conf.sh
6
7echo 1..4
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
30ENXIO=6
31# gmirror has special handling for ENXIO. It does not mark the failed component
32# as broken, allowing it to rejoin the mirror automatically when it appears.
33sysctl ${regreadfp}="1*return(${ENXIO})[pid $(gmirror_worker_pid)]"
34dd if=/dev/mirror/$name of=$tmp1 iseek=512 bs=$ddbs count=1 >/dev/null 2>&1
35dd if=/dev/$us1 of=$tmp2 iseek=512 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# Verify that the genids still match after ENXIO.
45genid1=$(gmirror dump /dev/$us0 | awk '/^[[:space:]]*genid: /{print $2}')
46genid2=$(gmirror dump /dev/$us1 | awk '/^[[:space:]]*genid: /{print $2}')
47if [ $genid1 -eq $genid2 ]; then
48	echo "ok 2"
49else
50	echo "not ok 2"
51fi
52
53# Trigger a syncid bump.
54dd if=/dev/zero of=/dev/mirror/$name bs=$ddbs count=1 >/dev/null 2>&1
55
56# The ENXIO+write should have caused a syncid bump.
57syncid1=$(gmirror dump /dev/$us0 | awk '/^[[:space:]]*syncid: /{print $2}')
58syncid2=$(gmirror dump /dev/$us1 | awk '/^[[:space:]]*syncid: /{print $2}')
59if [ $syncid1 -eq $(($syncid2 + 1)) -o $syncid2 -eq $(($syncid1 + 1)) ]; then
60	echo "ok 3"
61else
62	echo "not ok 3"
63fi
64
65# Force a retaste of the disconnected component.
66if [ $(gmirror status -s $name | awk '{print $3}') = $us0 ]; then
67	detach_md $us1
68	attach_md us1 -t vnode -f $m2
69else
70	detach_md $us0
71	attach_md us0 -t vnode -f $m1
72fi
73
74# Make sure that the retaste caused the mirror to automatically be re-added.
75if [ $(gmirror status -s $name | wc -l) -eq 2 ]; then
76	echo "ok 4"
77else
78	echo "not ok 4"
79fi
80
81syncwait
82
83rm -f $m1 $m2 $tmp1 $tmp2
84