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