]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/pool_names/pool_names_002_neg.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / pool_names / pool_names_002_neg.ksh
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 2008 Sun Microsystems, Inc.  All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/include/libtest.shlib
33
34 #
35 # DESCRIPTION:
36 #
37 # Ensure that a set of invalid names cannot be used to create pools.
38 #
39 # STRATEGY:
40 # 1) For each invalid character in the character set, try to create
41 # and destroy the pool. Verify it fails.
42 # 2) Given a list of invalid pool names, ensure the pools are not
43 # created.
44 #
45
46 verify_runnable "global"
47
48 log_assert "Ensure that a set of invalid names cannot be used to create pools."
49
50 # Global variable use to cleanup failures.
51 POOLNAME=""
52
53 function cleanup
54 {
55         if poolexists $POOLNAME; then
56                 log_must zpool destroy $POOLNAME
57         fi
58
59         if [[ -d $TESTDIR ]]; then
60                 log_must rm -rf $TESTDIR
61         fi
62 }
63
64 log_onexit cleanup
65
66 for pool in $(get_all_pools); do
67         if [[ "$pool" != "$TESTPOOL" ]]; then
68                 log_must zpool destroy $pool
69         fi
70 done
71
72 DISK=${DISKS%% *}
73 if [[ ! -e $TESTDIR ]]; then
74         log_must mkdir $TESTDIR
75 fi
76
77 log_note "Ensure invalid characters fail"
78 for POOLNAME in "!" "\"" "#" "$" "%" "&" "'" "(" ")" \
79     "\*" "+" "," "-" "\." "/" "\\" \
80     0 1 2 3 4 5 6 7 8 9 \
81     ":" ";" "<" "=" ">" "\?" "@" \
82     "[" "]" "^" "_" "\`" "{" "|" "}" "~"
83 do
84         log_mustnot zpool create -m $TESTDIR $POOLNAME $DISK
85         if poolexists $POOLNAME; then
86                 log_fail "Unexpectedly created pool: '$POOLNAME'"
87         fi
88
89         log_mustnot zpool destroy $POOLNAME
90 done
91
92 log_note "Check that invalid octal values fail"
93 for oct in "\000" "\001" "\002" "\003" "\004" "\005" "\006" "\007" \
94     "\010" "\011" "\012" "\013" "\014" "\015" "\017" \
95     "\020" "\021" "\022" "\023" "\024" "\025" "\026" "\027" \
96     "\030" "\031" "\032" "\033" "\034" "\035" "\036" "\037" \
97     "\040" "\177"
98 do
99         POOLNAME=`eval "echo x | tr 'x' '$oct'"`
100         log_mustnot zpool create -m $TESTDIR $POOLNAME $DISK
101         if poolexists $POOLNAME; then
102                 log_fail "Unexpectedly created pool: '$POOLNAME'"
103         fi
104
105         log_mustnot zpool destroy $POOLNAME
106 done
107
108 log_note "Verify invalid pool names fail"
109 set -A POOLNAME "c0t0d0s0" "c0t0d0" "c0t0d19" "c0t50000E0108D279d0" \
110     "mirror" "raidz" ",," ",,,,,,,,,,,,,,,,,,,,,,,,," \
111     "2222222222222222222" "mirror_pool" "raidz_pool" \
112     "mirror-pool" "raidz-pool" "spare" "spare_pool" \
113     "spare-pool" "raidz1-" "raidz2:" ":aaa" "-bbb" "_ccc" ".ddd"
114 if verify_slog_support ; then
115         POOLNAME[${#POOLNAME[@]}]='log'
116 fi
117 typeset -i i=0
118 while ((i < ${#POOLNAME[@]})); do
119         log_mustnot zpool create -m $TESTDIR ${POOLNAME[$i]} $DISK
120         if poolexists ${POOLNAME[$i]}; then
121                 log_fail "Unexpectedly created pool: '${POOLNAME[$i]}'"
122         fi
123
124         log_mustnot zpool destroy ${POOLNAME[$i]}
125
126         ((i += 1))
127 done
128
129 log_pass "Invalid names and characters were caught correctly"