ZTS: Clean up properties.shlib a bit

Fixes the last property having an empty value on FreeBSD and makes the
code a bit more readable.

Reviewed-by: Kjeld Schouten <kjeld@schouten-lebbing.nl>
Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
Closes #9834
This commit is contained in:
Ryan Moeller 2020-01-13 18:21:42 -05:00 committed by Brian Behlendorf
parent 6e1c594d64
commit 602f667285
1 changed files with 25 additions and 18 deletions

View File

@ -34,47 +34,54 @@ typeset -a vol_props=('compress' 'checksum' 'copies' 'logbias' 'primarycache'
'secondarycache' 'redundant_metadata' 'sync')
#
# Given the property array passed in, return 'num_props' elements to the
# user, excluding any elements below 'start.' This allows us to exclude
# 'off' and 'on' which can be either unwanted, or a duplicate of another
# property respectively.
# Given the 'prop' passed in, return 'num_vals' elements of the corresponding
# values array to the user, excluding any elements below 'first.' This allows
# us to exclude 'off' and 'on' which can be either unwanted, or a duplicate of
# another property respectively.
#
function get_rand_prop
function get_rand_prop_vals
{
typeset prop_array=($(eval echo \${$1[@]}))
typeset -i num_props=$2
typeset -i start=$3
typeset prop=$1
typeset -i num_vals=$2
typeset -i first=$3
[[ -z $prop || -z $num_vals || -z $first ]] && \
log_fail "get_rand_prop_vals: bad arguments"
typeset retstr=""
[[ -z $prop_array || -z $num_props || -z $start ]] && \
log_fail "get_rand_prop: bad arguments"
typeset prop_vals_var=${prop}_prop_vals
typeset -a prop_vals=($(eval echo \${${prop_vals_var}[@]}))
typeset prop_max=$((${#prop_array[@]} - 1))
[[ -z $prop_vals ]] && \
log_fail "get_rand_prop_vals: bad prop $prop"
typeset -i last=$((${#prop_vals[@]} - 1))
typeset -i i
for i in $(range_shuffle $start $prop_max | head -n $num_props); do
retstr="${prop_array[$i]} $retstr"
for i in $(range_shuffle $first $last | head -n $num_vals); do
retstr="${prop_vals[$i]} $retstr"
done
echo $retstr
}
function get_rand_checksum
{
get_rand_prop checksum_prop_vals $1 2
get_rand_prop_vals checksum $1 2
}
function get_rand_checksum_any
{
get_rand_prop checksum_prop_vals $1 0
get_rand_prop_vals checksum $1 0
}
function get_rand_recsize
{
get_rand_prop recsize_prop_vals $1 0
get_rand_prop_vals recsize $1 0
}
function get_rand_large_recsize
{
get_rand_prop recsize_prop_vals $1 9
get_rand_prop_vals recsize $1 9
}
#
@ -137,7 +144,7 @@ function randomize_ds_props
fi
for prop in $proplist; do
typeset val=$(get_rand_prop "${prop}_prop_vals" 1 0)
typeset val=$(get_rand_prop_vals $prop 1 0)
log_must zfs set $prop=$val $ds
done
}