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. $STF_SUITE/tests/zfsd/zfsd.kshlib 28. $STF_SUITE/include/libgnop.kshlib 29 30################################################################################ 31# 32# __stc_assertion_start 33# 34# ID: zfs_hotspare_007_pos 35# 36# DESCRIPTION: 37# If a vdev gets removed from a pool with a spare while zfsd is shut 38# down, then the spare will be activated when zfsd restarts 39# 40# 41# STRATEGY: 42# 1. Create 1 storage pools with hot spares. 43# 2. Turn off zfsd 44# 3. Remove one vdev 45# 4. Restart zfsd 46# 5. Verify that the spare is in use. 47# 48# TESTABILITY: explicit 49# 50# TEST_AUTOMATION_LEVEL: automated 51# 52# CODING STATUS: COMPLETED (2014-09-17) 53# 54# __stc_assertion_end 55# 56############################################################################### 57 58verify_runnable "global" 59 60log_assert "zfsd will spare missing drives on startup" 61 62 63function verify_assertion # spare_dev 64{ 65 typeset spare_dev=$1 66 stop_zfsd 67 68 log_must destroy_gnop $REMOVAL_DISK 69 70 # Check to make sure ZFS sees the disk as removed 71 wait_for_pool_removal 20 72 73 restart_zfsd 74 75 # Check that the spare was activated 76 wait_for_pool_dev_state_change 20 $spare_dev INUSE 77 78 # Re-enable the missing disk 79 log_must create_gnop $REMOVAL_DISK $PHYSPATH 80 81 # And now the spare should be released 82 wait_for_pool_dev_state_change 20 $spare_dev AVAIL 83} 84 85typeset PHYSPATH="some_physical_path" 86typeset REMOVAL_DISK=$DISK0 87typeset REMOVAL_NOP=${DISK0}.nop 88typeset SPARE_DISK=$DISK4 89typeset SPARE_NOP=${DISK4}.nop 90typeset OTHER_DISKS="${DISK1} ${DISK2} ${DISK3}" 91typeset OTHER_NOPS=${OTHER_DISKS//~(E)([[:space:]]+|$)/.nop\1} 92set -A MY_KEYWORDS "mirror" "raidz1" "raidz2" 93ensure_zfsd_running 94log_must create_gnops $OTHER_DISKS $SPARE_DISK 95log_must create_gnop $REMOVAL_DISK $PHYSPATH 96for keyword in "${MY_KEYWORDS[@]}" ; do 97 log_must create_pool $TESTPOOL $keyword $REMOVAL_NOP $OTHER_NOPS spare $SPARE_NOP 98 log_must $ZPOOL set autoreplace=on $TESTPOOL 99 iterate_over_hotspares verify_assertion $SPARE_NOP 100 101 destroy_pool "$TESTPOOL" 102done 103 104log_pass 105