]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/include/properties.shlib
Update ZTS to work on FreeBSD
[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, Delphix. All rights reserved.
14 #
15
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')
29
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')
35
36 #
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.
41 #
42 function get_rand_prop
43 {
44 typeset prop_array=($(eval echo \${$1[@]}))
45 typeset -i num_props=$2
46 typeset -i start=$3
47 typeset retstr=""
48
49 [[ -z $prop_array || -z $num_props || -z $start ]] && \
50 log_fail "get_rand_prop: bad arguments"
51
52 typeset prop_max=$((${#prop_array[@]} - 1))
53 typeset -i i
54 for i in $(shuf -i $start-$prop_max -n $num_props); do
55 retstr="${prop_array[$i]} $retstr"
56 done
57 echo $retstr
58 }
59
60 function get_rand_checksum
61 {
62 get_rand_prop checksum_prop_vals $1 2
63 }
64
65 function get_rand_checksum_any
66 {
67 get_rand_prop checksum_prop_vals $1 0
68 }
69
70 function get_rand_recsize
71 {
72 get_rand_prop recsize_prop_vals $1 0
73 }
74
75 function get_rand_large_recsize
76 {
77 get_rand_prop recsize_prop_vals $1 9
78 }
79
80 #
81 # Functions to toggle on/off properties
82 #
83 typeset -a binary_props=('atime' 'devices' 'exec' 'readonly' 'setuid' 'xattr')
84
85 if is_freebsd; then
86 binary_props+=('jailed')
87 else
88 binary_props+=('zoned')
89 fi
90
91 if is_linux; then
92 # Only older kernels support non-blocking mandatory locks
93 if [[ $(linux_version) -lt $(linux_version "4.4") ]]; then
94 binary_props+=('nbmand')
95 fi
96 else
97 binary_props+=('nbmand')
98 fi
99
100 function toggle_prop
101 {
102 typeset ds=$1
103 typeset prop=$2
104
105 datasetexists $ds || log_fail "$ds does not exist"
106 typeset val=$(get_prop $prop $ds)
107 typeset newval='off'
108
109 [[ $val = $newval ]] && newval='on'
110 log_must zfs set $prop=$newval $ds
111 }
112
113 function toggle_binary_props
114 {
115 typeset ds=$1
116 typeset prop
117
118 for prop in "${binary_props[@]}"; do
119 toggle_prop $ds $prop
120 done
121 }
122
123 function randomize_ds_props
124 {
125 typeset ds=$1
126 typeset prop proplist val
127
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[@]}"
135 else
136 log_fail "$ds is neither a volume nor a file system"
137 fi
138
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
142 done
143 }