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