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 2017 Spectra Logic.  All rights reserved.
25# Use is subject to license terms.
26
27. $STF_SUITE/tests/hotspare/hotspare.kshlib
28
29verify_runnable "global"
30
31function cleanup
32{
33	$ZPOOL status $TESTPOOL
34	if poolexists $TESTPOOL ; then
35		destroy_pool $TESTPOOL
36	fi
37
38	partition_cleanup
39}
40
41function verify_assertion # damage_type
42{
43	typeset mntp=$(get_prop mountpoint $TESTPOOL)
44
45	# Write some data to the pool so the replacing vdev doesn't complete
46	# immediately.
47	$TIMEOUT 60s $DD if=/dev/zero of=$mntp/zerofile bs=131072
48
49	log_must $ZINJECT -d $FAULT_DISK -A fault $TESTPOOL
50	log_must check_state $TESTPOOL $FAULT_DISK FAULTED
51
52	# Replace the failed device.  Realistically, the new device would have
53	# the same physical path as the failed one, but it doesn't matter for
54	# our purposes.
55	log_must $ZPOOL replace $TESTPOOL $FAULT_DISK $REPLACEMENT_DISK
56
57	# Add the spare, and check that it does not activate
58	log_must $ZPOOL add $TESTPOOL spare $SDEV
59
60	# Wait a few seconds before verifying the state
61	$SLEEP 10
62	log_must check_state $TESTPOOL "$SDEV" "AVAIL"
63}
64
65log_onexit cleanup
66
67log_assert "zfsd will not use newly added spares on replacing vdevs"
68
69ensure_zfsd_running
70
71typeset FAULT_DISK=$DISK0
72typeset REPLACEMENT_DISK=$DISK2
73typeset SDEV=$DISK3
74typeset POOLDEVS="$DISK0 $DISK1"
75set -A MY_KEYWORDS "mirror"
76for keyword in "${MY_KEYWORDS[@]}" ; do
77	log_must create_pool $TESTPOOL $keyword $POOLDEVS
78	verify_assertion
79
80	destroy_pool "$TESTPOOL"
81done
82