xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_export/zpool_export_004_pos.ksh (revision b6805bf78d2bbbeeaea8909a05623587b42d58b3)
1#!/bin/ksh -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
28. $STF_SUITE/include/libtest.shlib
29
30#
31# DESCRIPTION:
32#	Verify zpool export succeed or fail with spare.
33#
34# STRATEGY:
35#	1. Create two mirror pools with same spare.
36#	2. Verify zpool export one pool succeed.
37#	3. Import the pool.
38#	4. Replace one device with the spare and detach it in one pool.
39#	5. Verify zpool export the pool succeed.
40#	6. Import the pool.
41#	7. Replace one device with the spare in one pool.
42#	8. Verify zpool export the pool fail.
43#	9. Verify zpool export the pool with "-f" succeed.
44#	10. Import the pool.
45#
46
47verify_runnable "global"
48
49function cleanup
50{
51	mntpnt=$(get_prop mountpoint $TESTPOOL)
52        datasetexists $TESTPOOL1 || log_must $ZPOOL import -d $mntpnt $TESTPOOL1
53	datasetexists $TESTPOOL1 && destroy_pool $TESTPOOL1
54	datasetexists $TESTPOOL2 && destroy_pool $TESTPOOL2
55	typeset -i i=0
56	while ((i < 5)); do
57		if [[ -e $mntpnt/vdev$i ]]; then
58			log_must $RM -f $mntpnt/vdev$i
59		fi
60		((i += 1))
61	done
62}
63
64
65log_assert "Verify zpool export succeed or fail with spare."
66log_onexit cleanup
67
68mntpnt=$(get_prop mountpoint $TESTPOOL)
69
70typeset -i i=0
71while ((i < 5)); do
72	log_must $MKFILE 64M $mntpnt/vdev$i
73	eval vdev$i=$mntpnt/vdev$i
74	((i += 1))
75done
76
77log_must $ZPOOL create $TESTPOOL1 mirror $vdev0 $vdev1 spare $vdev4
78log_must $ZPOOL create $TESTPOOL2 mirror $vdev2 $vdev3 spare $vdev4
79
80log_must $ZPOOL export $TESTPOOL1
81log_must $ZPOOL import -d $mntpnt $TESTPOOL1
82
83log_must $ZPOOL replace $TESTPOOL1 $vdev0 $vdev4
84log_must $ZPOOL detach $TESTPOOL1 $vdev4
85log_must $ZPOOL export $TESTPOOL1
86log_must $ZPOOL import -d $mntpnt $TESTPOOL1
87
88log_must $ZPOOL replace $TESTPOOL1 $vdev0 $vdev4
89log_mustnot $ZPOOL export $TESTPOOL1
90
91log_must $ZPOOL export -f $TESTPOOL1
92log_must $ZPOOL import -d $mntpnt  $TESTPOOL1
93
94log_pass "Verify zpool export succeed or fail with spare."
95
96