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 2012 Spectra Logic.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/tests/hotspare/hotspare.kshlib
27
28################################################################################
29#
30# __stc_assertion_start
31#
32# ID: zfs_hotspare_003_pos
33#
34# DESCRIPTION:
35#	If a vdev becomes faulted in a pool with a spare, the spare will be
36#	activated.
37#
38#
39# STRATEGY:
40#	1. Create 1 storage pools with hot spares.
41#	2. Artificially fault one vdev in the pool to make 1 hotspare in use.
42#	3. Verify that the spare is in use.
43#
44# TESTABILITY: explicit
45#
46# TEST_AUTOMATION_LEVEL: automated
47#
48# CODING STATUS: COMPLETED (2012-08-06)
49#
50# __stc_assertion_end
51#
52###############################################################################
53
54verify_runnable "global"
55
56function cleanup
57{
58	poolexists $TESTPOOL && \
59		destroy_pool $TESTPOOL
60
61	partition_cleanup
62}
63
64function verify_assertion # spare_dev
65{
66	typeset err_dev=${devarray[3]}
67	typeset sdev=$1
68
69	log_must $ZINJECT -d $err_dev -A degrade $TESTPOOL
70	log_must check_state $TESTPOOL $err_dev "DEGRADED"
71
72	# ZFSD can take up to 60 seconds to degrade an array in response to
73	# errors (though it's usually faster).
74	for ((timeout=0; $timeout<10; timeout=$timeout+1)); do
75		check_state $TESTPOOL "$sdev" "INUSE"
76		spare_inuse=$?
77		if [[ $spare_inuse == 0 ]]; then
78			break
79		fi
80		$SLEEP 6
81	done
82	log_must $ZPOOL status $TESTPOOL
83	log_must check_state $TESTPOOL "$sdev" "INUSE"
84
85	# do cleanup
86	destroy_pool $TESTPOOL
87}
88
89
90log_assert "A faulted vdev will be replaced by an available spare"
91
92log_onexit cleanup
93
94ensure_zfsd_running
95set_devs
96typeset  sdev="${devarray[0]}"
97
98set -A my_keywords "mirror" "raidz1" "raidz2"
99for keyword in "${my_keywords[@]}" ; do
100	setup_hotspares "$keyword"
101	verify_assertion $sdev
102done
103
104log_pass "A faulted vdev will be replaced by an available spare"
105