xref: /freebsd/tests/sys/geom/class/mirror/13_test.sh (revision 81ad6265)
1#!/bin/sh
2# $FreeBSD$
3
4# Test handling of write errors.
5
6. $(dirname $0)/conf.sh
7
8echo 1..4
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/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 /dev/$us1
24devwait
25
26tmp1=$(mktemp $base.XXXXXX)
27tmp2=$(mktemp $base.XXXXXX)
28
29dd if=/dev/random of=$tmp1 bs=$ddbs count=1 >/dev/null 2>&1
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 ${regwritefp}="1*return(${ENXIO})[pid $(gmirror_worker_pid)]"
35dd if=$tmp1 of=/dev/mirror/$name bs=$ddbs count=1 >/dev/null 2>&1
36dd if=/dev/mirror/$name of=$tmp2 bs=$ddbs count=1 >/dev/null 2>&1
37sysctl ${regwritefp}='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# The ENXIO should have caused a syncid bump.
55syncid1=$(gmirror dump /dev/$us0 | awk '/^[[:space:]]*syncid: /{print $2}')
56syncid2=$(gmirror dump /dev/$us1 | awk '/^[[:space:]]*syncid: /{print $2}')
57if [ $syncid1 -eq $(($syncid2 + 1)) -o $syncid2 -eq $(($syncid1 + 1)) ]; then
58	echo "ok 3"
59else
60	echo "not ok 3"
61fi
62
63# Force a retaste of the disconnected component.
64if [ $(gmirror status -s $name | awk '{print $3}') = $us0 ]; then
65	detach_md $us1
66	us1=$(attach_md -t vnode -f $m2)
67else
68	detach_md $us0
69	us0=$(attach_md -t vnode -f $m1)
70fi
71
72# Make sure that the retaste caused the mirror to automatically be re-added.
73if [ $(gmirror status -s $name | wc -l) -eq 2 ]; then
74	echo "ok 4"
75else
76	echo "not ok 4"
77fi
78
79syncwait
80
81rm -f $m1 $m2 $tmp1 $tmp2
82