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 2012 Spectra Logic.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/tests/hotspare/hotspare.kshlib
27. $STF_SUITE/tests/zfsd/zfsd.kshlib
28. $STF_SUITE/include/libgnop.kshlib
29
30################################################################################
31#
32# __stc_assertion_start
33#
34# ID: zfs_hotspare_004_pos
35#
36# DESCRIPTION:
37#	If a vdev gets removed from a pool with a spare, the spare will be
38#	activated.
39#
40#
41# STRATEGY:
42#	1. Create 1 storage pools with hot spares.
43#	2. Remove one vdev
44#	3. Verify that the spare is in use.
45#	4. Recreate the vdev
46#	5. Verify that the vdev gets resilvered and the spare gets removed
47#
48# TESTABILITY: explicit
49#
50# TEST_AUTOMATION_LEVEL: automated
51#
52# CODING STATUS: COMPLETED (2012-08-10)
53#
54# __stc_assertion_end
55#
56###############################################################################
57
58log_assert "Removing a disk from a pool results in the spare activating"
59
60function verify_assertion # spare_dev
61{
62	typeset spare_dev=$1
63	log_must destroy_gnop $REMOVAL_DISK
64
65	# Check to make sure ZFS sees the disk as removed
66	wait_for_pool_removal 20
67
68	# Check that the spare was activated
69	wait_for_pool_dev_state_change 20 $spare_dev INUSE
70	log_must $ZPOOL status $TESTPOOL
71
72	# Re-enable the  missing disk
73	log_must create_gnop $REMOVAL_DISK $PHYSPATH
74
75	# Check that the disk has rejoined the pool & resilvered
76	wait_for_pool_dev_state_change 20 $REMOVAL_NOP ONLINE
77	wait_until_resilvered
78
79	# Finally, check that the spare deactivated
80	wait_for_pool_dev_state_change 20 $spare_dev AVAIL
81}
82
83
84typeset PHYSPATH="some_physical_path"
85typeset REMOVAL_DISK=$DISK0
86typeset REMOVAL_NOP=${DISK0}.nop
87typeset SPARE_DISK=$DISK4
88typeset SPARE_NOP=${DISK4}.nop
89typeset OTHER_DISKS="${DISK1} ${DISK2} ${DISK3}"
90typeset OTHER_NOPS=${OTHER_DISKS//~(E)([[:space:]]+|$)/.nop\1}
91set -A MY_KEYWORDS "mirror" "raidz1" "raidz2"
92ensure_zfsd_running
93log_must create_gnops $OTHER_DISKS $SPARE_DISK
94log_must create_gnop $REMOVAL_DISK $PHYSPATH
95for keyword in "${MY_KEYWORDS[@]}" ; do
96	log_must create_pool $TESTPOOL $keyword $REMOVAL_NOP $OTHER_NOPS spare $SPARE_NOP
97	log_must $ZPOOL set autoreplace=on $TESTPOOL
98	iterate_over_hotspares verify_assertion $SPARE_NOP
99
100	destroy_pool "$TESTPOOL"
101done
102
103log_pass
104