12fae26bdSAlan Somers#!/usr/local/bin/ksh93 -p 22fae26bdSAlan Somers# 32fae26bdSAlan Somers# CDDL HEADER START 42fae26bdSAlan Somers# 52fae26bdSAlan Somers# The contents of this file are subject to the terms of the 62fae26bdSAlan Somers# Common Development and Distribution License (the "License"). 72fae26bdSAlan Somers# You may not use this file except in compliance with the License. 82fae26bdSAlan Somers# 92fae26bdSAlan Somers# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 102fae26bdSAlan Somers# or http://www.opensolaris.org/os/licensing. 112fae26bdSAlan Somers# See the License for the specific language governing permissions 122fae26bdSAlan Somers# and limitations under the License. 132fae26bdSAlan Somers# 142fae26bdSAlan Somers# When distributing Covered Code, include this CDDL HEADER in each 152fae26bdSAlan Somers# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 162fae26bdSAlan Somers# If applicable, add the following below this CDDL HEADER, with the 172fae26bdSAlan Somers# fields enclosed by brackets "[]" replaced with your own identifying 182fae26bdSAlan Somers# information: Portions Copyright [yyyy] [name of copyright owner] 192fae26bdSAlan Somers# 202fae26bdSAlan Somers# CDDL HEADER END 212fae26bdSAlan Somers# 222fae26bdSAlan Somers 232fae26bdSAlan Somers# 242fae26bdSAlan Somers# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 252fae26bdSAlan Somers# Use is subject to license terms. 262fae26bdSAlan Somers. $STF_SUITE/tests/hotspare/hotspare.kshlib 272fae26bdSAlan Somers 282fae26bdSAlan Somers################################################################################ 292fae26bdSAlan Somers# 302fae26bdSAlan Somers# __stc_assertion_start 312fae26bdSAlan Somers# 322fae26bdSAlan Somers# ID: hotspare_onoffline_004_neg 332fae26bdSAlan Somers# 342fae26bdSAlan Somers# DESCRIPTION: 352fae26bdSAlan Somers# If a hot spare has been activated, 362fae26bdSAlan Somers# turning that basic vdev offline and back online during I/O completes. 372fae26bdSAlan Somers# Make sure the integrity of the file system and the resilvering. 382fae26bdSAlan Somers# 392fae26bdSAlan Somers# STRATEGY: 402fae26bdSAlan Somers# 1. Create a storage pool with hot spares 412fae26bdSAlan Somers# 2. Activate the hot spare 422fae26bdSAlan Somers# 3. Start some random I/O 432fae26bdSAlan Somers# 4. Try 'zpool offline' & 'zpool online' with the basic vdev 442fae26bdSAlan Somers# 5. Verify the integrity of the file system and the resilvering. 452fae26bdSAlan Somers# 462fae26bdSAlan Somers# TESTABILITY: explicit 472fae26bdSAlan Somers# 482fae26bdSAlan Somers# TEST_AUTOMATION_LEVEL: automated 492fae26bdSAlan Somers# 502fae26bdSAlan Somers# CODING STATUS: COMPLETED (2006-06-07) 512fae26bdSAlan Somers# 522fae26bdSAlan Somers# __stc_assertion_end 532fae26bdSAlan Somers# 542fae26bdSAlan Somers############################################################################### 552fae26bdSAlan Somers 562fae26bdSAlan Somersverify_runnable "global" 572fae26bdSAlan Somers 582fae26bdSAlan Somersfunction cleanup 592fae26bdSAlan Somers{ 602fae26bdSAlan Somers kill_all_wp 612fae26bdSAlan Somers poolexists $TESTPOOL && \ 622fae26bdSAlan Somers destroy_pool $TESTPOOL 632fae26bdSAlan Somers 642fae26bdSAlan Somers [[ -e $TESTDIR ]] && log_must $RM -rf $TESTDIR/* 652fae26bdSAlan Somers 662fae26bdSAlan Somers partition_cleanup 672fae26bdSAlan Somers} 682fae26bdSAlan Somers 692fae26bdSAlan Somersfunction kill_all_wp 702fae26bdSAlan Somers{ 712fae26bdSAlan Somers for wait_pid in $child_pids 722fae26bdSAlan Somers do 732fae26bdSAlan Somers $KILL $wait_pid 742fae26bdSAlan Somers $WAIT $wait_pid 752fae26bdSAlan Somers done 762fae26bdSAlan Somers} 772fae26bdSAlan Somers 782fae26bdSAlan Somersfunction start_all_wp 792fae26bdSAlan Somers{ 802fae26bdSAlan Somers typeset -i i=0 812fae26bdSAlan Somers typeset -i iters=1 822fae26bdSAlan Somers 832fae26bdSAlan Somers child_pids="" 842fae26bdSAlan Somers while (( i < iters )); do 852fae26bdSAlan Somers log_note "Invoking $FILE_TRUNC with: $options_display" 862fae26bdSAlan Somers $FILE_TRUNC $options $TESTDIR/$TESTFILE.$i & 872fae26bdSAlan Somers typeset pid=$! 882fae26bdSAlan Somers 892fae26bdSAlan Somers child_pids="$child_pids $pid" 902fae26bdSAlan Somers ((i = i + 1)) 912fae26bdSAlan Somers done 922fae26bdSAlan Somers} 932fae26bdSAlan Somers 942fae26bdSAlan Somersfunction verify_assertion # dev 952fae26bdSAlan Somers{ 962fae26bdSAlan Somers typeset dev=$1 972fae26bdSAlan Somers typeset -i i=0 982fae26bdSAlan Somers typeset -i iters=1 992fae26bdSAlan Somers typeset odev=${pooldevs[0]} 1002fae26bdSAlan Somers 1012fae26bdSAlan Somers log_must $ZPOOL replace $TESTPOOL $odev $dev 1022fae26bdSAlan Somers 1032fae26bdSAlan Somers i=0 1042fae26bdSAlan Somers while (( i < iters )); do 1052fae26bdSAlan Somers start_all_wp 1062fae26bdSAlan Somers while true; do 1072fae26bdSAlan Somers if is_pool_resilvered "$TESTPOOL"; then 1082fae26bdSAlan Somers [ -s "$TESTDIR/$TESTFILE.$i" ] && break 1092fae26bdSAlan Somers fi 1102fae26bdSAlan Somers $SLEEP 2 1112fae26bdSAlan Somers done 1122fae26bdSAlan Somers 1132fae26bdSAlan Somers kill_all_wp 1142fae26bdSAlan Somers log_must test -s $TESTDIR/$TESTFILE.$i 1152fae26bdSAlan Somers 1162fae26bdSAlan Somers log_must $ZPOOL offline $TESTPOOL $odev 1172fae26bdSAlan Somers log_must check_state $TESTPOOL $odev "offline" 1182fae26bdSAlan Somers 1192fae26bdSAlan Somers log_must $ZPOOL online $TESTPOOL $odev 1202fae26bdSAlan Somers log_must check_state $TESTPOOL $odev "online" 1212fae26bdSAlan Somers (( i = i + 1 )) 1222fae26bdSAlan Somers done 1232fae26bdSAlan Somers 1242fae26bdSAlan Somers log_must $ZPOOL detach $TESTPOOL $dev 1252fae26bdSAlan Somers} 1262fae26bdSAlan Somers 1272fae26bdSAlan Somerslog_assert "'zpool offline/online <pool> <vdev>' against a spared basic vdev during I/O completes." 1282fae26bdSAlan Somers 1292fae26bdSAlan Somerslog_onexit cleanup 1302fae26bdSAlan Somers 1312fae26bdSAlan Somersset_devs 1322fae26bdSAlan Somers 1332fae26bdSAlan Somersoptions="" 1342fae26bdSAlan Somersoptions_display="default options" 1352fae26bdSAlan Somers 1362fae26bdSAlan Somers[[ -n "$HOLES_FILESIZE" ]] && options=" $options -f $HOLES_FILESIZE " 1372fae26bdSAlan Somers 1382fae26bdSAlan Somers[[ -n "$HOLES_BLKSIZE" ]] && options="$options -b $HOLES_BLKSIZE " 1392fae26bdSAlan Somers 1402fae26bdSAlan Somers[[ -n "$HOLES_COUNT" ]] && options="$options -c $HOLES_COUNT " 1412fae26bdSAlan Somers 1422fae26bdSAlan Somers[[ -n "$HOLES_SEED" ]] && options="$options -s $HOLES_SEED " 1432fae26bdSAlan Somers 1442fae26bdSAlan Somers[[ -n "$HOLES_FILEOFFSET" ]] && options="$options -o $HOLES_FILEOFFSET " 1452fae26bdSAlan Somers 1462fae26bdSAlan Somersoptions="$options -r" 1472fae26bdSAlan Somers 1482fae26bdSAlan Somers[[ -n "$options" ]] && options_display=$options 1492fae26bdSAlan Somers 1502fae26bdSAlan Somerstypeset child_pid="" 1512fae26bdSAlan Somers 1522fae26bdSAlan Somersfor keyword in "${keywords[@]}" ; do 1532fae26bdSAlan Somers setup_hotspares "$keyword" 1542fae26bdSAlan Somers log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL 1552fae26bdSAlan Somers 1562fae26bdSAlan Somers iterate_over_hotspares verify_assertion 1572fae26bdSAlan Somers 1582fae26bdSAlan Somers verify_filesys "$TESTPOOL" "$TESTPOOL" "$HOTSPARE_TMPDIR" 1592fae26bdSAlan Somers destroy_pool "$TESTPOOL" 1602fae26bdSAlan Somersdone 1612fae26bdSAlan Somers 1622fae26bdSAlan Somerslog_pass "'zpool offline/online <pool> <vdev>' against a spared basic vdev during I/O completes." 163