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	"@(#)zpool_export_004_pos.ksh	1.2	09/06/22 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zpool_export_004_pos
39#
40# DESCRIPTION:
41#	Verify zpool export succeed or fail with spare.
42#
43# STRATEGY:
44#	1. Create two mirror pools with same spare.
45#	2. Verify zpool export one pool succeed.
46#	3. Import the pool.
47#	4. Replace one device with the spare and detach it in one pool.
48#	5. Verify zpool export the pool succeed.
49#	6. Import the pool.
50#	7. Replace one device with the spare in one pool.
51#	8. Verify zpool export the pool fail.
52#	9. Verify zpool export the pool with "-f" succeed.
53#	10. Import the pool.
54#
55# TESTABILITY: explicit
56#
57# TEST_AUTOMATION_LEVEL: automated
58#
59# CODING_STATUS: COMPLETED (2009-03-10)
60#
61# __stc_assertion_end
62#
63################################################################################
64
65verify_runnable "global"
66
67function cleanup
68{
69	restart_zfsd
70
71	mntpnt=$(get_prop mountpoint $TESTPOOL)
72        datasetexists $TESTPOOL1 || log_must $ZPOOL import -d $mntpnt $TESTPOOL1
73	datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1
74	datasetexists $TESTPOOL2 && destroy_pool $TESTPOOL2
75	typeset -i i=0
76	while ((i < 5)); do
77		if [[ -e $mntpnt/vdev$i ]]; then
78			log_must $RM -f $mntpnt/vdev$i
79		fi
80		((i += 1))
81	done
82}
83
84
85log_assert "Verify zpool export succeed or fail with spare."
86log_onexit cleanup
87# Stop ZFSD because it interferes with our manually activated spares
88stop_zfsd
89
90mntpnt=$(get_prop mountpoint $TESTPOOL)
91
92typeset -i i=0
93while ((i < 5)); do
94	log_must create_vdevs $mntpnt/vdev$i
95	eval vdev$i=$mntpnt/vdev$i
96	((i += 1))
97done
98
99log_must $ZPOOL create $TESTPOOL1 mirror $vdev0 $vdev1 spare $vdev4
100log_must $ZPOOL create $TESTPOOL2 mirror $vdev2 $vdev3 spare $vdev4
101
102log_must $ZPOOL export $TESTPOOL1
103log_must $ZPOOL import -d $mntpnt $TESTPOOL1
104
105log_must $ZPOOL replace $TESTPOOL1 $vdev0 $vdev4
106log_must $ZPOOL detach $TESTPOOL1 $vdev4
107log_must $ZPOOL export $TESTPOOL1
108log_must $ZPOOL import -d $mntpnt $TESTPOOL1
109
110log_must $ZPOOL replace $TESTPOOL1 $vdev0 $vdev4
111log_mustnot $ZPOOL export $TESTPOOL1
112
113log_must $ZPOOL export -f $TESTPOOL1
114log_must $ZPOOL import -d $mntpnt  $TESTPOOL1
115
116log_pass "Verify zpool export succeed or fail with spare."
117
118