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. $STF_SUITE/include/libtest.kshlib
28
29#################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zpool_create_009_neg
34#
35# DESCRIPTION:
36#	Create a pool with same devices twice or create two pools with same
37#	devices, 'zpool create' should failed.
38#
39# STRATEGY:
40#	1. Loop to create the following three kinds of pools.
41#		- Regular pool
42#		- Mirror
43#		- Raidz
44#	2. Create two pools but using the same disks, expect failed.
45#	3. Create one pool but using the same disks twice, expect failed.
46#
47# TESTABILITY: explicit
48#
49# TEST_AUTOMATION_LEVEL: automated
50#
51# CODING_STATUS: COMPLETED (2005-08-15)
52#
53# __stc_assertion_end
54#
55################################################################################
56
57verify_runnable "global"
58
59function cleanup
60{
61	typeset dtst
62	typeset disk
63
64	for dtst in $TESTPOOL $TESTPOOL1; do
65		poolexists $dtst && destroy_pool $dtst
66	done
67}
68
69log_assert "Create a pool with same devices twice or create two pools with " \
70	"same devices, 'zpool create' should fail."
71log_onexit cleanup
72
73typeset opt
74for opt in "" "mirror" "raidz" "raidz1"; do
75	typeset disk="$DISKS"
76	(( ${#opt} == 0 )) && disk=${DISKS%% *}
77
78	typeset -i count=$(get_word_count "$disk")
79	if (( count < 2  && ${#opt} != 0 )) ; then
80		continue
81	fi
82
83	# Create two pools but using the same disks.
84	create_pool $TESTPOOL $opt $disk
85	log_mustnot $ZPOOL create -f $TESTPOOL1 $opt $disk
86	destroy_pool $TESTPOOL
87
88	# Create two pools and part of the devices were overlapped
89	create_pool $TESTPOOL $opt $disk
90	log_mustnot $ZPOOL create -f $TESTPOOL1 $opt ${DISKS% *}
91	destroy_pool $TESTPOOL
92
93	# Create one pool but using the same disks twice.
94	log_mustnot $ZPOOL create -f $TESTPOOL $opt $disk $disk
95done
96
97log_pass "Using overlapping or in-use disks to create a new pool fails as expected."
98