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