1#!/usr/local/bin/ksh93
2#
3# Copyright (c) 2010 Spectra Logic Corporation
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions, and the following disclaimer,
11#    without modification.
12# 2. Redistributions in binary form must reproduce at minimum a disclaimer
13#    substantially similar to the "NO WARRANTY" disclaimer below
14#    ("Disclaimer") and any redistribution must be conditioned upon
15#    including a substantially similar Disclaimer requirement for further
16#    binary redistribution.
17#
18# NO WARRANTY
19# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
22# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23# HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29# POSSIBILITY OF SUCH DAMAGES.
30#
31# $FreeBSD$
32#
33
34. $STF_SUITE/include/libtest.kshlib
35. $STF_SUITE/include/libgnop.kshlib
36
37# Cleanup function.  Kill each of the children.
38function docleanup
39{
40	for CPID in $CHILDREN
41	do
42		echo "Killing $CPID"
43		kill $CPID
44	done
45	for CPID in $CHILDREN
46	do
47		wait $CPID
48	done
49}
50
51function childcleanup
52{
53	exit 0
54}
55
56# Wait for the timeout, and then kill the child processes.
57function childrentimeout
58{
59	log_note "childrentimeout process waiting $1 seconds"
60	sleep $1
61	docleanup
62}
63
64function mk_vols
65{
66	ADISKS=($DISKS)				#Create an array for convenience
67	N_DISKS=${#ADISKS[@]}
68	N_MIRRORS=$(($N_DISKS / 2 ))
69	# Use a special ksh93 expansion to generate the list of gnop devices
70	GNOPS=${DISKS//~(E)([[:space:]]+|$)/.nop\1}
71	setup_mirrors $N_MIRRORS $GNOPS
72	for pool in `all_pools`; do
73		# Create 4 ZVols per pool.  Write a geom label to each, just so
74		# that we have another geom class between zvol and the vdev
75		# taster.  That thwarts detection of zvols based on a geom
76		# producer's class name, as was attempted by Perforce change
77		# 538882
78		for ((j=0; $j<4; j=$j+1)); do
79			$ZFS create -V 10G $pool/testvol.$j
80			glabel label testlabel$j /dev/zvol/$pool/testvol.$j
81		done
82	done
83}
84
85export CHILDREN=""
86
87log_onexit docleanup
88
89log_assert "Cause frequent device removal and arrival in the prescence of zvols.  ZFS should not crash or hang while tasting them for VDev GUIDs."
90mk_vols
91for p in `all_pools`
92do
93	#Take the first gnop in the pool
94	typeset gnop
95	typeset disk
96	gnop=`get_disklist $p | cut -d " " -f 1`
97	disk=${gnop%.nop}
98
99	log_note "thrashing $gnop"
100	trap childcleanup INT TERM && while `true`; do
101	log_must destroy_gnop $disk
102	$SLEEP 5
103	log_must create_gnop $disk
104	$SLEEP 5
105	done &
106	CHILDREN="$CHILDREN $!"
107done
108
109log_note "Waiting $RUNTIME seconds for potential ZFS failure"
110childrentimeout $RUNTIME
111
112log_pass
113