xref: /freebsd/tools/test/stress2/misc/graid1_11.sh (revision 61e21613)
1#!/bin/sh
2
3# g_mirror: don't fail reads while losing next-to-last disk
4
5# Fixed by https://cgit.FreeBSD.org/src/commit/?id=5d5f44623eb3d121d528060d131ee5d6bcd63489
6# Test scenario by: Andriy Gapon <avg@FreeBSD.org>
7
8set -u
9
10cleanup()
11{
12	echo "cleanup" 2>&1
13	gnop destroy -f ${dev1}.nop
14	gnop destroy -f ${dev2}.nop
15	gmirror destroy testmirror
16	mdconfig -d -u ${dev2#md}
17	mdconfig -d -u ${dev1#md}
18}
19
20list_descendants()
21{
22	local children
23
24	children=$(pgrep -P "$1")
25	for pid in $children ; do
26		list_descendants "$pid"
27	done
28	echo "$children"
29}
30
31# Note that the size of gnop providers is smaller than the
32# size of backing md-s to avoid gmirror auto-tasting.
33for i in 1 2; do
34	eval dev$i=$(mdconfig -a -t swap -s 1024m)
35	eval gnop create -d 8 -s 1000m \${dev$i}
36done
37
38trap cleanup EXIT INT TERM QUIT
39
40gmirror load 2>/dev/null || true
41gmirror label -b round-robin -F testmirror ${dev1}.nop ${dev2}.nop
42
43(
44	#my_pid=$(exec sh -c 'echo "$PPID"')
45
46	sleep 100000 &
47	sentry=$!
48
49	children=""
50	for i in $(seq 8) ; do
51		(
52		while dd if=/dev/mirror/testmirror of=/dev/null > /dev/null ; ds=$? ; [ $ds -eq 0 ] ; do
53			:
54		done
55		if [ $ds -lt 128 ] ; then
56			# Not killed
57			echo "dd exited with $ds" 1>&2
58			kill $sentry 2>/dev/null
59		fi
60		) &
61
62		children="${children:+${children},}$!"
63
64		sleep 0.1
65	done
66
67	wait $sentry
68	pkill -P ${children} -x dd
69
70	# Reap background children
71	wait
72) &
73runner=$!
74
75# Give dd-s some time to get running
76sleep 2
77
78# Destroy one of the members
79echo "destroying one member" 1>&2
80gnop destroy -f ${dev1}.nop
81
82count=0
83while kill -0 $runner 2>/dev/null && [ $count -lt 5 ] ; do
84	sleep 1
85	count=$((count + 1))
86done
87
88if ! kill -0 $runner 2>/dev/null ; then
89	echo "the test has self-terminated" 1>&2
90	ret=1
91else
92	echo "the test is stuck, killing..." 1>&2
93	ret=0
94	kill $(list_descendants $runner) 2>/dev/null
95fi
96
97# Reap background processes
98wait
99
100# Just in case
101sleep 5
102
103exit $ret
104