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