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 2009 Sun Microsystems, Inc. All rights reserved. 27# Use is subject to license terms. 28# 29# ident "@(#)hotspare_detach_002_pos.ksh 1.3 09/06/22 SMI" 30# 31. $STF_SUITE/tests/hotspare/hotspare.kshlib 32 33################################################################################ 34# 35# __stc_assertion_start 36# 37# ID: hotspare_detach_002_pos 38# 39# DESCRIPTION: 40# If a hot spare have been activated, 41# and invoke "zpool detach" with the original device, 42# then the hot spare will become a functioning device, 43# and automatically be removed from the list of available hot spares 44# then the spare is automatically removed once the replace completes. 45# 46# STRATEGY: 47# 1. Create a storage pool with hot spares 48# 2. Activate a spare device to the pool 49# 3. Do 'zpool detach' with the original device 50# 4. Verify the spare device will become a functioning device, 51# be removed from the list of available spares as well, 52# and the original drive will removed once replace completes. 53# 54# TESTABILITY: explicit 55# 56# TEST_AUTOMATION_LEVEL: automated 57# 58# CODING STATUS: COMPLETED (2006-06-07) 59# 60# __stc_assertion_end 61# 62############################################################################### 63 64verify_runnable "global" 65 66function cleanup 67{ 68 poolexists $TESTPOOL && \ 69 destroy_pool $TESTPOOL 70 71 partition_cleanup 72} 73 74function verify_assertion # dev 75{ 76 typeset dev=$1 77 typeset odev=${pooldevs[0]} 78 79 log_must $ZPOOL replace $TESTPOOL $odev $dev 80 while check_state "$TESTPOOL" "replacing" \ 81 "online" || \ 82 ! is_pool_resilvered $TESTPOOL ; do 83 $SLEEP 2 84 done 85 log_must check_hotspare_state "$TESTPOOL" "$dev" "INUSE" 86 87 log_must $ZPOOL detach $TESTPOOL $odev 88 $SLEEP 5 89 log_must $ZPOOL replace $TESTPOOL $dev $odev 90 91 while check_state "$TESTPOOL" "replacing" \ 92 "online" ; do 93 $SLEEP 2 94 done 95 96 log_must $ZPOOL add -f $TESTPOOL spare $dev 97 log_must check_hotspare_state "$TESTPOOL" "$dev" "AVAIL" 98} 99 100log_assert "'zpool detach <pool> <vdev> ...' against a functioning device that have spared should take the hot spare permanently swapping in successfully." 101 102log_onexit cleanup 103 104set_devs 105 106for keyword in "${keywords[@]}" ; do 107 setup_hotspares "$keyword" 108 109 iterate_over_hotspares verify_assertion 110 111 destroy_pool "$TESTPOOL" 112done 113 114log_pass "'zpool detach <pool> <vdev> ...' against a functioning device that have spared take the hot spare permanently swapping in successfully." 115