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 (c) 2009, Sun Microsystems Inc. All rights reserved. 25# Copyright (c) 2016, 2017, Delphix. All rights reserved. 26# Use is subject to license terms. 27# 28 29. $STF_SUITE/include/properties.shlib 30. $STF_SUITE/include/libtest.shlib 31. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib 32 33# 34# DESCRIPTION: 35# Verify the properties with aliases also work with those aliases 36# 37# STRATEGY: 38# 1. Create pool, then create filesystem & volume within it. 39# 2. Set or retrieve property via alias with datasets. 40# 3. Verify the result should be successful. 41# 42 43verify_runnable "both" 44 45function set_and_check #<dataset><set_prop_name><set_value><check_prop_name> 46{ 47 typeset ds=$1 48 typeset setprop=$2 49 typeset setval=$3 50 typeset chkprop=$4 51 typeset getval 52 53 log_must zfs set $setprop=$setval $ds 54 if [[ $setval == "gzip-6" ]]; then 55 setval="gzip" 56 fi 57 getval=$(get_prop $chkprop $ds) 58 59 case $setprop in 60 reservation|reserv ) 61 if [[ $setval == "none" ]]; then 62 [[ $getval != "0" ]] && \ 63 log_fail "Setting the property $setprop" \ 64 "with value $setval fails." 65 elif [[ $getval != $setval ]]; then 66 log_fail "Setting the property $setprop with" \ 67 "with $setval fails." 68 fi 69 ;; 70 * ) 71 [[ $getval != $setval ]] && \ 72 log_fail "Setting the property $setprop with value \ 73 $setval fails." 74 ;; 75 esac 76} 77 78log_assert "Properties with aliases also work with those aliases." 79 80set -A ro_prop "available" "avail" "referenced" "refer" 81set -A rw_prop "readonly" "rdonly" "compression" "compress" "reservation" "reserv" 82set -A chk_prop "rdonly" "readonly" "compress" "compression" "reserv" "reservation" 83set -A size "512" "1024" "2048" "4096" "8192" "16384" "32768" "65536" "131072" 84 85pool=$TESTPOOL 86fs=$TESTPOOL/$TESTFS 87vol=$TESTPOOL/$TESTVOL 88typeset -l avail_space=$(get_prop avail $pool) 89typeset -l reservsize 90typeset -i i=0 91 92for ds in $pool $fs $vol; do 93 for propname in ${ro_prop[*]}; do 94 zfs get -pH -o value $propname $ds >/dev/null 2>&1 95 (( $? != 0 )) && \ 96 log_fail "Get the property $proname of $ds failed." 97 done 98 i=0 99 while (( i < ${#rw_prop[*]} )); do 100 case ${rw_prop[i]} in 101 readonly|rdonly ) 102 for val in "on" "off"; do 103 set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]} 104 done 105 ;; 106 compression|compress ) 107 for val in "${compress_prop_vals[@]}"; do 108 set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]} 109 done 110 ;; 111 reservation|reserv ) 112 (( reservsize = $avail_space % (( $RANDOM + 1 )) )) 113 for val in "0" "$reservsize" "none"; do 114 set_and_check $ds ${rw_prop[i]} $val ${chk_prop[i]} 115 done 116 ;; 117 esac 118 119 (( i = i + 1 )) 120 done 121 if [[ $ds == $vol ]]; then 122 for propname in "volblocksize" "volblock" ; do 123 zfs get -pH -o value $propname $ds >/dev/null 2>&1 124 (( $? != 0 )) && \ 125 log_fail "Get the property $propname of $ds failed." 126 done 127 fi 128done 129 130for ds in $pool $fs; do 131 for propname in "recordsize" "recsize"; do 132 for val in ${size[*]}; do 133 if [[ $propname == "recordsize" ]]; then 134 set_and_check $ds $propname $val "recsize" 135 else 136 set_and_check $ds $propname $val "recordsize" 137 fi 138 done 139 done 140done 141 142log_pass "The alias of a property works as expected." 143