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