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