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 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zpool_import_010_pos.ksh	1.2	07/01/09 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zpool_import_010_pos
39#
40# DESCRIPTION:
41#	'zpool -D -a' can import all the specified directories destroyed pools.
42#
43# STRATEGY:
44#	1. Create a 5 ways mirror pool A with dev0/1/2/3/4, then destroy it.
45#	2. Create a stripe pool B with dev1. Then destroy it.
46#	3. Create a raidz2 pool C with dev2/3/4. Then destroy it.
47#	4. Create a raidz pool D with dev3/4. Then destroy it.
48#	5. Create a stripe pool E with dev4. Then destroy it.
49#	6. Verify 'zpool import -D -a' recover all the pools.
50#
51# TESTABILITY: explicit
52#
53# TEST_AUTOMATION_LEVEL: automated
54#
55# CODING_STATUS: COMPLETED (2006-06-12)
56#
57# __stc_assertion_end
58#
59################################################################################
60
61verify_runnable "global"
62
63function cleanup
64{
65	typeset dt
66	for dt in $poolE $poolD $poolC $poolB $poolA; do
67		destroy_pool $dt
68	done
69
70	log_must $RM -rf $DEVICE_DIR/*
71	typeset i=0
72	while (( i < $MAX_NUM )); do
73		log_must create_vdevs ${DEVICE_DIR}/${DEVICE_FILE}$i
74		((i += 1))
75	done
76}
77
78log_assert "'zpool -D -a' can import all the specified directories " \
79	"destroyed pools."
80log_onexit cleanup
81
82poolA=poolA.${TESTCASE_ID}
83poolB=poolB.${TESTCASE_ID}
84poolC=poolC.${TESTCASE_ID}
85poolD=poolD.${TESTCASE_ID}
86poolE=poolE.${TESTCASE_ID}
87
88log_must $ZPOOL create $poolA mirror $VDEV0 $VDEV1 $VDEV2 $VDEV3 $VDEV4
89log_must $ZPOOL destroy $poolA
90
91log_must $ZPOOL create $poolB $VDEV1
92log_must $ZPOOL destroy $poolB
93
94log_must $ZPOOL create $poolC raidz2 $VDEV2 $VDEV3 $VDEV4
95log_must $ZPOOL destroy $poolC
96
97log_must $ZPOOL create $poolD raidz $VDEV3 $VDEV4
98log_must $ZPOOL destroy $poolD
99
100log_must $ZPOOL create $poolE $VDEV4
101log_must $ZPOOL destroy $poolE
102
103log_must $ZPOOL import -d $DEVICE_DIR -D -f -a
104
105for dt in $poolA $poolB $poolC $poolD $poolE; do
106	log_must datasetexists $dt
107done
108
109log_pass "'zpool -D -a' test passed."
110