5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
27 # Copyright 2016 Nexenta Systems, Inc.
28 # Copyright (c) 2017 Lawrence Livermore National Security, LLC.
29 # Copyright (c) 2017 Datto Inc.
32 .
${STF_TOOLS}/include
/logapi.shlib
33 .
${STF_SUITE}/include
/math.shlib
36 # Apply constrained path when available. This is required since the
37 # PATH may have been modified by sudo's secure_path behavior.
39 if [ -n "$STF_PATH" ]; then
43 # Linux kernel version comparison function
45 # $1 Linux version ("4.10", "2.6.32") or blank for installed Linux version
47 # Used for comparison: if [ $(linux_version) -ge $(linux_version "2.6.32") ]
49 function linux_version
53 [[ -z "$ver" ]] && ver
=$
(uname
-r |
grep -Eo "^[0-9]+\.[0-9]+\.[0-9]+")
55 typeset version
=$
(echo $ver | cut
-d '.' -f 1)
56 typeset major
=$
(echo $ver | cut
-d '.' -f 2)
57 typeset minor
=$
(echo $ver | cut
-d '.' -f 3)
59 [[ -z "$version" ]] && version
=0
60 [[ -z "$major" ]] && major
=0
61 [[ -z "$minor" ]] && minor
=0
63 echo $
((version
* 10000 + major
* 100 + minor
))
66 # Determine if this is a Linux test system
68 # Return 0 if platform Linux, 1 if otherwise
72 if [[ $
(uname
-o) == "GNU/Linux" ]]; then
79 # Determine if this is a 32-bit system
81 # Return 0 if platform is 32-bit, 1 if otherwise
85 if [[ $
(getconf LONG_BIT
) == "32" ]]; then
92 # Determine if kmemleak is enabled
94 # Return 0 if kmemleak is enabled, 1 if otherwise
98 if is_linux
&& [[ -e /sys
/kernel
/debug
/kmemleak
]]; then
105 # Determine whether a dataset is mounted
108 # $2 filesystem type; optional - defaulted to zfs
110 # Return 0 if dataset is mounted; 1 if unmounted; 2 on error
115 [[ -z $fstype ]] && fstype
=zfs
116 typeset out dir name ret
120 if [[ "$1" == "/"* ]] ; then
121 for out
in $
(zfs mount |
awk '{print $2}'); do
122 [[ $1 == $out ]] && return 0
125 for out
in $
(zfs mount |
awk '{print $1}'); do
126 [[ $1 == $out ]] && return 0
131 out
=$
(df
-F $fstype $1 2>/dev
/null
)
133 (($ret != 0)) && return $ret
141 [[ "$1" == "$dir" ||
"$1" == "$name" ]] && return 0
144 out
=$
(df
-t $fstype $1 2>/dev
/null
)
148 if [[ -L "$ZVOL_DEVDIR/$1" ]]; then
149 link
=$
(readlink
-f $ZVOL_DEVDIR/$1)
150 [[ -n "$link" ]] && \
151 mount |
grep -q "^$link" && \
160 # Return 0 if a dataset is mounted; 1 otherwise
163 # $2 filesystem type; optional - defaulted to zfs
168 (($?
== 0)) && return 0
172 # Return 0 if a dataset is unmounted; 1 otherwise
175 # $2 filesystem type; optional - defaulted to zfs
180 (($?
== 1)) && return 0
190 echo $1 |
sed "s/,/ /g"
193 function default_setup
195 default_setup_noexit
"$@"
201 # Given a list of disks, setup storage pools and datasets.
203 function default_setup_noexit
208 log_note begin default_setup_noexit
210 if is_global_zone
; then
211 if poolexists
$TESTPOOL ; then
212 destroy_pool
$TESTPOOL
214 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
215 log_must zpool create
-f $TESTPOOL $disklist
220 rm -rf $TESTDIR || log_unresolved Could not remove
$TESTDIR
221 mkdir
-p $TESTDIR || log_unresolved Could not create
$TESTDIR
223 log_must zfs create
$TESTPOOL/$TESTFS
224 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
226 if [[ -n $container ]]; then
227 rm -rf $TESTDIR1 || \
228 log_unresolved Could not remove
$TESTDIR1
229 mkdir
-p $TESTDIR1 || \
230 log_unresolved Could not create
$TESTDIR1
232 log_must zfs create
$TESTPOOL/$TESTCTR
233 log_must zfs
set canmount
=off
$TESTPOOL/$TESTCTR
234 log_must zfs create
$TESTPOOL/$TESTCTR/$TESTFS1
235 log_must zfs
set mountpoint
=$TESTDIR1 \
236 $TESTPOOL/$TESTCTR/$TESTFS1
239 if [[ -n $volume ]]; then
240 if is_global_zone
; then
241 log_must zfs create
-V $VOLSIZE $TESTPOOL/$TESTVOL
244 log_must zfs create
$TESTPOOL/$TESTVOL
250 # Given a list of disks, setup a storage pool, file system and
253 function default_container_setup
257 default_setup
"$disklist" "true"
261 # Given a list of disks, setup a storage pool,file system
264 function default_volume_setup
268 default_setup
"$disklist" "" "true"
272 # Given a list of disks, setup a storage pool,file system,
273 # a container and a volume.
275 function default_container_volume_setup
279 default_setup
"$disklist" "true" "true"
283 # Create a snapshot on a filesystem or volume. Defaultly create a snapshot on
286 # $1 Existing filesystem or volume name. Default, $TESTFS
287 # $2 snapshot name. Default, $TESTSNAP
289 function create_snapshot
291 typeset fs_vol
=${1:-$TESTFS}
292 typeset snap
=${2:-$TESTSNAP}
294 [[ -z $fs_vol ]] && log_fail
"Filesystem or volume's name is undefined."
295 [[ -z $snap ]] && log_fail
"Snapshot's name is undefined."
297 if snapexists
$fs_vol@
$snap; then
298 log_fail
"$fs_vol@$snap already exists."
300 datasetexists
$fs_vol || \
301 log_fail
"$fs_vol must exist."
303 log_must zfs snapshot
$fs_vol@
$snap
307 # Create a clone from a snapshot, default clone name is $TESTCLONE.
309 # $1 Existing snapshot, $TESTPOOL/$TESTFS@$TESTSNAP is default.
310 # $2 Clone name, $TESTPOOL/$TESTCLONE is default.
312 function create_clone
# snapshot clone
314 typeset snap
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
315 typeset clone
=${2:-$TESTPOOL/$TESTCLONE}
318 log_fail
"Snapshot name is undefined."
320 log_fail
"Clone name is undefined."
322 log_must zfs clone
$snap $clone
326 # Create a bookmark of the given snapshot. Defaultly create a bookmark on
329 # $1 Existing filesystem or volume name. Default, $TESTFS
330 # $2 Existing snapshot name. Default, $TESTSNAP
331 # $3 bookmark name. Default, $TESTBKMARK
333 function create_bookmark
335 typeset fs_vol
=${1:-$TESTFS}
336 typeset snap
=${2:-$TESTSNAP}
337 typeset bkmark
=${3:-$TESTBKMARK}
339 [[ -z $fs_vol ]] && log_fail
"Filesystem or volume's name is undefined."
340 [[ -z $snap ]] && log_fail
"Snapshot's name is undefined."
341 [[ -z $bkmark ]] && log_fail
"Bookmark's name is undefined."
343 if bkmarkexists
$fs_vol#$bkmark; then
344 log_fail
"$fs_vol#$bkmark already exists."
346 datasetexists
$fs_vol || \
347 log_fail
"$fs_vol must exist."
348 snapexists
$fs_vol@
$snap || \
349 log_fail
"$fs_vol@$snap must exist."
351 log_must zfs bookmark
$fs_vol@
$snap $fs_vol#$bkmark
354 function default_mirror_setup
356 default_mirror_setup_noexit
$1 $2 $3
362 # Given a pair of disks, set up a storage pool and dataset for the mirror
363 # @parameters: $1 the primary side of the mirror
364 # $2 the secondary side of the mirror
365 # @uses: ZPOOL ZFS TESTPOOL TESTFS
366 function default_mirror_setup_noexit
368 readonly func
="default_mirror_setup_noexit"
372 [[ -z $primary ]] && \
373 log_fail
"$func: No parameters passed"
374 [[ -z $secondary ]] && \
375 log_fail
"$func: No secondary partition passed"
376 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
377 log_must zpool create
-f $TESTPOOL mirror $@
378 log_must zfs create
$TESTPOOL/$TESTFS
379 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
383 # create a number of mirrors.
384 # We create a number($1) of 2 way mirrors using the pairs of disks named
385 # on the command line. These mirrors are *not* mounted
386 # @parameters: $1 the number of mirrors to create
387 # $... the devices to use to create the mirrors on
388 # @uses: ZPOOL ZFS TESTPOOL
389 function setup_mirrors
391 typeset
-i nmirrors
=$1
394 while ((nmirrors
> 0)); do
395 log_must
test -n "$1" -a -n "$2"
396 [[ -d /$TESTPOOL$nmirrors ]] && rm -rf /$TESTPOOL$nmirrors
397 log_must zpool create
-f $TESTPOOL$nmirrors mirror
$1 $2
399 ((nmirrors
= nmirrors
- 1))
404 # create a number of raidz pools.
405 # We create a number($1) of 2 raidz pools using the pairs of disks named
406 # on the command line. These pools are *not* mounted
407 # @parameters: $1 the number of pools to create
408 # $... the devices to use to create the pools on
409 # @uses: ZPOOL ZFS TESTPOOL
410 function setup_raidzs
412 typeset
-i nraidzs
=$1
415 while ((nraidzs
> 0)); do
416 log_must
test -n "$1" -a -n "$2"
417 [[ -d /$TESTPOOL$nraidzs ]] && rm -rf /$TESTPOOL$nraidzs
418 log_must zpool create
-f $TESTPOOL$nraidzs raidz
$1 $2
420 ((nraidzs
= nraidzs
- 1))
425 # Destroy the configured testpool mirrors.
426 # the mirrors are of the form ${TESTPOOL}{number}
427 # @uses: ZPOOL ZFS TESTPOOL
428 function destroy_mirrors
430 default_cleanup_noexit
436 # Given a minimum of two disks, set up a storage pool and dataset for the raid-z
437 # $1 the list of disks
439 function default_raidz_setup
441 typeset disklist
="$*"
442 disks
=(${disklist[*]})
444 if [[ ${#disks[*]} -lt 2 ]]; then
445 log_fail
"A raid-z requires a minimum of two disks."
448 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
449 log_must zpool create
-f $TESTPOOL raidz
$1 $2 $3
450 log_must zfs create
$TESTPOOL/$TESTFS
451 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
457 # Common function used to cleanup storage pools and datasets.
459 # Invoked at the start of the test suite to ensure the system
460 # is in a known state, and also at the end of each set of
461 # sub-tests to ensure errors from one set of tests doesn't
462 # impact the execution of the next set.
464 function default_cleanup
466 default_cleanup_noexit
471 function default_cleanup_noexit
476 # Destroying the pool will also destroy any
477 # filesystems it contains.
479 if is_global_zone
; then
480 zfs unmount
-a > /dev
/null
2>&1
481 exclude
=`eval echo \"'(${KEEP})'\"`
482 ALL_POOLS
=$
(zpool list
-H -o name \
483 |
grep -v "$NO_POOLS" |
egrep -v "$exclude")
484 # Here, we loop through the pools we're allowed to
485 # destroy, only destroying them if it's safe to do
487 while [ ! -z ${ALL_POOLS} ]
489 for pool
in ${ALL_POOLS}
491 if safe_to_destroy_pool
$pool ;
495 ALL_POOLS
=$
(zpool list
-H -o name \
496 |
grep -v "$NO_POOLS" \
497 |
egrep -v "$exclude")
504 for fs
in $
(zfs list
-H -o name \
505 |
grep "^$ZONE_POOL/$ZONE_CTR[01234]/"); do
506 datasetexists
$fs && \
507 log_must zfs destroy
-Rf $fs
510 # Need cleanup here to avoid garbage dir left.
511 for fs
in $
(zfs list
-H -o name
); do
512 [[ $fs == /$ZONE_POOL ]] && continue
513 [[ -d $fs ]] && log_must
rm -rf $fs/*
517 # Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to
520 for fs
in $
(zfs list
-H -o name
); do
521 if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then
522 log_must zfs
set reservation
=none
$fs
523 log_must zfs
set recordsize
=128K
$fs
524 log_must zfs
set mountpoint
=/$fs $fs
526 enc
=$
(get_prop encryption
$fs)
527 if [[ $?
-ne 0 ]] ||
[[ -z "$enc" ]] || \
528 [[ "$enc" == "off" ]]; then
529 log_must zfs
set checksum
=on
$fs
531 log_must zfs
set compression
=off
$fs
532 log_must zfs
set atime
=on
$fs
533 log_must zfs
set devices
=off
$fs
534 log_must zfs
set exec=on
$fs
535 log_must zfs
set setuid
=on
$fs
536 log_must zfs
set readonly=off
$fs
537 log_must zfs
set snapdir
=hidden
$fs
538 log_must zfs
set aclmode
=groupmask
$fs
539 log_must zfs
set aclinherit
=secure
$fs
544 [[ -d $TESTDIR ]] && \
545 log_must
rm -rf $TESTDIR
548 if is_mpath_device
$disk1; then
555 # Common function used to cleanup storage pools, file systems
558 function default_container_cleanup
560 if ! is_global_zone
; then
564 ismounted
$TESTPOOL/$TESTCTR/$TESTFS1
566 log_must zfs unmount
$TESTPOOL/$TESTCTR/$TESTFS1
568 datasetexists
$TESTPOOL/$TESTCTR/$TESTFS1 && \
569 log_must zfs destroy
-R $TESTPOOL/$TESTCTR/$TESTFS1
571 datasetexists
$TESTPOOL/$TESTCTR && \
572 log_must zfs destroy
-Rf $TESTPOOL/$TESTCTR
574 [[ -e $TESTDIR1 ]] && \
575 log_must
rm -rf $TESTDIR1 > /dev
/null
2>&1
581 # Common function used to cleanup snapshot of file system or volume. Default to
582 # delete the file system's snapshot
586 function destroy_snapshot
588 typeset snap
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
590 if ! snapexists
$snap; then
591 log_fail
"'$snap' does not existed."
595 # For the sake of the value which come from 'get_prop' is not equal
596 # to the really mountpoint when the snapshot is unmounted. So, firstly
597 # check and make sure this snapshot's been mounted in current system.
600 if ismounted
$snap; then
601 mtpt
=$
(get_prop mountpoint
$snap)
603 log_fail
"get_prop mountpoint $snap failed."
606 log_must zfs destroy
$snap
607 [[ $mtpt != "" && -d $mtpt ]] && \
608 log_must
rm -rf $mtpt
612 # Common function used to cleanup clone.
616 function destroy_clone
618 typeset clone
=${1:-$TESTPOOL/$TESTCLONE}
620 if ! datasetexists
$clone; then
621 log_fail
"'$clone' does not existed."
624 # With the same reason in destroy_snapshot
626 if ismounted
$clone; then
627 mtpt
=$
(get_prop mountpoint
$clone)
629 log_fail
"get_prop mountpoint $clone failed."
632 log_must zfs destroy
$clone
633 [[ $mtpt != "" && -d $mtpt ]] && \
634 log_must
rm -rf $mtpt
638 # Common function used to cleanup bookmark of file system or volume. Default
639 # to delete the file system's bookmark.
643 function destroy_bookmark
645 typeset bkmark
=${1:-$TESTPOOL/$TESTFS#$TESTBKMARK}
647 if ! bkmarkexists
$bkmark; then
648 log_fail
"'$bkmarkp' does not existed."
651 log_must zfs destroy
$bkmark
654 # Return 0 if a snapshot exists; $? otherwise
660 zfs list
-H -t snapshot
"$1" > /dev
/null
2>&1
665 # Return 0 if a bookmark exists; $? otherwise
669 function bkmarkexists
671 zfs list
-H -t bookmark
"$1" > /dev
/null
2>&1
676 # Set a property to a certain value on a dataset.
677 # Sets a property of the dataset to the value as passed in.
679 # $1 dataset who's property is being set
681 # $3 value to set property to
683 # 0 if the property could be set.
684 # non-zero otherwise.
687 function dataset_setprop
689 typeset fn
=dataset_setprop
692 log_note
"$fn: Insufficient parameters (need 3, had $#)"
696 output
=$
(zfs
set $2=$3 $1 2>&1)
699 log_note
"Setting property on $1 failed."
700 log_note
"property $2=$3"
701 log_note
"Return Code: $rv"
702 log_note
"Output: $output"
709 # Assign suite defined dataset properties.
710 # This function is used to apply the suite's defined default set of
711 # properties to a dataset.
712 # @parameters: $1 dataset to use
713 # @uses: ZFS COMPRESSION_PROP CHECKSUM_PROP
715 # 0 if the dataset has been altered.
716 # 1 if no pool name was passed in.
717 # 2 if the dataset could not be found.
718 # 3 if the dataset could not have it's properties set.
720 function dataset_set_defaultproperties
724 [[ -z $dataset ]] && return 1
728 for confset
in $
(zfs list
); do
729 if [[ $dataset = $confset ]]; then
734 [[ $found -eq 0 ]] && return 2
735 if [[ -n $COMPRESSION_PROP ]]; then
736 dataset_setprop
$dataset compression
$COMPRESSION_PROP || \
738 log_note
"Compression set to '$COMPRESSION_PROP' on $dataset"
740 if [[ -n $CHECKSUM_PROP ]]; then
741 dataset_setprop
$dataset checksum
$CHECKSUM_PROP || \
743 log_note
"Checksum set to '$CHECKSUM_PROP' on $dataset"
749 # Check a numeric assertion
750 # @parameter: $@ the assertion to check
751 # @output: big loud notice if assertion failed
756 (($@
)) || log_fail
"$@"
760 # Function to format partition size of a disk
761 # Given a disk cxtxdx reduces all partitions
764 function zero_partitions
#<whole_disk_name>
770 log_must parted
$DEV_DSKDIR/$diskname -s -- mklabel gpt
772 for i
in 0 1 3 4 5 6 7
774 log_must set_partition
$i "" 0mb
$diskname
782 # Given a slice, size and disk, this function
783 # formats the slice to the specified size.
784 # Size should be specified with units as per
785 # the `format` command requirements eg. 100mb 3gb
787 # NOTE: This entire interface is problematic for the Linux parted utilty
788 # which requires the end of the partition to be specified. It would be
789 # best to retire this interface and replace it with something more flexible.
790 # At the moment a best effort is made.
792 function set_partition
#<slice_num> <slice_start> <size_plus_units> <whole_disk_name>
794 typeset
-i slicenum
=$1
798 [[ -z $slicenum ||
-z $size ||
-z $disk ]] && \
799 log_fail
"The slice, size or disk name is unspecified."
802 typeset size_mb
=${size%%[mMgG]}
804 size_mb
=${size_mb%%[mMgG][bB]}
805 if [[ ${size:1:1} == 'g' ]]; then
806 ((size_mb
= size_mb
* 1024))
809 # Create GPT partition table when setting slice 0 or
810 # when the device doesn't already contain a GPT label.
811 parted
$DEV_DSKDIR/$disk -s -- print
1 >/dev
/null
813 if [[ $slicenum -eq 0 ||
$ret_val -ne 0 ]]; then
814 parted
$DEV_DSKDIR/$disk -s -- mklabel gpt
815 if [[ $?
-ne 0 ]]; then
816 log_note
"Failed to create GPT partition table on $disk"
821 # When no start is given align on the first cylinder.
822 if [[ -z "$start" ]]; then
826 # Determine the cylinder size for the device and using
827 # that calculate the end offset in cylinders.
828 typeset
-i cly_size_kb
=0
829 cly_size_kb
=$
(parted
-m $DEV_DSKDIR/$disk -s -- \
830 unit cyl print |
head -3 |
tail -1 | \
831 awk -F '[:k.]' '{print $4}')
832 ((end
= (size_mb
* 1024 / cly_size_kb
) + start
))
834 parted
$DEV_DSKDIR/$disk -s -- \
835 mkpart part
$slicenum ${start}cyl
${end}cyl
836 if [[ $?
-ne 0 ]]; then
837 log_note
"Failed to create partition $slicenum on $disk"
841 blockdev
--rereadpt $DEV_DSKDIR/$disk 2>/dev
/null
844 typeset format_file
=/var
/tmp
/format_in.$$
846 echo "partition" >$format_file
847 echo "$slicenum" >> $format_file
848 echo "" >> $format_file
849 echo "" >> $format_file
850 echo "$start" >> $format_file
851 echo "$size" >> $format_file
852 echo "label" >> $format_file
853 echo "" >> $format_file
854 echo "q" >> $format_file
855 echo "q" >> $format_file
857 format
-e -s -d $disk -f $format_file
862 if [[ $ret_val -ne 0 ]]; then
863 log_note
"Unable to format $disk slice $slicenum to $size"
870 # Delete all partitions on all disks - this is specifically for the use of multipath
871 # devices which currently can only be used in the test suite as raw/un-partitioned
872 # devices (ie a zpool cannot be created on a whole mpath device that has partitions)
874 function delete_partitions
878 if [[ -z $DISK_ARRAY_NUM ]]; then
879 DISK_ARRAY_NUM
=$
(echo ${DISKS} | nawk
'{print NF}')
881 if [[ -z $DISKSARRAY ]]; then
886 if (( $DISK_ARRAY_NUM == 1 )); then
887 while ((j
< MAX_PARTITIONS
)); do
888 parted
$DEV_DSKDIR/$DISK -s rm $j \
890 if (( $?
== 1 )); then
891 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
892 if (( $?
== 1 )); then
893 log_note
"Partitions for $DISK should be deleted"
895 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
899 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
900 if (( $?
== 0 )); then
901 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
907 for disk
in `echo $DISKSARRAY`; do
908 while ((j
< MAX_PARTITIONS
)); do
909 parted
$DEV_DSKDIR/$disk -s rm $j > /dev
/null
2>&1
910 if (( $?
== 1 )); then
911 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
912 if (( $?
== 1 )); then
913 log_note
"Partitions for $disk should be deleted"
915 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
919 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
920 if (( $?
== 0 )); then
921 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
934 # Get the end cyl of the given slice
936 function get_endslice
#<disk> <slice>
940 if [[ -z $disk ||
-z $slice ]] ; then
941 log_fail
"The disk name or slice number is unspecified."
945 endcyl
=$
(parted
-s $DEV_DSKDIR/$disk -- unit cyl print | \
946 grep "part${slice}" | \
949 ((endcyl
= (endcyl
+ 1)))
951 disk
=${disk#/dev/dsk/}
952 disk
=${disk#/dev/rdsk/}
956 ratio
=$
(prtvtoc
/dev
/rdsk
/${disk}s2 | \
957 grep "sectors\/cylinder" | \
960 if ((ratio
== 0)); then
964 typeset
-i endcyl
=$
(prtvtoc
-h /dev
/rdsk
/${disk}s2 |
965 nawk
-v token
="$slice" '{if ($1==token) print $6}')
967 ((endcyl
= (endcyl
+ 1) / ratio
))
975 # Given a size,disk and total slice number, this function formats the
976 # disk slices from 0 to the total slice number with the same specified
979 function partition_disk
#<slice_size> <whole_disk_name> <total_slices>
982 typeset slice_size
=$1
984 typeset total_slices
=$3
987 zero_partitions
$disk_name
988 while ((i
< $total_slices)); do
995 log_must set_partition
$i "$cyl" $slice_size $disk_name
996 cyl
=$
(get_endslice
$disk_name $i)
1002 # This function continues to write to a filenum number of files into dirnum
1003 # number of directories until either file_write returns an error or the
1004 # maximum number of files per directory have been written.
1007 # fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data]
1009 # Return value: 0 on success
1013 # destdir: is the directory where everything is to be created under
1014 # dirnum: the maximum number of subdirectories to use, -1 no limit
1015 # filenum: the maximum number of files per subdirectory
1016 # bytes: number of bytes to write
1017 # num_writes: numer of types to write out bytes
1018 # data: the data that will be written
1021 # file_fs /testdir 20 25 1024 256 0
1023 # Note: bytes * num_writes equals the size of the testfile
1025 function fill_fs
# destdir dirnum filenum bytes num_writes data
1027 typeset destdir
=${1:-$TESTDIR}
1028 typeset
-i dirnum
=${2:-50}
1029 typeset
-i filenum
=${3:-50}
1030 typeset
-i bytes
=${4:-8192}
1031 typeset
-i num_writes
=${5:-10240}
1032 typeset
-i data
=${6:-0}
1034 typeset
-i odirnum
=1
1035 typeset
-i idirnum
=0
1039 log_must mkdir
-p $destdir/$idirnum
1040 while (($odirnum > 0)); do
1041 if ((dirnum
>= 0 && idirnum
>= dirnum
)); then
1045 file_write
-o create
-f $destdir/$idirnum/$TESTFILE.
$fn \
1046 -b $bytes -c $num_writes -d $data
1048 if (($retval != 0)); then
1052 if (($fn >= $filenum)); then
1054 ((idirnum
= idirnum
+ 1))
1055 log_must mkdir
-p $destdir/$idirnum
1064 # Simple function to get the specified property. If unable to
1065 # get the property then exits.
1067 # Note property is in 'parsable' format (-p)
1069 function get_prop
# property dataset
1075 prop_val
=$
(zfs get
-pH -o value
$prop $dataset 2>/dev
/null
)
1076 if [[ $?
-ne 0 ]]; then
1077 log_note
"Unable to get $prop property for dataset " \
1087 # Simple function to get the specified property of pool. If unable to
1088 # get the property then exits.
1090 # Note property is in 'parsable' format (-p)
1092 function get_pool_prop
# property pool
1098 if poolexists
$pool ; then
1099 prop_val
=$
(zpool get
-pH $prop $pool 2>/dev
/null |
tail -1 | \
1101 if [[ $?
-ne 0 ]]; then
1102 log_note
"Unable to get $prop property for pool " \
1107 log_note
"Pool $pool not exists."
1115 # Return 0 if a pool exists; $? otherwise
1123 if [[ -z $pool ]]; then
1124 log_note
"No pool name given."
1128 zpool get name
"$pool" > /dev
/null
2>&1
1132 # Return 0 if all the specified datasets exist; $? otherwise
1135 function datasetexists
1137 if (($# == 0)); then
1138 log_note
"No dataset name given."
1142 while (($# > 0)); do
1143 zfs get name
$1 > /dev
/null
2>&1 || \
1151 # return 0 if none of the specified datasets exists, otherwise return 1.
1154 function datasetnonexists
1156 if (($# == 0)); then
1157 log_note
"No dataset name given."
1161 while (($# > 0)); do
1162 zfs list
-H -t filesystem
,snapshot
,volume
$1 > /dev
/null
2>&1 \
1171 # Given a mountpoint, or a dataset name, determine if it is shared via NFS.
1173 # Returns 0 if shared, 1 otherwise.
1180 if [[ $fs != "/"* ]] ; then
1181 if datasetnonexists
"$fs" ; then
1184 mtpt
=$
(get_prop mountpoint
"$fs")
1186 none|legacy|
-) return 1
1195 for mtpt
in `share | awk '{print $1}'` ; do
1196 if [[ $mtpt == $fs ]] ; then
1203 for mtpt
in `share | awk '{print $2}'` ; do
1204 if [[ $mtpt == $fs ]] ; then
1209 typeset stat
=$
(svcs
-H -o STA nfs
/server
:default
)
1210 if [[ $stat != "ON" ]]; then
1211 log_note
"Current nfs/server status: $stat"
1218 # Given a dataset name determine if it is shared via SMB.
1220 # Returns 0 if shared, 1 otherwise.
1222 function is_shared_smb
1227 if datasetnonexists
"$fs" ; then
1230 fs
=$
(echo $fs |
sed 's@/@_@g')
1234 for mtpt
in `net usershare list | awk '{print $1}'` ; do
1235 if [[ $mtpt == $fs ]] ; then
1241 log_unsupported
"Currently unsupported by the test framework"
1247 # Given a mountpoint, determine if it is not shared via NFS.
1249 # Returns 0 if not shared, 1 otherwise.
1256 if (($?
== 0)); then
1264 # Given a dataset determine if it is not shared via SMB.
1266 # Returns 0 if not shared, 1 otherwise.
1268 function not_shared_smb
1273 if (($?
== 0)); then
1281 # Helper function to unshare a mountpoint.
1283 function unshare_fs
#fs
1287 is_shared
$fs || is_shared_smb
$fs
1288 if (($?
== 0)); then
1289 log_must zfs unshare
$fs
1296 # Helper function to share a NFS mountpoint.
1298 function share_nfs
#fs
1304 if (($?
!= 0)); then
1305 log_must share
"*:$fs"
1309 if (($?
!= 0)); then
1310 log_must share
-F nfs
$fs
1318 # Helper function to unshare a NFS mountpoint.
1320 function unshare_nfs
#fs
1326 if (($?
== 0)); then
1327 log_must unshare
-u "*:$fs"
1331 if (($?
== 0)); then
1332 log_must unshare
-F nfs
$fs
1340 # Helper function to show NFS shares.
1342 function showshares_nfs
1354 # Helper function to show SMB shares.
1356 function showshares_smb
1368 # Check NFS server status and trigger it online.
1370 function setup_nfs_server
1372 # Cannot share directory in non-global zone.
1374 if ! is_global_zone
; then
1375 log_note
"Cannot trigger NFS server by sharing in LZ."
1380 log_note
"NFS server must started prior to running test framework."
1384 typeset nfs_fmri
="svc:/network/nfs/server:default"
1385 if [[ $
(svcs
-Ho STA
$nfs_fmri) != "ON" ]]; then
1387 # Only really sharing operation can enable NFS server
1388 # to online permanently.
1390 typeset dummy
=/tmp
/dummy
1392 if [[ -d $dummy ]]; then
1393 log_must
rm -rf $dummy
1396 log_must mkdir
$dummy
1397 log_must share
$dummy
1400 # Waiting for fmri's status to be the final status.
1401 # Otherwise, in transition, an asterisk (*) is appended for
1402 # instances, unshare will reverse status to 'DIS' again.
1404 # Waiting for 1's at least.
1408 while [[ timeout
-ne 0 && $
(svcs
-Ho STA
$nfs_fmri) == *'*' ]]
1415 log_must unshare
$dummy
1416 log_must
rm -rf $dummy
1419 log_note
"Current NFS status: '$(svcs -Ho STA,FMRI $nfs_fmri)'"
1423 # To verify whether calling process is in global zone
1425 # Return 0 if in global zone, 1 in non-global zone
1427 function is_global_zone
1432 typeset cur_zone
=$
(zonename
2>/dev
/null
)
1433 if [[ $cur_zone != "global" ]]; then
1441 # Verify whether test is permitted to run from
1442 # global zone, local zone, or both
1444 # $1 zone limit, could be "global", "local", or "both"(no limit)
1446 # Return 0 if permitted, otherwise exit with log_unsupported
1448 function verify_runnable
# zone limit
1452 [[ -z $limit ]] && return 0
1454 if is_global_zone
; then
1458 local) log_unsupported
"Test is unable to run from "\
1461 *) log_note
"Warning: unknown limit $limit - " \
1469 global
) log_unsupported
"Test is unable to run from "\
1472 *) log_note
"Warning: unknown limit $limit - " \
1483 # Return 0 if create successfully or the pool exists; $? otherwise
1484 # Note: In local zones, this function should return 0 silently.
1487 # $2-n - [keyword] devs_list
1489 function create_pool
#pool devs_list
1491 typeset pool
=${1%%/*}
1495 if [[ -z $pool ]]; then
1496 log_note
"Missing pool name."
1500 if poolexists
$pool ; then
1504 if is_global_zone
; then
1505 [[ -d /$pool ]] && rm -rf /$pool
1506 log_must zpool create
-f $pool $@
1512 # Return 0 if destroy successfully or the pool exists; $? otherwise
1513 # Note: In local zones, this function should return 0 silently.
1516 # Destroy pool with the given parameters.
1518 function destroy_pool
#pool
1520 typeset pool
=${1%%/*}
1523 if [[ -z $pool ]]; then
1524 log_note
"No pool name given."
1528 if is_global_zone
; then
1529 if poolexists
"$pool" ; then
1530 mtpt
=$
(get_prop mountpoint
"$pool")
1532 # At times, syseventd/udev activity can cause attempts
1533 # to destroy a pool to fail with EBUSY. We retry a few
1534 # times allowing failures before requiring the destroy
1536 log_must_busy zpool destroy
-f $pool
1539 log_must
rm -rf $mtpt
1541 log_note
"Pool does not exist. ($pool)"
1550 # Firstly, create a pool with 5 datasets. Then, create a single zone and
1551 # export the 5 datasets to it. In addition, we also add a ZFS filesystem
1552 # and a zvol device to the zone.
1555 # $2 zone root directory prefix
1558 function zfs_zones_setup
#zone_name zone_root zone_ip
1560 typeset zone_name
=${1:-$(hostname)-z}
1561 typeset zone_root
=${2:-"/zone_root"}
1562 typeset zone_ip
=${3:-"10.1.1.10"}
1563 typeset prefix_ctr
=$ZONE_CTR
1564 typeset pool_name
=$ZONE_POOL
1568 # Create pool and 5 container within it
1570 [[ -d /$pool_name ]] && rm -rf /$pool_name
1571 log_must zpool create
-f $pool_name $DISKS
1572 while ((i
< cntctr
)); do
1573 log_must zfs create
$pool_name/$prefix_ctr$i
1578 log_must zfs create
-V 1g
$pool_name/zone_zvol
1582 # If current system support slog, add slog device for pool
1584 if verify_slog_support
; then
1585 typeset sdevs
="/var/tmp/sdev1 /var/tmp/sdev2"
1586 log_must mkfile
$MINVDEVSIZE $sdevs
1587 log_must zpool add
$pool_name log mirror
$sdevs
1590 # this isn't supported just yet.
1591 # Create a filesystem. In order to add this to
1592 # the zone, it must have it's mountpoint set to 'legacy'
1593 # log_must zfs create $pool_name/zfs_filesystem
1594 # log_must zfs set mountpoint=legacy $pool_name/zfs_filesystem
1596 [[ -d $zone_root ]] && \
1597 log_must
rm -rf $zone_root/$zone_name
1598 [[ ! -d $zone_root ]] && \
1599 log_must mkdir
-p -m 0700 $zone_root/$zone_name
1601 # Create zone configure file and configure the zone
1603 typeset zone_conf
=/tmp
/zone_conf.$$
1604 echo "create" > $zone_conf
1605 echo "set zonepath=$zone_root/$zone_name" >> $zone_conf
1606 echo "set autoboot=true" >> $zone_conf
1608 while ((i
< cntctr
)); do
1609 echo "add dataset" >> $zone_conf
1610 echo "set name=$pool_name/$prefix_ctr$i" >> \
1612 echo "end" >> $zone_conf
1616 # add our zvol to the zone
1617 echo "add device" >> $zone_conf
1618 echo "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf
1619 echo "end" >> $zone_conf
1621 # add a corresponding zvol rdsk to the zone
1622 echo "add device" >> $zone_conf
1623 echo "set match=$ZVOL_RDEVDIR/$pool_name/zone_zvol" >> $zone_conf
1624 echo "end" >> $zone_conf
1626 # once it's supported, we'll add our filesystem to the zone
1627 # echo "add fs" >> $zone_conf
1628 # echo "set type=zfs" >> $zone_conf
1629 # echo "set special=$pool_name/zfs_filesystem" >> $zone_conf
1630 # echo "set dir=/export/zfs_filesystem" >> $zone_conf
1631 # echo "end" >> $zone_conf
1633 echo "verify" >> $zone_conf
1634 echo "commit" >> $zone_conf
1635 log_must zonecfg
-z $zone_name -f $zone_conf
1636 log_must
rm -f $zone_conf
1639 zoneadm
-z $zone_name install
1640 if (($?
== 0)); then
1641 log_note
"SUCCESS: zoneadm -z $zone_name install"
1643 log_fail
"FAIL: zoneadm -z $zone_name install"
1646 # Install sysidcfg file
1648 typeset sysidcfg
=$zone_root/$zone_name/root
/etc
/sysidcfg
1649 echo "system_locale=C" > $sysidcfg
1650 echo "terminal=dtterm" >> $sysidcfg
1651 echo "network_interface=primary {" >> $sysidcfg
1652 echo "hostname=$zone_name" >> $sysidcfg
1653 echo "}" >> $sysidcfg
1654 echo "name_service=NONE" >> $sysidcfg
1655 echo "root_password=mo791xfZ/SFiw" >> $sysidcfg
1656 echo "security_policy=NONE" >> $sysidcfg
1657 echo "timezone=US/Eastern" >> $sysidcfg
1660 log_must zoneadm
-z $zone_name boot
1664 # Reexport TESTPOOL & TESTPOOL(1-4)
1666 function reexport_pool
1671 while ((i
< cntctr
)); do
1673 TESTPOOL
=$ZONE_POOL/$ZONE_CTR$i
1674 if ! ismounted
$TESTPOOL; then
1675 log_must zfs mount
$TESTPOOL
1678 eval TESTPOOL
$i=$ZONE_POOL/$ZONE_CTR$i
1679 if eval ! ismounted \
$TESTPOOL$i; then
1680 log_must
eval zfs mount \
$TESTPOOL$i
1688 # Verify a given disk or pool state
1690 # Return 0 is pool/disk matches expected state, 1 otherwise
1692 function check_state
# pool disk state{online,offline,degraded}
1695 typeset disk
=${2#$DEV_DSKDIR/}
1698 [[ -z $pool ]] ||
[[ -z $state ]] \
1699 && log_fail
"Arguments invalid or missing"
1701 if [[ -z $disk ]]; then
1702 #check pool state only
1703 zpool get
-H -o value health
$pool \
1704 |
grep -i "$state" > /dev
/null
2>&1
1706 zpool status
-v $pool |
grep "$disk" \
1707 |
grep -i "$state" > /dev
/null
2>&1
1714 # Cause a scan of all scsi host adapters by default
1716 # $1 optional host number
1718 function scan_scsi_hosts
1720 typeset hostnum
=${1}
1723 if [[ -z $hostnum ]]; then
1724 for host in /sys
/class
/scsi_host
/host*; do
1725 log_must
eval "echo '- - -' > $host/scan"
1729 "echo /sys/class/scsi_host/host$hostnum/scan" \
1732 "echo '- - -' > /sys/class/scsi_host/host$hostnum/scan"
1737 # Wait for newly created block devices to have their minors created.
1739 function block_device_wait
1748 # Online or offline a disk on the system
1750 # First checks state of disk. Test will fail if disk is not properly onlined
1751 # or offlined. Online is a full rescan of SCSI disks by echoing to every
1754 function on_off_disk
# disk state{online,offline} host
1760 [[ -z $disk ]] ||
[[ -z $state ]] && \
1761 log_fail
"Arguments invalid or missing"
1764 if [[ $state == "offline" ]] && ( is_mpath_device
$disk ); then
1765 dm_name
="$(readlink $DEV_DSKDIR/$disk \
1766 | nawk -F / '{print $2}')"
1767 slave
="$(ls /sys/block/${dm_name}/slaves \
1768 | nawk '{print $1}')"
1769 while [[ -n $slave ]]; do
1770 #check if disk is online
1771 lsscsi |
egrep $slave > /dev
/null
1772 if (($?
== 0)); then
1773 slave_dir
="/sys/block/${dm_name}"
1774 slave_dir
+="/slaves/${slave}/device"
1775 ss
="${slave_dir}/state"
1776 sd
="${slave_dir}/delete"
1777 log_must
eval "echo 'offline' > ${ss}"
1778 log_must
eval "echo '1' > ${sd}"
1779 lsscsi |
egrep $slave > /dev
/null
1780 if (($?
== 0)); then
1781 log_fail
"Offlining" \
1785 slave
="$(ls /sys/block/$dm_name/slaves \
1786 2>/dev/null | nawk '{print $1}')"
1788 elif [[ $state == "offline" ]] && ( is_real_device
$disk ); then
1789 #check if disk is online
1790 lsscsi |
egrep $disk > /dev
/null
1791 if (($?
== 0)); then
1792 dev_state
="/sys/block/$disk/device/state"
1793 dev_delete
="/sys/block/$disk/device/delete"
1794 log_must
eval "echo 'offline' > ${dev_state}"
1795 log_must
eval "echo '1' > ${dev_delete}"
1796 lsscsi |
egrep $disk > /dev
/null
1797 if (($?
== 0)); then
1798 log_fail
"Offlining $disk" \
1802 log_note
"$disk is already offline"
1804 elif [[ $state == "online" ]]; then
1805 #force a full rescan
1806 scan_scsi_hosts
$host
1808 if is_mpath_device
$disk; then
1809 dm_name
="$(readlink $DEV_DSKDIR/$disk \
1810 | nawk -F / '{print $2}')"
1811 slave
="$(ls /sys/block/$dm_name/slaves \
1812 | nawk '{print $1}')"
1813 lsscsi |
egrep $slave > /dev
/null
1814 if (($?
!= 0)); then
1815 log_fail
"Onlining $disk failed"
1817 elif is_real_device
$disk; then
1818 lsscsi |
egrep $disk > /dev
/null
1819 if (($?
!= 0)); then
1820 log_fail
"Onlining $disk failed"
1823 log_fail
"$disk is not a real dev"
1826 log_fail
"$disk failed to $state"
1832 # Get the mountpoint of snapshot
1833 # For the snapshot use <mp_filesystem>/.zfs/snapshot/<snap>
1836 function snapshot_mountpoint
1838 typeset dataset
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
1840 if [[ $dataset != *@
* ]]; then
1841 log_fail
"Error name of snapshot '$dataset'."
1844 typeset fs
=${dataset%@*}
1845 typeset snap
=${dataset#*@}
1847 if [[ -z $fs ||
-z $snap ]]; then
1848 log_fail
"Error name of snapshot '$dataset'."
1851 echo $
(get_prop mountpoint
$fs)/.zfs
/snapshot
/$snap
1855 # Given a device and 'ashift' value verify it's correctly set on every label
1857 function verify_ashift
# device ashift
1862 zdb
-e -lll $device |
awk -v ashift
=$ashift '/ashift: / {
1878 # Given a pool and file system, this function will verify the file system
1879 # using the zdb internal tool. Note that the pool is exported and imported
1880 # to ensure it has consistent state.
1882 function verify_filesys
# pool filesystem dir
1885 typeset filesys
="$2"
1886 typeset zdbout
="/tmp/zdbout.$$"
1891 typeset search_path
=""
1893 log_note
"Calling zdb to verify filesystem '$filesys'"
1894 zfs unmount
-a > /dev
/null
2>&1
1895 log_must zpool
export $pool
1897 if [[ -n $dirs ]] ; then
1898 for dir
in $dirs ; do
1899 search_path
="$search_path -d $dir"
1903 log_must zpool import
$search_path $pool
1905 zdb
-cudi $filesys > $zdbout 2>&1
1906 if [[ $?
!= 0 ]]; then
1907 log_note
"Output: zdb -cudi $filesys"
1909 log_fail
"zdb detected errors with: '$filesys'"
1912 log_must zfs mount
-a
1913 log_must
rm -rf $zdbout
1917 # Given a pool, and this function list all disks in the pool
1919 function get_disklist
# pool
1923 disklist
=$
(zpool iostat
-v $1 | nawk
'(NR >4) {print $1}' | \
1924 grep -v "\-\-\-\-\-" | \
1925 egrep -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
1931 # Given a pool, and this function list all disks in the pool with their full
1932 # path (like "/dev/sda" instead of "sda").
1934 function get_disklist_fullpath
# pool
1943 # This function kills a given list of processes after a time period. We use
1944 # this in the stress tests instead of STF_TIMEOUT so that we can have processes
1945 # run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT
1946 # would be listed as FAIL, which we don't want : we're happy with stress tests
1947 # running for a certain amount of time, then finishing.
1949 # @param $1 the time in seconds after which we should terminate these processes
1950 # @param $2..$n the processes we wish to terminate.
1952 function stress_timeout
1954 typeset
-i TIMEOUT
=$1
1958 log_note
"Waiting for child processes($cpids). " \
1959 "It could last dozens of minutes, please be patient ..."
1960 log_must
sleep $TIMEOUT
1962 log_note
"Killing child processes after ${TIMEOUT} stress timeout."
1964 for pid
in $cpids; do
1965 ps
-p $pid > /dev
/null
2>&1
1966 if (($?
== 0)); then
1967 log_must
kill -USR1 $pid
1973 # Verify a given hotspare disk is inuse or avail
1975 # Return 0 is pool/disk matches expected state, 1 otherwise
1977 function check_hotspare_state
# pool disk state{inuse,avail}
1980 typeset disk
=${2#$DEV_DSKDIR/}
1983 cur_state
=$
(get_device_state
$pool $disk "spares")
1985 if [[ $state != ${cur_state} ]]; then
1992 # Verify a given slog disk is inuse or avail
1994 # Return 0 is pool/disk matches expected state, 1 otherwise
1996 function check_slog_state
# pool disk state{online,offline,unavail}
1999 typeset disk
=${2#$DEV_DSKDIR/}
2002 cur_state
=$
(get_device_state
$pool $disk "logs")
2004 if [[ $state != ${cur_state} ]]; then
2011 # Verify a given vdev disk is inuse or avail
2013 # Return 0 is pool/disk matches expected state, 1 otherwise
2015 function check_vdev_state
# pool disk state{online,offline,unavail}
2018 typeset disk
=${2#$/DEV_DSKDIR/}
2021 cur_state
=$
(get_device_state
$pool $disk)
2023 if [[ $state != ${cur_state} ]]; then
2030 # Check the output of 'zpool status -v <pool>',
2031 # and to see if the content of <token> contain the <keyword> specified.
2033 # Return 0 is contain, 1 otherwise
2035 function check_pool_status
# pool token keyword <verbose>
2040 typeset verbose
=${4:-false}
2042 scan
=$
(zpool status
-v "$pool" 2>/dev
/null | nawk
-v token
="$token:" '
2043 ($1==token) {print $0}')
2044 if [[ $verbose == true
]]; then
2047 echo $scan |
grep -i "$keyword" > /dev
/null
2>&1
2053 # These 6 following functions are instance of check_pool_status()
2054 # is_pool_resilvering - to check if the pool is resilver in progress
2055 # is_pool_resilvered - to check if the pool is resilver completed
2056 # is_pool_scrubbing - to check if the pool is scrub in progress
2057 # is_pool_scrubbed - to check if the pool is scrub completed
2058 # is_pool_scrub_stopped - to check if the pool is scrub stopped
2059 # is_pool_scrub_paused - to check if the pool has scrub paused
2061 function is_pool_resilvering
#pool <verbose>
2063 check_pool_status
"$1" "scan" "resilver in progress since " $2
2067 function is_pool_resilvered
#pool <verbose>
2069 check_pool_status
"$1" "scan" "resilvered " $2
2073 function is_pool_scrubbing
#pool <verbose>
2075 check_pool_status
"$1" "scan" "scrub in progress since " $2
2079 function is_pool_scrubbed
#pool <verbose>
2081 check_pool_status
"$1" "scan" "scrub repaired" $2
2085 function is_pool_scrub_stopped
#pool <verbose>
2087 check_pool_status
"$1" "scan" "scrub canceled" $2
2091 function is_pool_scrub_paused
#pool <verbose>
2093 check_pool_status
"$1" "scan" "scrub paused since " $2
2098 # Use create_pool()/destroy_pool() to clean up the information in
2099 # in the given disk to avoid slice overlapping.
2101 function cleanup_devices
#vdevs
2103 typeset pool
="foopool$$"
2105 if poolexists
$pool ; then
2109 create_pool
$pool $@
2116 # A function to find and locate free disks on a system or from given
2117 # disks as the parameter. It works by locating disks that are in use
2118 # as swap devices and dump devices, and also disks listed in /etc/vfstab
2120 # $@ given disks to find which are free, default is all disks in
2123 # @return a string containing the list of available disks
2127 # Trust provided list, no attempt is made to locate unused devices.
2134 sfi
=/tmp
/swaplist.$$
2135 dmpi
=/tmp
/dumpdev.$$
2136 max_finddisksnum
=${MAX_FINDDISKSNUM:-6}
2139 dumpadm
> $dmpi 2>/dev
/null
2141 # write an awk script that can process the output of format
2142 # to produce a list of disks we know about. Note that we have
2143 # to escape "$2" so that the shell doesn't interpret it while
2144 # we're creating the awk script.
2145 # -------------------
2146 cat > /tmp
/find_disks.
awk <<EOF
2155 if (searchdisks && \$2 !~ "^$"){
2161 /^AVAILABLE DISK SELECTIONS:/{
2165 #---------------------
2167 chmod 755 /tmp
/find_disks.
awk
2168 disks
=${@:-$(echo "" | format -e 2>/dev/null | /tmp/find_disks.awk)}
2169 rm /tmp
/find_disks.
awk
2172 for disk
in $disks; do
2174 grep "${disk}[sp]" /etc
/mnttab
>/dev
/null
2175 (($?
== 0)) && continue
2177 grep "${disk}[sp]" $sfi >/dev
/null
2178 (($?
== 0)) && continue
2179 # check for dump device
2180 grep "${disk}[sp]" $dmpi >/dev
/null
2181 (($?
== 0)) && continue
2182 # check to see if this disk hasn't been explicitly excluded
2183 # by a user-set environment variable
2184 echo "${ZFS_HOST_DEVICES_IGNORE}" |
grep "${disk}" > /dev
/null
2185 (($?
== 0)) && continue
2186 unused_candidates
="$unused_candidates $disk"
2191 # now just check to see if those disks do actually exist
2192 # by looking for a device pointing to the first slice in
2193 # each case. limit the number to max_finddisksnum
2195 for disk
in $unused_candidates; do
2196 if [ -b $DEV_DSKDIR/${disk}s0
]; then
2197 if [ $count -lt $max_finddisksnum ]; then
2198 unused
="$unused $disk"
2199 # do not impose limit if $@ is provided
2200 [[ -z $@
]] && ((count
= count
+ 1))
2205 # finally, return our disk list
2210 # Add specified user to specified group
2214 # $3 base of the homedir (optional)
2216 function add_user
#<group_name> <user_name> <basedir>
2220 typeset basedir
=${3:-"/var/tmp"}
2222 if ((${#gname} == 0 ||
${#uname} == 0)); then
2223 log_fail
"group name or user name are not defined."
2226 log_must useradd
-g $gname -d $basedir/$uname -m $uname
2227 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.profile
2228 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.bash_profile
2229 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.login
2231 # Add new users to the same group and the command line utils.
2232 # This allows them to be run out of the original users home
2233 # directory as long as it permissioned to be group readable.
2235 cmd_group
=$
(stat
--format="%G" $
(which zfs
))
2236 log_must usermod
-a -G $cmd_group $uname
2243 # Delete the specified user.
2246 # $2 base of the homedir (optional)
2248 function del_user
#<logname> <basedir>
2251 typeset basedir
=${2:-"/var/tmp"}
2253 if ((${#user} == 0)); then
2254 log_fail
"login name is necessary."
2257 if id
$user > /dev
/null
2>&1; then
2258 log_must_retry
"currently used" 5 userdel
$user
2261 [[ -d $basedir/$user ]] && rm -fr $basedir/$user
2267 # Select valid gid and create specified group.
2271 function add_group
#<group_name>
2275 if ((${#group} == 0)); then
2276 log_fail
"group name is necessary."
2279 # Assign 100 as the base gid, a larger value is selected for
2280 # Linux because for many distributions 1000 and under are reserved.
2283 groupadd
$group > /dev
/null
2>&1
2293 groupadd
-g $gid $group > /dev
/null
2>&1
2297 # The gid is not unique
2306 # Delete the specified group.
2310 function del_group
#<group_name>
2313 if ((${#grp} == 0)); then
2314 log_fail
"group name is necessary."
2318 getent group
$grp > /dev
/null
2>&1
2321 # Group does not exist.
2323 # Name already exists as a group name
2324 0) log_must groupdel
$grp ;;
2328 groupmod
-n $grp $grp > /dev
/null
2>&1
2331 # Group does not exist.
2333 # Name already exists as a group name
2334 9) log_must groupdel
$grp ;;
2343 # This function will return true if it's safe to destroy the pool passed
2344 # as argument 1. It checks for pools based on zvols and files, and also
2345 # files contained in a pool that may have a different mountpoint.
2347 function safe_to_destroy_pool
{ # $1 the pool name
2350 typeset DONT_DESTROY
=""
2352 # We check that by deleting the $1 pool, we're not
2353 # going to pull the rug out from other pools. Do this
2354 # by looking at all other pools, ensuring that they
2355 # aren't built from files or zvols contained in this pool.
2357 for pool
in $
(zpool list
-H -o name
)
2361 # this is a list of the top-level directories in each of the
2362 # files that make up the path to the files the pool is based on
2363 FILEPOOL
=$
(zpool status
-v $pool |
grep /$1/ | \
2366 # this is a list of the zvols that make up the pool
2367 ZVOLPOOL
=$
(zpool status
-v $pool |
grep "$ZVOL_DEVDIR/$1$" \
2370 # also want to determine if it's a file-based pool using an
2371 # alternate mountpoint...
2372 POOL_FILE_DIRS
=$
(zpool status
-v $pool | \
2373 grep / |
awk '{print $1}' | \
2374 awk -F/ '{print $2}' |
grep -v "dev")
2376 for pooldir
in $POOL_FILE_DIRS
2378 OUTPUT
=$
(zfs list
-H -r -o mountpoint
$1 | \
2379 grep "${pooldir}$" |
awk '{print $1}')
2381 ALTMOUNTPOOL
="${ALTMOUNTPOOL}${OUTPUT}"
2385 if [ ! -z "$ZVOLPOOL" ]
2388 log_note
"Pool $pool is built from $ZVOLPOOL on $1"
2391 if [ ! -z "$FILEPOOL" ]
2394 log_note
"Pool $pool is built from $FILEPOOL on $1"
2397 if [ ! -z "$ALTMOUNTPOOL" ]
2400 log_note
"Pool $pool is built from $ALTMOUNTPOOL on $1"
2404 if [ -z "${DONT_DESTROY}" ]
2408 log_note
"Warning: it is not safe to destroy $1!"
2414 # Get the available ZFS compression options
2415 # $1 option type zfs_set|zfs_compress
2417 function get_compress_opts
2419 typeset COMPRESS_OPTS
2420 typeset GZIP_OPTS
="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \
2421 gzip-6 gzip-7 gzip-8 gzip-9"
2423 if [[ $1 == "zfs_compress" ]] ; then
2424 COMPRESS_OPTS
="on lzjb"
2425 elif [[ $1 == "zfs_set" ]] ; then
2426 COMPRESS_OPTS
="on off lzjb"
2428 typeset valid_opts
="$COMPRESS_OPTS"
2429 zfs get
2>&1 |
grep gzip >/dev
/null
2>&1
2430 if [[ $?
-eq 0 ]]; then
2431 valid_opts
="$valid_opts $GZIP_OPTS"
2437 # Verify zfs operation with -p option work as expected
2438 # $1 operation, value could be create, clone or rename
2439 # $2 dataset type, value could be fs or vol
2441 # $4 new dataset name
2443 function verify_opt_p_ops
2448 typeset newdataset
=$4
2450 if [[ $datatype != "fs" && $datatype != "vol" ]]; then
2451 log_fail
"$datatype is not supported."
2454 # check parameters accordingly
2459 if [[ $datatype == "vol" ]]; then
2460 ops
="create -V $VOLSIZE"
2464 if [[ -z $newdataset ]]; then
2465 log_fail
"newdataset should not be empty" \
2468 log_must datasetexists
$dataset
2469 log_must snapexists
$dataset
2472 if [[ -z $newdataset ]]; then
2473 log_fail
"newdataset should not be empty" \
2476 log_must datasetexists
$dataset
2477 log_mustnot snapexists
$dataset
2480 log_fail
"$ops is not supported."
2484 # make sure the upper level filesystem does not exist
2485 if datasetexists
${newdataset%/*} ; then
2486 log_must zfs destroy
-rRf ${newdataset%/*}
2489 # without -p option, operation will fail
2490 log_mustnot zfs
$ops $dataset $newdataset
2491 log_mustnot datasetexists
$newdataset ${newdataset%/*}
2493 # with -p option, operation should succeed
2494 log_must zfs
$ops -p $dataset $newdataset
2497 if ! datasetexists
$newdataset ; then
2498 log_fail
"-p option does not work for $ops"
2501 # when $ops is create or clone, redo the operation still return zero
2502 if [[ $ops != "rename" ]]; then
2503 log_must zfs
$ops -p $dataset $newdataset
2510 # Get configuration of pool
2520 if ! poolexists
"$pool" ; then
2523 alt_root
=$
(zpool list
-H $pool |
awk '{print $NF}')
2524 if [[ $alt_root == "-" ]]; then
2525 value
=$
(zdb
-C $pool |
grep "$config:" |
awk -F: \
2528 value
=$
(zdb
-e $pool |
grep "$config:" |
awk -F: \
2531 if [[ -n $value ]] ; then
2541 # Privated function. Random select one of items from arguments.
2546 function _random_get
2553 ((ind
= RANDOM
% cnt
+ 1))
2555 typeset ret
=$
(echo "$str" | cut
-f $ind -d ' ')
2560 # Random select one of item from arguments which include NONE string
2562 function random_get_with_non
2567 _random_get
"$cnt" "$@"
2571 # Random select one of item from arguments which doesn't include NONE string
2575 _random_get
"$#" "$@"
2579 # Detect if the current system support slog
2581 function verify_slog_support
2583 typeset dir
=/tmp
/disk.$$
2589 mkfile
$MINVDEVSIZE $vdev $sdev
2592 if ! zpool create
-n $pool $vdev log
$sdev > /dev
/null
2>&1; then
2601 # The function will generate a dataset name with specific length
2602 # $1, the length of the name
2603 # $2, the base string to construct the name
2605 function gen_dataset_name
2608 typeset basestr
="$2"
2609 typeset
-i baselen
=${#basestr}
2613 if ((len
% baselen
== 0)); then
2614 ((iter
= len
/ baselen
))
2616 ((iter
= len
/ baselen
+ 1))
2618 while ((iter
> 0)); do
2619 l_name
="${l_name}$basestr"
2628 # Get cksum tuple of dataset
2631 # sample zdb output:
2632 # Dataset data/test [ZPL], ID 355, cr_txg 2413856, 31.0K, 7 objects, rootbp
2633 # DVA[0]=<0:803046400:200> DVA[1]=<0:81199000:200> [L0 DMU objset] fletcher4
2634 # lzjb LE contiguous unique double size=800L/200P birth=2413856L/2413856P
2635 # fill=7 cksum=11ce125712:643a9c18ee2:125e25238fca0:254a3f74b59744
2636 function datasetcksum
2640 cksum=$
(zdb
-vvv $1 |
grep "^Dataset $1 \[" |
grep "cksum" \
2641 |
awk -F= '{print $7}')
2652 cksum=$
(cksum $1 |
awk '{print $1}')
2657 # Get the given disk/slice state from the specific field of the pool
2659 function get_device_state
#pool disk field("", "spares","logs")
2662 typeset disk
=${2#$DEV_DSKDIR/}
2663 typeset field
=${3:-$pool}
2665 state
=$
(zpool status
-v "$pool" 2>/dev
/null | \
2666 nawk
-v device
=$disk -v pool
=$pool -v field
=$field \
2667 'BEGIN {startconfig=0; startfield=0; }
2668 /config:/ {startconfig=1}
2669 (startconfig==1) && ($1==field) {startfield=1; next;}
2670 (startfield==1) && ($1==device) {print $2; exit;}
2672 ($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}')
2678 # print the given directory filesystem type
2686 if [[ -z $dir ]]; then
2687 log_fail
"Usage: get_fstype <directory>"
2694 df
-n $dir |
awk '{print $3}'
2698 # Given a disk, label it to VTOC regardless what label was on the disk
2704 if [[ -z $disk ]]; then
2705 log_fail
"The disk name is unspecified."
2707 typeset label_file
=/var
/tmp
/labelvtoc.$$
2708 typeset arch
=$
(uname
-p)
2711 log_note
"Currently unsupported by the test framework"
2715 if [[ $arch == "i386" ]]; then
2716 echo "label" > $label_file
2717 echo "0" >> $label_file
2718 echo "" >> $label_file
2719 echo "q" >> $label_file
2720 echo "q" >> $label_file
2722 fdisk
-B $disk >/dev
/null
2>&1
2723 # wait a while for fdisk finishes
2725 elif [[ $arch == "sparc" ]]; then
2726 echo "label" > $label_file
2727 echo "0" >> $label_file
2728 echo "" >> $label_file
2729 echo "" >> $label_file
2730 echo "" >> $label_file
2731 echo "q" >> $label_file
2733 log_fail
"unknown arch type"
2736 format
-e -s -d $disk -f $label_file
2737 typeset
-i ret_val
=$?
2740 # wait the format to finish
2743 if ((ret_val
!= 0)); then
2744 log_fail
"unable to label $disk as VTOC."
2751 # check if the system was installed as zfsroot or not
2752 # return: 0 ture, otherwise false
2756 df
-n / |
grep zfs
> /dev
/null
2>&1
2761 # get the root filesystem name if it's zfsroot system.
2763 # return: root filesystem name
2769 rootfs
=$
(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \
2772 if [[ -z "$rootfs" ]]; then
2773 log_fail
"Can not get rootfs"
2775 zfs list
$rootfs > /dev
/null
2>&1
2776 if (($?
== 0)); then
2779 log_fail
"This is not a zfsroot system."
2784 # get the rootfs's pool name
2788 function get_rootpool
2794 rootfs
=$
(awk '{if ($2 == "/" && $3 =="zfs") print $1}' \
2797 if [[ -z "$rootfs" ]]; then
2798 log_fail
"Can not get rootpool"
2800 zfs list
$rootfs > /dev
/null
2>&1
2801 if (($?
== 0)); then
2802 rootpool
=`echo $rootfs | awk -F\/ '{print $1}'`
2805 log_fail
"This is not a zfsroot system."
2810 # Check if the given device is physical device
2812 function is_physical_device
#device
2814 typeset device
=${1#$DEV_DSKDIR}
2815 device
=${device#$DEV_RDSKDIR}
2818 [[ -b "$DEV_DSKDIR/$device" ]] && \
2819 [[ -f /sys
/module
/loop
/parameters
/max_part
]]
2822 echo $device |
egrep "^c[0-F]+([td][0-F]+)+$" > /dev
/null
2>&1
2828 # Check if the given device is a real device (ie SCSI device)
2830 function is_real_device
#disk
2833 [[ -z $disk ]] && log_fail
"No argument for disk given."
2836 lsblk
$DEV_RDSKDIR/$disk -o TYPE
2>/dev
/null | \
2837 egrep disk
>/dev
/null
2843 # Check if the given device is a loop device
2845 function is_loop_device
#disk
2848 [[ -z $disk ]] && log_fail
"No argument for disk given."
2851 lsblk
$DEV_RDSKDIR/$disk -o TYPE
2>/dev
/null | \
2852 egrep loop
>/dev
/null
2858 # Check if the given device is a multipath device and if there is a sybolic
2859 # link to a device mapper and to a disk
2860 # Currently no support for dm devices alone without multipath
2862 function is_mpath_device
#disk
2865 [[ -z $disk ]] && log_fail
"No argument for disk given."
2868 lsblk
$DEV_MPATHDIR/$disk -o TYPE
2>/dev
/null | \
2869 egrep mpath
>/dev
/null
2870 if (($?
== 0)); then
2871 readlink
$DEV_MPATHDIR/$disk > /dev
/null
2>&1
2879 # Set the slice prefix for disk partitioning depending
2880 # on whether the device is a real, multipath, or loop device.
2881 # Currently all disks have to be of the same type, so only
2882 # checks first disk to determine slice prefix.
2884 function set_slice_prefix
2890 while (( i
< $DISK_ARRAY_NUM )); do
2891 disk
="$(echo $DISKS | nawk '{print $(i + 1)}')"
2892 if ( is_mpath_device
$disk ) && [[ -z $
(echo $disk |
awk 'substr($1,18,1)\
2893 ~ /^[[:digit:]]+$/') ]] ||
( is_real_device
$disk ); then
2894 export SLICE_PREFIX
=""
2896 elif ( is_mpath_device
$disk || is_loop_device \
2898 export SLICE_PREFIX
="p"
2901 log_fail
"$disk not supported for partitioning."
2909 # Set the directory path of the listed devices in $DISK_ARRAY_NUM
2910 # Currently all disks have to be of the same type, so only
2911 # checks first disk to determine device directory
2912 # default = /dev (linux)
2913 # real disk = /dev (linux)
2914 # multipath device = /dev/mapper (linux)
2916 function set_device_dir
2922 while (( i
< $DISK_ARRAY_NUM )); do
2923 disk
="$(echo $DISKS | nawk '{print $(i + 1)}')"
2924 if is_mpath_device
$disk; then
2925 export DEV_DSKDIR
=$DEV_MPATHDIR
2928 export DEV_DSKDIR
=$DEV_RDSKDIR
2934 export DEV_DSKDIR
=$DEV_RDSKDIR
2939 # Get the directory path of given device
2941 function get_device_dir
#device
2945 if ! $
(is_physical_device
$device) ; then
2946 if [[ $device != "/" ]]; then
2949 if [[ -b "$DEV_DSKDIR/$device" ]]; then
2950 device
="$DEV_DSKDIR"
2959 # Get persistent name for given disk
2961 function get_persistent_disk_name
#device
2967 if is_real_device
$device; then
2968 dev_id
="$(udevadm info -q all -n $DEV_DSKDIR/$device \
2969 | egrep disk/by-id | nawk '{print $2; exit}' \
2970 | nawk -F / '{print $3}')"
2972 elif is_mpath_device
$device; then
2973 dev_id
="$(udevadm info -q all -n $DEV_DSKDIR/$device \
2974 | egrep disk/by-id/dm-uuid \
2975 | nawk '{print $2; exit}' \
2976 | nawk -F / '{print $3}')"
2987 # Load scsi_debug module with specified parameters
2989 function load_scsi_debug
# dev_size_mb add_host num_tgts max_luns
2996 [[ -z $devsize ]] ||
[[ -z $hosts ]] ||
[[ -z $tgts ]] || \
2997 [[ -z $luns ]] && log_fail
"Arguments invalid or missing"
3000 modprobe
-n scsi_debug
3001 if (($?
!= 0)); then
3002 log_unsupported
"Platform does not have scsi_debug"
3005 lsmod |
egrep scsi_debug
> /dev
/null
3006 if (($?
== 0)); then
3007 log_fail
"scsi_debug module already installed"
3009 log_must modprobe scsi_debug dev_size_mb
=$devsize \
3010 add_host
=$hosts num_tgts
=$tgts max_luns
=$luns
3012 lsscsi |
egrep scsi_debug
> /dev
/null
3013 if (($?
== 1)); then
3014 log_fail
"scsi_debug module install failed"
3021 # Get the package name
3023 function get_package_name
3025 typeset dirpath
=${1:-$STC_NAME}
3027 echo "SUNWstc-${dirpath}" |
/usr
/bin
/sed -e "s/\//-/g"
3031 # Get the word numbers from a string separated by white space
3033 function get_word_count
3039 # To verify if the require numbers of disks is given
3041 function verify_disk_count
3043 typeset
-i min
=${2:-1}
3045 typeset
-i count
=$
(get_word_count
"$1")
3047 if ((count
< min
)); then
3048 log_untested
"A minimum of $min disks is required to run." \
3049 " You specified $count disk(s)"
3053 function ds_is_volume
3055 typeset
type=$
(get_prop
type $1)
3056 [[ $type = "volume" ]] && return 0
3060 function ds_is_filesystem
3062 typeset
type=$
(get_prop
type $1)
3063 [[ $type = "filesystem" ]] && return 0
3067 function ds_is_snapshot
3069 typeset
type=$
(get_prop
type $1)
3070 [[ $type = "snapshot" ]] && return 0
3075 # Check if Trusted Extensions are installed and enabled
3077 function is_te_enabled
3079 svcs
-H -o state labeld
2>/dev
/null |
grep "enabled"
3080 if (($?
!= 0)); then
3087 # Utility function to determine if a system has multiple cpus.
3093 (($
(psrinfo |
wc -l) > 1))
3099 function get_cpu_freq
3102 lscpu |
awk '/CPU MHz/ { print $3 }'
3104 psrinfo
-v 0 |
awk '/processor operates at/ {print $6}'
3108 # Run the given command as the user provided.
3114 log_note
"user:$user $@"
3115 eval su
- \
$user -c \"$@
\" > /tmp
/out
2>/tmp
/err
3120 # Check if the pool contains the specified vdevs
3125 # Return 0 if the vdevs are contained in the pool, 1 if any of the specified
3126 # vdevs is not in the pool, and 2 if pool name is missing.
3128 function vdevs_in_pool
3133 if [[ -z $pool ]]; then
3134 log_note
"Missing pool name."
3140 typeset tmpfile
=$
(mktemp
)
3141 zpool list
-Hv "$pool" >$tmpfile
3143 grep -w ${vdev##*/} $tmpfile >/dev
/null
2>&1
3144 [[ $?
-ne 0 ]] && return 1
3158 max
=$
(echo $
((max
> i ? max
: i
)))
3170 min
=$
(echo $
((min
< i ? min
: i
)))
3177 # Generate a random number between 1 and the argument.
3182 echo $
(( ($RANDOM % $max) + 1 ))
3185 # Write data that can be compressed into a directory
3186 function write_compressible
3190 typeset nfiles
=${3:-1}
3191 typeset bs
=${4:-1024k}
3192 typeset fname
=${5:-file}
3194 [[ -d $dir ]] || log_fail
"No directory: $dir"
3196 # Under Linux fio is not currently used since its behavior can
3197 # differ significantly across versions. This includes missing
3198 # command line options and cases where the --buffer_compress_*
3199 # options fail to behave as expected.
3201 typeset file_bytes
=$
(to_bytes
$megs)
3202 typeset bs_bytes
=4096
3203 typeset blocks
=$
(($file_bytes / $bs_bytes))
3205 for (( i
= 0; i
< $nfiles; i
++ )); do
3206 truncate
-s $file_bytes $dir/$fname.
$i
3208 # Write every third block to get 66% compression.
3209 for (( j
= 0; j
< $blocks; j
+= 3 )); do
3210 dd if=/dev
/urandom of
=$dir/$fname.
$i \
3211 seek
=$j bs
=$bs_bytes count
=1 \
3212 conv
=notrunc
>/dev
/null
2>&1
3216 log_must
eval "fio \
3221 --buffer_compress_percentage=66 \
3222 --buffer_compress_chunk=4096 \
3229 --filename_format='$fname.\$jobnum' >/dev/null"
3238 [[ -e $pathname ]] || log_fail
"No such file or directory: $pathname"
3239 objnum
=$
(stat
-c %i
$pathname)
3244 # Sync data to the pool
3247 # $2 boolean to force uberblock (and config including zpool cache file) update
3249 function sync_pool
#pool <force>
3251 typeset pool
=${1:-$TESTPOOL}
3252 typeset force
=${2:-false}
3254 if [[ $force == true
]]; then
3255 log_must zpool sync
-f $pool
3257 log_must zpool sync
$pool
3264 # Wait for zpool 'freeing' property drops to zero.
3268 function wait_freeing
#pool
3270 typeset pool
=${1:-$TESTPOOL}
3272 [[ "0" == "$(zpool list -Ho freeing $pool)" ]] && break
3278 # Wait for every device replace operation to complete
3282 function wait_replacing
#pool
3284 typeset pool
=${1:-$TESTPOOL}
3286 [[ "" == "$(zpool status $pool |
3287 awk '/replacing-[0-9]+/ {print $1}')" ]] && break
3293 # Setup custom environment for the ZED.
3301 if [[ ! -d $ZEDLET_DIR ]]; then
3302 log_must mkdir
$ZEDLET_DIR
3305 if [[ ! -e $VDEVID_CONF ]]; then
3306 log_must
touch $VDEVID_CONF
3309 if [[ -e $VDEVID_CONF_ETC ]]; then
3310 log_fail
"Must not have $VDEVID_CONF_ETC file present on system"
3313 # Create a symlink for /etc/zfs/vdev_id.conf file.
3314 log_must
ln -s $VDEVID_CONF $VDEVID_CONF_ETC
3316 # Setup minimal ZED configuration. Individual test cases should
3317 # add additional ZEDLETs as needed for their specific test.
3318 log_must
cp ${ZEDLET_ETC_DIR}/zed.rc
$ZEDLET_DIR
3319 log_must
cp ${ZEDLET_ETC_DIR}/zed-functions.sh
$ZEDLET_DIR
3321 # Customize the zed.rc file to enable the full debug log.
3322 log_must
sed -i '/\#ZED_DEBUG_LOG=.*/d' $ZEDLET_DIR/zed.rc
3323 echo "ZED_DEBUG_LOG=$ZED_DEBUG_LOG" >>$ZEDLET_DIR/zed.rc
3325 # Scripts must only be user writable.
3326 saved_umask
=$
(umask)
3328 log_must
cp ${ZEDLET_LIBEXEC_DIR}/all-syslog.sh
$ZEDLET_DIR
3329 log_must
cp ${ZEDLET_LIBEXEC_DIR}/all-debug.sh
$ZEDLET_DIR
3330 log_must
umask $saved_umask
3334 # Cleanup custom ZED environment.
3336 function zed_cleanup
3342 log_must
rm -f ${ZEDLET_DIR}/zed.rc
3343 log_must
rm -f ${ZEDLET_DIR}/zed-functions.sh
3344 log_must
rm -f ${ZEDLET_DIR}/all-syslog.sh
3345 log_must
rm -f ${ZEDLET_DIR}/all-debug.sh
3346 log_must
rm -f ${ZEDLET_DIR}/state
3347 log_must
rm -f $ZED_LOG
3348 log_must
rm -f $ZED_DEBUG_LOG
3349 log_must
rm -f $VDEVID_CONF_ETC
3350 log_must
rm -f $VDEVID_CONF
3355 # Check if ZED is currently running, if not start ZED.
3363 # ZEDLET_DIR=/var/tmp/zed
3364 if [[ ! -d $ZEDLET_DIR ]]; then
3365 log_must mkdir
$ZEDLET_DIR
3368 # Verify the ZED is not already running.
3369 pgrep
-x zed
> /dev
/null
3370 if (($?
== 0)); then
3371 log_fail
"ZED already running"
3374 log_note
"Starting ZED"
3375 # run ZED in the background and redirect foreground logging
3376 # output to $ZED_LOG.
3377 log_must truncate
-s 0 $ZED_DEBUG_LOG
3378 log_must
eval "zed -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid" \
3379 "-s $ZEDLET_DIR/state 2>$ZED_LOG &"
3393 log_note
"Stopping ZED"
3394 if [[ -f ${ZEDLET_DIR}/zed.pid
]]; then
3395 zedpid
=$
(cat ${ZEDLET_DIR}/zed.pid
)
3398 rm -f ${ZEDLET_DIR}/zed.pid
3405 # Check is provided device is being active used as a swap device.
3407 function is_swap_inuse
3411 if [[ -z $device ]] ; then
3412 log_note
"No device specified."
3417 swapon
-s |
grep -w $
(readlink
-f $device) > /dev
/null
2>&1
3419 swap
-l |
grep -w $device > /dev
/null
2>&1
3426 # Setup a swap device using the provided device.
3433 log_must
eval "mkswap $swapdev > /dev/null 2>&1"
3434 log_must swapon
$swapdev
3436 log_must swap
-a $swapdev
3443 # Cleanup a swap device on the provided device.
3445 function swap_cleanup
3449 if is_swap_inuse
$swapdev; then
3451 log_must swapoff
$swapdev
3453 log_must swap
-d $swapdev
3461 # Set a global system tunable (64-bit value)
3466 function set_tunable64
3468 set_tunable_impl
"$1" "$2" Z
3472 # Set a global system tunable (32-bit value)
3477 function set_tunable32
3479 set_tunable_impl
"$1" "$2" W
3482 function set_tunable_impl
3484 typeset tunable
="$1"
3486 typeset mdb_cmd
="$3"
3487 typeset module
="${4:-zfs}"
3489 [[ -z "$tunable" ]] && return 1
3490 [[ -z "$value" ]] && return 1
3491 [[ -z "$mdb_cmd" ]] && return 1
3495 typeset zfs_tunables
="/sys/module/$module/parameters"
3496 [[ -w "$zfs_tunables/$tunable" ]] ||
return 1
3497 echo -n "$value" > "$zfs_tunables/$tunable"
3501 [[ "$module" -eq "zfs" ]] ||
return 1
3502 echo "${tunable}/${mdb_cmd}0t${value}" | mdb
-kw
3509 # Get a global system tunable
3513 function get_tunable
3515 get_tunable_impl
"$1"
3518 function get_tunable_impl
3520 typeset tunable
="$1"
3521 typeset module
="${2:-zfs}"
3523 [[ -z "$tunable" ]] && return 1
3527 typeset zfs_tunables
="/sys/module/$module/parameters"
3528 [[ -f "$zfs_tunables/$tunable" ]] ||
return 1
3529 cat $zfs_tunables/$tunable
3533 [[ "$module" -eq "zfs" ]] ||
return 1