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#
29# Copyright (c) 2012, 2015 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/cli_root/zpool_create/zpool_create.shlib
34
35#
36# DESCRIPTION:
37# 'zpool create <pool> <vspec> ...' can successfully create a
38# new pool with a name in ZFS namespace.
39#
40# STRATEGY:
41# 1. Create storage pools with a name in ZFS namespace with different
42# vdev specs.
43# 2. Verify the pool created successfully
44#
45
46verify_runnable "global"
47
48function cleanup
49{
50	poolexists $TESTPOOL && destroy_pool $TESTPOOL
51
52	clean_blockfile "$TESTDIR0 $TESTDIR1"
53
54	if [[ -n $DISK ]]; then
55		partition_disk $((($MINVDEVSIZE / (1024 * 1024)) * 3))m $DISK 7
56	else
57		typeset disk=""
58		for disk in $DISK0 $DISK1; do
59			partition_disk \
60			    $((($MINVDEVSIZE / (1024 * 1024)) * 3))m $disk 7
61		done
62	fi
63}
64
65log_assert "'zpool create <pool> <vspec> ...' can successfully create" \
66	"a new pool with a name in ZFS namespace."
67
68log_onexit cleanup
69
70set -A keywords "" "mirror" "raidz" "raidz1"
71
72case $DISK_ARRAY_NUM in
730|1)
74	typeset disk=""
75	if (( $DISK_ARRAY_NUM == 0 )); then
76		disk=$DISK
77	else
78		disk=$DISK0
79	fi
80	create_blockfile $FILESIZE $TESTDIR0/$FILEDISK0 ${disk}s${SLICE5}
81        create_blockfile $FILESIZE $TESTDIR1/$FILEDISK1 ${disk}s${SLICE6}
82
83	pooldevs="${disk}s${SLICE0} \
84                  /dev/dsk/${disk}s${SLICE0} \
85                  \"${disk}s${SLICE0} ${disk}s${SLICE1}\" \
86                  $TESTDIR0/$FILEDISK0"
87	raidzdevs="\"/dev/dsk/${disk}s${SLICE0} ${disk}s${SLICE1}\" \
88                   \"${disk}s${SLICE0} ${disk}s${SLICE1} ${disk}s${SLICE3}\" \
89                   \"${disk}s${SLICE0} ${disk}s${SLICE1} ${disk}s${SLICE3} \
90                     ${disk}s${SLICE4}\"\
91                   \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\""
92	mirrordevs=$raidzdevs
93	;;
942|*)
95	create_blockfile $FILESIZE $TESTDIR0/$FILEDISK0 ${DISK0}s${SLICE5}
96        create_blockfile $FILESIZE $TESTDIR1/$FILEDISK1 ${DISK1}s${SLICE5}
97
98	pooldevs="${DISK0}s${SLICE0}\
99                 \"/dev/dsk/${DISK0}s${SLICE0} ${DISK1}s${SLICE0}\" \
100                 \"${DISK0}s${SLICE0} ${DISK0}s${SLICE1} ${DISK1}s${SLICE1}\"\
101                 \"${DISK0}s${SLICE0} ${DISK1}s${SLICE0} ${DISK0}s${SLICE1}\
102                   ${DISK1}s${SLICE1}\" \
103                 \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\""
104	raidzdevs="\"/dev/dsk/${DISK0}s${SLICE0} ${DISK1}s${SLICE0}\" \
105                 \"${DISK0}s${SLICE0} ${DISK0}s${SLICE1} ${DISK1}s${SLICE1}\"\
106                 \"${DISK0}s${SLICE0} ${DISK1}s${SLICE0} ${DISK0}s${SLICE1}\
107                   ${DISK1}s${SLICE1}\" \
108                 \"$TESTDIR0/$FILEDISK0 $TESTDIR1/$FILEDISK1\""
109	mirrordevs=$raidzdevs
110	;;
111esac
112
113typeset -i i=0
114while (( $i < ${#keywords[*]} )); do
115	case ${keywords[i]} in
116	"")
117		create_pool_test "$TESTPOOL" "${keywords[i]}" "$pooldevs";;
118	mirror)
119		create_pool_test "$TESTPOOL" "${keywords[i]}" "$mirrordevs";;
120	raidz|raidz1)
121		create_pool_test "$TESTPOOL" "${keywords[i]}" "$raidzdevs" ;;
122	esac
123	(( i = i+1 ))
124done
125
126log_pass "'zpool create <pool> <vspec> ...' success."
127