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