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