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_005_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: zfs_hotspare_003_pos 38# 39# DESCRIPTION: 40# If a vdev becomes faulted 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 fault one vdev in the pool to make 1 hotspare in use. 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 poolexists $TESTPOOL && \ 64 destroy_pool $TESTPOOL 65 66 partition_cleanup 67} 68 69function verify_assertion # spare_dev 70{ 71 typeset err_dev=${devarray[3]} 72 typeset sdev=$1 73 74 log_must $ZINJECT -d $err_dev -A degrade $TESTPOOL 75 log_must check_state $TESTPOOL $err_dev "DEGRADED" 76 77 # ZFSD can take up to 60 seconds to degrade an array in response to 78 # errors (though it's usually faster). 79 for ((timeout=0; $timeout<10; timeout=$timeout+1)); do 80 check_state $TESTPOOL "$sdev" "INUSE" 81 spare_inuse=$? 82 if [[ $spare_inuse == 0 ]]; then 83 break 84 fi 85 $SLEEP 6 86 done 87 log_must $ZPOOL status $TESTPOOL 88 log_must check_state $TESTPOOL "$sdev" "INUSE" 89 90 # do cleanup 91 destroy_pool $TESTPOOL 92} 93 94 95log_assert "A faulted vdev will be replaced by an available spare" 96 97log_onexit cleanup 98 99ensure_zfsd_running 100set_devs 101typeset sdev="${devarray[0]}" 102 103set -A my_keywords "mirror" "raidz1" "raidz2" 104for keyword in "${my_keywords[@]}" ; do 105 setup_hotspares "$keyword" 106 verify_assertion $sdev 107done 108 109log_pass "A faulted vdev will be replaced by an available spare" 110