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 by Delphix. All rights reserved.
16 typeset -a compress_prop_vals=('on' 'off' 'lzjb' 'gzip' 'gzip-1' 'gzip-2'
17 'gzip-3' 'gzip-4' 'gzip-5' 'gzip-6' 'gzip-7' 'gzip-8' 'gzip-9' 'zle' 'lz4')
18 typeset -a checksum_prop_vals=('on' 'off' 'fletcher2' 'fletcher4' 'sha256'
19 'noparity' 'sha512' 'skein' 'edonr')
20 typeset -a recsize_prop_vals=('512' '1024' '2048' '4096' '8192' '16384'
21 '32768' '65536' '131072' '262144' '524288' '1048576')
22 typeset -a aclinherit_prop_vals=('discard' 'noallow' 'restricted' 'passthrough'
24 typeset -a aclmode_prop_vals=('discard' 'groupmask' 'passthrough' 'restricted')
25 typeset -a canmount_prop_vals=('on' 'off' 'noauto')
26 typeset -a copies_prop_vals=('1' '2' '3')
27 typeset -a logbias_prop_vals=('latency' 'throughput')
28 typeset -a primarycache_prop_vals=('all' 'none' 'metadata')
29 typeset -a redundant_metadata_prop_vals=('all' 'most')
30 typeset -a secondarycache_prop_vals=('all' 'none' 'metadata')
31 typeset -a snapdir_prop_vals=('hidden' 'visible')
32 typeset -a sync_prop_vals=('standard' 'always' 'disabled')
34 typeset -a fs_props=('compress' 'checksum' 'recsize' 'aclinherit' 'aclmode'
35 'canmount' 'copies' 'logbias' 'primarycache' 'redundant_metadata'
36 'secondarycache' 'snapdir' 'sync')
37 typeset -a vol_props=('compress' 'checksum' 'copies' 'logbias' 'primarycache'
38 'secondarycache' 'redundant_metadata' 'sync')
41 # Given the property array passed in, return 'num_props' elements to the
42 # user, excluding any elements below 'start.' This allows us to exclude
43 # 'off' and 'on' which can be either unwanted, or a duplicate of another
44 # property respectively.
46 function get_rand_prop
48 typeset prop_array=($(eval echo \${$1[@]}))
49 typeset -i num_props=$2
53 [[ -z $prop_array || -z $num_props || -z $start ]] && \
54 log_fail "get_rand_prop: bad arguments"
56 typeset prop_max=$((${#prop_array[@]} - 1))
58 for i in $(shuf -i $start-$prop_max -n $num_props); do
59 retstr="${prop_array[$i]} $retstr"
64 function get_rand_compress
66 get_rand_prop compress_prop_vals $1 2
69 function get_rand_compress_any
71 get_rand_prop compress_prop_vals $1 0
74 function get_rand_checksum
76 get_rand_prop checksum_prop_vals $1 2
79 function get_rand_checksum_any
81 get_rand_prop checksum_prop_vals $1 0
84 function get_rand_recsize
86 get_rand_prop recsize_prop_vals $1 0
89 function get_rand_large_recsize
91 get_rand_prop recsize_prop_vals $1 9
95 # Functions to toggle on/off properties
97 typeset -a binary_props=('atime' 'devices' 'exec' 'nbmand' 'readonly' 'setuid'
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