]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/include/properties.shlib
6a3a0e1ce84efc070b7ec886fd16d9db4ee34f0b
[mirror_zfs.git] / tests / zfs-tests / include / properties.shlib
1 #
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
5 # 1.0 of the CDDL.
6 #
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.
10 #
11
12 #
13 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
14 #
15
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 canmount_prop_vals=('on' 'off' 'noauto')
23 typeset -a copies_prop_vals=('1' '2' '3')
24 typeset -a logbias_prop_vals=('latency' 'throughput')
25 typeset -a primarycache_prop_vals=('all' 'none' 'metadata')
26 typeset -a redundant_metadata_prop_vals=('all' 'most')
27 typeset -a secondarycache_prop_vals=('all' 'none' 'metadata')
28 typeset -a snapdir_prop_vals=('hidden' 'visible')
29 typeset -a sync_prop_vals=('standard' 'always' 'disabled')
30
31 typeset -a fs_props=('compress' 'checksum' 'recsize'
32 'canmount' 'copies' 'logbias' 'primarycache' 'redundant_metadata'
33 'secondarycache' 'snapdir' 'sync')
34 typeset -a vol_props=('compress' 'checksum' 'copies' 'logbias' 'primarycache'
35 'secondarycache' 'redundant_metadata' 'sync')
36
37 #
38 # Given the property array passed in, return 'num_props' elements to the
39 # user, excluding any elements below 'start.' This allows us to exclude
40 # 'off' and 'on' which can be either unwanted, or a duplicate of another
41 # property respectively.
42 #
43 function get_rand_prop
44 {
45 typeset prop_array=($(eval echo \${$1[@]}))
46 typeset -i num_props=$2
47 typeset -i start=$3
48 typeset retstr=""
49
50 [[ -z $prop_array || -z $num_props || -z $start ]] && \
51 log_fail "get_rand_prop: bad arguments"
52
53 typeset prop_max=$((${#prop_array[@]} - 1))
54 typeset -i i
55 for i in $(shuf -i $start-$prop_max -n $num_props); do
56 retstr="${prop_array[$i]} $retstr"
57 done
58 echo $retstr
59 }
60
61 function get_rand_compress
62 {
63 get_rand_prop compress_prop_vals $1 2
64 }
65
66 function get_rand_compress_any
67 {
68 get_rand_prop compress_prop_vals $1 0
69 }
70
71 function get_rand_checksum
72 {
73 get_rand_prop checksum_prop_vals $1 2
74 }
75
76 function get_rand_checksum_any
77 {
78 get_rand_prop checksum_prop_vals $1 0
79 }
80
81 function get_rand_recsize
82 {
83 get_rand_prop recsize_prop_vals $1 0
84 }
85
86 function get_rand_large_recsize
87 {
88 get_rand_prop recsize_prop_vals $1 9
89 }
90
91 #
92 # Functions to toggle on/off properties
93 #
94 typeset -a binary_props=('atime' 'devices' 'exec' 'nbmand' 'readonly' 'setuid'
95 'xattr' 'zoned')
96
97 function toggle_prop
98 {
99 typeset ds=$1
100 typeset prop=$2
101
102 datasetexists $ds || log_fail "$ds does not exist"
103 typeset val=$(get_prop $prop $ds)
104 typeset newval='off'
105
106 [[ $val = $newval ]] && newval='on'
107 log_must zfs set $prop=$newval $ds
108 }
109
110 function toggle_binary_props
111 {
112 typeset ds=$1
113 typeset prop
114
115 for prop in "${binary_props[@]}"; do
116 toggle_prop $ds $prop
117 done
118 }
119
120 function randomize_ds_props
121 {
122 typeset ds=$1
123 typeset prop proplist val
124
125 datasetexists $ds || log_fail "$ds does not exist"
126 if ds_is_volume $ds; then
127 toggle_prop $ds readonly
128 proplist="${vol_props[@]}"
129 elif ds_is_filesystem $ds; then
130 toggle_binary_props $ds
131 proplist="${fs_props[@]}"
132 else
133 log_fail "$ds is neither a volume nor a file system"
134 fi
135
136 for prop in $proplist; do
137 typeset val=$(get_rand_prop "${prop}_prop_vals" 1 0)
138 log_must zfs set $prop=$val $ds
139 done
140 }