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