Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zfs_set/ro_props_001_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zfs_set/ro_props_001_pos.ksh (revision 292304) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zfs_set/ro_props_001_pos.ksh (revision 292305) @@ -1,129 +1,135 @@ #!/usr/local/bin/ksh93 -p # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)ro_props_001_pos.ksh 1.4 07/10/09 SMI" # . $STF_SUITE/include/libtest.kshlib . $STF_SUITE/tests/cli_root/zfs_set/zfs_set_common.kshlib ############################################################################### # # __stc_assertion_start # # ID: ro_props_001_pos # # DESCRIPTION: # Verify that read-only properties are immutable. # # STRATEGY: # 1. Create pool, fs, vol, fs@snap & vol@snap. # 2. Get the original property value and set value to those properties. # 3. Check return value. # 4. Compare the current property value with the original one. # # TESTABILITY: explicit # # TEST_AUTOMATION_LEVEL: automated # # CODING_STATUS: COMPLETED (2005-07-04) # # __stc_assertion_end # ################################################################################ verify_runnable "both" set -A values filesystem volume snapshot -3 0 1 50K 10G 80G \ 2005/06/17 30K 20x yes no \ on off default pool/fs@snap $TESTDIR set -A dataset $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS@$TESTSNAP \ $TESTPOOL/$TESTVOL@$TESTSNAP typeset ro_props="type used available avail creation referenced refer compressratio \ mounted origin" typeset snap_ro_props="volsize recordsize recsize quota reservation reserv mountpoint \ sharenfs checksum compression compress atime devices exec readonly rdonly \ setuid" $ZFS upgrade -v > /dev/null 2>&1 if [[ $? -eq 0 ]]; then snap_ro_props="$snap_ro_props version" fi function cleanup { datasetexists $TESTPOOL/$TESTVOL@$TESTSNAP && \ destroy_snapshot $TESTPOOL/$TESTVOL@$TESTSNAP datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ destroy_snapshot $TESTPOOL/$TESTFS@$TESTSNAP } log_assert "Verify that read-only properties are immutable." log_onexit cleanup # Create filesystem and volume's snapshot create_snapshot $TESTPOOL/$TESTFS $TESTSNAP create_snapshot $TESTPOOL/$TESTVOL $TESTSNAP +# Make sure any history logs have been synced. They're asynchronously +# pushed to the syncing context, and could influence the value of some +# properties on $TESTPOOL, like 'used'. Fetching it here forces the sync, +# per spa_history.c:spa_history_get(). +log_must $ZPOOL history $TESTPOOL + typeset -i i=0 typeset -i j=0 typeset cur_value="" typeset props="" while (( i < ${#dataset[@]} )); do props=$ro_props dst_type=$(get_prop type ${dataset[i]}) if [[ $dst_type == 'snapshot' ]]; then props="$ro_props $snap_ro_props" fi for prop in $props; do cur_value=$(get_prop $prop ${dataset[i]}) j=0 while (( j < ${#values[@]} )); do # # If the current property value is equal to values[j], # just expect it failed. Otherwise, set it to dataset, # expecting it failed and the property value is not # equal to values[j]. # if [[ $cur_value == ${values[j]} ]]; then log_mustnot $ZFS set $prop=${values[j]} \ ${dataset[i]} else set_n_check_prop ${values[j]} $prop \ ${dataset[i]} false fi (( j += 1 )) done done (( i += 1 )) done -log_pass "Setting uneditable properties should failed. It passed." +log_pass "Setting uneditable properties fail, as required." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_common.kshlib =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_common.kshlib (revision 292304) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zfs_set/zfs_set_common.kshlib (revision 292305) @@ -1,264 +1,247 @@ # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # ident "@(#)zfs_set_common.kshlib 1.7 09/05/19 SMI" # . $STF_SUITE/include/libtest.kshlib 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 \ 0 1 2 3 4 5 6 7 8 9 ':' '-' '.' '_' 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 \ '`' '~' '!' '@' '#' '$' '%' '^' '&' '(' ')' '+' '=' \ '|' '{' '[' ']' '}' ';' '"' '<' ',' '>' '?' '/' \ ' ' set -A ALL_CHAR ${VALID_NAME_CHAR[*]} ${INVALID_NAME_CHAR[*]} # # Firstly, set the property value to dataset. Then checking if the property # value is equal with the expected value, according to the expected result. # # $1 property value # $2 property name # $3 dataset # $4 expected result # function set_n_check_prop { typeset expect_value=$1 typeset prop=$2 typeset dataset=$3 typeset expect_result=${4:-true} - typeset old_value="" - typeset cur_value="" - - [[ -n $prop ]] && old_value=$(get_prop $prop $dataset) - - if [[ $expect_result == true ]]; then - [[ -z $prop || -z $dataset ]] && \ - log_fail "property or dataset isn't defined." - + typeset old_value=$(get_prop $prop $dataset) + if [ "$expect_result" = "true" ]; then log_must $ZFS set $prop=$expect_value $dataset - if [[ $expect_value == "gzip-6" ]]; then - expect_value="gzip" - fi - - [[ -n $prop ]] && cur_value=$(get_prop $prop $dataset) - - case $prop in - reservation|reserv|quota ) - if [[ $expect_value == "none" ]]; then - [[ $cur_value != "0" ]] && \ - log_fail "The '$dataset' '$prop' value \ - '$cur_value' is not expected." - elif [[ $cur_value != $expect_value ]]; then - log_fail "The '$dataset' '$prop' value '$cur_value' \ - does not equal the expected value '$expect_value'." - fi - ;; - * ) - if [[ $cur_value != $expect_value ]]; then - log_fail "The '$dataset' '$prop' value '$cur_value' \ - does not equal the expected value '$expect_value'." - fi - ;; - esac - else log_mustnot $ZFS set $prop=$expect_value $dataset + fi + typeset cur_value=$(get_prop $prop $dataset) - [[ -n $prop ]] && cur_value=$(get_prop $prop $dataset) - - if [[ "$expect_value" != "" && "$cur_value" != "$old_value" ]]; - then - log_fail "The '$dataset' '$prop' value '$cur_value' \ - should equal with '$old_value'." + err="ERROR: Dataset '$dataset': '$prop' value '$cur_value'" + if [ "$expect_result" = "true" ]; then + case "$prop" in + reservation|reserv|quota) + if [ "$expect_value" = "none" -a "$cur_value" != "0" ]; then + err="$err should not be set!" + log_fail "$err" + return + fi + ;; + esac + if [ "$cur_value" != "$expect_value" ]; then + err="$err should have changed to '$expect_value'!" + log_fail "$err" + fi + else + if [ "$expect_value" != "" -a "$cur_value" != "$old_value" ]; then + err="$err should be unchanged at '$old_value'!" + log_fail "$err" fi fi } # # Cleanup all the user properties of the pool and the dataset reside it. # # $1 pool name # function cleanup_user_prop { typeset pool=$1 typeset dtst=$($ZFS list -H -r -o name -t filesystem,volume $pool) typeset user_prop for dt in $dtst; do user_prop=$($ZFS get -H -o property all $dtst | grep ":") typeset prop for prop in $user_prop; do $ZFS inherit $prop $dt (($? != 0)) && log_must $ZFS inherit $prop $dt done done } # # Random select charactor from the specified charactor set and combine into a # random string # # $1 character set name # $2 String length # function random_string { typeset char_set=${1:-VALID_NAME_CHAR} typeset -i len=${2:-5} eval typeset -i count=\${#$char_set[@]} typeset str typeset -i i=0 while ((i < len)); do typeset -i ind ((ind = RANDOM % count)) eval str=\${str}\${$char_set[\$ind]} ((i += 1)) done $ECHO "$str" } # # Get vaild user defined property name # # $1 user defined property name length # function valid_user_property { typeset -i sumlen=${1:-10} ((sumlen < 2 )) && sumlen=2 typeset -i len ((len = RANDOM % sumlen)) typeset part1 part2 while true; do part1="$(random_string VALID_NAME_CHAR $len)" if [[ "$part1" == "-"* ]]; then continue fi break done ((len = sumlen - (len + 1))) while true; do part2="$(random_string VALID_NAME_CHAR $len)" if [[ -z $part1 && -z $part2 ]]; then continue fi break done $ECHO "${part1}:${part2}" } # # Get invaild user defined property name # # $1 user defined property name length # function invalid_user_property { typeset -i sumlen=${1:-10} ((sumlen == 0)) && sumlen=1 typeset -i len ((len = RANDOM % sumlen)) typeset part1 part2 while true; do part1="$(random_string VALID_NAME_CHAR $len)" ((len = sumlen - len)) part2="$(random_string INVALID_NAME_CHAR $len)" # Avoid $part1 is *:* and $part2 is "=*" if [[ "$part1" == *":"* && "$part2" == "="* ]]; then continue fi break done $ECHO "${part1}${part2}" } # # Get user property value # # $1 user defined property name length # function user_property_value { typeset -i len=${1:-100} ((len < 1 )) && len=1 typeset value=$(random_string ALL_CHAR $len) $ECHO "$value" } # # Check if the user property is identical to the expected value. # # $1 dataset # $2 user property # $3 expected value # function check_user_prop { typeset dtst=$1 typeset user_prop="$2" typeset expect_value="$3" typeset value=$($ZFS get -p -H -o value "$user_prop" $dtst 2>&1) if [[ "$expect_value" == "$value" ]]; then return 0 else return 1 fi } # # Get source of the dataset # function get_source { typeset prop=$1 typeset dataset=$2 typeset source source=$($ZFS get -H -o source $prop $dataset) if (($? != 0)); then log_fail "Unable to get $prop source for dataset $dataset" fi $ECHO "$source" }