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 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)hotspare_export_001_neg.ksh	1.2	09/06/22 SMI"
30#
31. $STF_SUITE/tests/hotspare/hotspare.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID: hotspare_export_001_neg
38#
39# DESCRIPTION:
40#	If 2 storage pools have shared hotspares, if the shared hotspare was used by
41#	one of the pool, the export of the pool that use hotspare will fail.
42#
43# STRATEGY:
44#	1. Create 2 storage pools with hot spares shared.
45#	2. Fail one vdev in one pool to make the hotspare in use.
46#	3. Export the pool that currently use the hotspare
47#	4. Verify the export will failed with warning message.
48#	5. Verify export -f will success.
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING STATUS: COMPLETED (2008-12-12)
55#
56# __stc_assertion_end
57#
58###############################################################################
59
60verify_runnable "global"
61
62function cleanup
63{
64
65	if poolexists $TESTPOOL ; then
66		destroy_pool $TESTPOOL
67	else
68		$ZPOOL import -d $HOTSPARE_TMPDIR -f | $GREP  \
69			"pool: $TESTPOOL">/dev/null 2>&1
70		if (( $? == 0 )); then
71			log_must $ZPOOL import -d $HOTSPARE_TMPDIR -f $TESTPOOL
72			destroy_pool $TESTPOOL
73		fi
74	fi
75
76	poolexists $TESTPOOL1 && \
77		destroy_pool $TESTPOOL1
78
79	partition_cleanup
80
81}
82
83
84log_onexit cleanup
85
86function verify_assertion # type, dev
87{
88	typeset pool_type=$1
89	typeset hotspare=$2
90
91	typeset err_dev=${devarray[3]}
92	typeset pool_dev="${devarray[6]}"
93	typeset mntp=$(get_prop mountpoint $TESTPOOL)
94
95	create_pool $TESTPOOL1 $pool_dev spare $hotspare
96
97	zpool replace $TESTPOOL $err_dev $hotspare
98	log_must check_hotspare_state "$TESTPOOL" "$hotspare" "INUSE"
99
100	log_must $ZPOOL status $TESTPOOL
101	log_must $ZPOOL status $TESTPOOL1
102
103	log_mustnot $ZPOOL export $TESTPOOL
104	log_must $ZPOOL export -f $TESTPOOL
105
106	log_must $ZPOOL import -d $HOTSPARE_TMPDIR -f $TESTPOOL
107	destroy_pool $TESTPOOL
108
109	destroy_pool $TESTPOOL1
110}
111
112log_onexit cleanup
113
114log_assert "export pool that using shared hotspares will fail"
115
116set_devs
117
118typeset share_spare="${devarray[0]}"
119set -A my_keywords "mirror" "raidz1" "raidz2"
120
121for keyword in "${my_keywords[@]}" ; do
122        setup_hotspares $keyword $share_spare
123        verify_assertion $keyword $share_spare
124done
125
126log_pass "export pool that using shared hotspares will fail"
127
128