Print this page
7290 ZFS test suite needs to control what utilities it can run
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/test/zfs-tests/tests/functional/redundancy/redundancy.kshlib
+++ new/usr/src/test/zfs-tests/tests/functional/redundancy/redundancy.kshlib
1 1 #
2 2 # CDDL HEADER START
3 3 #
4 4 # The contents of this file are subject to the terms of the
5 5 # Common Development and Distribution License (the "License").
6 6 # You may not use this file except in compliance with the License.
7 7 #
8 8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 # or http://www.opensolaris.org/os/licensing.
10 10 # See the License for the specific language governing permissions
11 11 # and limitations under the License.
12 12 #
13 13 # When distributing Covered Code, include this CDDL HEADER in each
14 14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 # If applicable, add the following below this CDDL HEADER, with the
16 16 # fields enclosed by brackets "[]" replaced with your own identifying
17 17 # information: Portions Copyright [yyyy] [name of copyright owner]
|
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
18 18 #
19 19 # CDDL HEADER END
20 20 #
21 21
22 22 #
23 23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 # Use is subject to license terms.
25 25 #
26 26
27 27 #
28 -# Copyright (c) 2013, 2015 by Delphix. All rights reserved.
28 +# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
29 29 #
30 30
31 31 . $STF_SUITE/include/libtest.shlib
32 32 . $STF_SUITE/tests/functional/redundancy/redundancy.cfg
33 33
34 34 function cleanup
35 35 {
36 36 if poolexists $TESTPOOL; then
37 37 destroy_pool $TESTPOOL
38 38 fi
39 39 typeset dir
40 40 for dir in $TESTDIR $BASEDIR; do
41 41 if [[ -d $dir ]]; then
42 - log_must $RM -rf $dir
42 + log_must rm -rf $dir
43 43 fi
44 44 done
45 45 }
46 46
47 47 #
48 48 # Get random number between min and max number.
49 49 #
50 50 # $1 Minimal value
51 51 # $2 Maximal value
52 52 #
53 53 function random
54 54 {
55 55 typeset -i min=$1
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
56 56 typeset -i max=$2
57 57 typeset -i value
58 58
59 59 while true; do
60 60 ((value = RANDOM % (max + 1)))
61 61 if ((value >= min)); then
62 62 break
63 63 fi
64 64 done
65 65
66 - $ECHO $value
66 + echo $value
67 67 }
68 68
69 69 #
70 70 # Record the directories construction and checksum all the files which reside
71 71 # within the specified pool
72 72 #
73 73 # $1 The specified pool
74 74 # $2 The file which save the record.
75 75 #
76 76 function record_data
77 77 {
78 78 typeset pool=$1
79 79 typeset recordfile=$2
80 80
81 81 [[ -z $pool ]] && log_fail "No specified pool."
82 - [[ -f $recordfile ]] && log_must $RM -f $recordfile
82 + [[ -f $recordfile ]] && log_must rm -f $recordfile
83 83
84 84 typeset mntpnt
85 85 mntpnt=$(get_prop mountpoint $pool)
86 - log_must eval "$DU -a $mntpnt > $recordfile 2>&1"
86 + log_must eval "du -a $mntpnt > $recordfile 2>&1"
87 87 #
88 88 # When the data was damaged, checksum is failing and return 1
89 89 # So, will not use log_must
90 90 #
91 - $FIND $mntpnt -type f -exec $CKSUM {} + >> $recordfile 2>&1
91 + find $mntpnt -type f -exec cksum {} + >> $recordfile 2>&1
92 92 }
93 93
94 94 #
95 95 # Create test pool and fill with files and directories.
96 96 #
97 97 # $1 pool name
98 98 # $2 pool type
99 99 # $3 virtual devices number
100 100 #
101 101 function setup_test_env
102 102 {
103 103 typeset pool=$1
104 104 typeset keyword=$2
|
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
105 105 typeset -i vdev_cnt=$3
106 106 typeset vdevs
107 107
108 108 typeset -i i=0
109 109 while (( i < vdev_cnt )); do
110 110 vdevs="$vdevs $BASEDIR/vdev$i"
111 111 ((i += 1))
112 112 done
113 113
114 114 if [[ ! -d $BASEDIR ]]; then
115 - log_must $MKDIR $BASEDIR
115 + log_must mkdir $BASEDIR
116 116 fi
117 117
118 118 if poolexists $pool ; then
119 119 destroy_pool $pool
120 120 fi
121 121
122 - log_must $MKFILE $MINVDEVSIZE $vdevs
122 + log_must mkfile $MINVDEVSIZE $vdevs
123 123
124 - log_must $ZPOOL create -m $TESTDIR $pool $keyword $vdevs
124 + log_must zpool create -m $TESTDIR $pool $keyword $vdevs
125 125
126 126 log_note "Filling up the filesystem ..."
127 127 typeset -i ret=0
128 128 typeset -i i=0
129 129 typeset file=$TESTDIR/file
130 - while $TRUE ; do
131 - $FILE_WRITE -o create -f $file.$i \
130 + while true ; do
131 + file_write -o create -f $file.$i \
132 132 -b $BLOCKSZ -c $NUM_WRITES
133 133 ret=$?
134 134 (( $ret != 0 )) && break
135 135 (( i = i + 1 ))
136 136 done
137 - (($ret != 28 )) && log_note "$FILE_WRITE return value($ret) is unexpected."
137 + (($ret != 28 )) && log_note "file_write return value($ret) is unexpected."
138 138
139 139 record_data $TESTPOOL $PRE_RECORD_FILE
140 140 }
141 141
142 142 #
143 143 # Check pool status is healthy
144 144 #
145 145 # $1 pool
146 146 #
147 147 function is_healthy
148 148 {
149 149 typeset pool=$1
150 150
151 151 typeset healthy_output="pool '$pool' is healthy"
152 - typeset real_output=$($ZPOOL status -x $pool)
152 + typeset real_output=$(zpool status -x $pool)
153 153
154 154 if [[ "$real_output" == "$healthy_output" ]]; then
155 155 return 0
156 156 else
157 157 typeset -i ret
158 - $ZPOOL status -x $pool | $GREP "state:" | \
159 - $GREP "FAULTED" >/dev/null 2>&1
158 + zpool status -x $pool | grep "state:" | \
159 + grep "FAULTED" >/dev/null 2>&1
160 160 ret=$?
161 161 (( $ret == 0 )) && return 1
162 162 typeset l_scan
163 163 typeset errnum
164 - l_scan=$($ZPOOL status -x $pool | $GREP "scan:")
164 + l_scan=$(zpool status -x $pool | grep "scan:")
165 165 l_scan=${l_scan##*"with"}
166 - errnum=$($ECHO $l_scan | $AWK '{print $1}')
166 + errnum=$(echo $l_scan | awk '{print $1}')
167 167
168 168 return $errnum
169 169 fi
170 170 }
171 171
172 172 #
173 173 # Check pool data is valid
174 174 #
175 175 # $1 pool
176 176 #
177 177 function is_data_valid
178 178 {
179 179 typeset pool=$1
180 180
181 181 record_data $pool $PST_RECORD_FILE
182 - if ! $DIFF $PRE_RECORD_FILE $PST_RECORD_FILE > /dev/null 2>&1; then
182 + if ! diff $PRE_RECORD_FILE $PST_RECORD_FILE > /dev/null 2>&1; then
183 183 return 1
184 184 fi
185 185
186 186 return 0
187 187 }
188 188
189 189 #
190 190 # Get the specified count devices name
191 191 #
192 192 # $1 pool name
193 193 # $2 devices count
194 194 #
195 195 function get_vdevs #pool cnt
196 196 {
197 197 typeset pool=$1
198 198 typeset -i cnt=$2
199 199
200 - typeset all_devs=$($ZPOOL iostat -v $pool | $AWK '{print $1}'| \
201 - $EGREP -v "^pool$|^capacity$|^mirror$|^raidz1$|^raidz2$|---" | \
202 - $EGREP -v "/old$|^$pool$")
200 + typeset all_devs=$(zpool iostat -v $pool | awk '{print $1}'| \
201 + egrep -v "^pool$|^capacity$|^mirror$|^raidz1$|^raidz2$|---" | \
202 + egrep -v "/old$|^$pool$")
203 203 typeset -i i=0
204 204 typeset vdevs
205 205 while ((i < cnt)); do
206 - typeset dev=$($ECHO $all_devs | $AWK '{print $1}')
206 + typeset dev=$(echo $all_devs | awk '{print $1}')
207 207 eval all_devs=\${all_devs##*$dev}
208 208
209 209 vdevs="$dev $vdevs"
210 210 ((i += 1))
211 211 done
212 212
213 - $ECHO "$vdevs"
213 + echo "$vdevs"
214 214 }
215 215
216 216 #
217 217 # Synchronize all the data in pool
218 218 #
219 219 # $1 pool name
220 220 #
221 221 function sync_pool #pool
222 222 {
223 223 typeset pool=$1
224 224
225 - log_must $SYNC
226 - log_must $SLEEP 2
225 + log_must sync
226 + log_must sleep 2
227 227 # Flush all the pool data.
228 228 typeset -i ret
229 - $ZPOOL scrub $pool >/dev/null 2>&1
229 + zpool scrub $pool >/dev/null 2>&1
230 230 ret=$?
231 231 (( $ret != 0 )) && \
232 - log_fail "$ZPOOL scrub $pool failed."
232 + log_fail "zpool scrub $pool failed."
233 233
234 234 while ! is_pool_scrubbed $pool; do
235 235 if is_pool_resilvered $pool ; then
236 236 log_fail "$pool should not be resilver completed."
237 237 fi
238 - log_must $SLEEP 2
238 + log_must sleep 2
239 239 done
240 240 }
241 241
242 242 #
243 243 # Create and replace the same name virtual device files
244 244 #
245 245 # $1 pool name
246 246 # $2-n virtual device files
247 247 #
248 248 function replace_missing_devs
249 249 {
250 250 typeset pool=$1
251 251 shift
252 252
253 253 typeset vdev
254 254 for vdev in $@; do
255 - log_must $MKFILE $MINVDEVSIZE $vdev
256 - log_must $ZPOOL replace -f $pool $vdev $vdev
255 + log_must mkfile $MINVDEVSIZE $vdev
256 + log_must zpool replace -f $pool $vdev $vdev
257 257 while true; do
258 258 if ! is_pool_resilvered $pool ; then
259 - log_must $SLEEP 2
259 + log_must sleep 2
260 260 else
261 261 break
262 262 fi
263 263 done
264 264 done
265 265 }
266 266
267 267 #
268 268 # Damage the pool's virtual device files.
269 269 #
270 270 # $1 pool name
271 271 # $2 Failing devices count
272 272 # $3 damage vdevs method, if not null, we keep
273 273 # the label for the vdevs
274 274 #
275 275 function damage_devs
276 276 {
|
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
277 277 typeset pool=$1
278 278 typeset -i cnt=$2
279 279 typeset label="$3"
280 280 typeset vdevs
281 281 typeset -i bs_count=$((64 * 1024))
282 282
283 283 vdevs=$(get_vdevs $pool $cnt)
284 284 typeset dev
285 285 if [[ -n $label ]]; then
286 286 for dev in $vdevs; do
287 - $DD if=/dev/zero of=$dev seek=512 bs=1024 \
287 + dd if=/dev/zero of=$dev seek=512 bs=1024 \
288 288 count=$bs_count conv=notrunc >/dev/null 2>&1
289 289 done
290 290 else
291 291 for dev in $vdevs; do
292 - $DD if=/dev/zero of=$dev bs=1024 count=$bs_count \
292 + dd if=/dev/zero of=$dev bs=1024 count=$bs_count \
293 293 conv=notrunc >/dev/null 2>&1
294 294 done
295 295 fi
296 296
297 297 sync_pool $pool
298 298 }
299 299
300 300 #
301 301 # Clear errors in the pool caused by data corruptions
302 302 #
303 303 # $1 pool name
304 304 #
305 305 function clear_errors
306 306 {
307 307 typeset pool=$1
308 308
309 - log_must $ZPOOL clear $pool
309 + log_must zpool clear $pool
310 310
311 311 if ! is_healthy $pool ; then
312 312 log_note "$pool should be healthy."
313 313 return 1
314 314 fi
315 315 if ! is_data_valid $pool ; then
316 316 log_note "Data should be valid in $pool."
317 317 return 1
318 318 fi
319 319
320 320 return 0
321 321 }
322 322
323 323 #
324 324 # Remove the specified pool's virtual device files
325 325 #
|
↓ open down ↓ |
6 lines elided |
↑ open up ↑ |
326 326 # $1 Pool name
327 327 # $2 Missing devices count
328 328 #
329 329 function remove_devs
330 330 {
331 331 typeset pool=$1
332 332 typeset -i cnt=$2
333 333 typeset vdevs
334 334
335 335 vdevs=$(get_vdevs $pool $cnt)
336 - log_must $RM -f $vdevs
336 + log_must rm -f $vdevs
337 337
338 338 sync_pool $pool
339 339 }
340 340
341 341 #
342 342 # Recover the bad or missing device files in the pool
343 343 #
344 344 # $1 Pool name
345 345 # $2 Missing devices count
346 346 #
347 347 function recover_bad_missing_devs
348 348 {
349 349 typeset pool=$1
350 350 typeset -i cnt=$2
351 351 typeset vdevs
352 352
353 353 vdevs=$(get_vdevs $pool $cnt)
354 354 replace_missing_devs $pool $vdevs
355 355
356 356 if ! is_healthy $pool ; then
357 357 log_note "$pool should be healthy."
358 358 return 1
359 359 fi
360 360 if ! is_data_valid $pool ; then
361 361 log_note "Data should be valid in $pool."
362 362 return 1
363 363 fi
364 364
365 365 return 0
366 366 }
|
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX