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 # Determine if this is a Linux test system
45 # Return 0 if platform Linux, 1 if otherwise
49 if [[ $
(uname
-o) == "GNU/Linux" ]]; then
56 # Determine if this is a 32-bit system
58 # Return 0 if platform is 32-bit, 1 if otherwise
62 if [[ $
(getconf LONG_BIT
) == "32" ]]; then
69 # Determine if kmemleak is enabled
71 # Return 0 if kmemleak is enabled, 1 if otherwise
75 if is_linux
&& [[ -e /sys
/kernel
/debug
/kmemleak
]]; then
82 # Determine whether a dataset is mounted
85 # $2 filesystem type; optional - defaulted to zfs
87 # Return 0 if dataset is mounted; 1 if unmounted; 2 on error
92 [[ -z $fstype ]] && fstype
=zfs
93 typeset out dir name ret
97 if [[ "$1" == "/"* ]] ; then
98 for out
in $
(zfs mount |
awk '{print $2}'); do
99 [[ $1 == $out ]] && return 0
102 for out
in $
(zfs mount |
awk '{print $1}'); do
103 [[ $1 == $out ]] && return 0
108 out
=$
(df
-F $fstype $1 2>/dev
/null
)
110 (($ret != 0)) && return $ret
118 [[ "$1" == "$dir" ||
"$1" == "$name" ]] && return 0
121 out
=$
(df
-t $fstype $1 2>/dev
/null
)
125 if [[ -L "$ZVOL_DEVDIR/$1" ]]; then
126 link
=$
(readlink
-f $ZVOL_DEVDIR/$1)
127 [[ -n "$link" ]] && \
128 mount |
grep -q "^$link" && \
137 # Return 0 if a dataset is mounted; 1 otherwise
140 # $2 filesystem type; optional - defaulted to zfs
145 (($?
== 0)) && return 0
149 # Return 0 if a dataset is unmounted; 1 otherwise
152 # $2 filesystem type; optional - defaulted to zfs
157 (($?
== 1)) && return 0
167 echo $1 |
sed "s/,/ /g"
170 function default_setup
172 default_setup_noexit
"$@"
178 # Given a list of disks, setup storage pools and datasets.
180 function default_setup_noexit
185 log_note begin default_setup_noexit
187 if is_global_zone
; then
188 if poolexists
$TESTPOOL ; then
189 destroy_pool
$TESTPOOL
191 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
192 log_must zpool create
-f $TESTPOOL $disklist
197 rm -rf $TESTDIR || log_unresolved Could not remove
$TESTDIR
198 mkdir
-p $TESTDIR || log_unresolved Could not create
$TESTDIR
200 log_must zfs create
$TESTPOOL/$TESTFS
201 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
203 if [[ -n $container ]]; then
204 rm -rf $TESTDIR1 || \
205 log_unresolved Could not remove
$TESTDIR1
206 mkdir
-p $TESTDIR1 || \
207 log_unresolved Could not create
$TESTDIR1
209 log_must zfs create
$TESTPOOL/$TESTCTR
210 log_must zfs
set canmount
=off
$TESTPOOL/$TESTCTR
211 log_must zfs create
$TESTPOOL/$TESTCTR/$TESTFS1
212 log_must zfs
set mountpoint
=$TESTDIR1 \
213 $TESTPOOL/$TESTCTR/$TESTFS1
216 if [[ -n $volume ]]; then
217 if is_global_zone
; then
218 log_must zfs create
-V $VOLSIZE $TESTPOOL/$TESTVOL
221 log_must zfs create
$TESTPOOL/$TESTVOL
227 # Given a list of disks, setup a storage pool, file system and
230 function default_container_setup
234 default_setup
"$disklist" "true"
238 # Given a list of disks, setup a storage pool,file system
241 function default_volume_setup
245 default_setup
"$disklist" "" "true"
249 # Given a list of disks, setup a storage pool,file system,
250 # a container and a volume.
252 function default_container_volume_setup
256 default_setup
"$disklist" "true" "true"
260 # Create a snapshot on a filesystem or volume. Defaultly create a snapshot on
263 # $1 Existing filesystem or volume name. Default, $TESTFS
264 # $2 snapshot name. Default, $TESTSNAP
266 function create_snapshot
268 typeset fs_vol
=${1:-$TESTFS}
269 typeset snap
=${2:-$TESTSNAP}
271 [[ -z $fs_vol ]] && log_fail
"Filesystem or volume's name is undefined."
272 [[ -z $snap ]] && log_fail
"Snapshot's name is undefined."
274 if snapexists
$fs_vol@
$snap; then
275 log_fail
"$fs_vol@$snap already exists."
277 datasetexists
$fs_vol || \
278 log_fail
"$fs_vol must exist."
280 log_must zfs snapshot
$fs_vol@
$snap
284 # Create a clone from a snapshot, default clone name is $TESTCLONE.
286 # $1 Existing snapshot, $TESTPOOL/$TESTFS@$TESTSNAP is default.
287 # $2 Clone name, $TESTPOOL/$TESTCLONE is default.
289 function create_clone
# snapshot clone
291 typeset snap
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
292 typeset clone
=${2:-$TESTPOOL/$TESTCLONE}
295 log_fail
"Snapshot name is undefined."
297 log_fail
"Clone name is undefined."
299 log_must zfs clone
$snap $clone
303 # Create a bookmark of the given snapshot. Defaultly create a bookmark on
306 # $1 Existing filesystem or volume name. Default, $TESTFS
307 # $2 Existing snapshot name. Default, $TESTSNAP
308 # $3 bookmark name. Default, $TESTBKMARK
310 function create_bookmark
312 typeset fs_vol
=${1:-$TESTFS}
313 typeset snap
=${2:-$TESTSNAP}
314 typeset bkmark
=${3:-$TESTBKMARK}
316 [[ -z $fs_vol ]] && log_fail
"Filesystem or volume's name is undefined."
317 [[ -z $snap ]] && log_fail
"Snapshot's name is undefined."
318 [[ -z $bkmark ]] && log_fail
"Bookmark's name is undefined."
320 if bkmarkexists
$fs_vol#$bkmark; then
321 log_fail
"$fs_vol#$bkmark already exists."
323 datasetexists
$fs_vol || \
324 log_fail
"$fs_vol must exist."
325 snapexists
$fs_vol@
$snap || \
326 log_fail
"$fs_vol@$snap must exist."
328 log_must zfs bookmark
$fs_vol@
$snap $fs_vol#$bkmark
331 function default_mirror_setup
333 default_mirror_setup_noexit
$1 $2 $3
339 # Given a pair of disks, set up a storage pool and dataset for the mirror
340 # @parameters: $1 the primary side of the mirror
341 # $2 the secondary side of the mirror
342 # @uses: ZPOOL ZFS TESTPOOL TESTFS
343 function default_mirror_setup_noexit
345 readonly func
="default_mirror_setup_noexit"
349 [[ -z $primary ]] && \
350 log_fail
"$func: No parameters passed"
351 [[ -z $secondary ]] && \
352 log_fail
"$func: No secondary partition passed"
353 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
354 log_must zpool create
-f $TESTPOOL mirror $@
355 log_must zfs create
$TESTPOOL/$TESTFS
356 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
360 # create a number of mirrors.
361 # We create a number($1) of 2 way mirrors using the pairs of disks named
362 # on the command line. These mirrors are *not* mounted
363 # @parameters: $1 the number of mirrors to create
364 # $... the devices to use to create the mirrors on
365 # @uses: ZPOOL ZFS TESTPOOL
366 function setup_mirrors
368 typeset
-i nmirrors
=$1
371 while ((nmirrors
> 0)); do
372 log_must
test -n "$1" -a -n "$2"
373 [[ -d /$TESTPOOL$nmirrors ]] && rm -rf /$TESTPOOL$nmirrors
374 log_must zpool create
-f $TESTPOOL$nmirrors mirror
$1 $2
376 ((nmirrors
= nmirrors
- 1))
381 # create a number of raidz pools.
382 # We create a number($1) of 2 raidz pools using the pairs of disks named
383 # on the command line. These pools are *not* mounted
384 # @parameters: $1 the number of pools to create
385 # $... the devices to use to create the pools on
386 # @uses: ZPOOL ZFS TESTPOOL
387 function setup_raidzs
389 typeset
-i nraidzs
=$1
392 while ((nraidzs
> 0)); do
393 log_must
test -n "$1" -a -n "$2"
394 [[ -d /$TESTPOOL$nraidzs ]] && rm -rf /$TESTPOOL$nraidzs
395 log_must zpool create
-f $TESTPOOL$nraidzs raidz
$1 $2
397 ((nraidzs
= nraidzs
- 1))
402 # Destroy the configured testpool mirrors.
403 # the mirrors are of the form ${TESTPOOL}{number}
404 # @uses: ZPOOL ZFS TESTPOOL
405 function destroy_mirrors
407 default_cleanup_noexit
413 # Given a minimum of two disks, set up a storage pool and dataset for the raid-z
414 # $1 the list of disks
416 function default_raidz_setup
418 typeset disklist
="$*"
419 disks
=(${disklist[*]})
421 if [[ ${#disks[*]} -lt 2 ]]; then
422 log_fail
"A raid-z requires a minimum of two disks."
425 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
426 log_must zpool create
-f $TESTPOOL raidz
$1 $2 $3
427 log_must zfs create
$TESTPOOL/$TESTFS
428 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
434 # Common function used to cleanup storage pools and datasets.
436 # Invoked at the start of the test suite to ensure the system
437 # is in a known state, and also at the end of each set of
438 # sub-tests to ensure errors from one set of tests doesn't
439 # impact the execution of the next set.
441 function default_cleanup
443 default_cleanup_noexit
448 function default_cleanup_noexit
453 # Destroying the pool will also destroy any
454 # filesystems it contains.
456 if is_global_zone
; then
457 zfs unmount
-a > /dev
/null
2>&1
458 exclude
=`eval echo \"'(${KEEP})'\"`
459 ALL_POOLS
=$
(zpool list
-H -o name \
460 |
grep -v "$NO_POOLS" |
egrep -v "$exclude")
461 # Here, we loop through the pools we're allowed to
462 # destroy, only destroying them if it's safe to do
464 while [ ! -z ${ALL_POOLS} ]
466 for pool
in ${ALL_POOLS}
468 if safe_to_destroy_pool
$pool ;
472 ALL_POOLS
=$
(zpool list
-H -o name \
473 |
grep -v "$NO_POOLS" \
474 |
egrep -v "$exclude")
481 for fs
in $
(zfs list
-H -o name \
482 |
grep "^$ZONE_POOL/$ZONE_CTR[01234]/"); do
483 datasetexists
$fs && \
484 log_must zfs destroy
-Rf $fs
487 # Need cleanup here to avoid garbage dir left.
488 for fs
in $
(zfs list
-H -o name
); do
489 [[ $fs == /$ZONE_POOL ]] && continue
490 [[ -d $fs ]] && log_must
rm -rf $fs/*
494 # Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to
497 for fs
in $
(zfs list
-H -o name
); do
498 if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then
499 log_must zfs
set reservation
=none
$fs
500 log_must zfs
set recordsize
=128K
$fs
501 log_must zfs
set mountpoint
=/$fs $fs
503 enc
=$
(get_prop encryption
$fs)
504 if [[ $?
-ne 0 ]] ||
[[ -z "$enc" ]] || \
505 [[ "$enc" == "off" ]]; then
506 log_must zfs
set checksum
=on
$fs
508 log_must zfs
set compression
=off
$fs
509 log_must zfs
set atime
=on
$fs
510 log_must zfs
set devices
=off
$fs
511 log_must zfs
set exec=on
$fs
512 log_must zfs
set setuid
=on
$fs
513 log_must zfs
set readonly=off
$fs
514 log_must zfs
set snapdir
=hidden
$fs
515 log_must zfs
set aclmode
=groupmask
$fs
516 log_must zfs
set aclinherit
=secure
$fs
521 [[ -d $TESTDIR ]] && \
522 log_must
rm -rf $TESTDIR
525 if is_mpath_device
$disk1; then
532 # Common function used to cleanup storage pools, file systems
535 function default_container_cleanup
537 if ! is_global_zone
; then
541 ismounted
$TESTPOOL/$TESTCTR/$TESTFS1
543 log_must zfs unmount
$TESTPOOL/$TESTCTR/$TESTFS1
545 datasetexists
$TESTPOOL/$TESTCTR/$TESTFS1 && \
546 log_must zfs destroy
-R $TESTPOOL/$TESTCTR/$TESTFS1
548 datasetexists
$TESTPOOL/$TESTCTR && \
549 log_must zfs destroy
-Rf $TESTPOOL/$TESTCTR
551 [[ -e $TESTDIR1 ]] && \
552 log_must
rm -rf $TESTDIR1 > /dev
/null
2>&1
558 # Common function used to cleanup snapshot of file system or volume. Default to
559 # delete the file system's snapshot
563 function destroy_snapshot
565 typeset snap
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
567 if ! snapexists
$snap; then
568 log_fail
"'$snap' does not existed."
572 # For the sake of the value which come from 'get_prop' is not equal
573 # to the really mountpoint when the snapshot is unmounted. So, firstly
574 # check and make sure this snapshot's been mounted in current system.
577 if ismounted
$snap; then
578 mtpt
=$
(get_prop mountpoint
$snap)
580 log_fail
"get_prop mountpoint $snap failed."
583 log_must zfs destroy
$snap
584 [[ $mtpt != "" && -d $mtpt ]] && \
585 log_must
rm -rf $mtpt
589 # Common function used to cleanup clone.
593 function destroy_clone
595 typeset clone
=${1:-$TESTPOOL/$TESTCLONE}
597 if ! datasetexists
$clone; then
598 log_fail
"'$clone' does not existed."
601 # With the same reason in destroy_snapshot
603 if ismounted
$clone; then
604 mtpt
=$
(get_prop mountpoint
$clone)
606 log_fail
"get_prop mountpoint $clone failed."
609 log_must zfs destroy
$clone
610 [[ $mtpt != "" && -d $mtpt ]] && \
611 log_must
rm -rf $mtpt
615 # Common function used to cleanup bookmark of file system or volume. Default
616 # to delete the file system's bookmark.
620 function destroy_bookmark
622 typeset bkmark
=${1:-$TESTPOOL/$TESTFS#$TESTBKMARK}
624 if ! bkmarkexists
$bkmark; then
625 log_fail
"'$bkmarkp' does not existed."
628 log_must zfs destroy
$bkmark
631 # Return 0 if a snapshot exists; $? otherwise
637 zfs list
-H -t snapshot
"$1" > /dev
/null
2>&1
642 # Return 0 if a bookmark exists; $? otherwise
646 function bkmarkexists
648 zfs list
-H -t bookmark
"$1" > /dev
/null
2>&1
653 # Set a property to a certain value on a dataset.
654 # Sets a property of the dataset to the value as passed in.
656 # $1 dataset who's property is being set
658 # $3 value to set property to
660 # 0 if the property could be set.
661 # non-zero otherwise.
664 function dataset_setprop
666 typeset fn
=dataset_setprop
669 log_note
"$fn: Insufficient parameters (need 3, had $#)"
673 output
=$
(zfs
set $2=$3 $1 2>&1)
676 log_note
"Setting property on $1 failed."
677 log_note
"property $2=$3"
678 log_note
"Return Code: $rv"
679 log_note
"Output: $output"
686 # Assign suite defined dataset properties.
687 # This function is used to apply the suite's defined default set of
688 # properties to a dataset.
689 # @parameters: $1 dataset to use
690 # @uses: ZFS COMPRESSION_PROP CHECKSUM_PROP
692 # 0 if the dataset has been altered.
693 # 1 if no pool name was passed in.
694 # 2 if the dataset could not be found.
695 # 3 if the dataset could not have it's properties set.
697 function dataset_set_defaultproperties
701 [[ -z $dataset ]] && return 1
705 for confset
in $
(zfs list
); do
706 if [[ $dataset = $confset ]]; then
711 [[ $found -eq 0 ]] && return 2
712 if [[ -n $COMPRESSION_PROP ]]; then
713 dataset_setprop
$dataset compression
$COMPRESSION_PROP || \
715 log_note
"Compression set to '$COMPRESSION_PROP' on $dataset"
717 if [[ -n $CHECKSUM_PROP ]]; then
718 dataset_setprop
$dataset checksum
$CHECKSUM_PROP || \
720 log_note
"Checksum set to '$CHECKSUM_PROP' on $dataset"
726 # Check a numeric assertion
727 # @parameter: $@ the assertion to check
728 # @output: big loud notice if assertion failed
733 (($@
)) || log_fail
"$@"
737 # Function to format partition size of a disk
738 # Given a disk cxtxdx reduces all partitions
741 function zero_partitions
#<whole_disk_name>
747 log_must parted
$DEV_DSKDIR/$diskname -s -- mklabel gpt
749 for i
in 0 1 3 4 5 6 7
751 log_must set_partition
$i "" 0mb
$diskname
759 # Given a slice, size and disk, this function
760 # formats the slice to the specified size.
761 # Size should be specified with units as per
762 # the `format` command requirements eg. 100mb 3gb
764 # NOTE: This entire interface is problematic for the Linux parted utilty
765 # which requires the end of the partition to be specified. It would be
766 # best to retire this interface and replace it with something more flexible.
767 # At the moment a best effort is made.
769 function set_partition
#<slice_num> <slice_start> <size_plus_units> <whole_disk_name>
771 typeset
-i slicenum
=$1
775 [[ -z $slicenum ||
-z $size ||
-z $disk ]] && \
776 log_fail
"The slice, size or disk name is unspecified."
779 typeset size_mb
=${size%%[mMgG]}
781 size_mb
=${size_mb%%[mMgG][bB]}
782 if [[ ${size:1:1} == 'g' ]]; then
783 ((size_mb
= size_mb
* 1024))
786 # Create GPT partition table when setting slice 0 or
787 # when the device doesn't already contain a GPT label.
788 parted
$DEV_DSKDIR/$disk -s -- print
1 >/dev
/null
790 if [[ $slicenum -eq 0 ||
$ret_val -ne 0 ]]; then
791 parted
$DEV_DSKDIR/$disk -s -- mklabel gpt
792 if [[ $?
-ne 0 ]]; then
793 log_note
"Failed to create GPT partition table on $disk"
798 # When no start is given align on the first cylinder.
799 if [[ -z "$start" ]]; then
803 # Determine the cylinder size for the device and using
804 # that calculate the end offset in cylinders.
805 typeset
-i cly_size_kb
=0
806 cly_size_kb
=$
(parted
-m $DEV_DSKDIR/$disk -s -- \
807 unit cyl print |
head -3 |
tail -1 | \
808 awk -F '[:k.]' '{print $4}')
809 ((end
= (size_mb
* 1024 / cly_size_kb
) + start
))
811 parted
$DEV_DSKDIR/$disk -s -- \
812 mkpart part
$slicenum ${start}cyl
${end}cyl
813 if [[ $?
-ne 0 ]]; then
814 log_note
"Failed to create partition $slicenum on $disk"
818 blockdev
--rereadpt $DEV_DSKDIR/$disk 2>/dev
/null
821 typeset format_file
=/var
/tmp
/format_in.$$
823 echo "partition" >$format_file
824 echo "$slicenum" >> $format_file
825 echo "" >> $format_file
826 echo "" >> $format_file
827 echo "$start" >> $format_file
828 echo "$size" >> $format_file
829 echo "label" >> $format_file
830 echo "" >> $format_file
831 echo "q" >> $format_file
832 echo "q" >> $format_file
834 format
-e -s -d $disk -f $format_file
839 if [[ $ret_val -ne 0 ]]; then
840 log_note
"Unable to format $disk slice $slicenum to $size"
847 # Delete all partitions on all disks - this is specifically for the use of multipath
848 # devices which currently can only be used in the test suite as raw/un-partitioned
849 # devices (ie a zpool cannot be created on a whole mpath device that has partitions)
851 function delete_partitions
855 if [[ -z $DISK_ARRAY_NUM ]]; then
856 DISK_ARRAY_NUM
=$
(echo ${DISKS} | nawk
'{print NF}')
858 if [[ -z $DISKSARRAY ]]; then
863 if (( $DISK_ARRAY_NUM == 1 )); then
864 while ((j
< MAX_PARTITIONS
)); do
865 parted
$DEV_DSKDIR/$DISK -s rm $j \
867 if (( $?
== 1 )); then
868 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
869 if (( $?
== 1 )); then
870 log_note
"Partitions for $DISK should be deleted"
872 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
876 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
877 if (( $?
== 0 )); then
878 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
884 for disk
in `echo $DISKSARRAY`; do
885 while ((j
< MAX_PARTITIONS
)); do
886 parted
$DEV_DSKDIR/$disk -s rm $j > /dev
/null
2>&1
887 if (( $?
== 1 )); then
888 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
889 if (( $?
== 1 )); then
890 log_note
"Partitions for $disk should be deleted"
892 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
896 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
897 if (( $?
== 0 )); then
898 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
911 # Get the end cyl of the given slice
913 function get_endslice
#<disk> <slice>
917 if [[ -z $disk ||
-z $slice ]] ; then
918 log_fail
"The disk name or slice number is unspecified."
922 endcyl
=$
(parted
-s $DEV_DSKDIR/$disk -- unit cyl print | \
923 grep "part${slice}" | \
926 ((endcyl
= (endcyl
+ 1)))
928 disk
=${disk#/dev/dsk/}
929 disk
=${disk#/dev/rdsk/}
933 ratio
=$
(prtvtoc
/dev
/rdsk
/${disk}s2 | \
934 grep "sectors\/cylinder" | \
937 if ((ratio
== 0)); then
941 typeset
-i endcyl
=$
(prtvtoc
-h /dev
/rdsk
/${disk}s2 |
942 nawk
-v token
="$slice" '{if ($1==token) print $6}')
944 ((endcyl
= (endcyl
+ 1) / ratio
))
952 # Given a size,disk and total slice number, this function formats the
953 # disk slices from 0 to the total slice number with the same specified
956 function partition_disk
#<slice_size> <whole_disk_name> <total_slices>
959 typeset slice_size
=$1
961 typeset total_slices
=$3
964 zero_partitions
$disk_name
965 while ((i
< $total_slices)); do
972 log_must set_partition
$i "$cyl" $slice_size $disk_name
973 cyl
=$
(get_endslice
$disk_name $i)
979 # This function continues to write to a filenum number of files into dirnum
980 # number of directories until either file_write returns an error or the
981 # maximum number of files per directory have been written.
984 # fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data]
986 # Return value: 0 on success
990 # destdir: is the directory where everything is to be created under
991 # dirnum: the maximum number of subdirectories to use, -1 no limit
992 # filenum: the maximum number of files per subdirectory
993 # bytes: number of bytes to write
994 # num_writes: numer of types to write out bytes
995 # data: the data that will be written
998 # file_fs /testdir 20 25 1024 256 0
1000 # Note: bytes * num_writes equals the size of the testfile
1002 function fill_fs
# destdir dirnum filenum bytes num_writes data
1004 typeset destdir
=${1:-$TESTDIR}
1005 typeset
-i dirnum
=${2:-50}
1006 typeset
-i filenum
=${3:-50}
1007 typeset
-i bytes
=${4:-8192}
1008 typeset
-i num_writes
=${5:-10240}
1009 typeset
-i data
=${6:-0}
1011 typeset
-i odirnum
=1
1012 typeset
-i idirnum
=0
1016 log_must mkdir
-p $destdir/$idirnum
1017 while (($odirnum > 0)); do
1018 if ((dirnum
>= 0 && idirnum
>= dirnum
)); then
1022 file_write
-o create
-f $destdir/$idirnum/$TESTFILE.
$fn \
1023 -b $bytes -c $num_writes -d $data
1025 if (($retval != 0)); then
1029 if (($fn >= $filenum)); then
1031 ((idirnum
= idirnum
+ 1))
1032 log_must mkdir
-p $destdir/$idirnum
1041 # Simple function to get the specified property. If unable to
1042 # get the property then exits.
1044 # Note property is in 'parsable' format (-p)
1046 function get_prop
# property dataset
1052 prop_val
=$
(zfs get
-pH -o value
$prop $dataset 2>/dev
/null
)
1053 if [[ $?
-ne 0 ]]; then
1054 log_note
"Unable to get $prop property for dataset " \
1064 # Simple function to get the specified property of pool. If unable to
1065 # get the property then exits.
1067 # Note property is in 'parsable' format (-p)
1069 function get_pool_prop
# property pool
1075 if poolexists
$pool ; then
1076 prop_val
=$
(zpool get
-pH $prop $pool 2>/dev
/null |
tail -1 | \
1078 if [[ $?
-ne 0 ]]; then
1079 log_note
"Unable to get $prop property for pool " \
1084 log_note
"Pool $pool not exists."
1092 # Return 0 if a pool exists; $? otherwise
1100 if [[ -z $pool ]]; then
1101 log_note
"No pool name given."
1105 zpool get name
"$pool" > /dev
/null
2>&1
1109 # Return 0 if all the specified datasets exist; $? otherwise
1112 function datasetexists
1114 if (($# == 0)); then
1115 log_note
"No dataset name given."
1119 while (($# > 0)); do
1120 zfs get name
$1 > /dev
/null
2>&1 || \
1128 # return 0 if none of the specified datasets exists, otherwise return 1.
1131 function datasetnonexists
1133 if (($# == 0)); then
1134 log_note
"No dataset name given."
1138 while (($# > 0)); do
1139 zfs list
-H -t filesystem
,snapshot
,volume
$1 > /dev
/null
2>&1 \
1148 # Given a mountpoint, or a dataset name, determine if it is shared via NFS.
1150 # Returns 0 if shared, 1 otherwise.
1157 if [[ $fs != "/"* ]] ; then
1158 if datasetnonexists
"$fs" ; then
1161 mtpt
=$
(get_prop mountpoint
"$fs")
1163 none|legacy|
-) return 1
1172 for mtpt
in `share | awk '{print $1}'` ; do
1173 if [[ $mtpt == $fs ]] ; then
1180 for mtpt
in `share | awk '{print $2}'` ; do
1181 if [[ $mtpt == $fs ]] ; then
1186 typeset stat
=$
(svcs
-H -o STA nfs
/server
:default
)
1187 if [[ $stat != "ON" ]]; then
1188 log_note
"Current nfs/server status: $stat"
1195 # Given a dataset name determine if it is shared via SMB.
1197 # Returns 0 if shared, 1 otherwise.
1199 function is_shared_smb
1204 if datasetnonexists
"$fs" ; then
1207 fs
=$
(echo $fs |
sed 's@/@_@g')
1211 for mtpt
in `net usershare list | awk '{print $1}'` ; do
1212 if [[ $mtpt == $fs ]] ; then
1218 log_unsupported
"Currently unsupported by the test framework"
1224 # Given a mountpoint, determine if it is not shared via NFS.
1226 # Returns 0 if not shared, 1 otherwise.
1233 if (($?
== 0)); then
1241 # Given a dataset determine if it is not shared via SMB.
1243 # Returns 0 if not shared, 1 otherwise.
1245 function not_shared_smb
1250 if (($?
== 0)); then
1258 # Helper function to unshare a mountpoint.
1260 function unshare_fs
#fs
1264 is_shared
$fs || is_shared_smb
$fs
1265 if (($?
== 0)); then
1266 log_must zfs unshare
$fs
1273 # Helper function to share a NFS mountpoint.
1275 function share_nfs
#fs
1281 if (($?
!= 0)); then
1282 log_must share
"*:$fs"
1286 if (($?
!= 0)); then
1287 log_must share
-F nfs
$fs
1295 # Helper function to unshare a NFS mountpoint.
1297 function unshare_nfs
#fs
1303 if (($?
== 0)); then
1304 log_must unshare
-u "*:$fs"
1308 if (($?
== 0)); then
1309 log_must unshare
-F nfs
$fs
1317 # Helper function to show NFS shares.
1319 function showshares_nfs
1331 # Helper function to show SMB shares.
1333 function showshares_smb
1345 # Check NFS server status and trigger it online.
1347 function setup_nfs_server
1349 # Cannot share directory in non-global zone.
1351 if ! is_global_zone
; then
1352 log_note
"Cannot trigger NFS server by sharing in LZ."
1357 log_note
"NFS server must started prior to running test framework."
1361 typeset nfs_fmri
="svc:/network/nfs/server:default"
1362 if [[ $
(svcs
-Ho STA
$nfs_fmri) != "ON" ]]; then
1364 # Only really sharing operation can enable NFS server
1365 # to online permanently.
1367 typeset dummy
=/tmp
/dummy
1369 if [[ -d $dummy ]]; then
1370 log_must
rm -rf $dummy
1373 log_must mkdir
$dummy
1374 log_must share
$dummy
1377 # Waiting for fmri's status to be the final status.
1378 # Otherwise, in transition, an asterisk (*) is appended for
1379 # instances, unshare will reverse status to 'DIS' again.
1381 # Waiting for 1's at least.
1385 while [[ timeout
-ne 0 && $
(svcs
-Ho STA
$nfs_fmri) == *'*' ]]
1392 log_must unshare
$dummy
1393 log_must
rm -rf $dummy
1396 log_note
"Current NFS status: '$(svcs -Ho STA,FMRI $nfs_fmri)'"
1400 # To verify whether calling process is in global zone
1402 # Return 0 if in global zone, 1 in non-global zone
1404 function is_global_zone
1409 typeset cur_zone
=$
(zonename
2>/dev
/null
)
1410 if [[ $cur_zone != "global" ]]; then
1418 # Verify whether test is permitted to run from
1419 # global zone, local zone, or both
1421 # $1 zone limit, could be "global", "local", or "both"(no limit)
1423 # Return 0 if permitted, otherwise exit with log_unsupported
1425 function verify_runnable
# zone limit
1429 [[ -z $limit ]] && return 0
1431 if is_global_zone
; then
1435 local) log_unsupported
"Test is unable to run from "\
1438 *) log_note
"Warning: unknown limit $limit - " \
1446 global
) log_unsupported
"Test is unable to run from "\
1449 *) log_note
"Warning: unknown limit $limit - " \
1460 # Return 0 if create successfully or the pool exists; $? otherwise
1461 # Note: In local zones, this function should return 0 silently.
1464 # $2-n - [keyword] devs_list
1466 function create_pool
#pool devs_list
1468 typeset pool
=${1%%/*}
1472 if [[ -z $pool ]]; then
1473 log_note
"Missing pool name."
1477 if poolexists
$pool ; then
1481 if is_global_zone
; then
1482 [[ -d /$pool ]] && rm -rf /$pool
1483 log_must zpool create
-f $pool $@
1489 # Return 0 if destroy successfully or the pool exists; $? otherwise
1490 # Note: In local zones, this function should return 0 silently.
1493 # Destroy pool with the given parameters.
1495 function destroy_pool
#pool
1497 typeset pool
=${1%%/*}
1500 if [[ -z $pool ]]; then
1501 log_note
"No pool name given."
1505 if is_global_zone
; then
1506 if poolexists
"$pool" ; then
1507 mtpt
=$
(get_prop mountpoint
"$pool")
1509 # At times, syseventd/udev activity can cause attempts
1510 # to destroy a pool to fail with EBUSY. We retry a few
1511 # times allowing failures before requiring the destroy
1513 log_must_busy zpool destroy
-f $pool
1516 log_must
rm -rf $mtpt
1518 log_note
"Pool does not exist. ($pool)"
1527 # Firstly, create a pool with 5 datasets. Then, create a single zone and
1528 # export the 5 datasets to it. In addition, we also add a ZFS filesystem
1529 # and a zvol device to the zone.
1532 # $2 zone root directory prefix
1535 function zfs_zones_setup
#zone_name zone_root zone_ip
1537 typeset zone_name
=${1:-$(hostname)-z}
1538 typeset zone_root
=${2:-"/zone_root"}
1539 typeset zone_ip
=${3:-"10.1.1.10"}
1540 typeset prefix_ctr
=$ZONE_CTR
1541 typeset pool_name
=$ZONE_POOL
1545 # Create pool and 5 container within it
1547 [[ -d /$pool_name ]] && rm -rf /$pool_name
1548 log_must zpool create
-f $pool_name $DISKS
1549 while ((i
< cntctr
)); do
1550 log_must zfs create
$pool_name/$prefix_ctr$i
1555 log_must zfs create
-V 1g
$pool_name/zone_zvol
1559 # If current system support slog, add slog device for pool
1561 if verify_slog_support
; then
1562 typeset sdevs
="/var/tmp/sdev1 /var/tmp/sdev2"
1563 log_must mkfile
$MINVDEVSIZE $sdevs
1564 log_must zpool add
$pool_name log mirror
$sdevs
1567 # this isn't supported just yet.
1568 # Create a filesystem. In order to add this to
1569 # the zone, it must have it's mountpoint set to 'legacy'
1570 # log_must zfs create $pool_name/zfs_filesystem
1571 # log_must zfs set mountpoint=legacy $pool_name/zfs_filesystem
1573 [[ -d $zone_root ]] && \
1574 log_must
rm -rf $zone_root/$zone_name
1575 [[ ! -d $zone_root ]] && \
1576 log_must mkdir
-p -m 0700 $zone_root/$zone_name
1578 # Create zone configure file and configure the zone
1580 typeset zone_conf
=/tmp
/zone_conf.$$
1581 echo "create" > $zone_conf
1582 echo "set zonepath=$zone_root/$zone_name" >> $zone_conf
1583 echo "set autoboot=true" >> $zone_conf
1585 while ((i
< cntctr
)); do
1586 echo "add dataset" >> $zone_conf
1587 echo "set name=$pool_name/$prefix_ctr$i" >> \
1589 echo "end" >> $zone_conf
1593 # add our zvol to the zone
1594 echo "add device" >> $zone_conf
1595 echo "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf
1596 echo "end" >> $zone_conf
1598 # add a corresponding zvol rdsk to the zone
1599 echo "add device" >> $zone_conf
1600 echo "set match=$ZVOL_RDEVDIR/$pool_name/zone_zvol" >> $zone_conf
1601 echo "end" >> $zone_conf
1603 # once it's supported, we'll add our filesystem to the zone
1604 # echo "add fs" >> $zone_conf
1605 # echo "set type=zfs" >> $zone_conf
1606 # echo "set special=$pool_name/zfs_filesystem" >> $zone_conf
1607 # echo "set dir=/export/zfs_filesystem" >> $zone_conf
1608 # echo "end" >> $zone_conf
1610 echo "verify" >> $zone_conf
1611 echo "commit" >> $zone_conf
1612 log_must zonecfg
-z $zone_name -f $zone_conf
1613 log_must
rm -f $zone_conf
1616 zoneadm
-z $zone_name install
1617 if (($?
== 0)); then
1618 log_note
"SUCCESS: zoneadm -z $zone_name install"
1620 log_fail
"FAIL: zoneadm -z $zone_name install"
1623 # Install sysidcfg file
1625 typeset sysidcfg
=$zone_root/$zone_name/root
/etc
/sysidcfg
1626 echo "system_locale=C" > $sysidcfg
1627 echo "terminal=dtterm" >> $sysidcfg
1628 echo "network_interface=primary {" >> $sysidcfg
1629 echo "hostname=$zone_name" >> $sysidcfg
1630 echo "}" >> $sysidcfg
1631 echo "name_service=NONE" >> $sysidcfg
1632 echo "root_password=mo791xfZ/SFiw" >> $sysidcfg
1633 echo "security_policy=NONE" >> $sysidcfg
1634 echo "timezone=US/Eastern" >> $sysidcfg
1637 log_must zoneadm
-z $zone_name boot
1641 # Reexport TESTPOOL & TESTPOOL(1-4)
1643 function reexport_pool
1648 while ((i
< cntctr
)); do
1650 TESTPOOL
=$ZONE_POOL/$ZONE_CTR$i
1651 if ! ismounted
$TESTPOOL; then
1652 log_must zfs mount
$TESTPOOL
1655 eval TESTPOOL
$i=$ZONE_POOL/$ZONE_CTR$i
1656 if eval ! ismounted \
$TESTPOOL$i; then
1657 log_must
eval zfs mount \
$TESTPOOL$i
1665 # Verify a given disk or pool state
1667 # Return 0 is pool/disk matches expected state, 1 otherwise
1669 function check_state
# pool disk state{online,offline,degraded}
1672 typeset disk
=${2#$DEV_DSKDIR/}
1675 [[ -z $pool ]] ||
[[ -z $state ]] \
1676 && log_fail
"Arguments invalid or missing"
1678 if [[ -z $disk ]]; then
1679 #check pool state only
1680 zpool get
-H -o value health
$pool \
1681 |
grep -i "$state" > /dev
/null
2>&1
1683 zpool status
-v $pool |
grep "$disk" \
1684 |
grep -i "$state" > /dev
/null
2>&1
1691 # Cause a scan of all scsi host adapters by default
1693 # $1 optional host number
1695 function scan_scsi_hosts
1697 typeset hostnum
=${1}
1700 if [[ -z $hostnum ]]; then
1701 for host in /sys
/class
/scsi_host
/host*; do
1702 log_must
eval "echo '- - -' > $host/scan"
1706 "echo /sys/class/scsi_host/host$hostnum/scan" \
1709 "echo '- - -' > /sys/class/scsi_host/host$hostnum/scan"
1714 # Wait for newly created block devices to have their minors created.
1716 function block_device_wait
1725 # Online or offline a disk on the system
1727 # First checks state of disk. Test will fail if disk is not properly onlined
1728 # or offlined. Online is a full rescan of SCSI disks by echoing to every
1731 function on_off_disk
# disk state{online,offline} host
1737 [[ -z $disk ]] ||
[[ -z $state ]] && \
1738 log_fail
"Arguments invalid or missing"
1741 if [[ $state == "offline" ]] && ( is_mpath_device
$disk ); then
1742 dm_name
="$(readlink $DEV_DSKDIR/$disk \
1743 | nawk -F / '{print $2}')"
1744 slave
="$(ls /sys/block/${dm_name}/slaves \
1745 | nawk '{print $1}')"
1746 while [[ -n $slave ]]; do
1747 #check if disk is online
1748 lsscsi |
egrep $slave > /dev
/null
1749 if (($?
== 0)); then
1750 slave_dir
="/sys/block/${dm_name}"
1751 slave_dir
+="/slaves/${slave}/device"
1752 ss
="${slave_dir}/state"
1753 sd
="${slave_dir}/delete"
1754 log_must
eval "echo 'offline' > ${ss}"
1755 log_must
eval "echo '1' > ${sd}"
1756 lsscsi |
egrep $slave > /dev
/null
1757 if (($?
== 0)); then
1758 log_fail
"Offlining" \
1762 slave
="$(ls /sys/block/$dm_name/slaves \
1763 2>/dev/null | nawk '{print $1}')"
1765 elif [[ $state == "offline" ]] && ( is_real_device
$disk ); then
1766 #check if disk is online
1767 lsscsi |
egrep $disk > /dev
/null
1768 if (($?
== 0)); then
1769 dev_state
="/sys/block/$disk/device/state"
1770 dev_delete
="/sys/block/$disk/device/delete"
1771 log_must
eval "echo 'offline' > ${dev_state}"
1772 log_must
eval "echo '1' > ${dev_delete}"
1773 lsscsi |
egrep $disk > /dev
/null
1774 if (($?
== 0)); then
1775 log_fail
"Offlining $disk" \
1779 log_note
"$disk is already offline"
1781 elif [[ $state == "online" ]]; then
1782 #force a full rescan
1783 scan_scsi_hosts
$host
1785 if is_mpath_device
$disk; then
1786 dm_name
="$(readlink $DEV_DSKDIR/$disk \
1787 | nawk -F / '{print $2}')"
1788 slave
="$(ls /sys/block/$dm_name/slaves \
1789 | nawk '{print $1}')"
1790 lsscsi |
egrep $slave > /dev
/null
1791 if (($?
!= 0)); then
1792 log_fail
"Onlining $disk failed"
1794 elif is_real_device
$disk; then
1795 lsscsi |
egrep $disk > /dev
/null
1796 if (($?
!= 0)); then
1797 log_fail
"Onlining $disk failed"
1800 log_fail
"$disk is not a real dev"
1803 log_fail
"$disk failed to $state"
1809 # Get the mountpoint of snapshot
1810 # For the snapshot use <mp_filesystem>/.zfs/snapshot/<snap>
1813 function snapshot_mountpoint
1815 typeset dataset
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
1817 if [[ $dataset != *@
* ]]; then
1818 log_fail
"Error name of snapshot '$dataset'."
1821 typeset fs
=${dataset%@*}
1822 typeset snap
=${dataset#*@}
1824 if [[ -z $fs ||
-z $snap ]]; then
1825 log_fail
"Error name of snapshot '$dataset'."
1828 echo $
(get_prop mountpoint
$fs)/.zfs
/snapshot
/$snap
1832 # Given a device and 'ashift' value verify it's correctly set on every label
1834 function verify_ashift
# device ashift
1839 zdb
-e -lll $device |
awk -v ashift
=$ashift '/ashift: / {
1855 # Given a pool and file system, this function will verify the file system
1856 # using the zdb internal tool. Note that the pool is exported and imported
1857 # to ensure it has consistent state.
1859 function verify_filesys
# pool filesystem dir
1862 typeset filesys
="$2"
1863 typeset zdbout
="/tmp/zdbout.$$"
1868 typeset search_path
=""
1870 log_note
"Calling zdb to verify filesystem '$filesys'"
1871 zfs unmount
-a > /dev
/null
2>&1
1872 log_must zpool
export $pool
1874 if [[ -n $dirs ]] ; then
1875 for dir
in $dirs ; do
1876 search_path
="$search_path -d $dir"
1880 log_must zpool import
$search_path $pool
1882 zdb
-cudi $filesys > $zdbout 2>&1
1883 if [[ $?
!= 0 ]]; then
1884 log_note
"Output: zdb -cudi $filesys"
1886 log_fail
"zdb detected errors with: '$filesys'"
1889 log_must zfs mount
-a
1890 log_must
rm -rf $zdbout
1894 # Given a pool, and this function list all disks in the pool
1896 function get_disklist
# pool
1900 disklist
=$
(zpool iostat
-v $1 | nawk
'(NR >4) {print $1}' | \
1901 grep -v "\-\-\-\-\-" | \
1902 egrep -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
1908 # Given a pool, and this function list all disks in the pool with their full
1909 # path (like "/dev/sda" instead of "sda").
1911 function get_disklist_fullpath
# pool
1920 # This function kills a given list of processes after a time period. We use
1921 # this in the stress tests instead of STF_TIMEOUT so that we can have processes
1922 # run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT
1923 # would be listed as FAIL, which we don't want : we're happy with stress tests
1924 # running for a certain amount of time, then finishing.
1926 # @param $1 the time in seconds after which we should terminate these processes
1927 # @param $2..$n the processes we wish to terminate.
1929 function stress_timeout
1931 typeset
-i TIMEOUT
=$1
1935 log_note
"Waiting for child processes($cpids). " \
1936 "It could last dozens of minutes, please be patient ..."
1937 log_must
sleep $TIMEOUT
1939 log_note
"Killing child processes after ${TIMEOUT} stress timeout."
1941 for pid
in $cpids; do
1942 ps
-p $pid > /dev
/null
2>&1
1943 if (($?
== 0)); then
1944 log_must
kill -USR1 $pid
1950 # Verify a given hotspare disk is inuse or avail
1952 # Return 0 is pool/disk matches expected state, 1 otherwise
1954 function check_hotspare_state
# pool disk state{inuse,avail}
1957 typeset disk
=${2#$DEV_DSKDIR/}
1960 cur_state
=$
(get_device_state
$pool $disk "spares")
1962 if [[ $state != ${cur_state} ]]; then
1969 # Verify a given slog disk is inuse or avail
1971 # Return 0 is pool/disk matches expected state, 1 otherwise
1973 function check_slog_state
# pool disk state{online,offline,unavail}
1976 typeset disk
=${2#$DEV_DSKDIR/}
1979 cur_state
=$
(get_device_state
$pool $disk "logs")
1981 if [[ $state != ${cur_state} ]]; then
1988 # Verify a given vdev disk is inuse or avail
1990 # Return 0 is pool/disk matches expected state, 1 otherwise
1992 function check_vdev_state
# pool disk state{online,offline,unavail}
1995 typeset disk
=${2#$/DEV_DSKDIR/}
1998 cur_state
=$
(get_device_state
$pool $disk)
2000 if [[ $state != ${cur_state} ]]; then
2007 # Check the output of 'zpool status -v <pool>',
2008 # and to see if the content of <token> contain the <keyword> specified.
2010 # Return 0 is contain, 1 otherwise
2012 function check_pool_status
# pool token keyword <verbose>
2017 typeset verbose
=${4:-false}
2019 scan
=$
(zpool status
-v "$pool" 2>/dev
/null | nawk
-v token
="$token:" '
2020 ($1==token) {print $0}')
2021 if [[ $verbose == true
]]; then
2024 echo $scan |
grep -i "$keyword" > /dev
/null
2>&1
2030 # These 6 following functions are instance of check_pool_status()
2031 # is_pool_resilvering - to check if the pool is resilver in progress
2032 # is_pool_resilvered - to check if the pool is resilver completed
2033 # is_pool_scrubbing - to check if the pool is scrub in progress
2034 # is_pool_scrubbed - to check if the pool is scrub completed
2035 # is_pool_scrub_stopped - to check if the pool is scrub stopped
2036 # is_pool_scrub_paused - to check if the pool has scrub paused
2038 function is_pool_resilvering
#pool <verbose>
2040 check_pool_status
"$1" "scan" "resilver in progress since " $2
2044 function is_pool_resilvered
#pool <verbose>
2046 check_pool_status
"$1" "scan" "resilvered " $2
2050 function is_pool_scrubbing
#pool <verbose>
2052 check_pool_status
"$1" "scan" "scrub in progress since " $2
2056 function is_pool_scrubbed
#pool <verbose>
2058 check_pool_status
"$1" "scan" "scrub repaired" $2
2062 function is_pool_scrub_stopped
#pool <verbose>
2064 check_pool_status
"$1" "scan" "scrub canceled" $2
2068 function is_pool_scrub_paused
#pool <verbose>
2070 check_pool_status
"$1" "scan" "scrub paused since " $2
2075 # Use create_pool()/destroy_pool() to clean up the information in
2076 # in the given disk to avoid slice overlapping.
2078 function cleanup_devices
#vdevs
2080 typeset pool
="foopool$$"
2082 if poolexists
$pool ; then
2086 create_pool
$pool $@
2093 # A function to find and locate free disks on a system or from given
2094 # disks as the parameter. It works by locating disks that are in use
2095 # as swap devices and dump devices, and also disks listed in /etc/vfstab
2097 # $@ given disks to find which are free, default is all disks in
2100 # @return a string containing the list of available disks
2104 # Trust provided list, no attempt is made to locate unused devices.
2111 sfi
=/tmp
/swaplist.$$
2112 dmpi
=/tmp
/dumpdev.$$
2113 max_finddisksnum
=${MAX_FINDDISKSNUM:-6}
2116 dumpadm
> $dmpi 2>/dev
/null
2118 # write an awk script that can process the output of format
2119 # to produce a list of disks we know about. Note that we have
2120 # to escape "$2" so that the shell doesn't interpret it while
2121 # we're creating the awk script.
2122 # -------------------
2123 cat > /tmp
/find_disks.
awk <<EOF
2132 if (searchdisks && \$2 !~ "^$"){
2138 /^AVAILABLE DISK SELECTIONS:/{
2142 #---------------------
2144 chmod 755 /tmp
/find_disks.
awk
2145 disks
=${@:-$(echo "" | format -e 2>/dev/null | /tmp/find_disks.awk)}
2146 rm /tmp
/find_disks.
awk
2149 for disk
in $disks; do
2151 grep "${disk}[sp]" /etc
/mnttab
>/dev
/null
2152 (($?
== 0)) && continue
2154 grep "${disk}[sp]" $sfi >/dev
/null
2155 (($?
== 0)) && continue
2156 # check for dump device
2157 grep "${disk}[sp]" $dmpi >/dev
/null
2158 (($?
== 0)) && continue
2159 # check to see if this disk hasn't been explicitly excluded
2160 # by a user-set environment variable
2161 echo "${ZFS_HOST_DEVICES_IGNORE}" |
grep "${disk}" > /dev
/null
2162 (($?
== 0)) && continue
2163 unused_candidates
="$unused_candidates $disk"
2168 # now just check to see if those disks do actually exist
2169 # by looking for a device pointing to the first slice in
2170 # each case. limit the number to max_finddisksnum
2172 for disk
in $unused_candidates; do
2173 if [ -b $DEV_DSKDIR/${disk}s0
]; then
2174 if [ $count -lt $max_finddisksnum ]; then
2175 unused
="$unused $disk"
2176 # do not impose limit if $@ is provided
2177 [[ -z $@
]] && ((count
= count
+ 1))
2182 # finally, return our disk list
2187 # Add specified user to specified group
2191 # $3 base of the homedir (optional)
2193 function add_user
#<group_name> <user_name> <basedir>
2197 typeset basedir
=${3:-"/var/tmp"}
2199 if ((${#gname} == 0 ||
${#uname} == 0)); then
2200 log_fail
"group name or user name are not defined."
2203 log_must useradd
-g $gname -d $basedir/$uname -m $uname
2204 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.profile
2205 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.bash_profile
2206 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.login
2208 # Add new users to the same group and the command line utils.
2209 # This allows them to be run out of the original users home
2210 # directory as long as it permissioned to be group readable.
2212 cmd_group
=$
(stat
--format="%G" $
(which zfs
))
2213 log_must usermod
-a -G $cmd_group $uname
2220 # Delete the specified user.
2223 # $2 base of the homedir (optional)
2225 function del_user
#<logname> <basedir>
2228 typeset basedir
=${2:-"/var/tmp"}
2230 if ((${#user} == 0)); then
2231 log_fail
"login name is necessary."
2234 if id
$user > /dev
/null
2>&1; then
2235 log_must userdel
$user
2238 [[ -d $basedir/$user ]] && rm -fr $basedir/$user
2244 # Select valid gid and create specified group.
2248 function add_group
#<group_name>
2252 if ((${#group} == 0)); then
2253 log_fail
"group name is necessary."
2256 # Assign 100 as the base gid, a larger value is selected for
2257 # Linux because for many distributions 1000 and under are reserved.
2260 groupadd
$group > /dev
/null
2>&1
2270 groupadd
-g $gid $group > /dev
/null
2>&1
2274 # The gid is not unique
2283 # Delete the specified group.
2287 function del_group
#<group_name>
2290 if ((${#grp} == 0)); then
2291 log_fail
"group name is necessary."
2295 getent group
$grp > /dev
/null
2>&1
2298 # Group does not exist.
2300 # Name already exists as a group name
2301 0) log_must groupdel
$grp ;;
2305 groupmod
-n $grp $grp > /dev
/null
2>&1
2308 # Group does not exist.
2310 # Name already exists as a group name
2311 9) log_must groupdel
$grp ;;
2320 # This function will return true if it's safe to destroy the pool passed
2321 # as argument 1. It checks for pools based on zvols and files, and also
2322 # files contained in a pool that may have a different mountpoint.
2324 function safe_to_destroy_pool
{ # $1 the pool name
2327 typeset DONT_DESTROY
=""
2329 # We check that by deleting the $1 pool, we're not
2330 # going to pull the rug out from other pools. Do this
2331 # by looking at all other pools, ensuring that they
2332 # aren't built from files or zvols contained in this pool.
2334 for pool
in $
(zpool list
-H -o name
)
2338 # this is a list of the top-level directories in each of the
2339 # files that make up the path to the files the pool is based on
2340 FILEPOOL
=$
(zpool status
-v $pool |
grep /$1/ | \
2343 # this is a list of the zvols that make up the pool
2344 ZVOLPOOL
=$
(zpool status
-v $pool |
grep "$ZVOL_DEVDIR/$1$" \
2347 # also want to determine if it's a file-based pool using an
2348 # alternate mountpoint...
2349 POOL_FILE_DIRS
=$
(zpool status
-v $pool | \
2350 grep / |
awk '{print $1}' | \
2351 awk -F/ '{print $2}' |
grep -v "dev")
2353 for pooldir
in $POOL_FILE_DIRS
2355 OUTPUT
=$
(zfs list
-H -r -o mountpoint
$1 | \
2356 grep "${pooldir}$" |
awk '{print $1}')
2358 ALTMOUNTPOOL
="${ALTMOUNTPOOL}${OUTPUT}"
2362 if [ ! -z "$ZVOLPOOL" ]
2365 log_note
"Pool $pool is built from $ZVOLPOOL on $1"
2368 if [ ! -z "$FILEPOOL" ]
2371 log_note
"Pool $pool is built from $FILEPOOL on $1"
2374 if [ ! -z "$ALTMOUNTPOOL" ]
2377 log_note
"Pool $pool is built from $ALTMOUNTPOOL on $1"
2381 if [ -z "${DONT_DESTROY}" ]
2385 log_note
"Warning: it is not safe to destroy $1!"
2391 # Get the available ZFS compression options
2392 # $1 option type zfs_set|zfs_compress
2394 function get_compress_opts
2396 typeset COMPRESS_OPTS
2397 typeset GZIP_OPTS
="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \
2398 gzip-6 gzip-7 gzip-8 gzip-9"
2400 if [[ $1 == "zfs_compress" ]] ; then
2401 COMPRESS_OPTS
="on lzjb"
2402 elif [[ $1 == "zfs_set" ]] ; then
2403 COMPRESS_OPTS
="on off lzjb"
2405 typeset valid_opts
="$COMPRESS_OPTS"
2406 zfs get
2>&1 |
grep gzip >/dev
/null
2>&1
2407 if [[ $?
-eq 0 ]]; then
2408 valid_opts
="$valid_opts $GZIP_OPTS"
2414 # Verify zfs operation with -p option work as expected
2415 # $1 operation, value could be create, clone or rename
2416 # $2 dataset type, value could be fs or vol
2418 # $4 new dataset name
2420 function verify_opt_p_ops
2425 typeset newdataset
=$4
2427 if [[ $datatype != "fs" && $datatype != "vol" ]]; then
2428 log_fail
"$datatype is not supported."
2431 # check parameters accordingly
2436 if [[ $datatype == "vol" ]]; then
2437 ops
="create -V $VOLSIZE"
2441 if [[ -z $newdataset ]]; then
2442 log_fail
"newdataset should not be empty" \
2445 log_must datasetexists
$dataset
2446 log_must snapexists
$dataset
2449 if [[ -z $newdataset ]]; then
2450 log_fail
"newdataset should not be empty" \
2453 log_must datasetexists
$dataset
2454 log_mustnot snapexists
$dataset
2457 log_fail
"$ops is not supported."
2461 # make sure the upper level filesystem does not exist
2462 if datasetexists
${newdataset%/*} ; then
2463 log_must zfs destroy
-rRf ${newdataset%/*}
2466 # without -p option, operation will fail
2467 log_mustnot zfs
$ops $dataset $newdataset
2468 log_mustnot datasetexists
$newdataset ${newdataset%/*}
2470 # with -p option, operation should succeed
2471 log_must zfs
$ops -p $dataset $newdataset
2474 if ! datasetexists
$newdataset ; then
2475 log_fail
"-p option does not work for $ops"
2478 # when $ops is create or clone, redo the operation still return zero
2479 if [[ $ops != "rename" ]]; then
2480 log_must zfs
$ops -p $dataset $newdataset
2487 # Get configuration of pool
2497 if ! poolexists
"$pool" ; then
2500 alt_root
=$
(zpool list
-H $pool |
awk '{print $NF}')
2501 if [[ $alt_root == "-" ]]; then
2502 value
=$
(zdb
-C $pool |
grep "$config:" |
awk -F: \
2505 value
=$
(zdb
-e $pool |
grep "$config:" |
awk -F: \
2508 if [[ -n $value ]] ; then
2518 # Privated function. Random select one of items from arguments.
2523 function _random_get
2530 ((ind
= RANDOM
% cnt
+ 1))
2532 typeset ret
=$
(echo "$str" | cut
-f $ind -d ' ')
2537 # Random select one of item from arguments which include NONE string
2539 function random_get_with_non
2544 _random_get
"$cnt" "$@"
2548 # Random select one of item from arguments which doesn't include NONE string
2552 _random_get
"$#" "$@"
2556 # Detect if the current system support slog
2558 function verify_slog_support
2560 typeset dir
=/tmp
/disk.$$
2566 mkfile
$MINVDEVSIZE $vdev $sdev
2569 if ! zpool create
-n $pool $vdev log
$sdev > /dev
/null
2>&1; then
2578 # The function will generate a dataset name with specific length
2579 # $1, the length of the name
2580 # $2, the base string to construct the name
2582 function gen_dataset_name
2585 typeset basestr
="$2"
2586 typeset
-i baselen
=${#basestr}
2590 if ((len
% baselen
== 0)); then
2591 ((iter
= len
/ baselen
))
2593 ((iter
= len
/ baselen
+ 1))
2595 while ((iter
> 0)); do
2596 l_name
="${l_name}$basestr"
2605 # Get cksum tuple of dataset
2608 # sample zdb output:
2609 # Dataset data/test [ZPL], ID 355, cr_txg 2413856, 31.0K, 7 objects, rootbp
2610 # DVA[0]=<0:803046400:200> DVA[1]=<0:81199000:200> [L0 DMU objset] fletcher4
2611 # lzjb LE contiguous unique double size=800L/200P birth=2413856L/2413856P
2612 # fill=7 cksum=11ce125712:643a9c18ee2:125e25238fca0:254a3f74b59744
2613 function datasetcksum
2617 cksum=$
(zdb
-vvv $1 |
grep "^Dataset $1 \[" |
grep "cksum" \
2618 |
awk -F= '{print $7}')
2629 cksum=$
(cksum $1 |
awk '{print $1}')
2634 # Get the given disk/slice state from the specific field of the pool
2636 function get_device_state
#pool disk field("", "spares","logs")
2639 typeset disk
=${2#$DEV_DSKDIR/}
2640 typeset field
=${3:-$pool}
2642 state
=$
(zpool status
-v "$pool" 2>/dev
/null | \
2643 nawk
-v device
=$disk -v pool
=$pool -v field
=$field \
2644 'BEGIN {startconfig=0; startfield=0; }
2645 /config:/ {startconfig=1}
2646 (startconfig==1) && ($1==field) {startfield=1; next;}
2647 (startfield==1) && ($1==device) {print $2; exit;}
2649 ($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}')
2655 # print the given directory filesystem type
2663 if [[ -z $dir ]]; then
2664 log_fail
"Usage: get_fstype <directory>"
2671 df
-n $dir |
awk '{print $3}'
2675 # Given a disk, label it to VTOC regardless what label was on the disk
2681 if [[ -z $disk ]]; then
2682 log_fail
"The disk name is unspecified."
2684 typeset label_file
=/var
/tmp
/labelvtoc.$$
2685 typeset arch
=$
(uname
-p)
2688 log_note
"Currently unsupported by the test framework"
2692 if [[ $arch == "i386" ]]; then
2693 echo "label" > $label_file
2694 echo "0" >> $label_file
2695 echo "" >> $label_file
2696 echo "q" >> $label_file
2697 echo "q" >> $label_file
2699 fdisk
-B $disk >/dev
/null
2>&1
2700 # wait a while for fdisk finishes
2702 elif [[ $arch == "sparc" ]]; then
2703 echo "label" > $label_file
2704 echo "0" >> $label_file
2705 echo "" >> $label_file
2706 echo "" >> $label_file
2707 echo "" >> $label_file
2708 echo "q" >> $label_file
2710 log_fail
"unknown arch type"
2713 format
-e -s -d $disk -f $label_file
2714 typeset
-i ret_val
=$?
2717 # wait the format to finish
2720 if ((ret_val
!= 0)); then
2721 log_fail
"unable to label $disk as VTOC."
2728 # check if the system was installed as zfsroot or not
2729 # return: 0 ture, otherwise false
2733 df
-n / |
grep zfs
> /dev
/null
2>&1
2738 # get the root filesystem name if it's zfsroot system.
2740 # return: root filesystem name
2746 rootfs
=$
(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \
2749 if [[ -z "$rootfs" ]]; then
2750 log_fail
"Can not get rootfs"
2752 zfs list
$rootfs > /dev
/null
2>&1
2753 if (($?
== 0)); then
2756 log_fail
"This is not a zfsroot system."
2761 # get the rootfs's pool name
2765 function get_rootpool
2771 rootfs
=$
(awk '{if ($2 == "/" && $3 =="zfs") print $1}' \
2774 if [[ -z "$rootfs" ]]; then
2775 log_fail
"Can not get rootpool"
2777 zfs list
$rootfs > /dev
/null
2>&1
2778 if (($?
== 0)); then
2779 rootpool
=`echo $rootfs | awk -F\/ '{print $1}'`
2782 log_fail
"This is not a zfsroot system."
2787 # Check if the given device is physical device
2789 function is_physical_device
#device
2791 typeset device
=${1#$DEV_DSKDIR}
2792 device
=${device#$DEV_RDSKDIR}
2795 [[ -b "$DEV_DSKDIR/$device" ]] && \
2796 [[ -f /sys
/module
/loop
/parameters
/max_part
]]
2799 echo $device |
egrep "^c[0-F]+([td][0-F]+)+$" > /dev
/null
2>&1
2805 # Check if the given device is a real device (ie SCSI device)
2807 function is_real_device
#disk
2810 [[ -z $disk ]] && log_fail
"No argument for disk given."
2813 lsblk
$DEV_RDSKDIR/$disk -o TYPE
2>/dev
/null | \
2814 egrep disk
>/dev
/null
2820 # Check if the given device is a loop device
2822 function is_loop_device
#disk
2825 [[ -z $disk ]] && log_fail
"No argument for disk given."
2828 lsblk
$DEV_RDSKDIR/$disk -o TYPE
2>/dev
/null | \
2829 egrep loop
>/dev
/null
2835 # Check if the given device is a multipath device and if there is a sybolic
2836 # link to a device mapper and to a disk
2837 # Currently no support for dm devices alone without multipath
2839 function is_mpath_device
#disk
2842 [[ -z $disk ]] && log_fail
"No argument for disk given."
2845 lsblk
$DEV_MPATHDIR/$disk -o TYPE
2>/dev
/null | \
2846 egrep mpath
>/dev
/null
2847 if (($?
== 0)); then
2848 readlink
$DEV_MPATHDIR/$disk > /dev
/null
2>&1
2856 # Set the slice prefix for disk partitioning depending
2857 # on whether the device is a real, multipath, or loop device.
2858 # Currently all disks have to be of the same type, so only
2859 # checks first disk to determine slice prefix.
2861 function set_slice_prefix
2867 while (( i
< $DISK_ARRAY_NUM )); do
2868 disk
="$(echo $DISKS | nawk '{print $(i + 1)}')"
2869 if ( is_mpath_device
$disk ) && [[ -z $
(echo $disk |
awk 'substr($1,18,1)\
2870 ~ /^[[:digit:]]+$/') ]] ||
( is_real_device
$disk ); then
2871 export SLICE_PREFIX
=""
2873 elif ( is_mpath_device
$disk || is_loop_device \
2875 export SLICE_PREFIX
="p"
2878 log_fail
"$disk not supported for partitioning."
2886 # Set the directory path of the listed devices in $DISK_ARRAY_NUM
2887 # Currently all disks have to be of the same type, so only
2888 # checks first disk to determine device directory
2889 # default = /dev (linux)
2890 # real disk = /dev (linux)
2891 # multipath device = /dev/mapper (linux)
2893 function set_device_dir
2899 while (( i
< $DISK_ARRAY_NUM )); do
2900 disk
="$(echo $DISKS | nawk '{print $(i + 1)}')"
2901 if is_mpath_device
$disk; then
2902 export DEV_DSKDIR
=$DEV_MPATHDIR
2905 export DEV_DSKDIR
=$DEV_RDSKDIR
2911 export DEV_DSKDIR
=$DEV_RDSKDIR
2916 # Get the directory path of given device
2918 function get_device_dir
#device
2922 if ! $
(is_physical_device
$device) ; then
2923 if [[ $device != "/" ]]; then
2926 if [[ -b "$DEV_DSKDIR/$device" ]]; then
2927 device
="$DEV_DSKDIR"
2936 # Get persistent name for given disk
2938 function get_persistent_disk_name
#device
2944 if is_real_device
$device; then
2945 dev_id
="$(udevadm info -q all -n $DEV_DSKDIR/$device \
2946 | egrep disk/by-id | nawk '{print $2; exit}' \
2947 | nawk -F / '{print $3}')"
2949 elif is_mpath_device
$device; then
2950 dev_id
="$(udevadm info -q all -n $DEV_DSKDIR/$device \
2951 | egrep disk/by-id/dm-uuid \
2952 | nawk '{print $2; exit}' \
2953 | nawk -F / '{print $3}')"
2964 # Load scsi_debug module with specified parameters
2966 function load_scsi_debug
# dev_size_mb add_host num_tgts max_luns
2973 [[ -z $devsize ]] ||
[[ -z $hosts ]] ||
[[ -z $tgts ]] || \
2974 [[ -z $luns ]] && log_fail
"Arguments invalid or missing"
2977 modprobe
-n scsi_debug
2978 if (($?
!= 0)); then
2979 log_unsupported
"Platform does not have scsi_debug"
2982 lsmod |
egrep scsi_debug
> /dev
/null
2983 if (($?
== 0)); then
2984 log_fail
"scsi_debug module already installed"
2986 log_must modprobe scsi_debug dev_size_mb
=$devsize \
2987 add_host
=$hosts num_tgts
=$tgts max_luns
=$luns
2989 lsscsi |
egrep scsi_debug
> /dev
/null
2990 if (($?
== 1)); then
2991 log_fail
"scsi_debug module install failed"
2998 # Get the package name
3000 function get_package_name
3002 typeset dirpath
=${1:-$STC_NAME}
3004 echo "SUNWstc-${dirpath}" |
/usr
/bin
/sed -e "s/\//-/g"
3008 # Get the word numbers from a string separated by white space
3010 function get_word_count
3016 # To verify if the require numbers of disks is given
3018 function verify_disk_count
3020 typeset
-i min
=${2:-1}
3022 typeset
-i count
=$
(get_word_count
"$1")
3024 if ((count
< min
)); then
3025 log_untested
"A minimum of $min disks is required to run." \
3026 " You specified $count disk(s)"
3030 function ds_is_volume
3032 typeset
type=$
(get_prop
type $1)
3033 [[ $type = "volume" ]] && return 0
3037 function ds_is_filesystem
3039 typeset
type=$
(get_prop
type $1)
3040 [[ $type = "filesystem" ]] && return 0
3044 function ds_is_snapshot
3046 typeset
type=$
(get_prop
type $1)
3047 [[ $type = "snapshot" ]] && return 0
3052 # Check if Trusted Extensions are installed and enabled
3054 function is_te_enabled
3056 svcs
-H -o state labeld
2>/dev
/null |
grep "enabled"
3057 if (($?
!= 0)); then
3064 # Utility function to determine if a system has multiple cpus.
3070 (($
(psrinfo |
wc -l) > 1))
3076 function get_cpu_freq
3079 lscpu |
awk '/CPU MHz/ { print $3 }'
3081 psrinfo
-v 0 |
awk '/processor operates at/ {print $6}'
3085 # Run the given command as the user provided.
3091 log_note
"user:$user $@"
3092 eval su
- \
$user -c \"$@
\" > /tmp
/out
2>/tmp
/err
3097 # Check if the pool contains the specified vdevs
3102 # Return 0 if the vdevs are contained in the pool, 1 if any of the specified
3103 # vdevs is not in the pool, and 2 if pool name is missing.
3105 function vdevs_in_pool
3110 if [[ -z $pool ]]; then
3111 log_note
"Missing pool name."
3117 typeset tmpfile
=$
(mktemp
)
3118 zpool list
-Hv "$pool" >$tmpfile
3120 grep -w ${vdev##*/} $tmpfile >/dev
/null
2>&1
3121 [[ $?
-ne 0 ]] && return 1
3135 max
=$
(echo $
((max
> i ? max
: i
)))
3147 min
=$
(echo $
((min
< i ? min
: i
)))
3154 # Generate a random number between 1 and the argument.
3159 echo $
(( ($RANDOM % $max) + 1 ))
3162 # Write data that can be compressed into a directory
3163 function write_compressible
3167 typeset nfiles
=${3:-1}
3168 typeset bs
=${4:-1024k}
3169 typeset fname
=${5:-file}
3171 [[ -d $dir ]] || log_fail
"No directory: $dir"
3173 # Under Linux fio is not currently used since its behavior can
3174 # differ significantly across versions. This includes missing
3175 # command line options and cases where the --buffer_compress_*
3176 # options fail to behave as expected.
3178 typeset file_bytes
=$
(to_bytes
$megs)
3179 typeset bs_bytes
=4096
3180 typeset blocks
=$
(($file_bytes / $bs_bytes))
3182 for (( i
= 0; i
< $nfiles; i
++ )); do
3183 truncate
-s $file_bytes $dir/$fname.
$i
3185 # Write every third block to get 66% compression.
3186 for (( j
= 0; j
< $blocks; j
+= 3 )); do
3187 dd if=/dev
/urandom of
=$dir/$fname.
$i \
3188 seek
=$j bs
=$bs_bytes count
=1 \
3189 conv
=notrunc
>/dev
/null
2>&1
3193 log_must
eval "fio \
3198 --buffer_compress_percentage=66 \
3199 --buffer_compress_chunk=4096 \
3206 --filename_format='$fname.\$jobnum' >/dev/null"
3215 [[ -e $pathname ]] || log_fail
"No such file or directory: $pathname"
3216 objnum
=$
(stat
-c %i
$pathname)
3221 # Sync data to the pool
3224 # $2 boolean to force uberblock (and config including zpool cache file) update
3226 function sync_pool
#pool <force>
3228 typeset pool
=${1:-$TESTPOOL}
3229 typeset force
=${2:-false}
3231 if [[ $force == true
]]; then
3232 log_must zpool sync
-f $pool
3234 log_must zpool sync
$pool
3241 # Wait for zpool 'freeing' property drops to zero.
3245 function wait_freeing
#pool
3247 typeset pool
=${1:-$TESTPOOL}
3249 [[ "0" == "$(zpool list -Ho freeing $pool)" ]] && break
3255 # Wait for every device replace operation to complete
3259 function wait_replacing
#pool
3261 typeset pool
=${1:-$TESTPOOL}
3263 [[ "" == "$(zpool status $pool |
3264 awk '/replacing-[0-9]+/ {print $1}')" ]] && break
3270 # Setup custom environment for the ZED.
3278 if [[ ! -d $ZEDLET_DIR ]]; then
3279 log_must mkdir
$ZEDLET_DIR
3282 if [[ ! -e $VDEVID_CONF ]]; then
3283 log_must
touch $VDEVID_CONF
3286 if [[ -e $VDEVID_CONF_ETC ]]; then
3287 log_fail
"Must not have $VDEVID_CONF_ETC file present on system"
3290 # Create a symlink for /etc/zfs/vdev_id.conf file.
3291 log_must
ln -s $VDEVID_CONF $VDEVID_CONF_ETC
3293 # Setup minimal ZED configuration. Individual test cases should
3294 # add additional ZEDLETs as needed for their specific test.
3295 log_must
cp ${ZEDLET_ETC_DIR}/zed.rc
$ZEDLET_DIR
3296 log_must
cp ${ZEDLET_ETC_DIR}/zed-functions.sh
$ZEDLET_DIR
3298 # Customize the zed.rc file to enable the full debug log.
3299 log_must
sed -i '/\#ZED_DEBUG_LOG=.*/d' $ZEDLET_DIR/zed.rc
3300 echo "ZED_DEBUG_LOG=$ZEDLET_DIR/zed.debug.log" >>$ZEDLET_DIR/zed.rc
3302 log_must
cp ${ZEDLET_LIBEXEC_DIR}/all-syslog.sh
$ZEDLET_DIR
3303 log_must
cp ${ZEDLET_LIBEXEC_DIR}/all-debug.sh
$ZEDLET_DIR
3304 log_must
touch $ZEDLET_DIR/zed.debug.log
3308 # Cleanup custom ZED environment.
3310 function zed_cleanup
3316 log_must
rm -f ${ZEDLET_DIR}/zed.rc
3317 log_must
rm -f ${ZEDLET_DIR}/zed-functions.sh
3318 log_must
rm -f ${ZEDLET_DIR}/all-syslog.sh
3319 log_must
rm -f ${ZEDLET_DIR}/all-debug.sh
3320 log_must
rm -f ${ZEDLET_DIR}/zed.pid
3321 log_must
rm -f ${ZEDLET_DIR}/zedlog
3322 log_must
rm -f ${ZEDLET_DIR}/zed.debug.log
3323 log_must
rm -f ${ZEDLET_DIR}/state
3324 log_must
rm -f $VDEVID_CONF_ETC
3325 log_must
rm -f $VDEVID_CONF
3330 # Check if ZED is currently running, if not start ZED.
3338 # ZEDLET_DIR=/var/tmp/zed
3339 if [[ ! -d $ZEDLET_DIR ]]; then
3340 log_must mkdir
$ZEDLET_DIR
3343 # Verify the ZED is not already running.
3344 pgrep
-x zed
> /dev
/null
3345 if (($?
== 0)); then
3346 log_fail
"ZED already running"
3349 log_note
"Starting ZED"
3350 # run ZED in the background and redirect foreground logging
3352 log_must
eval "zed -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid" \
3353 "-s $ZEDLET_DIR/state 2>${ZEDLET_DIR}/zedlog &"
3367 log_note
"Stopping ZED"
3368 if [[ -f ${ZEDLET_DIR}/zed.pid
]]; then
3369 zedpid
=$
(cat ${ZEDLET_DIR}/zed.pid
)
3370 log_must
kill $zedpid
3377 # Check is provided device is being active used as a swap device.
3379 function is_swap_inuse
3383 if [[ -z $device ]] ; then
3384 log_note
"No device specified."
3389 swapon
-s |
grep -w $
(readlink
-f $device) > /dev
/null
2>&1
3391 swap
-l |
grep -w $device > /dev
/null
2>&1
3398 # Setup a swap device using the provided device.
3405 log_must mkswap
$swapdev > /dev
/null
2>&1
3406 log_must swapon
$swapdev
3408 log_must swap
-a $swapdev
3415 # Cleanup a swap device on the provided device.
3417 function swap_cleanup
3421 if is_swap_inuse
$swapdev; then
3423 log_must swapoff
$swapdev
3425 log_must swap
-d $swapdev