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.
16 typeset -a compress_prop_vals=('off' 'lzjb' 'lz4' 'gzip' 'zle')
17 typeset -a checksum_prop_vals=('on' 'off' 'fletcher2' 'fletcher4' 'sha256'
18 'noparity' 'sha512' 'skein' 'edonr')
19 typeset -a recsize_prop_vals=('512' '1024' '2048' '4096' '8192' '16384'
20 '32768' '65536' '131072' '262144' '524288' '1048576')
21 typeset -a canmount_prop_vals=('on' 'off' 'noauto')
22 typeset -a copies_prop_vals=('1' '2' '3')
23 typeset -a logbias_prop_vals=('latency' 'throughput')
24 typeset -a primarycache_prop_vals=('all' 'none' 'metadata')
25 typeset -a redundant_metadata_prop_vals=('all' 'most')
26 typeset -a secondarycache_prop_vals=('all' 'none' 'metadata')
27 typeset -a snapdir_prop_vals=('hidden' 'visible')
28 typeset -a sync_prop_vals=('standard' 'always' 'disabled')
30 typeset -a fs_props=('compress' 'checksum' 'recsize'
31 'canmount' 'copies' 'logbias' 'primarycache' 'redundant_metadata'
32 'secondarycache' 'snapdir' 'sync')
33 typeset -a vol_props=('compress' 'checksum' 'copies' 'logbias' 'primarycache'
34 'secondarycache' 'redundant_metadata' 'sync')
37 # Given the property array passed in, return 'num_props' elements to the
38 # user, excluding any elements below 'start.' This allows us to exclude
39 # 'off' and 'on' which can be either unwanted, or a duplicate of another
40 # property respectively.
42 function get_rand_prop
44 typeset prop_array=($(eval echo \${$1[@]}))
45 typeset -i num_props=$2
49 [[ -z $prop_array || -z $num_props || -z $start ]] && \
50 log_fail "get_rand_prop: bad arguments"
52 typeset prop_max=$((${#prop_array[@]} - 1))
54 for i in $(shuf -i $start-$prop_max -n $num_props); do
55 retstr="${prop_array[$i]} $retstr"
60 function get_rand_checksum
62 get_rand_prop checksum_prop_vals $1 2
65 function get_rand_checksum_any
67 get_rand_prop checksum_prop_vals $1 0
70 function get_rand_recsize
72 get_rand_prop recsize_prop_vals $1 0
75 function get_rand_large_recsize
77 get_rand_prop recsize_prop_vals $1 9
81 # Functions to toggle on/off properties
83 typeset -a binary_props=('atime' 'devices' 'exec' 'readonly' 'setuid' 'xattr')
86 binary_props+=('jailed')
88 binary_props+=('zoned')
92 # Only older kernels support non-blocking mandatory locks
93 if [[ $(linux_version) -lt $(linux_version "4.4") ]]; then
94 binary_props+=('nbmand')
97 binary_props+=('nbmand')
105 datasetexists $ds || log_fail "$ds does not exist"
106 typeset val=$(get_prop $prop $ds)
109 [[ $val = $newval ]] && newval='on'
110 log_must zfs set $prop=$newval $ds
113 function toggle_binary_props
118 for prop in "${binary_props[@]}"; do
119 toggle_prop $ds $prop
123 function randomize_ds_props
126 typeset prop proplist val
128 datasetexists $ds || log_fail "$ds does not exist"
129 if ds_is_volume $ds; then
130 toggle_prop $ds readonly
131 proplist="${vol_props[@]}"
132 elif ds_is_filesystem $ds; then
133 toggle_binary_props $ds
134 proplist="${fs_props[@]}"
136 log_fail "$ds is neither a volume nor a file system"
139 for prop in $proplist; do
140 typeset val=$(get_rand_prop "${prop}_prop_vals" 1 0)
141 log_must zfs set $prop=$val $ds