Print this page
NEX-9752 backport illumos 6950 ARC should cache compressed data
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
6950 ARC should cache compressed data
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Dan Kimmel <dan.kimmel@delphix.com>
Reviewed by: Matt Ahrens <mahrens@delphix.com>
Reviewed by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Don Brady <don.brady@intel.com>
Reviewed by: Richard Elling <Richard.Elling@RichardElling.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
6369 remove SVM tests from ZFS test suite
Reviewed by: John Kennedy <john.kennedy@delphix.com>
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Albert Lee <trisk@omniti.com>
Approved by: Dan McDonald <danmcd@omniti.com>
6248 zpool_create_008_pos and zpool_create_009_neg can fail intermittently
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
4185 add new cryptographic checksums to ZFS: SHA-512, Skein, Edon-R (fix studio build)
4185 add new cryptographic checksums to ZFS: SHA-512, Skein, Edon-R
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Approved by: Garrett D'Amore <garrett@damore.org>
5767 fix several problems with zfs test suite
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Approved by: Gordon Ross <gwr@nexenta.com>
NEX-3974 Remove timing issues so the robot can run consistently
Reviewed by: Steve Peng <steve.peng@nexenta.com>
Reviewed by: Josef Sipek <josef.sipek@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-3363 Test suites don't cleanup after themselves properly.
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
NEX-3740 The zfs tests use psrinfo instead of /usr/sbin/psrinfo
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
Reviewed by: Steve Peng <steve.peng@nexenta.com>
NEX-3258 Remove dependency upon SVM from zfs-tests
Reviewed by: Josef Sipek <josef.sipek@nexenta.com>
Reviewed by: Steve Peng <steve.peng@nexenta.com>
Reviewed by: Alek Pinchuk <alek.pinchuk@nexenta.com>
NEX-2744 zfs-tests suite fails rootpool_002_neg
NEX-2739 zfs-tests suite fails link_count_001
NEX-2741 zfs-tests suite fails mmap_write_001_pos
4206 history_003_pos relies on exact size of history log and entries
4207 history_008_pos depends on obsolete internal history log message
4208 Typo in zfs_main.c: "posxiuser"
4209 Populate zfstest with the remainder of the STF tests
Reviewed by: Sonu Pillai <sonu.pillai@delphix.com>
Reviewed by: Will Guyette <will.guyette@delphix.com>
Reviewed by: Eric Diven <eric.diven@delphix.com>
Reviewed by: Christopher Siden <christopher.siden@delphix.com>
Approved by: Richard Lowe <richlowe@richlowe.net>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/test/zfs-tests/include/libtest.shlib
+++ new/usr/src/test/zfs-tests/include/libtest.shlib
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]
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 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
26 26 # Copyright 2016 Nexenta Systems, Inc.
27 27 # Copyright (c) 2017 Datto Inc.
28 28 #
29 29
30 30 . ${STF_TOOLS}/contrib/include/logapi.shlib
31 31
32 32 # Determine whether a dataset is mounted
33 33 #
34 34 # $1 dataset name
35 35 # $2 filesystem type; optional - defaulted to zfs
36 36 #
37 37 # Return 0 if dataset is mounted; 1 if unmounted; 2 on error
38 38
39 39 function ismounted
40 40 {
41 41 typeset fstype=$2
42 42 [[ -z $fstype ]] && fstype=zfs
43 43 typeset out dir name ret
44 44
45 45 case $fstype in
46 46 zfs)
47 47 if [[ "$1" == "/"* ]] ; then
48 48 for out in $(zfs mount | awk '{print $2}'); do
49 49 [[ $1 == $out ]] && return 0
50 50 done
51 51 else
52 52 for out in $(zfs mount | awk '{print $1}'); do
53 53 [[ $1 == $out ]] && return 0
54 54 done
55 55 fi
56 56 ;;
57 57 ufs|nfs)
58 58 out=$(df -F $fstype $1 2>/dev/null)
59 59 ret=$?
60 60 (($ret != 0)) && return $ret
61 61
62 62 dir=${out%%\(*}
63 63 dir=${dir%% *}
64 64 name=${out##*\(}
65 65 name=${name%%\)*}
66 66 name=${name%% *}
67 67
68 68 [[ "$1" == "$dir" || "$1" == "$name" ]] && return 0
69 69 ;;
70 70 esac
71 71
72 72 return 1
73 73 }
74 74
75 75 # Return 0 if a dataset is mounted; 1 otherwise
76 76 #
77 77 # $1 dataset name
78 78 # $2 filesystem type; optional - defaulted to zfs
79 79
80 80 function mounted
81 81 {
82 82 ismounted $1 $2
83 83 (($? == 0)) && return 0
84 84 return 1
85 85 }
86 86
87 87 # Return 0 if a dataset is unmounted; 1 otherwise
88 88 #
89 89 # $1 dataset name
90 90 # $2 filesystem type; optional - defaulted to zfs
91 91
92 92 function unmounted
93 93 {
94 94 ismounted $1 $2
95 95 (($? == 1)) && return 0
96 96 return 1
97 97 }
98 98
99 99 # split line on ","
100 100 #
101 101 # $1 - line to split
102 102
103 103 function splitline
104 104 {
105 105 echo $1 | sed "s/,/ /g"
106 106 }
107 107
108 108 function default_setup
109 109 {
110 110 default_setup_noexit "$@"
111 111
112 112 log_pass
113 113 }
114 114
115 115 #
116 116 # Given a list of disks, setup storage pools and datasets.
117 117 #
118 118 function default_setup_noexit
119 119 {
120 120 typeset disklist=$1
121 121 typeset container=$2
122 122 typeset volume=$3
123 123
124 124 if is_global_zone; then
125 125 if poolexists $TESTPOOL ; then
126 126 destroy_pool $TESTPOOL
127 127 fi
128 128 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
129 129 log_must zpool create -f $TESTPOOL $disklist
130 130 else
131 131 reexport_pool
132 132 fi
133 133
134 134 rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
135 135 mkdir -p $TESTDIR || log_unresolved Could not create $TESTDIR
136 136
137 137 log_must zfs create $TESTPOOL/$TESTFS
138 138 log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
139 139
140 140 if [[ -n $container ]]; then
141 141 rm -rf $TESTDIR1 || \
142 142 log_unresolved Could not remove $TESTDIR1
143 143 mkdir -p $TESTDIR1 || \
144 144 log_unresolved Could not create $TESTDIR1
145 145
146 146 log_must zfs create $TESTPOOL/$TESTCTR
147 147 log_must zfs set canmount=off $TESTPOOL/$TESTCTR
148 148 log_must zfs create $TESTPOOL/$TESTCTR/$TESTFS1
149 149 log_must zfs set mountpoint=$TESTDIR1 \
150 150 $TESTPOOL/$TESTCTR/$TESTFS1
151 151 fi
152 152
153 153 if [[ -n $volume ]]; then
154 154 if is_global_zone ; then
155 155 log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL
156 156 else
157 157 log_must zfs create $TESTPOOL/$TESTVOL
158 158 fi
159 159 fi
160 160 }
161 161
162 162 #
163 163 # Given a list of disks, setup a storage pool, file system and
164 164 # a container.
165 165 #
166 166 function default_container_setup
167 167 {
168 168 typeset disklist=$1
169 169
170 170 default_setup "$disklist" "true"
171 171 }
172 172
173 173 #
174 174 # Given a list of disks, setup a storage pool,file system
175 175 # and a volume.
176 176 #
177 177 function default_volume_setup
178 178 {
179 179 typeset disklist=$1
180 180
181 181 default_setup "$disklist" "" "true"
182 182 }
183 183
184 184 #
185 185 # Given a list of disks, setup a storage pool,file system,
186 186 # a container and a volume.
187 187 #
188 188 function default_container_volume_setup
189 189 {
190 190 typeset disklist=$1
191 191
192 192 default_setup "$disklist" "true" "true"
193 193 }
194 194
195 195 #
196 196 # Create a snapshot on a filesystem or volume. Defaultly create a snapshot on
197 197 # filesystem
198 198 #
199 199 # $1 Existing filesystem or volume name. Default, $TESTPOOL/$TESTFS
200 200 # $2 snapshot name. Default, $TESTSNAP
201 201 #
202 202 function create_snapshot
203 203 {
204 204 typeset fs_vol=${1:-$TESTPOOL/$TESTFS}
205 205 typeset snap=${2:-$TESTSNAP}
206 206
207 207 [[ -z $fs_vol ]] && log_fail "Filesystem or volume's name is undefined."
208 208 [[ -z $snap ]] && log_fail "Snapshot's name is undefined."
209 209
210 210 if snapexists $fs_vol@$snap; then
211 211 log_fail "$fs_vol@$snap already exists."
212 212 fi
213 213 datasetexists $fs_vol || \
214 214 log_fail "$fs_vol must exist."
215 215
216 216 log_must zfs snapshot $fs_vol@$snap
217 217 }
218 218
219 219 #
220 220 # Create a clone from a snapshot, default clone name is $TESTCLONE.
221 221 #
222 222 # $1 Existing snapshot, $TESTPOOL/$TESTFS@$TESTSNAP is default.
223 223 # $2 Clone name, $TESTPOOL/$TESTCLONE is default.
224 224 #
225 225 function create_clone # snapshot clone
226 226 {
227 227 typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
228 228 typeset clone=${2:-$TESTPOOL/$TESTCLONE}
229 229
230 230 [[ -z $snap ]] && \
231 231 log_fail "Snapshot name is undefined."
232 232 [[ -z $clone ]] && \
233 233 log_fail "Clone name is undefined."
234 234
235 235 log_must zfs clone $snap $clone
236 236 }
237 237
238 238 #
239 239 # Create a bookmark of the given snapshot. Defaultly create a bookmark on
240 240 # filesystem.
241 241 #
242 242 # $1 Existing filesystem or volume name. Default, $TESTFS
243 243 # $2 Existing snapshot name. Default, $TESTSNAP
244 244 # $3 bookmark name. Default, $TESTBKMARK
245 245 #
246 246 function create_bookmark
247 247 {
248 248 typeset fs_vol=${1:-$TESTFS}
249 249 typeset snap=${2:-$TESTSNAP}
250 250 typeset bkmark=${3:-$TESTBKMARK}
251 251
252 252 [[ -z $fs_vol ]] && log_fail "Filesystem or volume's name is undefined."
253 253 [[ -z $snap ]] && log_fail "Snapshot's name is undefined."
254 254 [[ -z $bkmark ]] && log_fail "Bookmark's name is undefined."
255 255
256 256 if bkmarkexists $fs_vol#$bkmark; then
|
↓ open down ↓ |
256 lines elided |
↑ open up ↑ |
257 257 log_fail "$fs_vol#$bkmark already exists."
258 258 fi
259 259 datasetexists $fs_vol || \
260 260 log_fail "$fs_vol must exist."
261 261 snapexists $fs_vol@$snap || \
262 262 log_fail "$fs_vol@$snap must exist."
263 263
264 264 log_must zfs bookmark $fs_vol@$snap $fs_vol#$bkmark
265 265 }
266 266
267 -#
268 -# Create a temporary clone result of an interrupted resumable 'zfs receive'
269 -# $1 Destination filesystem name. Must not exist, will be created as the result
270 -# of this function along with its %recv temporary clone
271 -# $2 Source filesystem name. Must not exist, will be created and destroyed
272 -#
273 -function create_recv_clone
274 -{
275 - typeset recvfs="$1"
276 - typeset sendfs="${2:-$TESTPOOL/create_recv_clone}"
277 - typeset snap="$sendfs@snap1"
278 - typeset incr="$sendfs@snap2"
279 - typeset mountpoint="$TESTDIR/create_recv_clone"
280 - typeset sendfile="$TESTDIR/create_recv_clone.zsnap"
281 -
282 - [[ -z $recvfs ]] && log_fail "Recv filesystem's name is undefined."
283 -
284 - datasetexists $recvfs && log_fail "Recv filesystem must not exist."
285 - datasetexists $sendfs && log_fail "Send filesystem must not exist."
286 -
287 - log_must zfs create -o mountpoint="$mountpoint" $sendfs
288 - log_must zfs snapshot $snap
289 - log_must eval "zfs send $snap | zfs recv -u $recvfs"
290 - log_must mkfile 1m "$mountpoint/data"
291 - log_must zfs snapshot $incr
292 - log_must eval "zfs send -i $snap $incr | dd bs=10k count=1 > $sendfile"
293 - log_mustnot eval "zfs recv -su $recvfs < $sendfile"
294 - log_must zfs destroy -r $sendfs
295 - log_must rm -f "$sendfile"
296 -
297 - if [[ $(get_prop 'inconsistent' "$recvfs/%recv") -ne 1 ]]; then
298 - log_fail "Error creating temporary $recvfs/%recv clone"
299 - fi
300 -}
301 -
302 267 function default_mirror_setup
303 268 {
304 269 default_mirror_setup_noexit $1 $2 $3
305 270
306 271 log_pass
307 272 }
308 273
309 274 #
310 275 # Given a pair of disks, set up a storage pool and dataset for the mirror
311 276 # @parameters: $1 the primary side of the mirror
312 277 # $2 the secondary side of the mirror
313 278 # @uses: ZPOOL ZFS TESTPOOL TESTFS
314 279 function default_mirror_setup_noexit
315 280 {
316 281 readonly func="default_mirror_setup_noexit"
317 282 typeset primary=$1
318 283 typeset secondary=$2
319 284
320 285 [[ -z $primary ]] && \
321 286 log_fail "$func: No parameters passed"
322 287 [[ -z $secondary ]] && \
323 288 log_fail "$func: No secondary partition passed"
324 289 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
325 290 log_must zpool create -f $TESTPOOL mirror $@
326 291 log_must zfs create $TESTPOOL/$TESTFS
327 292 log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
328 293 }
329 294
330 295 #
331 296 # create a number of mirrors.
332 297 # We create a number($1) of 2 way mirrors using the pairs of disks named
333 298 # on the command line. These mirrors are *not* mounted
334 299 # @parameters: $1 the number of mirrors to create
335 300 # $... the devices to use to create the mirrors on
336 301 # @uses: ZPOOL ZFS TESTPOOL
337 302 function setup_mirrors
338 303 {
339 304 typeset -i nmirrors=$1
340 305
341 306 shift
342 307 while ((nmirrors > 0)); do
343 308 log_must test -n "$1" -a -n "$2"
344 309 [[ -d /$TESTPOOL$nmirrors ]] && rm -rf /$TESTPOOL$nmirrors
345 310 log_must zpool create -f $TESTPOOL$nmirrors mirror $1 $2
346 311 shift 2
347 312 ((nmirrors = nmirrors - 1))
348 313 done
349 314 }
350 315
351 316 #
352 317 # create a number of raidz pools.
353 318 # We create a number($1) of 2 raidz pools using the pairs of disks named
354 319 # on the command line. These pools are *not* mounted
355 320 # @parameters: $1 the number of pools to create
356 321 # $... the devices to use to create the pools on
357 322 # @uses: ZPOOL ZFS TESTPOOL
358 323 function setup_raidzs
359 324 {
360 325 typeset -i nraidzs=$1
361 326
362 327 shift
363 328 while ((nraidzs > 0)); do
364 329 log_must test -n "$1" -a -n "$2"
365 330 [[ -d /$TESTPOOL$nraidzs ]] && rm -rf /$TESTPOOL$nraidzs
366 331 log_must zpool create -f $TESTPOOL$nraidzs raidz $1 $2
367 332 shift 2
368 333 ((nraidzs = nraidzs - 1))
369 334 done
370 335 }
371 336
372 337 #
373 338 # Destroy the configured testpool mirrors.
374 339 # the mirrors are of the form ${TESTPOOL}{number}
375 340 # @uses: ZPOOL ZFS TESTPOOL
376 341 function destroy_mirrors
377 342 {
378 343 default_cleanup_noexit
379 344
380 345 log_pass
381 346 }
382 347
383 348 #
384 349 # Given a minimum of two disks, set up a storage pool and dataset for the raid-z
385 350 # $1 the list of disks
386 351 #
387 352 function default_raidz_setup
388 353 {
389 354 typeset disklist="$*"
390 355 disks=(${disklist[*]})
391 356
392 357 if [[ ${#disks[*]} -lt 2 ]]; then
393 358 log_fail "A raid-z requires a minimum of two disks."
394 359 fi
395 360
396 361 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
397 362 log_must zpool create -f $TESTPOOL raidz $1 $2 $3
398 363 log_must zfs create $TESTPOOL/$TESTFS
399 364 log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
400 365
401 366 log_pass
402 367 }
403 368
404 369 #
405 370 # Common function used to cleanup storage pools and datasets.
406 371 #
407 372 # Invoked at the start of the test suite to ensure the system
408 373 # is in a known state, and also at the end of each set of
409 374 # sub-tests to ensure errors from one set of tests doesn't
410 375 # impact the execution of the next set.
411 376
412 377 function default_cleanup
413 378 {
414 379 default_cleanup_noexit
415 380
416 381 log_pass
417 382 }
418 383
419 384 function default_cleanup_noexit
420 385 {
421 386 typeset exclude=""
422 387 typeset pool=""
423 388 #
424 389 # Destroying the pool will also destroy any
425 390 # filesystems it contains.
426 391 #
427 392 if is_global_zone; then
428 393 zfs unmount -a > /dev/null 2>&1
429 394 exclude=`eval echo \"'(${KEEP})'\"`
430 395 ALL_POOLS=$(zpool list -H -o name \
431 396 | grep -v "$NO_POOLS" | egrep -v "$exclude")
432 397 # Here, we loop through the pools we're allowed to
433 398 # destroy, only destroying them if it's safe to do
434 399 # so.
435 400 while [ ! -z ${ALL_POOLS} ]
436 401 do
437 402 for pool in ${ALL_POOLS}
438 403 do
439 404 if safe_to_destroy_pool $pool ;
440 405 then
441 406 destroy_pool $pool
442 407 fi
443 408 ALL_POOLS=$(zpool list -H -o name \
444 409 | grep -v "$NO_POOLS" \
445 410 | egrep -v "$exclude")
446 411 done
447 412 done
448 413
449 414 zfs mount -a
450 415 else
451 416 typeset fs=""
452 417 for fs in $(zfs list -H -o name \
453 418 | grep "^$ZONE_POOL/$ZONE_CTR[01234]/"); do
454 419 datasetexists $fs && \
455 420 log_must zfs destroy -Rf $fs
456 421 done
457 422
458 423 # Need cleanup here to avoid garbage dir left.
459 424 for fs in $(zfs list -H -o name); do
460 425 [[ $fs == /$ZONE_POOL ]] && continue
461 426 [[ -d $fs ]] && log_must rm -rf $fs/*
462 427 done
463 428
464 429 #
465 430 # Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to
466 431 # the default value
467 432 #
468 433 for fs in $(zfs list -H -o name); do
469 434 if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then
470 435 log_must zfs set reservation=none $fs
471 436 log_must zfs set recordsize=128K $fs
472 437 log_must zfs set mountpoint=/$fs $fs
473 438 typeset enc=""
474 439 enc=$(get_prop encryption $fs)
475 440 if [[ $? -ne 0 ]] || [[ -z "$enc" ]] || \
476 441 [[ "$enc" == "off" ]]; then
477 442 log_must zfs set checksum=on $fs
478 443 fi
479 444 log_must zfs set compression=off $fs
480 445 log_must zfs set atime=on $fs
481 446 log_must zfs set devices=off $fs
482 447 log_must zfs set exec=on $fs
483 448 log_must zfs set setuid=on $fs
|
↓ open down ↓ |
172 lines elided |
↑ open up ↑ |
484 449 log_must zfs set readonly=off $fs
485 450 log_must zfs set snapdir=hidden $fs
486 451 log_must zfs set aclmode=groupmask $fs
487 452 log_must zfs set aclinherit=secure $fs
488 453 fi
489 454 done
490 455 fi
491 456
492 457 [[ -d $TESTDIR ]] && \
493 458 log_must rm -rf $TESTDIR
459 + [[ -d $TESTDIR1 ]] && \
460 + log_must rm -rf $TESTDIR1
494 461 }
495 462
496 463
497 464 #
498 465 # Common function used to cleanup storage pools, file systems
499 466 # and containers.
500 467 #
501 468 function default_container_cleanup
502 469 {
503 470 if ! is_global_zone; then
504 471 reexport_pool
505 472 fi
506 473
507 474 ismounted $TESTPOOL/$TESTCTR/$TESTFS1
508 475 [[ $? -eq 0 ]] && \
509 476 log_must zfs unmount $TESTPOOL/$TESTCTR/$TESTFS1
510 477
511 478 datasetexists $TESTPOOL/$TESTCTR/$TESTFS1 && \
512 479 log_must zfs destroy -R $TESTPOOL/$TESTCTR/$TESTFS1
513 480
514 481 datasetexists $TESTPOOL/$TESTCTR && \
515 482 log_must zfs destroy -Rf $TESTPOOL/$TESTCTR
516 483
517 484 [[ -e $TESTDIR1 ]] && \
518 485 log_must rm -rf $TESTDIR1 > /dev/null 2>&1
519 486
520 487 default_cleanup
521 488 }
522 489
523 490 #
524 491 # Common function used to cleanup snapshot of file system or volume. Default to
525 492 # delete the file system's snapshot
526 493 #
527 494 # $1 snapshot name
528 495 #
529 496 function destroy_snapshot
530 497 {
531 498 typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
532 499
533 500 if ! snapexists $snap; then
534 501 log_fail "'$snap' does not existed."
535 502 fi
536 503
537 504 #
538 505 # For the sake of the value which come from 'get_prop' is not equal
539 506 # to the really mountpoint when the snapshot is unmounted. So, firstly
540 507 # check and make sure this snapshot's been mounted in current system.
541 508 #
542 509 typeset mtpt=""
543 510 if ismounted $snap; then
544 511 mtpt=$(get_prop mountpoint $snap)
545 512 (($? != 0)) && \
546 513 log_fail "get_prop mountpoint $snap failed."
547 514 fi
548 515
549 516 log_must zfs destroy $snap
550 517 [[ $mtpt != "" && -d $mtpt ]] && \
551 518 log_must rm -rf $mtpt
552 519 }
553 520
554 521 #
555 522 # Common function used to cleanup clone.
556 523 #
557 524 # $1 clone name
558 525 #
559 526 function destroy_clone
560 527 {
561 528 typeset clone=${1:-$TESTPOOL/$TESTCLONE}
562 529
563 530 if ! datasetexists $clone; then
564 531 log_fail "'$clone' does not existed."
565 532 fi
566 533
567 534 # With the same reason in destroy_snapshot
568 535 typeset mtpt=""
569 536 if ismounted $clone; then
570 537 mtpt=$(get_prop mountpoint $clone)
571 538 (($? != 0)) && \
572 539 log_fail "get_prop mountpoint $clone failed."
573 540 fi
574 541
575 542 log_must zfs destroy $clone
576 543 [[ $mtpt != "" && -d $mtpt ]] && \
577 544 log_must rm -rf $mtpt
578 545 }
579 546
580 547 #
581 548 # Common function used to cleanup bookmark of file system or volume. Default
582 549 # to delete the file system's bookmark.
583 550 #
584 551 # $1 bookmark name
585 552 #
586 553 function destroy_bookmark
587 554 {
588 555 typeset bkmark=${1:-$TESTPOOL/$TESTFS#$TESTBKMARK}
589 556
590 557 if ! bkmarkexists $bkmark; then
591 558 log_fail "'$bkmarkp' does not existed."
592 559 fi
593 560
594 561 log_must zfs destroy $bkmark
595 562 }
596 563
597 564 # Return 0 if a snapshot exists; $? otherwise
598 565 #
599 566 # $1 - snapshot name
600 567
601 568 function snapexists
602 569 {
603 570 zfs list -H -t snapshot "$1" > /dev/null 2>&1
604 571 return $?
605 572 }
606 573
607 574 #
608 575 # Return 0 if a bookmark exists; $? otherwise
609 576 #
610 577 # $1 - bookmark name
611 578 #
612 579 function bkmarkexists
613 580 {
614 581 zfs list -H -t bookmark "$1" > /dev/null 2>&1
615 582 return $?
616 583 }
617 584
618 585 #
619 586 # Set a property to a certain value on a dataset.
620 587 # Sets a property of the dataset to the value as passed in.
621 588 # @param:
622 589 # $1 dataset who's property is being set
623 590 # $2 property to set
624 591 # $3 value to set property to
625 592 # @return:
626 593 # 0 if the property could be set.
627 594 # non-zero otherwise.
628 595 # @use: ZFS
629 596 #
630 597 function dataset_setprop
631 598 {
632 599 typeset fn=dataset_setprop
633 600
634 601 if (($# < 3)); then
635 602 log_note "$fn: Insufficient parameters (need 3, had $#)"
636 603 return 1
637 604 fi
638 605 typeset output=
639 606 output=$(zfs set $2=$3 $1 2>&1)
640 607 typeset rv=$?
641 608 if ((rv != 0)); then
642 609 log_note "Setting property on $1 failed."
643 610 log_note "property $2=$3"
644 611 log_note "Return Code: $rv"
645 612 log_note "Output: $output"
646 613 return $rv
647 614 fi
648 615 return 0
649 616 }
650 617
651 618 #
652 619 # Assign suite defined dataset properties.
653 620 # This function is used to apply the suite's defined default set of
654 621 # properties to a dataset.
655 622 # @parameters: $1 dataset to use
656 623 # @uses: ZFS COMPRESSION_PROP CHECKSUM_PROP
657 624 # @returns:
658 625 # 0 if the dataset has been altered.
659 626 # 1 if no pool name was passed in.
660 627 # 2 if the dataset could not be found.
661 628 # 3 if the dataset could not have it's properties set.
662 629 #
663 630 function dataset_set_defaultproperties
664 631 {
665 632 typeset dataset="$1"
666 633
667 634 [[ -z $dataset ]] && return 1
668 635
669 636 typeset confset=
670 637 typeset -i found=0
671 638 for confset in $(zfs list); do
672 639 if [[ $dataset = $confset ]]; then
673 640 found=1
674 641 break
675 642 fi
676 643 done
677 644 [[ $found -eq 0 ]] && return 2
678 645 if [[ -n $COMPRESSION_PROP ]]; then
679 646 dataset_setprop $dataset compression $COMPRESSION_PROP || \
680 647 return 3
681 648 log_note "Compression set to '$COMPRESSION_PROP' on $dataset"
682 649 fi
683 650 if [[ -n $CHECKSUM_PROP ]]; then
684 651 dataset_setprop $dataset checksum $CHECKSUM_PROP || \
685 652 return 3
686 653 log_note "Checksum set to '$CHECKSUM_PROP' on $dataset"
687 654 fi
688 655 return 0
689 656 }
690 657
691 658 #
692 659 # Check a numeric assertion
693 660 # @parameter: $@ the assertion to check
694 661 # @output: big loud notice if assertion failed
695 662 # @use: log_fail
696 663 #
697 664 function assert
698 665 {
699 666 (($@)) || log_fail "$@"
700 667 }
701 668
702 669 #
703 670 # Function to format partition size of a disk
704 671 # Given a disk cxtxdx reduces all partitions
705 672 # to 0 size
706 673 #
707 674 function zero_partitions #<whole_disk_name>
708 675 {
709 676 typeset diskname=$1
710 677 typeset i
711 678
712 679 for i in 0 1 3 4 5 6 7
713 680 do
714 681 set_partition $i "" 0mb $diskname
715 682 done
716 683 }
717 684
718 685 #
719 686 # Given a slice, size and disk, this function
720 687 # formats the slice to the specified size.
721 688 # Size should be specified with units as per
722 689 # the `format` command requirements eg. 100mb 3gb
723 690 #
724 691 function set_partition #<slice_num> <slice_start> <size_plus_units> <whole_disk_name>
725 692 {
726 693 typeset -i slicenum=$1
727 694 typeset start=$2
728 695 typeset size=$3
729 696 typeset disk=$4
730 697 [[ -z $slicenum || -z $size || -z $disk ]] && \
731 698 log_fail "The slice, size or disk name is unspecified."
732 699 typeset format_file=/var/tmp/format_in.$$
733 700
734 701 echo "partition" >$format_file
735 702 echo "$slicenum" >> $format_file
736 703 echo "" >> $format_file
737 704 echo "" >> $format_file
738 705 echo "$start" >> $format_file
739 706 echo "$size" >> $format_file
740 707 echo "label" >> $format_file
741 708 echo "" >> $format_file
742 709 echo "q" >> $format_file
743 710 echo "q" >> $format_file
744 711
745 712 format -e -s -d $disk -f $format_file
746 713 typeset ret_val=$?
747 714 rm -f $format_file
748 715 [[ $ret_val -ne 0 ]] && \
749 716 log_fail "Unable to format $disk slice $slicenum to $size"
750 717 return 0
751 718 }
752 719
753 720 #
754 721 # Get the end cyl of the given slice
755 722 #
756 723 function get_endslice #<disk> <slice>
757 724 {
758 725 typeset disk=$1
759 726 typeset slice=$2
760 727 if [[ -z $disk || -z $slice ]] ; then
761 728 log_fail "The disk name or slice number is unspecified."
762 729 fi
763 730
764 731 disk=${disk#/dev/dsk/}
765 732 disk=${disk#/dev/rdsk/}
766 733 disk=${disk%s*}
767 734
768 735 typeset -i ratio=0
769 736 ratio=$(prtvtoc /dev/rdsk/${disk}s2 | \
770 737 grep "sectors\/cylinder" | \
771 738 awk '{print $2}')
772 739
773 740 if ((ratio == 0)); then
774 741 return
775 742 fi
776 743
777 744 typeset -i endcyl=$(prtvtoc -h /dev/rdsk/${disk}s2 |
778 745 nawk -v token="$slice" '{if ($1==token) print $6}')
779 746
780 747 ((endcyl = (endcyl + 1) / ratio))
781 748 echo $endcyl
782 749 }
783 750
784 751
785 752 #
786 753 # Given a size,disk and total slice number, this function formats the
787 754 # disk slices from 0 to the total slice number with the same specified
788 755 # size.
789 756 #
790 757 function partition_disk #<slice_size> <whole_disk_name> <total_slices>
791 758 {
792 759 typeset -i i=0
793 760 typeset slice_size=$1
794 761 typeset disk_name=$2
795 762 typeset total_slices=$3
796 763 typeset cyl
797 764
798 765 zero_partitions $disk_name
799 766 while ((i < $total_slices)); do
800 767 if ((i == 2)); then
801 768 ((i = i + 1))
802 769 continue
803 770 fi
804 771 set_partition $i "$cyl" $slice_size $disk_name
805 772 cyl=$(get_endslice $disk_name $i)
806 773 ((i = i+1))
807 774 done
808 775 }
809 776
810 777 #
811 778 # This function continues to write to a filenum number of files into dirnum
812 779 # number of directories until either file_write returns an error or the
813 780 # maximum number of files per directory have been written.
814 781 #
815 782 # Usage:
816 783 # fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data]
817 784 #
818 785 # Return value: 0 on success
819 786 # non 0 on error
820 787 #
821 788 # Where :
822 789 # destdir: is the directory where everything is to be created under
823 790 # dirnum: the maximum number of subdirectories to use, -1 no limit
824 791 # filenum: the maximum number of files per subdirectory
825 792 # bytes: number of bytes to write
826 793 # num_writes: numer of types to write out bytes
827 794 # data: the data that will be writen
828 795 #
829 796 # E.g.
830 797 # file_fs /testdir 20 25 1024 256 0
831 798 #
832 799 # Note: bytes * num_writes equals the size of the testfile
833 800 #
834 801 function fill_fs # destdir dirnum filenum bytes num_writes data
835 802 {
836 803 typeset destdir=${1:-$TESTDIR}
837 804 typeset -i dirnum=${2:-50}
838 805 typeset -i filenum=${3:-50}
839 806 typeset -i bytes=${4:-8192}
840 807 typeset -i num_writes=${5:-10240}
841 808 typeset -i data=${6:-0}
842 809
843 810 typeset -i odirnum=1
844 811 typeset -i idirnum=0
845 812 typeset -i fn=0
846 813 typeset -i retval=0
847 814
848 815 log_must mkdir -p $destdir/$idirnum
849 816 while (($odirnum > 0)); do
850 817 if ((dirnum >= 0 && idirnum >= dirnum)); then
851 818 odirnum=0
852 819 break
853 820 fi
854 821 file_write -o create -f $destdir/$idirnum/$TESTFILE.$fn \
855 822 -b $bytes -c $num_writes -d $data
856 823 retval=$?
857 824 if (($retval != 0)); then
858 825 odirnum=0
859 826 break
860 827 fi
861 828 if (($fn >= $filenum)); then
862 829 fn=0
863 830 ((idirnum = idirnum + 1))
864 831 log_must mkdir -p $destdir/$idirnum
865 832 else
866 833 ((fn = fn + 1))
867 834 fi
868 835 done
869 836 return $retval
870 837 }
871 838
872 839 #
873 840 # Simple function to get the specified property. If unable to
874 841 # get the property then exits.
875 842 #
876 843 # Note property is in 'parsable' format (-p)
877 844 #
878 845 function get_prop # property dataset
879 846 {
880 847 typeset prop_val
881 848 typeset prop=$1
882 849 typeset dataset=$2
883 850
884 851 prop_val=$(zfs get -pH -o value $prop $dataset 2>/dev/null)
885 852 if [[ $? -ne 0 ]]; then
886 853 log_note "Unable to get $prop property for dataset " \
887 854 "$dataset"
888 855 return 1
889 856 fi
890 857
891 858 echo "$prop_val"
892 859 return 0
893 860 }
894 861
895 862 #
896 863 # Simple function to get the specified property of pool. If unable to
897 864 # get the property then exits.
898 865 #
899 866 function get_pool_prop # property pool
900 867 {
901 868 typeset prop_val
902 869 typeset prop=$1
903 870 typeset pool=$2
904 871
905 872 if poolexists $pool ; then
906 873 prop_val=$(zpool get $prop $pool 2>/dev/null | tail -1 | \
907 874 awk '{print $3}')
908 875 if [[ $? -ne 0 ]]; then
909 876 log_note "Unable to get $prop property for pool " \
910 877 "$pool"
911 878 return 1
912 879 fi
913 880 else
914 881 log_note "Pool $pool not exists."
915 882 return 1
916 883 fi
917 884
918 885 echo $prop_val
919 886 return 0
920 887 }
921 888
922 889 # Return 0 if a pool exists; $? otherwise
923 890 #
924 891 # $1 - pool name
925 892
926 893 function poolexists
927 894 {
928 895 typeset pool=$1
929 896
930 897 if [[ -z $pool ]]; then
931 898 log_note "No pool name given."
932 899 return 1
933 900 fi
934 901
935 902 zpool get name "$pool" > /dev/null 2>&1
936 903 return $?
937 904 }
938 905
939 906 # Return 0 if all the specified datasets exist; $? otherwise
940 907 #
941 908 # $1-n dataset name
942 909 function datasetexists
943 910 {
944 911 if (($# == 0)); then
945 912 log_note "No dataset name given."
946 913 return 1
947 914 fi
948 915
949 916 while (($# > 0)); do
950 917 zfs get name $1 > /dev/null 2>&1 || \
951 918 return $?
952 919 shift
953 920 done
954 921
955 922 return 0
956 923 }
957 924
958 925 # return 0 if none of the specified datasets exists, otherwise return 1.
959 926 #
960 927 # $1-n dataset name
961 928 function datasetnonexists
962 929 {
963 930 if (($# == 0)); then
964 931 log_note "No dataset name given."
965 932 return 1
966 933 fi
967 934
968 935 while (($# > 0)); do
969 936 zfs list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 \
970 937 && return 1
971 938 shift
972 939 done
973 940
974 941 return 0
975 942 }
976 943
977 944 #
978 945 # Given a mountpoint, or a dataset name, determine if it is shared.
979 946 #
980 947 # Returns 0 if shared, 1 otherwise.
981 948 #
982 949 function is_shared
983 950 {
984 951 typeset fs=$1
985 952 typeset mtpt
986 953
987 954 if [[ $fs != "/"* ]] ; then
988 955 if datasetnonexists "$fs" ; then
989 956 return 1
990 957 else
991 958 mtpt=$(get_prop mountpoint "$fs")
992 959 case $mtpt in
993 960 none|legacy|-) return 1
994 961 ;;
995 962 *) fs=$mtpt
996 963 ;;
997 964 esac
998 965 fi
999 966 fi
1000 967
1001 968 for mtpt in `share | awk '{print $2}'` ; do
1002 969 if [[ $mtpt == $fs ]] ; then
1003 970 return 0
1004 971 fi
1005 972 done
1006 973
1007 974 typeset stat=$(svcs -H -o STA nfs/server:default)
1008 975 if [[ $stat != "ON" ]]; then
1009 976 log_note "Current nfs/server status: $stat"
1010 977 fi
1011 978
1012 979 return 1
1013 980 }
1014 981
1015 982 #
1016 983 # Given a mountpoint, determine if it is not shared.
1017 984 #
1018 985 # Returns 0 if not shared, 1 otherwise.
1019 986 #
1020 987 function not_shared
1021 988 {
1022 989 typeset fs=$1
1023 990
1024 991 is_shared $fs
1025 992 if (($? == 0)); then
1026 993 return 1
1027 994 fi
1028 995
1029 996 return 0
1030 997 }
1031 998
1032 999 #
1033 1000 # Helper function to unshare a mountpoint.
1034 1001 #
1035 1002 function unshare_fs #fs
1036 1003 {
1037 1004 typeset fs=$1
1038 1005
1039 1006 is_shared $fs
1040 1007 if (($? == 0)); then
1041 1008 log_must zfs unshare $fs
1042 1009 fi
1043 1010
1044 1011 return 0
1045 1012 }
1046 1013
1047 1014 #
1048 1015 # Check NFS server status and trigger it online.
1049 1016 #
1050 1017 function setup_nfs_server
1051 1018 {
1052 1019 # Cannot share directory in non-global zone.
1053 1020 #
1054 1021 if ! is_global_zone; then
1055 1022 log_note "Cannot trigger NFS server by sharing in LZ."
1056 1023 return
1057 1024 fi
1058 1025
1059 1026 typeset nfs_fmri="svc:/network/nfs/server:default"
1060 1027 if [[ $(svcs -Ho STA $nfs_fmri) != "ON" ]]; then
1061 1028 #
1062 1029 # Only really sharing operation can enable NFS server
1063 1030 # to online permanently.
1064 1031 #
1065 1032 typeset dummy=/tmp/dummy
1066 1033
1067 1034 if [[ -d $dummy ]]; then
1068 1035 log_must rm -rf $dummy
1069 1036 fi
1070 1037
1071 1038 log_must mkdir $dummy
1072 1039 log_must share $dummy
1073 1040
1074 1041 #
1075 1042 # Waiting for fmri's status to be the final status.
1076 1043 # Otherwise, in transition, an asterisk (*) is appended for
1077 1044 # instances, unshare will reverse status to 'DIS' again.
1078 1045 #
1079 1046 # Waiting for 1's at least.
1080 1047 #
1081 1048 log_must sleep 1
1082 1049 timeout=10
1083 1050 while [[ timeout -ne 0 && $(svcs -Ho STA $nfs_fmri) == *'*' ]]
1084 1051 do
1085 1052 log_must sleep 1
1086 1053
1087 1054 ((timeout -= 1))
1088 1055 done
1089 1056
1090 1057 log_must unshare $dummy
1091 1058 log_must rm -rf $dummy
1092 1059 fi
1093 1060
1094 1061 log_note "Current NFS status: '$(svcs -Ho STA,FMRI $nfs_fmri)'"
1095 1062 }
1096 1063
1097 1064 #
1098 1065 # To verify whether calling process is in global zone
1099 1066 #
1100 1067 # Return 0 if in global zone, 1 in non-global zone
1101 1068 #
1102 1069 function is_global_zone
1103 1070 {
1104 1071 typeset cur_zone=$(zonename 2>/dev/null)
1105 1072 if [[ $cur_zone != "global" ]]; then
1106 1073 return 1
1107 1074 fi
1108 1075 return 0
1109 1076 }
1110 1077
1111 1078 #
1112 1079 # Verify whether test is permitted to run from
1113 1080 # global zone, local zone, or both
1114 1081 #
1115 1082 # $1 zone limit, could be "global", "local", or "both"(no limit)
1116 1083 #
1117 1084 # Return 0 if permitted, otherwise exit with log_unsupported
1118 1085 #
1119 1086 function verify_runnable # zone limit
1120 1087 {
1121 1088 typeset limit=$1
1122 1089
1123 1090 [[ -z $limit ]] && return 0
1124 1091
1125 1092 if is_global_zone ; then
1126 1093 case $limit in
1127 1094 global|both)
1128 1095 ;;
1129 1096 local) log_unsupported "Test is unable to run from "\
1130 1097 "global zone."
1131 1098 ;;
1132 1099 *) log_note "Warning: unknown limit $limit - " \
1133 1100 "use both."
1134 1101 ;;
1135 1102 esac
1136 1103 else
1137 1104 case $limit in
1138 1105 local|both)
1139 1106 ;;
1140 1107 global) log_unsupported "Test is unable to run from "\
1141 1108 "local zone."
1142 1109 ;;
1143 1110 *) log_note "Warning: unknown limit $limit - " \
1144 1111 "use both."
1145 1112 ;;
1146 1113 esac
1147 1114
1148 1115 reexport_pool
1149 1116 fi
1150 1117
1151 1118 return 0
1152 1119 }
1153 1120
1154 1121 # Return 0 if create successfully or the pool exists; $? otherwise
1155 1122 # Note: In local zones, this function should return 0 silently.
1156 1123 #
1157 1124 # $1 - pool name
1158 1125 # $2-n - [keyword] devs_list
1159 1126
1160 1127 function create_pool #pool devs_list
1161 1128 {
1162 1129 typeset pool=${1%%/*}
1163 1130
1164 1131 shift
1165 1132
1166 1133 if [[ -z $pool ]]; then
1167 1134 log_note "Missing pool name."
1168 1135 return 1
1169 1136 fi
1170 1137
1171 1138 if poolexists $pool ; then
1172 1139 destroy_pool $pool
1173 1140 fi
1174 1141
1175 1142 if is_global_zone ; then
1176 1143 [[ -d /$pool ]] && rm -rf /$pool
|
↓ open down ↓ |
673 lines elided |
↑ open up ↑ |
1177 1144 log_must zpool create -f $pool $@
1178 1145 fi
1179 1146
1180 1147 return 0
1181 1148 }
1182 1149
1183 1150 # Return 0 if destroy successfully or the pool exists; $? otherwise
1184 1151 # Note: In local zones, this function should return 0 silently.
1185 1152 #
1186 1153 # $1 - pool name
1154 +# $2 - optional force flag
1187 1155 # Destroy pool with the given parameters.
1188 1156
1189 -function destroy_pool #pool
1157 +function do_destroy_pool #pool <-f>
1190 1158 {
1191 1159 typeset pool=${1%%/*}
1160 + typeset force=$2
1192 1161 typeset mtpt
1193 1162
1194 1163 if [[ -z $pool ]]; then
1195 1164 log_note "No pool name given."
1196 1165 return 1
1197 1166 fi
1198 1167
1199 1168 if is_global_zone ; then
1200 1169 if poolexists "$pool" ; then
1201 1170 mtpt=$(get_prop mountpoint "$pool")
1202 1171
1203 1172 # At times, syseventd activity can cause attempts to
1204 1173 # destroy a pool to fail with EBUSY. We retry a few
1205 1174 # times allowing failures before requiring the destroy
1206 1175 # to succeed.
1207 - typeset -i wait_time=10 ret=1 count=0
1176 + typeset -i wait_time=$DESTROY_SLEEP_TIME ret=1 count=0
1208 1177 must=""
1209 1178 while [[ $ret -ne 0 ]]; do
1210 - $must zpool destroy -f $pool
1179 + $must zpool destroy $force $pool
1211 1180 ret=$?
1212 1181 [[ $ret -eq 0 ]] && break
1213 1182 log_note "zpool destroy failed with $ret"
1214 - [[ count++ -ge 7 ]] && must=log_must
1183 + [[ count++ -ge $NUM_RETRIES ]] && must=log_must
1215 1184 sleep $wait_time
1216 1185 done
1217 1186
1218 1187 [[ -d $mtpt ]] && \
1219 1188 log_must rm -rf $mtpt
1220 1189 else
1221 1190 log_note "Pool does not exist. ($pool)"
1222 1191 return 1
1223 1192 fi
1224 1193 fi
1225 1194
1226 1195 return 0
1227 1196 }
1228 1197
1198 +# Return 0 if destroy successfully or the pool exists; $? otherwise
1199 +# Note: In local zones, this function should return 0 silently.
1229 1200 #
1201 +# $1 - pool name
1202 +# Destroy pool with the given parameters.
1203 +
1204 +function destroy_pool_no_force #pool
1205 +{
1206 + typeset pool=${1%%/*}
1207 +
1208 + do_destroy_pool $pool
1209 + if (( $? != 0 )); then
1210 + return 1
1211 + else
1212 + return 0
1213 + fi
1214 +}
1215 +
1216 +# Return 0 if destroy successfully or the pool exists; $? otherwise
1217 +# Note: In local zones, this function should return 0 silently.
1218 +#
1219 +# $1 - pool name
1220 +# Force a destroy pool with the given parameters.
1221 +
1222 +function destroy_pool #pool
1223 +{
1224 + typeset pool=${1%%/*}
1225 +
1226 + do_destroy_pool $pool -f
1227 + if (( $? != 0 )); then
1228 + return 1
1229 + else
1230 + return 0
1231 + fi
1232 +}
1233 +
1234 +#
1230 1235 # Firstly, create a pool with 5 datasets. Then, create a single zone and
1231 1236 # export the 5 datasets to it. In addition, we also add a ZFS filesystem
1232 1237 # and a zvol device to the zone.
1233 1238 #
1234 1239 # $1 zone name
1235 1240 # $2 zone root directory prefix
1236 1241 # $3 zone ip
1237 1242 #
1238 1243 function zfs_zones_setup #zone_name zone_root zone_ip
1239 1244 {
1240 1245 typeset zone_name=${1:-$(hostname)-z}
1241 1246 typeset zone_root=${2:-"/zone_root"}
1242 1247 typeset zone_ip=${3:-"10.1.1.10"}
1243 1248 typeset prefix_ctr=$ZONE_CTR
1244 1249 typeset pool_name=$ZONE_POOL
1245 1250 typeset -i cntctr=5
1246 1251 typeset -i i=0
1247 1252
1248 1253 # Create pool and 5 container within it
1249 1254 #
1250 1255 [[ -d /$pool_name ]] && rm -rf /$pool_name
1251 1256 log_must zpool create -f $pool_name $DISKS
1252 1257 while ((i < cntctr)); do
1253 1258 log_must zfs create $pool_name/$prefix_ctr$i
1254 1259 ((i += 1))
1255 1260 done
1256 1261
1257 1262 # create a zvol
1258 1263 log_must zfs create -V 1g $pool_name/zone_zvol
1259 1264
1260 1265 #
1261 1266 # If current system support slog, add slog device for pool
1262 1267 #
1263 1268 if verify_slog_support ; then
1264 1269 typeset sdevs="/var/tmp/sdev1 /var/tmp/sdev2"
1265 1270 log_must mkfile $MINVDEVSIZE $sdevs
1266 1271 log_must zpool add $pool_name log mirror $sdevs
1267 1272 fi
1268 1273
1269 1274 # this isn't supported just yet.
1270 1275 # Create a filesystem. In order to add this to
1271 1276 # the zone, it must have it's mountpoint set to 'legacy'
1272 1277 # log_must zfs create $pool_name/zfs_filesystem
1273 1278 # log_must zfs set mountpoint=legacy $pool_name/zfs_filesystem
1274 1279
1275 1280 [[ -d $zone_root ]] && \
1276 1281 log_must rm -rf $zone_root/$zone_name
1277 1282 [[ ! -d $zone_root ]] && \
1278 1283 log_must mkdir -p -m 0700 $zone_root/$zone_name
1279 1284
1280 1285 # Create zone configure file and configure the zone
1281 1286 #
1282 1287 typeset zone_conf=/tmp/zone_conf.$$
1283 1288 echo "create" > $zone_conf
1284 1289 echo "set zonepath=$zone_root/$zone_name" >> $zone_conf
1285 1290 echo "set autoboot=true" >> $zone_conf
1286 1291 i=0
1287 1292 while ((i < cntctr)); do
1288 1293 echo "add dataset" >> $zone_conf
1289 1294 echo "set name=$pool_name/$prefix_ctr$i" >> \
1290 1295 $zone_conf
1291 1296 echo "end" >> $zone_conf
1292 1297 ((i += 1))
1293 1298 done
1294 1299
1295 1300 # add our zvol to the zone
1296 1301 echo "add device" >> $zone_conf
1297 1302 echo "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf
1298 1303 echo "end" >> $zone_conf
1299 1304
1300 1305 # add a corresponding zvol rdsk to the zone
1301 1306 echo "add device" >> $zone_conf
1302 1307 echo "set match=/dev/zvol/rdsk/$pool_name/zone_zvol" >> $zone_conf
1303 1308 echo "end" >> $zone_conf
1304 1309
1305 1310 # once it's supported, we'll add our filesystem to the zone
1306 1311 # echo "add fs" >> $zone_conf
1307 1312 # echo "set type=zfs" >> $zone_conf
1308 1313 # echo "set special=$pool_name/zfs_filesystem" >> $zone_conf
1309 1314 # echo "set dir=/export/zfs_filesystem" >> $zone_conf
1310 1315 # echo "end" >> $zone_conf
1311 1316
1312 1317 echo "verify" >> $zone_conf
1313 1318 echo "commit" >> $zone_conf
1314 1319 log_must zonecfg -z $zone_name -f $zone_conf
1315 1320 log_must rm -f $zone_conf
1316 1321
1317 1322 # Install the zone
1318 1323 zoneadm -z $zone_name install
1319 1324 if (($? == 0)); then
1320 1325 log_note "SUCCESS: zoneadm -z $zone_name install"
1321 1326 else
1322 1327 log_fail "FAIL: zoneadm -z $zone_name install"
1323 1328 fi
1324 1329
1325 1330 # Install sysidcfg file
1326 1331 #
1327 1332 typeset sysidcfg=$zone_root/$zone_name/root/etc/sysidcfg
1328 1333 echo "system_locale=C" > $sysidcfg
1329 1334 echo "terminal=dtterm" >> $sysidcfg
1330 1335 echo "network_interface=primary {" >> $sysidcfg
1331 1336 echo "hostname=$zone_name" >> $sysidcfg
1332 1337 echo "}" >> $sysidcfg
1333 1338 echo "name_service=NONE" >> $sysidcfg
1334 1339 echo "root_password=mo791xfZ/SFiw" >> $sysidcfg
1335 1340 echo "security_policy=NONE" >> $sysidcfg
1336 1341 echo "timezone=US/Eastern" >> $sysidcfg
1337 1342
1338 1343 # Boot this zone
1339 1344 log_must zoneadm -z $zone_name boot
1340 1345 }
1341 1346
1342 1347 #
1343 1348 # Reexport TESTPOOL & TESTPOOL(1-4)
1344 1349 #
1345 1350 function reexport_pool
1346 1351 {
1347 1352 typeset -i cntctr=5
1348 1353 typeset -i i=0
1349 1354
1350 1355 while ((i < cntctr)); do
1351 1356 if ((i == 0)); then
1352 1357 TESTPOOL=$ZONE_POOL/$ZONE_CTR$i
1353 1358 if ! ismounted $TESTPOOL; then
1354 1359 log_must zfs mount $TESTPOOL
1355 1360 fi
1356 1361 else
1357 1362 eval TESTPOOL$i=$ZONE_POOL/$ZONE_CTR$i
1358 1363 if eval ! ismounted \$TESTPOOL$i; then
1359 1364 log_must eval zfs mount \$TESTPOOL$i
1360 1365 fi
1361 1366 fi
1362 1367 ((i += 1))
1363 1368 done
1364 1369 }
1365 1370
1366 1371 #
1367 1372 # Verify a given disk is online or offline
1368 1373 #
1369 1374 # Return 0 is pool/disk matches expected state, 1 otherwise
1370 1375 #
1371 1376 function check_state # pool disk state{online,offline}
1372 1377 {
1373 1378 typeset pool=$1
1374 1379 typeset disk=${2#/dev/dsk/}
1375 1380 typeset state=$3
1376 1381
1377 1382 zpool status -v $pool | grep "$disk" \
1378 1383 | grep -i "$state" > /dev/null 2>&1
1379 1384
1380 1385 return $?
1381 1386 }
1382 1387
1383 1388 #
1384 1389 # Get the mountpoint of snapshot
1385 1390 # For the snapshot use <mp_filesystem>/.zfs/snapshot/<snap>
1386 1391 # as its mountpoint
1387 1392 #
1388 1393 function snapshot_mountpoint
1389 1394 {
1390 1395 typeset dataset=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
1391 1396
1392 1397 if [[ $dataset != *@* ]]; then
1393 1398 log_fail "Error name of snapshot '$dataset'."
1394 1399 fi
1395 1400
1396 1401 typeset fs=${dataset%@*}
1397 1402 typeset snap=${dataset#*@}
1398 1403
1399 1404 if [[ -z $fs || -z $snap ]]; then
1400 1405 log_fail "Error name of snapshot '$dataset'."
1401 1406 fi
1402 1407
1403 1408 echo $(get_prop mountpoint $fs)/.zfs/snapshot/$snap
1404 1409 }
1405 1410
1406 1411 #
1407 1412 # Given a pool and file system, this function will verify the file system
1408 1413 # using the zdb internal tool. Note that the pool is exported and imported
1409 1414 # to ensure it has consistent state.
1410 1415 #
1411 1416 function verify_filesys # pool filesystem dir
1412 1417 {
1413 1418 typeset pool="$1"
1414 1419 typeset filesys="$2"
1415 1420 typeset zdbout="/tmp/zdbout.$$"
1416 1421
1417 1422 shift
1418 1423 shift
1419 1424 typeset dirs=$@
1420 1425 typeset search_path=""
1421 1426
1422 1427 log_note "Calling zdb to verify filesystem '$filesys'"
1423 1428 zfs unmount -a > /dev/null 2>&1
1424 1429 log_must zpool export $pool
1425 1430
1426 1431 if [[ -n $dirs ]] ; then
1427 1432 for dir in $dirs ; do
1428 1433 search_path="$search_path -d $dir"
1429 1434 done
1430 1435 fi
1431 1436
1432 1437 log_must zpool import $search_path $pool
1433 1438
1434 1439 zdb -cudi $filesys > $zdbout 2>&1
1435 1440 if [[ $? != 0 ]]; then
1436 1441 log_note "Output: zdb -cudi $filesys"
1437 1442 cat $zdbout
1438 1443 log_fail "zdb detected errors with: '$filesys'"
1439 1444 fi
1440 1445
1441 1446 log_must zfs mount -a
1442 1447 log_must rm -rf $zdbout
1443 1448 }
1444 1449
1445 1450 #
1446 1451 # Given a pool, and this function list all disks in the pool
1447 1452 #
1448 1453 function get_disklist # pool
1449 1454 {
1450 1455 typeset disklist=""
1451 1456
1452 1457 disklist=$(zpool iostat -v $1 | nawk '(NR >4) {print $1}' | \
1453 1458 grep -v "\-\-\-\-\-" | \
1454 1459 egrep -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
1455 1460
1456 1461 echo $disklist
1457 1462 }
1458 1463
1459 1464 # /**
1460 1465 # This function kills a given list of processes after a time period. We use
1461 1466 # this in the stress tests instead of STF_TIMEOUT so that we can have processes
1462 1467 # run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT
1463 1468 # would be listed as FAIL, which we don't want : we're happy with stress tests
1464 1469 # running for a certain amount of time, then finishing.
1465 1470 #
1466 1471 # @param $1 the time in seconds after which we should terminate these processes
1467 1472 # @param $2..$n the processes we wish to terminate.
1468 1473 # */
1469 1474 function stress_timeout
1470 1475 {
1471 1476 typeset -i TIMEOUT=$1
1472 1477 shift
1473 1478 typeset cpids="$@"
1474 1479
1475 1480 log_note "Waiting for child processes($cpids). " \
1476 1481 "It could last dozens of minutes, please be patient ..."
1477 1482 log_must sleep $TIMEOUT
1478 1483
1479 1484 log_note "Killing child processes after ${TIMEOUT} stress timeout."
1480 1485 typeset pid
1481 1486 for pid in $cpids; do
1482 1487 ps -p $pid > /dev/null 2>&1
1483 1488 if (($? == 0)); then
1484 1489 log_must kill -USR1 $pid
1485 1490 fi
1486 1491 done
1487 1492 }
1488 1493
1489 1494 #
1490 1495 # Verify a given hotspare disk is inuse or avail
1491 1496 #
1492 1497 # Return 0 is pool/disk matches expected state, 1 otherwise
1493 1498 #
1494 1499 function check_hotspare_state # pool disk state{inuse,avail}
1495 1500 {
1496 1501 typeset pool=$1
1497 1502 typeset disk=${2#/dev/dsk/}
1498 1503 typeset state=$3
|
↓ open down ↓ |
259 lines elided |
↑ open up ↑ |
1499 1504
1500 1505 cur_state=$(get_device_state $pool $disk "spares")
1501 1506
1502 1507 if [[ $state != ${cur_state} ]]; then
1503 1508 return 1
1504 1509 fi
1505 1510 return 0
1506 1511 }
1507 1512
1508 1513 #
1509 -# Wait until a hotspare transitions to a given state or times out.
1510 -#
1511 -# Return 0 when pool/disk matches expected state, 1 on timeout.
1512 -#
1513 -function wait_hotspare_state # pool disk state timeout
1514 -{
1515 - typeset pool=$1
1516 - typeset disk=${2#$/DEV_DSKDIR/}
1517 - typeset state=$3
1518 - typeset timeout=${4:-60}
1519 - typeset -i i=0
1520 -
1521 - while [[ $i -lt $timeout ]]; do
1522 - if check_hotspare_state $pool $disk $state; then
1523 - return 0
1524 - fi
1525 -
1526 - i=$((i+1))
1527 - sleep 1
1528 - done
1529 -
1530 - return 1
1531 -}
1532 -
1533 -#
1534 1514 # Verify a given slog disk is inuse or avail
1535 1515 #
1536 1516 # Return 0 is pool/disk matches expected state, 1 otherwise
1537 1517 #
1538 1518 function check_slog_state # pool disk state{online,offline,unavail}
1539 1519 {
1540 1520 typeset pool=$1
1541 1521 typeset disk=${2#/dev/dsk/}
1542 1522 typeset state=$3
1543 1523
1544 1524 cur_state=$(get_device_state $pool $disk "logs")
1545 1525
1546 1526 if [[ $state != ${cur_state} ]]; then
1547 1527 return 1
1548 1528 fi
1549 1529 return 0
1550 1530 }
1551 1531
1552 1532 #
1553 1533 # Verify a given vdev disk is inuse or avail
1554 1534 #
1555 1535 # Return 0 is pool/disk matches expected state, 1 otherwise
1556 1536 #
1557 1537 function check_vdev_state # pool disk state{online,offline,unavail}
1558 1538 {
1559 1539 typeset pool=$1
1560 1540 typeset disk=${2#/dev/dsk/}
1561 1541 typeset state=$3
|
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
1562 1542
1563 1543 cur_state=$(get_device_state $pool $disk)
1564 1544
1565 1545 if [[ $state != ${cur_state} ]]; then
1566 1546 return 1
1567 1547 fi
1568 1548 return 0
1569 1549 }
1570 1550
1571 1551 #
1572 -# Wait until a vdev transitions to a given state or times out.
1573 -#
1574 -# Return 0 when pool/disk matches expected state, 1 on timeout.
1575 -#
1576 -function wait_vdev_state # pool disk state timeout
1577 -{
1578 - typeset pool=$1
1579 - typeset disk=${2#$/DEV_DSKDIR/}
1580 - typeset state=$3
1581 - typeset timeout=${4:-60}
1582 - typeset -i i=0
1583 -
1584 - while [[ $i -lt $timeout ]]; do
1585 - if check_vdev_state $pool $disk $state; then
1586 - return 0
1587 - fi
1588 -
1589 - i=$((i+1))
1590 - sleep 1
1591 - done
1592 -
1593 - return 1
1594 -}
1595 -
1596 -#
1597 1552 # Check the output of 'zpool status -v <pool>',
1598 1553 # and to see if the content of <token> contain the <keyword> specified.
1599 1554 #
1600 1555 # Return 0 is contain, 1 otherwise
1601 1556 #
1602 1557 function check_pool_status # pool token keyword <verbose>
1603 1558 {
1604 1559 typeset pool=$1
1605 1560 typeset token=$2
1606 1561 typeset keyword=$3
1607 1562 typeset verbose=${4:-false}
1608 1563
1609 1564 scan=$(zpool status -v "$pool" 2>/dev/null | nawk -v token="$token:" '
1610 1565 ($1==token) {print $0}')
1611 1566 if [[ $verbose == true ]]; then
1612 1567 log_note $scan
1613 1568 fi
1614 1569 echo $scan | grep -i "$keyword" > /dev/null 2>&1
1615 1570
1616 1571 return $?
|
↓ open down ↓ |
10 lines elided |
↑ open up ↑ |
1617 1572 }
1618 1573
1619 1574 #
1620 1575 # These 6 following functions are instance of check_pool_status()
1621 1576 # is_pool_resilvering - to check if the pool is resilver in progress
1622 1577 # is_pool_resilvered - to check if the pool is resilver completed
1623 1578 # is_pool_scrubbing - to check if the pool is scrub in progress
1624 1579 # is_pool_scrubbed - to check if the pool is scrub completed
1625 1580 # is_pool_scrub_stopped - to check if the pool is scrub stopped
1626 1581 # is_pool_scrub_paused - to check if the pool has scrub paused
1627 -# is_pool_removing - to check if the pool is removing a vdev
1628 -# is_pool_removed - to check if the pool is remove completed
1629 1582 #
1630 1583 function is_pool_resilvering #pool <verbose>
1631 1584 {
1632 1585 check_pool_status "$1" "scan" "resilver in progress since " $2
1633 1586 return $?
1634 1587 }
1635 1588
1636 1589 function is_pool_resilvered #pool <verbose>
1637 1590 {
1638 1591 check_pool_status "$1" "scan" "resilvered " $2
1639 1592 return $?
1640 1593 }
1641 1594
1642 1595 function is_pool_scrubbing #pool <verbose>
1643 1596 {
1644 1597 check_pool_status "$1" "scan" "scrub in progress since " $2
1645 1598 return $?
1646 1599 }
1647 1600
1648 1601 function is_pool_scrubbed #pool <verbose>
1649 1602 {
1650 1603 check_pool_status "$1" "scan" "scrub repaired" $2
1651 1604 return $?
1652 1605 }
1653 1606
1654 1607 function is_pool_scrub_stopped #pool <verbose>
1655 1608 {
|
↓ open down ↓ |
17 lines elided |
↑ open up ↑ |
1656 1609 check_pool_status "$1" "scan" "scrub canceled" $2
1657 1610 return $?
1658 1611 }
1659 1612
1660 1613 function is_pool_scrub_paused #pool <verbose>
1661 1614 {
1662 1615 check_pool_status "$1" "scan" "scrub paused since " $2
1663 1616 return $?
1664 1617 }
1665 1618
1666 -function is_pool_removing #pool
1667 -{
1668 - check_pool_status "$1" "remove" "in progress since "
1669 - return $?
1670 -}
1671 -
1672 -function is_pool_removed #pool
1673 -{
1674 - check_pool_status "$1" "remove" "completed on"
1675 - return $?
1676 -}
1677 -
1678 1619 #
1679 1620 # Use create_pool()/destroy_pool() to clean up the infomation in
1680 1621 # in the given disk to avoid slice overlapping.
1681 1622 #
1682 1623 function cleanup_devices #vdevs
1683 1624 {
1684 1625 typeset pool="foopool$$"
1685 1626
1686 1627 if poolexists $pool ; then
1687 1628 destroy_pool $pool
1688 1629 fi
1689 1630
1690 1631 create_pool $pool $@
1691 1632 destroy_pool $pool
1692 1633
1693 1634 return 0
1694 1635 }
1695 1636
1696 1637 #/**
1697 1638 # A function to find and locate free disks on a system or from given
1698 1639 # disks as the parameter. It works by locating disks that are in use
1699 1640 # as swap devices and dump devices, and also disks listed in /etc/vfstab
1700 1641 #
1701 1642 # $@ given disks to find which are free, default is all disks in
1702 1643 # the test system
1703 1644 #
1704 1645 # @return a string containing the list of available disks
1705 1646 #*/
1706 1647 function find_disks
1707 1648 {
1708 1649 sfi=/tmp/swaplist.$$
1709 1650 dmpi=/tmp/dumpdev.$$
1710 1651 max_finddisksnum=${MAX_FINDDISKSNUM:-6}
1711 1652
1712 1653 swap -l > $sfi
1713 1654 dumpadm > $dmpi 2>/dev/null
1714 1655
1715 1656 # write an awk script that can process the output of format
1716 1657 # to produce a list of disks we know about. Note that we have
1717 1658 # to escape "$2" so that the shell doesn't interpret it while
1718 1659 # we're creating the awk script.
1719 1660 # -------------------
1720 1661 cat > /tmp/find_disks.awk <<EOF
1721 1662 #!/bin/nawk -f
1722 1663 BEGIN { FS="."; }
1723 1664
1724 1665 /^Specify disk/{
1725 1666 searchdisks=0;
1726 1667 }
1727 1668
1728 1669 {
1729 1670 if (searchdisks && \$2 !~ "^$"){
1730 1671 split(\$2,arr," ");
1731 1672 print arr[1];
1732 1673 }
1733 1674 }
1734 1675
1735 1676 /^AVAILABLE DISK SELECTIONS:/{
1736 1677 searchdisks=1;
1737 1678 }
1738 1679 EOF
1739 1680 #---------------------
1740 1681
1741 1682 chmod 755 /tmp/find_disks.awk
1742 1683 disks=${@:-$(echo "" | format -e 2>/dev/null | /tmp/find_disks.awk)}
1743 1684 rm /tmp/find_disks.awk
1744 1685
1745 1686 unused=""
1746 1687 for disk in $disks; do
1747 1688 # Check for mounted
1748 1689 grep "${disk}[sp]" /etc/mnttab >/dev/null
1749 1690 (($? == 0)) && continue
1750 1691 # Check for swap
1751 1692 grep "${disk}[sp]" $sfi >/dev/null
1752 1693 (($? == 0)) && continue
1753 1694 # check for dump device
1754 1695 grep "${disk}[sp]" $dmpi >/dev/null
1755 1696 (($? == 0)) && continue
1756 1697 # check to see if this disk hasn't been explicitly excluded
1757 1698 # by a user-set environment variable
1758 1699 echo "${ZFS_HOST_DEVICES_IGNORE}" | grep "${disk}" > /dev/null
1759 1700 (($? == 0)) && continue
1760 1701 unused_candidates="$unused_candidates $disk"
1761 1702 done
1762 1703 rm $sfi
1763 1704 rm $dmpi
1764 1705
1765 1706 # now just check to see if those disks do actually exist
1766 1707 # by looking for a device pointing to the first slice in
1767 1708 # each case. limit the number to max_finddisksnum
1768 1709 count=0
1769 1710 for disk in $unused_candidates; do
1770 1711 if [ -b /dev/dsk/${disk}s0 ]; then
1771 1712 if [ $count -lt $max_finddisksnum ]; then
1772 1713 unused="$unused $disk"
1773 1714 # do not impose limit if $@ is provided
1774 1715 [[ -z $@ ]] && ((count = count + 1))
1775 1716 fi
1776 1717 fi
1777 1718 done
1778 1719
1779 1720 # finally, return our disk list
1780 1721 echo $unused
1781 1722 }
1782 1723
1783 1724 #
1784 1725 # Add specified user to specified group
1785 1726 #
1786 1727 # $1 group name
1787 1728 # $2 user name
1788 1729 # $3 base of the homedir (optional)
1789 1730 #
1790 1731 function add_user #<group_name> <user_name> <basedir>
1791 1732 {
1792 1733 typeset gname=$1
1793 1734 typeset uname=$2
1794 1735 typeset basedir=${3:-"/var/tmp"}
1795 1736
1796 1737 if ((${#gname} == 0 || ${#uname} == 0)); then
1797 1738 log_fail "group name or user name are not defined."
1798 1739 fi
1799 1740
1800 1741 log_must useradd -g $gname -d $basedir/$uname -m $uname
1801 1742
1802 1743 return 0
1803 1744 }
1804 1745
1805 1746 #
1806 1747 # Delete the specified user.
1807 1748 #
1808 1749 # $1 login name
1809 1750 # $2 base of the homedir (optional)
1810 1751 #
1811 1752 function del_user #<logname> <basedir>
1812 1753 {
1813 1754 typeset user=$1
1814 1755 typeset basedir=${2:-"/var/tmp"}
1815 1756
1816 1757 if ((${#user} == 0)); then
1817 1758 log_fail "login name is necessary."
1818 1759 fi
1819 1760
1820 1761 if id $user > /dev/null 2>&1; then
1821 1762 log_must userdel $user
1822 1763 fi
1823 1764
1824 1765 [[ -d $basedir/$user ]] && rm -fr $basedir/$user
1825 1766
1826 1767 return 0
1827 1768 }
1828 1769
1829 1770 #
1830 1771 # Select valid gid and create specified group.
1831 1772 #
1832 1773 # $1 group name
1833 1774 #
1834 1775 function add_group #<group_name>
1835 1776 {
1836 1777 typeset group=$1
1837 1778
1838 1779 if ((${#group} == 0)); then
1839 1780 log_fail "group name is necessary."
1840 1781 fi
1841 1782
1842 1783 # Assign 100 as the base gid
1843 1784 typeset -i gid=100
1844 1785 while true; do
1845 1786 groupadd -g $gid $group > /dev/null 2>&1
1846 1787 typeset -i ret=$?
1847 1788 case $ret in
1848 1789 0) return 0 ;;
1849 1790 # The gid is not unique
1850 1791 4) ((gid += 1)) ;;
1851 1792 *) return 1 ;;
1852 1793 esac
1853 1794 done
1854 1795 }
1855 1796
1856 1797 #
1857 1798 # Delete the specified group.
1858 1799 #
1859 1800 # $1 group name
1860 1801 #
1861 1802 function del_group #<group_name>
1862 1803 {
1863 1804 typeset grp=$1
1864 1805 if ((${#grp} == 0)); then
1865 1806 log_fail "group name is necessary."
1866 1807 fi
1867 1808
1868 1809 groupmod -n $grp $grp > /dev/null 2>&1
1869 1810 typeset -i ret=$?
1870 1811 case $ret in
1871 1812 # Group does not exist.
1872 1813 6) return 0 ;;
1873 1814 # Name already exists as a group name
1874 1815 9) log_must groupdel $grp ;;
1875 1816 *) return 1 ;;
1876 1817 esac
1877 1818
1878 1819 return 0
1879 1820 }
1880 1821
1881 1822 #
1882 1823 # This function will return true if it's safe to destroy the pool passed
1883 1824 # as argument 1. It checks for pools based on zvols and files, and also
1884 1825 # files contained in a pool that may have a different mountpoint.
1885 1826 #
1886 1827 function safe_to_destroy_pool { # $1 the pool name
1887 1828
1888 1829 typeset pool=""
1889 1830 typeset DONT_DESTROY=""
1890 1831
1891 1832 # We check that by deleting the $1 pool, we're not
1892 1833 # going to pull the rug out from other pools. Do this
1893 1834 # by looking at all other pools, ensuring that they
1894 1835 # aren't built from files or zvols contained in this pool.
1895 1836
1896 1837 for pool in $(zpool list -H -o name)
1897 1838 do
1898 1839 ALTMOUNTPOOL=""
1899 1840
1900 1841 # this is a list of the top-level directories in each of the
1901 1842 # files that make up the path to the files the pool is based on
1902 1843 FILEPOOL=$(zpool status -v $pool | grep /$1/ | \
1903 1844 awk '{print $1}')
1904 1845
1905 1846 # this is a list of the zvols that make up the pool
1906 1847 ZVOLPOOL=$(zpool status -v $pool | grep "/dev/zvol/dsk/$1$" \
1907 1848 | awk '{print $1}')
1908 1849
1909 1850 # also want to determine if it's a file-based pool using an
1910 1851 # alternate mountpoint...
1911 1852 POOL_FILE_DIRS=$(zpool status -v $pool | \
1912 1853 grep / | awk '{print $1}' | \
1913 1854 awk -F/ '{print $2}' | grep -v "dev")
1914 1855
1915 1856 for pooldir in $POOL_FILE_DIRS
1916 1857 do
1917 1858 OUTPUT=$(zfs list -H -r -o mountpoint $1 | \
1918 1859 grep "${pooldir}$" | awk '{print $1}')
1919 1860
1920 1861 ALTMOUNTPOOL="${ALTMOUNTPOOL}${OUTPUT}"
1921 1862 done
1922 1863
1923 1864
1924 1865 if [ ! -z "$ZVOLPOOL" ]
1925 1866 then
1926 1867 DONT_DESTROY="true"
1927 1868 log_note "Pool $pool is built from $ZVOLPOOL on $1"
1928 1869 fi
1929 1870
1930 1871 if [ ! -z "$FILEPOOL" ]
1931 1872 then
1932 1873 DONT_DESTROY="true"
1933 1874 log_note "Pool $pool is built from $FILEPOOL on $1"
1934 1875 fi
1935 1876
1936 1877 if [ ! -z "$ALTMOUNTPOOL" ]
1937 1878 then
1938 1879 DONT_DESTROY="true"
1939 1880 log_note "Pool $pool is built from $ALTMOUNTPOOL on $1"
1940 1881 fi
1941 1882 done
1942 1883
1943 1884 if [ -z "${DONT_DESTROY}" ]
1944 1885 then
1945 1886 return 0
1946 1887 else
1947 1888 log_note "Warning: it is not safe to destroy $1!"
1948 1889 return 1
1949 1890 fi
1950 1891 }
1951 1892
1952 1893 #
1953 1894 # Get the available ZFS compression options
1954 1895 # $1 option type zfs_set|zfs_compress
1955 1896 #
1956 1897 function get_compress_opts
1957 1898 {
1958 1899 typeset COMPRESS_OPTS
1959 1900 typeset GZIP_OPTS="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \
1960 1901 gzip-6 gzip-7 gzip-8 gzip-9"
1961 1902
1962 1903 if [[ $1 == "zfs_compress" ]] ; then
1963 1904 COMPRESS_OPTS="on lzjb"
1964 1905 elif [[ $1 == "zfs_set" ]] ; then
1965 1906 COMPRESS_OPTS="on off lzjb"
1966 1907 fi
1967 1908 typeset valid_opts="$COMPRESS_OPTS"
1968 1909 zfs get 2>&1 | grep gzip >/dev/null 2>&1
1969 1910 if [[ $? -eq 0 ]]; then
1970 1911 valid_opts="$valid_opts $GZIP_OPTS"
1971 1912 fi
1972 1913 echo "$valid_opts"
1973 1914 }
1974 1915
1975 1916 #
1976 1917 # Verify zfs operation with -p option work as expected
1977 1918 # $1 operation, value could be create, clone or rename
1978 1919 # $2 dataset type, value could be fs or vol
1979 1920 # $3 dataset name
1980 1921 # $4 new dataset name
1981 1922 #
1982 1923 function verify_opt_p_ops
1983 1924 {
1984 1925 typeset ops=$1
1985 1926 typeset datatype=$2
1986 1927 typeset dataset=$3
1987 1928 typeset newdataset=$4
1988 1929
1989 1930 if [[ $datatype != "fs" && $datatype != "vol" ]]; then
1990 1931 log_fail "$datatype is not supported."
1991 1932 fi
1992 1933
1993 1934 # check parameters accordingly
1994 1935 case $ops in
1995 1936 create)
1996 1937 newdataset=$dataset
1997 1938 dataset=""
1998 1939 if [[ $datatype == "vol" ]]; then
1999 1940 ops="create -V $VOLSIZE"
2000 1941 fi
2001 1942 ;;
2002 1943 clone)
2003 1944 if [[ -z $newdataset ]]; then
2004 1945 log_fail "newdataset should not be empty" \
2005 1946 "when ops is $ops."
2006 1947 fi
2007 1948 log_must datasetexists $dataset
2008 1949 log_must snapexists $dataset
2009 1950 ;;
2010 1951 rename)
2011 1952 if [[ -z $newdataset ]]; then
2012 1953 log_fail "newdataset should not be empty" \
2013 1954 "when ops is $ops."
2014 1955 fi
2015 1956 log_must datasetexists $dataset
2016 1957 log_mustnot snapexists $dataset
2017 1958 ;;
2018 1959 *)
2019 1960 log_fail "$ops is not supported."
2020 1961 ;;
2021 1962 esac
2022 1963
2023 1964 # make sure the upper level filesystem does not exist
2024 1965 if datasetexists ${newdataset%/*} ; then
2025 1966 log_must zfs destroy -rRf ${newdataset%/*}
2026 1967 fi
2027 1968
2028 1969 # without -p option, operation will fail
2029 1970 log_mustnot zfs $ops $dataset $newdataset
2030 1971 log_mustnot datasetexists $newdataset ${newdataset%/*}
2031 1972
2032 1973 # with -p option, operation should succeed
2033 1974 log_must zfs $ops -p $dataset $newdataset
2034 1975 if ! datasetexists $newdataset ; then
2035 1976 log_fail "-p option does not work for $ops"
2036 1977 fi
2037 1978
2038 1979 # when $ops is create or clone, redo the operation still return zero
2039 1980 if [[ $ops != "rename" ]]; then
2040 1981 log_must zfs $ops -p $dataset $newdataset
2041 1982 fi
2042 1983
2043 1984 return 0
2044 1985 }
2045 1986
2046 1987 #
2047 1988 # Get configuration of pool
2048 1989 # $1 pool name
2049 1990 # $2 config name
2050 1991 #
2051 1992 function get_config
2052 1993 {
2053 1994 typeset pool=$1
2054 1995 typeset config=$2
2055 1996 typeset alt_root
2056 1997
2057 1998 if ! poolexists "$pool" ; then
2058 1999 return 1
2059 2000 fi
2060 2001 alt_root=$(zpool list -H $pool | awk '{print $NF}')
2061 2002 if [[ $alt_root == "-" ]]; then
2062 2003 value=$(zdb -C $pool | grep "$config:" | awk -F: \
2063 2004 '{print $2}')
2064 2005 else
2065 2006 value=$(zdb -e $pool | grep "$config:" | awk -F: \
2066 2007 '{print $2}')
2067 2008 fi
2068 2009 if [[ -n $value ]] ; then
2069 2010 value=${value#'}
2070 2011 value=${value%'}
2071 2012 fi
2072 2013 echo $value
2073 2014
2074 2015 return 0
2075 2016 }
2076 2017
2077 2018 #
2078 2019 # Privated function. Random select one of items from arguments.
2079 2020 #
2080 2021 # $1 count
2081 2022 # $2-n string
2082 2023 #
2083 2024 function _random_get
2084 2025 {
2085 2026 typeset cnt=$1
2086 2027 shift
2087 2028
2088 2029 typeset str="$@"
2089 2030 typeset -i ind
2090 2031 ((ind = RANDOM % cnt + 1))
2091 2032
2092 2033 typeset ret=$(echo "$str" | cut -f $ind -d ' ')
2093 2034 echo $ret
2094 2035 }
2095 2036
2096 2037 #
2097 2038 # Random select one of item from arguments which include NONE string
2098 2039 #
2099 2040 function random_get_with_non
2100 2041 {
2101 2042 typeset -i cnt=$#
2102 2043 ((cnt =+ 1))
2103 2044
2104 2045 _random_get "$cnt" "$@"
2105 2046 }
2106 2047
2107 2048 #
2108 2049 # Random select one of item from arguments which doesn't include NONE string
2109 2050 #
2110 2051 function random_get
2111 2052 {
2112 2053 _random_get "$#" "$@"
2113 2054 }
2114 2055
2115 2056 #
2116 2057 # Detect if the current system support slog
2117 2058 #
2118 2059 function verify_slog_support
2119 2060 {
2120 2061 typeset dir=/tmp/disk.$$
2121 2062 typeset pool=foo.$$
2122 2063 typeset vdev=$dir/a
2123 2064 typeset sdev=$dir/b
2124 2065
2125 2066 mkdir -p $dir
2126 2067 mkfile $MINVDEVSIZE $vdev $sdev
2127 2068
2128 2069 typeset -i ret=0
2129 2070 if ! zpool create -n $pool $vdev log $sdev > /dev/null 2>&1; then
2130 2071 ret=1
2131 2072 fi
2132 2073 rm -r $dir
2133 2074
2134 2075 return $ret
2135 2076 }
2136 2077
2137 2078 #
2138 2079 # The function will generate a dataset name with specific length
2139 2080 # $1, the length of the name
2140 2081 # $2, the base string to construct the name
2141 2082 #
2142 2083 function gen_dataset_name
2143 2084 {
2144 2085 typeset -i len=$1
2145 2086 typeset basestr="$2"
2146 2087 typeset -i baselen=${#basestr}
2147 2088 typeset -i iter=0
2148 2089 typeset l_name=""
2149 2090
2150 2091 if ((len % baselen == 0)); then
2151 2092 ((iter = len / baselen))
2152 2093 else
2153 2094 ((iter = len / baselen + 1))
2154 2095 fi
2155 2096 while ((iter > 0)); do
2156 2097 l_name="${l_name}$basestr"
2157 2098
2158 2099 ((iter -= 1))
2159 2100 done
2160 2101
2161 2102 echo $l_name
2162 2103 }
2163 2104
2164 2105 #
2165 2106 # Get cksum tuple of dataset
2166 2107 # $1 dataset name
2167 2108 #
2168 2109 # sample zdb output:
2169 2110 # Dataset data/test [ZPL], ID 355, cr_txg 2413856, 31.0K, 7 objects, rootbp
2170 2111 # DVA[0]=<0:803046400:200> DVA[1]=<0:81199000:200> [L0 DMU objset] fletcher4
2171 2112 # lzjb LE contiguous unique double size=800L/200P birth=2413856L/2413856P
2172 2113 # fill=7 cksum=11ce125712:643a9c18ee2:125e25238fca0:254a3f74b59744
2173 2114 function datasetcksum
2174 2115 {
2175 2116 typeset cksum
2176 2117 sync
2177 2118 cksum=$(zdb -vvv $1 | grep "^Dataset $1 \[" | grep "cksum" \
2178 2119 | awk -F= '{print $7}')
2179 2120 echo $cksum
2180 2121 }
2181 2122
2182 2123 #
2183 2124 # Get cksum of file
2184 2125 # #1 file path
2185 2126 #
2186 2127 function checksum
2187 2128 {
2188 2129 typeset cksum
2189 2130 cksum=$(cksum $1 | awk '{print $1}')
2190 2131 echo $cksum
2191 2132 }
2192 2133
2193 2134 #
2194 2135 # Get the given disk/slice state from the specific field of the pool
2195 2136 #
2196 2137 function get_device_state #pool disk field("", "spares","logs")
2197 2138 {
2198 2139 typeset pool=$1
2199 2140 typeset disk=${2#/dev/dsk/}
2200 2141 typeset field=${3:-$pool}
2201 2142
2202 2143 state=$(zpool status -v "$pool" 2>/dev/null | \
2203 2144 nawk -v device=$disk -v pool=$pool -v field=$field \
2204 2145 'BEGIN {startconfig=0; startfield=0; }
2205 2146 /config:/ {startconfig=1}
2206 2147 (startconfig==1) && ($1==field) {startfield=1; next;}
2207 2148 (startfield==1) && ($1==device) {print $2; exit;}
2208 2149 (startfield==1) &&
2209 2150 ($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}')
2210 2151 echo $state
2211 2152 }
2212 2153
2213 2154
2214 2155 #
2215 2156 # print the given directory filesystem type
2216 2157 #
2217 2158 # $1 directory name
2218 2159 #
2219 2160 function get_fstype
2220 2161 {
2221 2162 typeset dir=$1
2222 2163
2223 2164 if [[ -z $dir ]]; then
2224 2165 log_fail "Usage: get_fstype <directory>"
2225 2166 fi
2226 2167
2227 2168 #
2228 2169 # $ df -n /
2229 2170 # / : ufs
2230 2171 #
2231 2172 df -n $dir | awk '{print $3}'
2232 2173 }
2233 2174
2234 2175 #
2235 2176 # Given a disk, label it to VTOC regardless what label was on the disk
2236 2177 # $1 disk
2237 2178 #
2238 2179 function labelvtoc
2239 2180 {
2240 2181 typeset disk=$1
2241 2182 if [[ -z $disk ]]; then
2242 2183 log_fail "The disk name is unspecified."
2243 2184 fi
2244 2185 typeset label_file=/var/tmp/labelvtoc.$$
2245 2186 typeset arch=$(uname -p)
2246 2187
2247 2188 if [[ $arch == "i386" ]]; then
2248 2189 echo "label" > $label_file
2249 2190 echo "0" >> $label_file
2250 2191 echo "" >> $label_file
2251 2192 echo "q" >> $label_file
2252 2193 echo "q" >> $label_file
2253 2194
2254 2195 fdisk -B $disk >/dev/null 2>&1
2255 2196 # wait a while for fdisk finishes
2256 2197 sleep 60
2257 2198 elif [[ $arch == "sparc" ]]; then
2258 2199 echo "label" > $label_file
2259 2200 echo "0" >> $label_file
2260 2201 echo "" >> $label_file
2261 2202 echo "" >> $label_file
2262 2203 echo "" >> $label_file
2263 2204 echo "q" >> $label_file
2264 2205 else
2265 2206 log_fail "unknown arch type"
2266 2207 fi
2267 2208
2268 2209 format -e -s -d $disk -f $label_file
2269 2210 typeset -i ret_val=$?
2270 2211 rm -f $label_file
2271 2212 #
2272 2213 # wait the format to finish
2273 2214 #
2274 2215 sleep 60
2275 2216 if ((ret_val != 0)); then
2276 2217 log_fail "unable to label $disk as VTOC."
2277 2218 fi
2278 2219
2279 2220 return 0
2280 2221 }
2281 2222
2282 2223 #
2283 2224 # check if the system was installed as zfsroot or not
2284 2225 # return: 0 ture, otherwise false
2285 2226 #
2286 2227 function is_zfsroot
2287 2228 {
2288 2229 df -n / | grep zfs > /dev/null 2>&1
2289 2230 return $?
2290 2231 }
2291 2232
2292 2233 #
2293 2234 # get the root filesystem name if it's zfsroot system.
2294 2235 #
2295 2236 # return: root filesystem name
2296 2237 function get_rootfs
2297 2238 {
2298 2239 typeset rootfs=""
2299 2240 rootfs=$(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \
2300 2241 /etc/mnttab)
2301 2242 if [[ -z "$rootfs" ]]; then
2302 2243 log_fail "Can not get rootfs"
2303 2244 fi
2304 2245 zfs list $rootfs > /dev/null 2>&1
2305 2246 if (($? == 0)); then
2306 2247 echo $rootfs
2307 2248 else
2308 2249 log_fail "This is not a zfsroot system."
2309 2250 fi
2310 2251 }
2311 2252
2312 2253 #
2313 2254 # get the rootfs's pool name
2314 2255 # return:
2315 2256 # rootpool name
2316 2257 #
2317 2258 function get_rootpool
2318 2259 {
2319 2260 typeset rootfs=""
2320 2261 typeset rootpool=""
2321 2262 rootfs=$(awk '{if ($2 == "/" && $3 =="zfs") print $1}' \
2322 2263 /etc/mnttab)
2323 2264 if [[ -z "$rootfs" ]]; then
2324 2265 log_fail "Can not get rootpool"
2325 2266 fi
2326 2267 zfs list $rootfs > /dev/null 2>&1
2327 2268 if (($? == 0)); then
2328 2269 rootpool=`echo $rootfs | awk -F\/ '{print $1}'`
2329 2270 echo $rootpool
2330 2271 else
2331 2272 log_fail "This is not a zfsroot system."
2332 2273 fi
2333 2274 }
2334 2275
2335 2276 #
2336 2277 # Check if the given device is physical device
2337 2278 #
2338 2279 function is_physical_device #device
2339 2280 {
2340 2281 typeset device=${1#/dev/dsk/}
2341 2282 device=${device#/dev/rdsk/}
2342 2283
2343 2284 echo $device | egrep "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1
2344 2285 return $?
2345 2286 }
2346 2287
2347 2288 #
2348 2289 # Get the directory path of given device
2349 2290 #
2350 2291 function get_device_dir #device
2351 2292 {
2352 2293 typeset device=$1
2353 2294
2354 2295 if ! $(is_physical_device $device) ; then
2355 2296 if [[ $device != "/" ]]; then
2356 2297 device=${device%/*}
2357 2298 fi
2358 2299 echo $device
2359 2300 else
2360 2301 echo "/dev/dsk"
2361 2302 fi
2362 2303 }
2363 2304
2364 2305 #
2365 2306 # Get the package name
2366 2307 #
2367 2308 function get_package_name
2368 2309 {
2369 2310 typeset dirpath=${1:-$STC_NAME}
2370 2311
2371 2312 echo "SUNWstc-${dirpath}" | /usr/bin/sed -e "s/\//-/g"
2372 2313 }
2373 2314
2374 2315 #
2375 2316 # Get the word numbers from a string separated by white space
2376 2317 #
2377 2318 function get_word_count
2378 2319 {
2379 2320 echo $1 | wc -w
2380 2321 }
2381 2322
2382 2323 #
2383 2324 # To verify if the require numbers of disks is given
2384 2325 #
2385 2326 function verify_disk_count
2386 2327 {
2387 2328 typeset -i min=${2:-1}
2388 2329
2389 2330 typeset -i count=$(get_word_count "$1")
2390 2331
2391 2332 if ((count < min)); then
2392 2333 log_untested "A minimum of $min disks is required to run." \
2393 2334 " You specified $count disk(s)"
2394 2335 fi
2395 2336 }
2396 2337
2397 2338 function ds_is_volume
2398 2339 {
2399 2340 typeset type=$(get_prop type $1)
2400 2341 [[ $type = "volume" ]] && return 0
2401 2342 return 1
2402 2343 }
2403 2344
2404 2345 function ds_is_filesystem
2405 2346 {
2406 2347 typeset type=$(get_prop type $1)
2407 2348 [[ $type = "filesystem" ]] && return 0
2408 2349 return 1
2409 2350 }
2410 2351
2411 2352 function ds_is_snapshot
2412 2353 {
2413 2354 typeset type=$(get_prop type $1)
2414 2355 [[ $type = "snapshot" ]] && return 0
2415 2356 return 1
2416 2357 }
2417 2358
2418 2359 #
2419 2360 # Check if Trusted Extensions are installed and enabled
2420 2361 #
2421 2362 function is_te_enabled
2422 2363 {
2423 2364 svcs -H -o state labeld 2>/dev/null | grep "enabled"
2424 2365 if (($? != 0)); then
2425 2366 return 1
2426 2367 else
2427 2368 return 0
2428 2369 fi
2429 2370 }
2430 2371
2431 2372 # Utility function to determine if a system has multiple cpus.
2432 2373 function is_mp
2433 2374 {
2434 2375 (($(psrinfo | wc -l) > 1))
2435 2376 }
2436 2377
2437 2378 function get_cpu_freq
2438 2379 {
2439 2380 psrinfo -v 0 | awk '/processor operates at/ {print $6}'
2440 2381 }
2441 2382
|
↓ open down ↓ |
754 lines elided |
↑ open up ↑ |
2442 2383 # Run the given command as the user provided.
2443 2384 function user_run
2444 2385 {
2445 2386 typeset user=$1
2446 2387 shift
2447 2388
2448 2389 eval su \$user -c \"$@\" > /tmp/out 2>/tmp/err
2449 2390 return $?
2450 2391 }
2451 2392
2393 +# Return 0 if the pool is successfully epxorted; $? otherwise
2452 2394 #
2395 +# $1 - pool name
2396 +# Export pool.
2397 +function export_pool #pool
2398 +{
2399 + typeset pool=${1%%/*}
2400 + # Checking to see if the device is busy. If so, we'll
2401 + # retry the export a few times with a sleep between tries.
2402 + errmsg='device is busy'
2403 + retry_num=$NUM_RETRIES
2404 + TMPFILE=`mktemp`
2405 + if [ -z "$TMPFILE" ] ; then
2406 + log_note "Unable to create temporary file $TMPFILE"
2407 + return 1
2408 + fi
2409 + until [ $retry_num == 0 ] ; do
2410 + log_note "zpool export $pool"
2411 + zpool export $pool 2>$TMPFILE
2412 + # If the export failed, see if it's due to a
2413 + # device is busy issue and retry if it is.
2414 + if (( $? != 0 )); then
2415 + # if this is busy then we want to retry
2416 + if [ "`grep "$errmsg" $TMPFILE`" != "" ]; then
2417 + retry_num-=1
2418 + log_note "Device is busy, retry zpool export"
2419 + sleep $EXPORT_SLEEP_TIME
2420 + else # return here if error is something else
2421 + rn $TMPFILE
2422 + return 1
2423 + fi
2424 + else
2425 + # export succeeded.
2426 + rm $TMPFILE
2427 + return 0
2428 + fi
2429 + done
2430 + # We've reached our max retries, try to export one more time
2431 + # and require it to succeed.
2432 + log_must zpool export $pool
2433 +}
2434 +
2435 +#
2453 2436 # Check if the pool contains the specified vdevs
2454 2437 #
2455 2438 # $1 pool
2456 2439 # $2..n <vdev> ...
2457 2440 #
2458 2441 # Return 0 if the vdevs are contained in the pool, 1 if any of the specified
2459 2442 # vdevs is not in the pool, and 2 if pool name is missing.
2460 2443 #
2461 2444 function vdevs_in_pool
2462 2445 {
2463 2446 typeset pool=$1
2464 2447 typeset vdev
2465 2448
2466 2449 if [[ -z $pool ]]; then
2467 2450 log_note "Missing pool name."
2468 2451 return 2
2469 2452 fi
2470 2453
2471 2454 shift
2472 2455
2473 2456 typeset tmpfile=$(mktemp)
2474 2457 zpool list -Hv "$pool" >$tmpfile
2475 2458 for vdev in $@; do
2476 2459 grep -w ${vdev##*/} $tmpfile >/dev/null 2>&1
2477 2460 [[ $? -ne 0 ]] && return 1
2478 2461 done
2479 2462
2480 2463 rm -f $tmpfile
2481 2464
2482 2465 return 0;
2483 2466 }
2484 2467
2485 2468 function get_max
2486 2469 {
2487 2470 typeset -l i max=$1
2488 2471 shift
2489 2472
2490 2473 for i in "$@"; do
2491 2474 max=$(echo $((max > i ? max : i)))
2492 2475 done
2493 2476
2494 2477 echo $max
2495 2478 }
2496 2479
2497 2480 function get_min
2498 2481 {
2499 2482 typeset -l i min=$1
2500 2483 shift
2501 2484
2502 2485 for i in "$@"; do
2503 2486 min=$(echo $((min < i ? min : i)))
|
↓ open down ↓ |
41 lines elided |
↑ open up ↑ |
2504 2487 done
2505 2488
2506 2489 echo $min
2507 2490 }
2508 2491
2509 2492 #
2510 2493 # Generate a random number between 1 and the argument.
2511 2494 #
2512 2495 function random
2513 2496 {
2514 - typeset max=$1
2515 - echo $(( ($RANDOM % $max) + 1 ))
2497 + typeset max=$1
2498 + echo $(( ($RANDOM % $max) + 1 ))
2516 2499 }
2517 2500
2518 2501 # Write data that can be compressed into a directory
2519 2502 function write_compressible
2520 2503 {
2521 2504 typeset dir=$1
2522 2505 typeset megs=$2
2523 2506 typeset nfiles=${3:-1}
2524 2507 typeset bs=${4:-1024k}
2525 2508 typeset fname=${5:-file}
2526 2509
2527 2510 [[ -d $dir ]] || log_fail "No directory: $dir"
2528 2511
2529 2512 log_must eval "fio \
2530 2513 --name=job \
2531 2514 --fallocate=0 \
2532 2515 --minimal \
2533 2516 --randrepeat=0 \
2534 2517 --buffer_compress_percentage=66 \
2535 2518 --buffer_compress_chunk=4096 \
2536 2519 --directory=$dir \
2537 2520 --numjobs=$nfiles \
2538 2521 --rw=write \
2539 2522 --bs=$bs \
2540 2523 --filesize=$megs \
2541 2524 --filename_format='$fname.\$jobnum' >/dev/null"
|
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
2542 2525 }
2543 2526
2544 2527 function get_objnum
2545 2528 {
2546 2529 typeset pathname=$1
2547 2530 typeset objnum
2548 2531
2549 2532 [[ -e $pathname ]] || log_fail "No such file or directory: $pathname"
2550 2533 objnum=$(stat -c %i $pathname)
2551 2534 echo $objnum
2552 -}
2553 -
2554 -#
2555 -# Prints the current time in seconds since UNIX Epoch.
2556 -#
2557 -function current_epoch
2558 -{
2559 - printf '%(%s)T'
2560 -}
2561 -
2562 -#
2563 -# Get decimal value of global uint32_t variable using mdb.
2564 -#
2565 -function mdb_get_uint32
2566 -{
2567 - typeset variable=$1
2568 - typeset value
2569 -
2570 - value=$(mdb -k -e "$variable/X | ::eval .=U")
2571 - if [[ $? -ne 0 ]]; then
2572 - log_fail "Failed to get value of '$variable' from mdb."
2573 - return 1
2574 - fi
2575 -
2576 - echo $value
2577 - return 0
2578 -}
2579 -
2580 -#
2581 -# Set global uint32_t variable to a decimal value using mdb.
2582 -#
2583 -function mdb_set_uint32
2584 -{
2585 - typeset variable=$1
2586 - typeset value=$2
2587 -
2588 - mdb -kw -e "$variable/W 0t$value" > /dev/null
2589 - if [[ $? -ne 0 ]]; then
2590 - echo "Failed to set '$variable' to '$value' in mdb."
2591 - return 1
2592 - fi
2593 -
2594 - return 0
2595 2535 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX