2 # This file and its contents are supplied under the terms of the
3 # Common Development and Distribution License ("CDDL"), version 1.0.
4 # You may only use this file in accordance with the terms of version
7 # A full copy of the text of the CDDL should have accompanied this
8 # source. A copy of the CDDL is also available via the Internet at
9 # http://www.illumos.org/license/CDDL.
13 # Copyright (c) 2012, 2016, Delphix. All rights reserved.
14 # Copyright (c) 2022 Hewlett Packard Enterprise Development LP.
17 . $STF_SUITE/include/libtest.shlib
19 typeset -a compress_prop_vals=('off' 'lzjb' 'lz4' 'gzip' 'zle' 'zstd')
20 typeset -a checksum_prop_vals=('on' 'off' 'fletcher2' 'fletcher4' 'sha256'
21 'noparity' 'sha512' 'skein' 'blake3')
23 checksum_prop_vals+=('edonr')
25 typeset -a recsize_prop_vals=('512' '1024' '2048' '4096' '8192' '16384'
26 '32768' '65536' '131072' '262144' '524288' '1048576')
27 typeset -a canmount_prop_vals=('on' 'off' 'noauto')
28 typeset -a copies_prop_vals=('1' '2' '3')
29 typeset -a logbias_prop_vals=('latency' 'throughput')
30 typeset -a primarycache_prop_vals=('all' 'none' 'metadata')
31 typeset -a redundant_metadata_prop_vals=('all' 'most' 'some' 'none')
32 typeset -a secondarycache_prop_vals=('all' 'none' 'metadata')
33 typeset -a snapdir_prop_vals=('disabled' 'hidden' 'visible')
34 typeset -a sync_prop_vals=('standard' 'always' 'disabled')
36 typeset -a fs_props=('compress' 'checksum' 'recsize'
37 'canmount' 'copies' 'logbias' 'primarycache' 'redundant_metadata'
38 'secondarycache' 'snapdir' 'sync')
39 typeset -a vol_props=('compress' 'checksum' 'copies' 'logbias' 'primarycache'
40 'secondarycache' 'redundant_metadata' 'sync')
43 # Given the 'prop' passed in, return 'num_vals' elements of the corresponding
44 # values array to the user, excluding any elements below 'first.' This allows
45 # us to exclude 'off' and 'on' which can be either unwanted, or a duplicate of
46 # another property respectively.
48 function get_rand_prop_vals
51 typeset -i num_vals=$2
54 [[ -z $prop || -z $num_vals || -z $first ]] && \
55 log_fail "get_rand_prop_vals: bad arguments"
59 typeset prop_vals_var=${prop}_prop_vals
60 typeset -a prop_vals=($(eval echo \${${prop_vals_var}[@]}))
62 [[ -z $prop_vals ]] && \
63 log_fail "get_rand_prop_vals: bad prop $prop"
65 typeset -i last=$((${#prop_vals[@]} - 1))
67 for i in $(range_shuffle $first $last | head -n $num_vals); do
68 retstr="${prop_vals[$i]} $retstr"
74 # Functions to toggle on/off properties
76 typeset -a binary_props=('atime' 'devices' 'exec' 'readonly' 'setuid' 'xattr')
79 binary_props+=('jailed')
81 binary_props+=('zoned')
84 # Newer Linuxes dropped non-blocking mandatory locks
85 if ! is_linux || [ $(linux_version) -lt $(linux_version "4.4") ]; then
86 binary_props+=('nbmand')
94 typeset val=$(get_prop $prop $ds)
97 [[ $val = $newval ]] && newval='on'
98 log_must zfs set $prop=$newval $ds
101 function toggle_binary_props
106 for prop in "${binary_props[@]}"; do
107 toggle_prop $ds $prop
111 function randomize_ds_props
114 typeset prop proplist val
116 if ds_is_volume $ds; then
117 toggle_prop $ds readonly
118 proplist="${vol_props[@]}"
119 elif ds_is_filesystem $ds; then
120 toggle_binary_props $ds
121 proplist="${fs_props[@]}"
123 log_fail "$ds is neither a volume nor a file system"
126 for prop in $proplist; do
127 typeset val=$(get_rand_prop_vals $prop 1 0)
128 log_must zfs set $prop=$val $ds