4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
28 # Copyright (c) 2014 by Delphix. All rights reserved.
31 . $STF_SUITE/include/libtest.shlib
33 set -A VALID_NAME_CHAR a b c d e f g h i j k l m n o p q r s t u v w x y z \
34 0 1 2 3 4 5 6 7 8 9 ':' '-' '.' '_'
35 set -A INVALID_NAME_CHAR A B C D E F G H I J K L M N O P Q R S T U V W X Y Z \
36 '`' '~' '!' '@' '#' '$' '%' '^' '&' '(' ')' '+' '=' '|' "\\" '{' '[' ']' \
37 '}' ';' '"' '<' ',' '>' '?' '/' ' '
38 set -A ALL_CHAR ${VALID_NAME_CHAR[*]} ${INVALID_NAME_CHAR[*]}
41 # Firstly, set the property value to dataset. Then checking if the property
42 # value is equal with the expected value, according to the expected result.
49 function set_n_check_prop
51 typeset expect_value=$1
54 typeset expect_result=${4:-true}
59 [[ -n $prop ]] && old_value=$(get_prop $prop $dataset)
61 if [[ $expect_result == true ]]; then
62 [[ -z $prop || -z $dataset ]] && \
63 log_fail "property or dataset isn't defined."
65 log_must $ZFS set $prop=$expect_value $dataset
66 if [[ $expect_value == "gzip-6" ]]; then
70 [[ -n $prop ]] && cur_value=$(get_prop $prop $dataset)
73 reservation|reserv|quota )
74 if [[ $expect_value == "none" ]]; then
75 [[ $cur_value != "0" ]] && \
76 log_fail "The '$dataset' '$prop' value \
77 '$cur_value' is not expected."
78 elif [[ $cur_value != $expect_value ]]; then
79 log_fail "The '$dataset' '$prop' value '$cur_value' \
80 does not equal the expected value '$expect_value'."
84 if [[ $cur_value != $expect_value ]]; then
85 log_fail "The '$dataset' '$prop' value '$cur_value' \
86 does not equal the expected value '$expect_value'."
92 log_mustnot $ZFS set $prop=$expect_value $dataset
94 [[ -n $prop ]] && cur_value=$(get_prop $prop $dataset)
96 if [[ "$expect_value" != "" && "$cur_value" != "$old_value" ]];
98 log_fail "The '$dataset' '$prop' value '$cur_value' \
99 should equal with '$old_value'."
105 # Cleanup all the user properties of the pool and the dataset reside it.
109 function cleanup_user_prop
112 typeset dtst=$($ZFS list -H -r -o name -t filesystem,volume $pool)
116 user_prop=$($ZFS get -H -o property all $dtst | grep ":")
119 for prop in $user_prop; do
120 $ZFS inherit $prop $dt
121 (($? != 0)) && log_must $ZFS inherit $prop $dt
127 # Random select charactor from the specified charactor set and combine into a
130 # $1 character set name
133 function random_string
135 typeset char_set=${1:-VALID_NAME_CHAR}
136 typeset -i len=${2:-5}
138 eval typeset -i count=\${#$char_set[@]}
140 # No consumers want an empty string.
141 ((len == 0)) && len=3
145 while ((i < len)); do
147 ((ind = RANDOM % count))
148 eval str=\${str}\${$char_set[\$ind]}
157 # Get vaild user defined property name
159 # $1 user defined property name length
161 function valid_user_property
163 typeset -i sumlen=${1:-10}
164 ((sumlen < 2 )) && sumlen=2
166 ((len = RANDOM % sumlen))
170 part1="$(random_string VALID_NAME_CHAR $len)"
171 if [[ "$part1" == "-"* ]]; then
176 ((len = sumlen - (len + 1)))
179 part2="$(random_string VALID_NAME_CHAR $len)"
180 if [[ -z $part1 && -z $part2 ]]; then
186 $ECHO "${part1}:${part2}"
190 # Get invaild user defined property name
192 # $1 user defined property name length
194 function invalid_user_property
196 typeset -i sumlen=${1:-10}
197 ((sumlen == 0)) && sumlen=1
199 ((len = RANDOM % sumlen))
203 part1="$(random_string VALID_NAME_CHAR $len)"
204 ((len = sumlen - len))
205 part2="$(random_string INVALID_NAME_CHAR $len)"
207 # Avoid $part1 is *:* and $part2 is "=*"
208 if [[ "$part1" == *":"* && "$part2" == "="* ]]; then
214 $ECHO "${part1}${part2}"
218 # Get user property value
220 # $1 user defined property name length
222 function user_property_value
224 typeset -i len=${1:-100}
226 typeset value=$(random_string ALL_CHAR $len)
232 # Check if the user property is identical to the expected value.
238 function check_user_prop
241 typeset user_prop="$2"
242 typeset expect_value="$3"
243 typeset value=$($ZFS get -p -H -o value "$user_prop" $dtst 2>&1)
245 if [[ "$expect_value" == "$value" ]]; then
253 # Get source of the dataset
261 source=$($ZFS get -H -o source $prop $dataset)
263 log_fail "Unable to get $prop source for dataset $dataset"