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 https://opensource.org/licenses/CDDL-1.0.
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 <filesystem>' fails with bad <filesystem> arguments, including:
39#	*Invalid character against the ZFS namespace
40#	*Incomplete component
41#	*Too many arguments
42#	*Filesystem already exists
43#	*Beyond maximal name length.
44#	*Same property set multiple times via '-o property=value'
45#	*Volume's property set on filesystem
46#	*Exceeding maximum name nesting
47#
48# STRATEGY:
49# 1. Create an array of <filesystem> arguments
50# 2. Execute 'zfs create <filesystem>' with each argument
51# 3. Verify an error is returned.
52#
53
54verify_runnable "both"
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 | awk '$1 ~ /\/ {print $1}'); do
66		found=false
67		i=0
68		while (( $i < ${#existed_fs[*]} )); do
69			if [[ $dset == ${existed_fs[i]} ]]; then
70				found=true
71				break
72			fi
73			(( i = i  + 1 ))
74		done
75
76		#
77		# new fs created during the test, cleanup it
78		#
79		if [[ $found == "false" ]]; then
80			log_must zfs destroy -f $dset
81		fi
82	done
83}
84
85log_onexit cleanup
86
87set -A args  "$TESTPOOL/" "$TESTPOOL//blah" "$TESTPOOL/@blah" \
88	"$TESTPOOL/blah@blah" "$TESTPOOL/blah^blah" "$TESTPOOL/blah%blah" \
89	"$TESTPOOL/blah*blah" "$TESTPOOL/blah blah" \
90	"-s $TESTPOOL/$TESTFS1" "-b 1092 $TESTPOOL/$TESTFS1" \
91	"-b 64k $TESTPOOL/$TESTFS1" "-s -b 32k $TESTPOOL/$TESTFS1" \
92	"$TESTPOOL/$BYND_MAX_NAME" "$TESTPOOL/$BYND_NEST_LIMIT" \
93	"$TESTPOOL/." "$TESTPOOL/.." "$TESTPOOL/../blah" "$TESTPOOL/./blah" \
94	"$TESTPOOL/blah/./blah" "$TESTPOOL/blah/../blah"
95
96log_assert "Verify 'zfs create <filesystem>' fails with bad <filesystem> argument."
97
98datasetexists $TESTPOOL/$TESTFS || \
99	log_must zfs create $TESTPOOL/$TESTFS
100
101set -A existed_fs $(zfs list -H | awk '$1 ~ /\// {print $1}')
102
103log_mustnot zfs create $TESTPOOL
104log_mustnot zfs create $TESTPOOL/$TESTFS
105
106typeset -i i=0
107while (( $i < ${#args[*]} )); do
108	log_mustnot zfs create ${args[$i]}
109	log_mustnot zfs create -p ${args[$i]}
110	((i = i + 1))
111done
112
113i=0
114while (( $i < ${#RW_FS_PROP[*]} )); do
115	log_mustnot zfs create -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \
116		$TESTPOOL/$TESTFS1
117	log_mustnot zfs create -p -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \
118		$TESTPOOL/$TESTFS1
119	((i = i + 1))
120done
121
122i=0
123while (( $i < ${#VOL_ONLY_PROP[*]} )); do
124	log_mustnot zfs create -o ${VOL_ONLY_PROP[i]} $TESTPOOL/$TESTFS1
125	log_mustnot zfs create -p -o ${VOL_ONLY_PROP[i]} $TESTPOOL/$TESTFS1
126	((i = i + 1))
127done
128
129log_pass "'zfs create <filesystem>' fails as expected with bad <filesystem> argument."
130