1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27# ident	"@(#)hotspare_onoffline_004_neg.ksh	1.5	09/06/22 SMI"
28#
29. $STF_SUITE/tests/hotspare/hotspare.kshlib
30
31################################################################################
32#
33# __stc_assertion_start
34#
35# ID: hotspare_onoffline_004_neg
36#
37# DESCRIPTION:
38#	If a hot spare has been activated,
39#	turning that basic vdev offline and back online during I/O completes.
40#	Make sure the integrity of the file system and the resilvering.
41#
42# STRATEGY:
43#	1. Create a storage pool with hot spares
44#	2. Activate the hot spare
45#	3. Start some random I/O
46#	4. Try 'zpool offline' & 'zpool online' with the basic vdev
47#	5. Verify the integrity of the file system and the resilvering.
48#
49# TESTABILITY: explicit
50#
51# TEST_AUTOMATION_LEVEL: automated
52#
53# CODING STATUS: COMPLETED (2006-06-07)
54#
55# __stc_assertion_end
56#
57###############################################################################
58
59verify_runnable "global"
60
61function cleanup
62{
63	kill_all_wp
64	poolexists $TESTPOOL && \
65		destroy_pool $TESTPOOL
66
67	[[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/*
68
69	partition_cleanup
70}
71
72function kill_all_wp
73{
74	for wait_pid in $child_pids
75	do
76		$KILL $wait_pid
77		$WAIT $wait_pid
78	done
79}
80
81function start_all_wp
82{
83	typeset -i i=0
84	typeset -i iters=1
85
86	child_pids=""
87	while (( i < iters )); do
88		log_note "Invoking $FILE_TRUNC with: $options_display"
89		$FILE_TRUNC $options $TESTDIR/$TESTFILE.$i &
90		typeset pid=$!
91
92		child_pids="$child_pids $pid"
93		((i = i + 1))
94	done
95}
96
97function verify_assertion # dev
98{
99	typeset dev=$1
100	typeset -i i=0
101	typeset -i iters=1
102	typeset odev=${pooldevs[0]}
103
104	log_must $ZPOOL replace $TESTPOOL $odev $dev
105
106	i=0
107	while (( i < iters )); do
108		start_all_wp
109		while true; do
110			if is_pool_resilvered "$TESTPOOL"; then
111				[ -s "$TESTDIR/$TESTFILE.$i" ] && break
112			fi
113			$SLEEP 2
114		done
115
116		kill_all_wp
117		log_must test -s $TESTDIR/$TESTFILE.$i
118
119		log_must $ZPOOL offline $TESTPOOL $odev
120		log_must check_state $TESTPOOL $odev "offline"
121
122		log_must $ZPOOL online $TESTPOOL $odev
123		log_must check_state $TESTPOOL $odev "online"
124		(( i = i + 1 ))
125	done
126
127	log_must $ZPOOL detach $TESTPOOL $dev
128}
129
130log_assert "'zpool offline/online <pool> <vdev>' against a spared basic vdev during I/O completes."
131
132log_onexit cleanup
133
134set_devs
135
136options=""
137options_display="default options"
138
139[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE "
140
141[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE "
142
143[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT "
144
145[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED "
146
147[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET "
148
149options="$options -r"
150
151[[ -n "$options" ]] && options_display=$options
152
153typeset child_pid=""
154
155for keyword in "${keywords[@]}" ; do
156	setup_hotspares "$keyword"
157	log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL
158
159	iterate_over_hotspares verify_assertion
160
161	verify_filesys "$TESTPOOL" "$TESTPOOL" "$HOTSPARE_TMPDIR"
162	destroy_pool "$TESTPOOL"
163done
164
165log_pass "'zpool offline/online <pool> <vdev>' against a spared basic vdev during I/O completes."
166