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#
32
33. $STF_SUITE/include/libtest.kshlib
34. $STF_SUITE/include/libgnop.kshlib
35
36# Cleanup function.  Kill each of the children.
37function docleanup
38{
39	for CPID in $CHILDREN
40	do
41		echo "Killing $CPID"
42		kill $CPID
43	done
44	for CPID in $CHILDREN
45	do
46		wait $CPID
47	done
48}
49
50function childcleanup
51{
52	exit 0
53}
54
55# Wait for the timeout, and then kill the child processes.
56function childrentimeout
57{
58	log_note "childrentimeout process waiting $1 seconds"
59	sleep $1
60	docleanup
61}
62
63function mk_vols
64{
65	ADISKS=($DISKS)				#Create an array for convenience
66	N_DISKS=${#ADISKS[@]}
67	N_MIRRORS=$(($N_DISKS / 2 ))
68	# Use a special ksh93 expansion to generate the list of gnop devices
69	GNOPS=${DISKS//~(E)([[:space:]]+|$)/.nop\1}
70	setup_mirrors $N_MIRRORS $GNOPS
71	for pool in `all_pools`; do
72		# Create 4 ZVols per pool.  Write a geom label to each, just so
73		# that we have another geom class between zvol and the vdev
74		# taster.  That thwarts detection of zvols based on a geom
75		# producer's class name, as was attempted by Perforce change
76		# 538882
77		for ((j=0; $j<4; j=$j+1)); do
78			$ZFS create -V 10G $pool/testvol.$j
79			glabel label testlabel$j /dev/zvol/$pool/testvol.$j
80		done
81	done
82}
83
84export CHILDREN=""
85
86log_onexit docleanup
87
88log_assert "Cause frequent device removal and arrival in the prescence of zvols.  ZFS should not crash or hang while tasting them for VDev GUIDs."
89mk_vols
90for p in `all_pools`
91do
92	#Take the first gnop in the pool
93	typeset gnop
94	typeset disk
95	gnop=`get_disklist $p | cut -d " " -f 1`
96	disk=${gnop%.nop}
97
98	log_note "thrashing $gnop"
99	trap childcleanup INT TERM && while `true`; do
100	log_must destroy_gnop $disk
101	$SLEEP 5
102	log_must create_gnop $disk
103	$SLEEP 5
104	done &
105	CHILDREN="$CHILDREN $!"
106done
107
108log_note "Waiting $RUNTIME seconds for potential ZFS failure"
109childrentimeout $RUNTIME
110
111log_pass
112