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