xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_009_neg.ksh (revision a61ed2ce7a86a4d6428f2a83eb4739fae945447e)
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 <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 | \
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
88set -A args  "$TESTPOOL/" "$TESTPOOL//blah" "$TESTPOOL/@blah" \
89	"$TESTPOOL/blah@blah" "$TESTPOOL/blah^blah" "$TESTPOOL/blah%blah" \
90	"$TESTPOOL/blah*blah" "$TESTPOOL/blah blah" \
91	"-s $TESTPOOL/$TESTFS1" "-b 1092 $TESTPOOL/$TESTFS1" \
92	"-b 64k $TESTPOOL/$TESTFS1" "-s -b 32k $TESTPOOL/$TESTFS1" \
93	"$TESTPOOL/$BYND_MAX_NAME" "$TESTPOOL/$BYND_NEST_LIMIT"
94
95log_assert "Verify 'zfs create <filesystem>' fails with bad <filesystem> argument."
96
97datasetexists $TESTPOOL/$TESTFS || \
98	log_must zfs create $TESTPOOL/$TESTFS
99
100set -A existed_fs $(zfs list -H | awk '{print $1}' | grep / )
101
102log_mustnot zfs create $TESTPOOL
103log_mustnot zfs create $TESTPOOL/$TESTFS
104
105typeset -i i=0
106while (( $i < ${#args[*]} )); do
107	log_mustnot zfs create ${args[$i]}
108	log_mustnot zfs create -p ${args[$i]}
109	((i = i + 1))
110done
111
112i=0
113while (( $i < ${#RW_FS_PROP[*]} )); do
114	log_mustnot zfs create -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \
115		$TESTPOOL/$TESTFS1
116	log_mustnot zfs create -p -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \
117		$TESTPOOL/$TESTFS1
118	((i = i + 1))
119done
120
121i=0
122while (( $i < ${#VOL_ONLY_PROP[*]} )); do
123	log_mustnot zfs create -o ${VOL_ONLY_PROP[i]} $TESTPOOL/$TESTFS1
124	log_mustnot zfs create -p -o ${VOL_ONLY_PROP[i]} $TESTPOOL/$TESTFS1
125	((i = i + 1))
126done
127
128log_pass "'zfs create <filesystem>' fails as expected with bad <filesystem> argument."
129