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