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 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/include/libtest.kshlib
27. $STF_SUITE/tests/cli_root/zfs_create/properties.kshlib
28
29################################################################################
30#
31# __stc_assertion_start
32#
33# ID: zfs_create_010_neg
34#
35# DESCRIPTION:
36# 'zfs create [-b <blocksize> ] -V <size> <volume>' fails with badly formed
37# <size> or <volume> arguments,including:
38#	*Invalid volume size and volume name
39#	*Invalid blocksize
40#	*Incomplete component in the dataset tree
41#	*The volume already exists
42#	*The volume name beyond the maximal name length - 256.
43#       *Same property set multiple times via '-o property=value'
44#       *Filesystems's property set on volume
45#
46# STRATEGY:
47# 1. Create an array of badly formed arguments
48# 2. For each argument, execute 'zfs create -V <size> <volume>'
49# 3. Verify an error is returned.
50#
51# TESTABILITY: explicit
52#
53# TEST_AUTOMATION_LEVEL: automated
54#
55# CODING_STATUS: COMPLETED (2005-07-04)
56#
57# __stc_assertion_end
58#
59################################################################################
60
61verify_runnable "global"
62
63function cleanup
64{
65	typeset -i i
66	typeset found
67
68	#
69	# check to see if there is any new fs created during the test
70	# if so destroy it.
71	#
72	for dset in $($ZFS list -H | \
73		$AWK '{print $1}' | $GREP / ); do
74		found=false
75		i=0
76		while (( $i < ${#existed_fs[*]} )); do
77			if [[ $dset == ${existed_fs[i]} ]]; then
78				found=true
79				break
80			fi
81			(( i = i  + 1 ))
82		done
83
84		#
85		# new fs created during the test, cleanup it
86		#
87		if [[ $found == "false" ]]; then
88			log_must $ZFS destroy -f $dset
89		fi
90	done
91}
92
93log_onexit cleanup
94
95log_assert "Verify 'zfs create [-s] [-b <blocksize> ] -V <size> <volume>' fails with" \
96    "badly-formed <size> or <volume> arguments."
97
98set -A args "$VOLSIZE" "$TESTVOL1" \
99	"$VOLSIZE $TESTVOL1" "0 $TESTPOOL/$TESTVOL1" \
100	"-1gb $TESTPOOL/$TESTVOL1" "1g? $TESTPOOL/$TESTVOL1" \
101	"1.01BB $TESTPOOL/$TESTVOL1" "1%g $TESTPOOL/$TESTVOL1" \
102	"1g% $TESTPOOL/$TESTVOL1" "1g$ $TESTPOOL/$TESTVOL1" \
103	"$m $TESTPOOL/$TESTVOL1" "1m$ $TESTPOOL/$TESTVOL1" \
104	"1m! $TESTPOOL/$TESTVOL1" \
105	"1gbb $TESTPOOL/blah" "1blah $TESTPOOL/blah" "blah $TESTPOOL/blah" \
106	"$VOLSIZE $TESTPOOL" "$VOLSIZE $TESTPOOL/" "$VOLSIZE $TESTPOOL//blah"\
107	"$VOLSIZE $TESTPOOL/blah@blah" "$VOLSIZE $TESTPOOL/blah^blah" \
108	"$VOLSIZE $TESTPOOL/blah*blah" "$VOLSIZE $TESTPOOL/blah%blah" \
109	"$VOLSIZE blah" "$VOLSIZE $TESTPOOL/$BYND_MAX_NAME" \
110	"1m -b $TESTPOOL/$TESTVOL1" "1m -b 11k $TESTPOOL/$TESTVOL1" \
111	"1m -b 511 $TESTPOOL/$TESTVOL1" "1m -b 256k $TESTPOOL/$TESTVOL1"
112
113set -A options "" "-s"
114
115datasetexists $TESTPOOL/$TESTVOL || \
116		log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
117
118set -A existed_fs $($ZFS list -H | $AWK '{print $1}' | $GREP / )
119
120log_mustnot $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
121log_mustnot $ZFS create -s -V $VOLSIZE $TESTPOOL/$TESTVOL
122
123typeset -i i=0
124typeset -i j=0
125while (( i < ${#options[*]} )); do
126
127	j=0
128	while (( j < ${#args[*]} )); do
129		log_mustnot $ZFS create ${options[$i]} -V ${args[$j]}
130		log_mustnot $ZFS create -p ${options[$i]} -V ${args[$j]}
131
132		((j = j + 1))
133	done
134
135	j=0
136	while (( $j < ${#RW_VOL_PROP[*]} )); do
137        	log_mustnot $ZFS create ${options[$i]} -o ${RW_VOL_PROP[j]} \
138			-o ${RW_VOL_PROP[j]} -V $VOLSIZE $TESTPOOL/$TESTVOL1
139        	log_mustnot $ZFS create -p ${options[$i]} -o ${RW_VOL_PROP[j]} \
140			-o ${RW_VOL_PROP[j]} -V $VOLSIZE $TESTPOOL/$TESTVOL1
141		((j = j + 1))
142	done
143
144	j=0
145	while (( $j < ${#FS_ONLY_PROP[*]} )); do
146		log_mustnot $ZFS create ${options[$i]} -o ${FS_ONLY_PROP[j]} \
147			-V $VOLSIZE $TESTPOOL/$TESTVOL1
148		log_mustnot $ZFS create -p ${options[$i]} -o ${FS_ONLY_PROP[j]} \
149			-V $VOLSIZE $TESTPOOL/$TESTVOL1
150        	((j = j + 1))
151	done
152
153	((i = i + 1))
154done
155
156log_pass "'zfs create [-s][-b <blocksize>] -V <size> <volume>' fails as expected."
157