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, 2016 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)
98 if [[ "$expect_value" != "" && "$cur_value" != "$old_value" ]];
100 log_fail "The '$dataset' '$prop' value '$cur_value' \
101 should equal with '$old_value'."
107 # Cleanup all the user properties of the pool and the dataset reside it.
111 function cleanup_user_prop
114 typeset dtst=$(zfs list -H -r -o name -t filesystem,volume $pool)
118 user_prop=$(zfs get -H -o property all $dtst | grep ":")
121 for prop in $user_prop; do
122 zfs inherit $prop $dt
123 (($? != 0)) && log_must zfs inherit $prop $dt
129 # Random select character from the specified character set and combine into a
132 # $1 character set name
135 function random_string
137 typeset char_set=${1:-VALID_NAME_CHAR}
138 typeset -i len=${2:-5}
140 eval typeset -i count=\${#$char_set[@]}
142 # No consumers want an empty string.
143 ((len == 0)) && len=3
147 while ((i < len)); do
149 ((ind = RANDOM % count))
150 eval str=\${str}\${$char_set[\$ind]}
159 # Get valid user defined property name
161 # $1 user defined property name length
163 function valid_user_property
165 typeset -i sumlen=${1:-10}
166 ((sumlen < 2 )) && sumlen=2
168 ((len = RANDOM % sumlen))
172 part1="$(random_string VALID_NAME_CHAR $len)"
173 if [[ "$part1" == "-"* ]]; then
178 ((len = sumlen - (len + 1)))
181 part2="$(random_string VALID_NAME_CHAR $len)"
182 if [[ -z $part1 && -z $part2 ]]; then
188 echo "${part1}:${part2}"
192 # Get invalid user defined property name
194 # $1 user defined property name length
196 function invalid_user_property
198 typeset -i sumlen=${1:-10}
199 ((sumlen == 0)) && sumlen=1
201 ((len = RANDOM % sumlen))
205 part1="$(random_string VALID_NAME_CHAR $len)"
206 ((len = sumlen - len))
207 part2="$(random_string INVALID_NAME_CHAR $len)"
209 # Avoid $part1 is *:* and $part2 is "=*"
210 if [[ "$part1" == *":"* && "$part2" == "="* ]]; then
216 echo "${part1}${part2}"
220 # Get user property value
222 # $1 user defined property name length
224 function user_property_value
226 typeset -i len=${1:-100}
228 typeset value=$(random_string ALL_CHAR $len)
234 # Check if the user property is identical to the expected value.
240 function check_user_prop
243 typeset user_prop="$2"
244 typeset expect_value="$3"
245 typeset value=$(zfs get -p -H -o value "$user_prop" $dtst 2>&1)
247 if [[ "$expect_value" == "$value" ]]; then
255 # Get source of the dataset
263 source=$(zfs get -H -o source $prop $dataset)
265 log_fail "Unable to get $prop source for dataset $dataset"
272 # Verify property $2 is set from source $4 on dataset $1 and has value $3.
279 # Returns: 0 if both expected source and value match, 1 otherwise
281 function check_prop_source
287 typeset chk_value=$(get_prop "$prop" "$dataset")
288 typeset chk_source=$(get_source "$prop" "$dataset")
290 if [[ "$chk_value" != "$value" || "$chk_source" != "$4" ]]
299 # Verify target dataset $1 inherit property $2 from dataset $3.
303 # $3 inherited dataset
305 # Returns: 0 if property has expected value and is inherited, 1 otherwise
307 function check_prop_inherit
309 typeset checked_dtst="$1"
311 typeset inherited_dtst="$3"
312 typeset inherited_value=$(get_prop "$prop" "$inherited_dtst")
313 typeset value=$(get_prop "$prop" "$checked_dtst")
314 typeset source=$(get_source "$prop" "$checked_dtst")
316 if [[ "$value" != "$inherited_value" || \
317 "$source" != "inherited from $inherited_dtst" ]]
326 # Verify property $2 received value on dataset $1 has value $3
332 # Returns: 0 if property has expected value and is received, 1 otherwise
334 function check_prop_received
340 received=$(zfs get -H -o received "$prop" "$dataset")
342 log_fail "Unable to get $prop received value for dataset " \
345 if [[ "$received" == "$value" ]]
354 # Verify user property $2 is not set on dataset $1
359 # Returns: 0 if property is missing (not set), 1 otherwise
361 function check_prop_missing
366 value=$(zfs get -H -o value "$prop" "$dataset")
368 log_fail "Unable to get $prop value for dataset $dataset"
370 if [[ "-" == "$value" ]]