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 2009 Sun Microsystems, Inc. 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: hotspare_onoffline_004_neg 33# 34# DESCRIPTION: 35# If a hot spare has been activated, 36# turning that basic vdev offline and back online during I/O completes. 37# Make sure the integrity of the file system and the resilvering. 38# 39# STRATEGY: 40# 1. Create a storage pool with hot spares 41# 2. Activate the hot spare 42# 3. Start some random I/O 43# 4. Try 'zpool offline' & 'zpool online' with the basic vdev 44# 5. Verify the integrity of the file system and the resilvering. 45# 46# TESTABILITY: explicit 47# 48# TEST_AUTOMATION_LEVEL: automated 49# 50# CODING STATUS: COMPLETED (2006-06-07) 51# 52# __stc_assertion_end 53# 54############################################################################### 55 56verify_runnable "global" 57 58function cleanup 59{ 60 kill_all_wp 61 poolexists $TESTPOOL && \ 62 destroy_pool $TESTPOOL 63 64 [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/* 65 66 partition_cleanup 67} 68 69function kill_all_wp 70{ 71 for wait_pid in $child_pids 72 do 73 $KILL $wait_pid 74 $WAIT $wait_pid 75 done 76} 77 78function start_all_wp 79{ 80 typeset -i i=0 81 typeset -i iters=1 82 83 child_pids="" 84 while (( i < iters )); do 85 log_note "Invoking $FILE_TRUNC with: $options_display" 86 $FILE_TRUNC $options $TESTDIR/$TESTFILE.$i & 87 typeset pid=$! 88 89 child_pids="$child_pids $pid" 90 ((i = i + 1)) 91 done 92} 93 94function verify_assertion # dev 95{ 96 typeset dev=$1 97 typeset -i i=0 98 typeset -i iters=1 99 typeset odev=${pooldevs[0]} 100 101 log_must $ZPOOL replace $TESTPOOL $odev $dev 102 103 i=0 104 while (( i < iters )); do 105 start_all_wp 106 while true; do 107 if is_pool_resilvered "$TESTPOOL"; then 108 [ -s "$TESTDIR/$TESTFILE.$i" ] && break 109 fi 110 $SLEEP 2 111 done 112 113 kill_all_wp 114 log_must test -s $TESTDIR/$TESTFILE.$i 115 116 log_must $ZPOOL offline $TESTPOOL $odev 117 log_must check_state $TESTPOOL $odev "offline" 118 119 log_must $ZPOOL online $TESTPOOL $odev 120 log_must check_state $TESTPOOL $odev "online" 121 (( i = i + 1 )) 122 done 123 124 log_must $ZPOOL detach $TESTPOOL $dev 125} 126 127log_assert "'zpool offline/online <pool> <vdev>' against a spared basic vdev during I/O completes." 128 129log_onexit cleanup 130 131set_devs 132 133options="" 134options_display="default options" 135 136[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE " 137 138[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE " 139 140[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT " 141 142[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED " 143 144[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET " 145 146options="$options -r" 147 148[[ -n "$options" ]] && options_display=$options 149 150typeset child_pid="" 151 152for keyword in "${keywords[@]}" ; do 153 setup_hotspares "$keyword" 154 log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL 155 156 iterate_over_hotspares verify_assertion 157 158 verify_filesys "$TESTPOOL" "$TESTPOOL" "$HOTSPARE_TMPDIR" 159 destroy_pool "$TESTPOOL" 160done 161 162log_pass "'zpool offline/online <pool> <vdev>' against a spared basic vdev during I/O completes." 163