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 [-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 | 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 87log_assert "Verify 'zfs create [-s] [-b <blocksize> ] -V <size> <volume>' fails with" \ 88 "badly-formed <size> or <volume> arguments." 89 90set -A args "$VOLSIZE" "$TESTVOL1" \ 91 "$VOLSIZE $TESTVOL1" "0 $TESTPOOL/$TESTVOL1" \ 92 "-1gb $TESTPOOL/$TESTVOL1" "1g? $TESTPOOL/$TESTVOL1" \ 93 "1.01BB $TESTPOOL/$TESTVOL1" "1%g $TESTPOOL/$TESTVOL1" \ 94 "1g% $TESTPOOL/$TESTVOL1" "1g$ $TESTPOOL/$TESTVOL1" \ 95 "$m $TESTPOOL/$TESTVOL1" "1m$ $TESTPOOL/$TESTVOL1" \ 96 "1m! $TESTPOOL/$TESTVOL1" \ 97 "1gbb $TESTPOOL/blah" "1blah $TESTPOOL/blah" "blah $TESTPOOL/blah" \ 98 "$VOLSIZE $TESTPOOL" "$VOLSIZE $TESTPOOL/" "$VOLSIZE $TESTPOOL//blah"\ 99 "$VOLSIZE $TESTPOOL/blah@blah" "$VOLSIZE $TESTPOOL/blah^blah" \ 100 "$VOLSIZE $TESTPOOL/blah*blah" "$VOLSIZE $TESTPOOL/blah%blah" \ 101 "$VOLSIZE blah" "$VOLSIZE $TESTPOOL/$BYND_MAX_NAME" \ 102 "1m -b $TESTPOOL/$TESTVOL1" "1m -b 11k $TESTPOOL/$TESTVOL1" \ 103 "1m -b 511 $TESTPOOL/$TESTVOL1" 104 105set -A options "" "-s" 106 107datasetexists $TESTPOOL/$TESTVOL || \ 108 log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL 109 110set -A existed_fs $(zfs list -H | awk '$1 ~ /\// {print $1}') 111 112log_mustnot zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL 113log_mustnot zfs create -s -V $VOLSIZE $TESTPOOL/$TESTVOL 114 115typeset -i i=0 116typeset -i j=0 117while (( i < ${#options[*]} )); do 118 119 j=0 120 while (( j < ${#args[*]} )); do 121 log_mustnot zfs create ${options[$i]} -V ${args[$j]} 122 log_mustnot zfs create -p ${options[$i]} -V ${args[$j]} 123 124 ((j = j + 1)) 125 done 126 127 j=0 128 while (( $j < ${#RW_VOL_PROP[*]} )); do 129 log_mustnot zfs create ${options[$i]} -o ${RW_VOL_PROP[j]} \ 130 -o ${RW_VOL_PROP[j]} -V $VOLSIZE $TESTPOOL/$TESTVOL1 131 log_mustnot zfs create -p ${options[$i]} -o ${RW_VOL_PROP[j]} \ 132 -o ${RW_VOL_PROP[j]} -V $VOLSIZE $TESTPOOL/$TESTVOL1 133 ((j = j + 1)) 134 done 135 136 j=0 137 while (( $j < ${#FS_ONLY_PROP[*]} )); do 138 log_mustnot zfs create ${options[$i]} -o ${FS_ONLY_PROP[j]} \ 139 -V $VOLSIZE $TESTPOOL/$TESTVOL1 140 log_mustnot zfs create -p ${options[$i]} -o ${FS_ONLY_PROP[j]} \ 141 -V $VOLSIZE $TESTPOOL/$TESTVOL1 142 ((j = j + 1)) 143 done 144 145 ((i = i + 1)) 146done 147 148log_pass "'zfs create [-s][-b <blocksize>] -V <size> <volume>' fails as expected." 149