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 2014 Spectra Logic.  All rights reserved.
25# Use is subject to license terms.
26#
27#
28. $STF_SUITE/tests/hotspare/hotspare.kshlib
29. $STF_SUITE/tests/zfsd/zfsd.kshlib
30. $STF_SUITE/include/libgnop.kshlib
31
32################################################################################
33#
34# __stc_assertion_start
35#
36# ID: zfsd_autoreplace_003_pos
37#
38# DESCRIPTION:
39#	In a pool with the autoreplace property set, a vdev will be
40#	replaced by physical path even if a spare is already active for that
41#	vdev
42#
43# STRATEGY:
44#	1. Create 1 storage pool with a hot spare
45#	2. Remove a vdev
46#	3. Wait for the hotspare to fully resilver
47#	4. Create a new vdev with the same physical path as the first one
48#	10. Verify that it does get added to the pool.
49#	11. Verify that the hotspare gets removed.
50#
51# TESTABILITY: explicit
52#
53# TEST_AUTOMATION_LEVEL: automated
54#
55# CODING STATUS: COMPLETED (2013-05-13)
56#
57# __stc_assertion_end
58#
59###############################################################################
60
61log_assert "A pool with the autoreplace property will replace disks by physical path, even if a spare is active"
62
63function verify_assertion
64{
65	# Verify that the replacement disk gets added to the pool
66	wait_for_pool_dev_state_change 20 $NEW_DISK ONLINE
67
68	# Wait for resilvering to complete
69	wait_until_resilvered
70
71	# Check that the spare is deactivated
72	wait_for_pool_dev_state_change 20 "$SPARE_DISK" "AVAIL"
73}
74
75
76typeset PHYSPATH="some_physical_path"
77typeset REMOVAL_DISK=$DISK0
78typeset REMOVAL_NOP=${DISK0}.nop
79typeset NEW_DISK=$DISK3
80typeset NEW_NOP=${DISK3}.nop
81typeset SPARE_DISK=${DISK4}
82typeset SPARE_NOP=${DISK4}.nop
83typeset OTHER_DISKS="${DISK1} ${DISK2}"
84typeset OTHER_NOPS=${OTHER_DISKS//~(E)([[:space:]]+|$)/.nop\1}
85set -A MY_KEYWORDS "mirror" "raidz1" "raidz2"
86ensure_zfsd_running
87log_must create_gnops $OTHER_DISKS $SPARE_DISK
88for keyword in "${MY_KEYWORDS[@]}" ; do
89	log_must create_gnop $REMOVAL_DISK $PHYSPATH
90	log_must create_pool $TESTPOOL $keyword $REMOVAL_NOP $OTHER_NOPS spare $SPARE_NOP
91	log_must $ZPOOL set autoreplace=on $TESTPOOL
92
93	log_must destroy_gnop $REMOVAL_DISK
94	log_must wait_for_pool_removal 20
95	log_must create_gnop $NEW_DISK $PHYSPATH
96	verify_assertion
97	destroy_pool "$TESTPOOL"
98	log_must destroy_gnop $NEW_DISK
99done
100
101log_pass
102