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 set_partition
$i "" 0mb
$diskname
757 # Given a slice, size and disk, this function
758 # formats the slice to the specified size.
759 # Size should be specified with units as per
760 # the `format` command requirements eg. 100mb 3gb
762 # NOTE: This entire interface is problematic for the Linux parted utilty
763 # which requires the end of the partition to be specified. It would be
764 # best to retire this interface and replace it with something more flexible.
765 # At the moment a best effort is made.
767 function set_partition
#<slice_num> <slice_start> <size_plus_units> <whole_disk_name>
769 typeset
-i slicenum
=$1
773 [[ -z $slicenum ||
-z $size ||
-z $disk ]] && \
774 log_fail
"The slice, size or disk name is unspecified."
777 typeset size_mb
=${size%%[mMgG]}
779 size_mb
=${size_mb%%[mMgG][bB]}
780 if [[ ${size:1:1} == 'g' ]]; then
781 ((size_mb
= size_mb
* 1024))
784 # Create GPT partition table when setting slice 0 or
785 # when the device doesn't already contain a GPT label.
786 parted
$DEV_DSKDIR/$disk -s -- print
1 >/dev
/null
788 if [[ $slicenum -eq 0 ||
$ret_val -ne 0 ]]; then
789 log_must parted
$DEV_DSKDIR/$disk -s -- mklabel gpt
792 # When no start is given align on the first cylinder.
793 if [[ -z "$start" ]]; then
797 # Determine the cylinder size for the device and using
798 # that calculate the end offset in cylinders.
799 typeset
-i cly_size_kb
=0
800 cly_size_kb
=$
(parted
-m $DEV_DSKDIR/$disk -s -- \
801 unit cyl print |
head -3 |
tail -1 | \
802 awk -F '[:k.]' '{print $4}')
803 ((end
= (size_mb
* 1024 / cly_size_kb
) + start
))
805 log_must parted
$DEV_DSKDIR/$disk -s -- \
806 mkpart part
$slicenum ${start}cyl
${end}cyl
808 blockdev
--rereadpt $DEV_DSKDIR/$disk 2>/dev
/null
811 typeset format_file
=/var
/tmp
/format_in.$$
813 echo "partition" >$format_file
814 echo "$slicenum" >> $format_file
815 echo "" >> $format_file
816 echo "" >> $format_file
817 echo "$start" >> $format_file
818 echo "$size" >> $format_file
819 echo "label" >> $format_file
820 echo "" >> $format_file
821 echo "q" >> $format_file
822 echo "q" >> $format_file
824 format
-e -s -d $disk -f $format_file
829 [[ $ret_val -ne 0 ]] && \
830 log_fail
"Unable to format $disk slice $slicenum to $size"
835 # Delete all partitions on all disks - this is specifically for the use of multipath
836 # devices which currently can only be used in the test suite as raw/un-partitioned
837 # devices (ie a zpool cannot be created on a whole mpath device that has partitions)
839 function delete_partitions
843 if [[ -z $DISK_ARRAY_NUM ]]; then
844 DISK_ARRAY_NUM
=$
(echo ${DISKS} | nawk
'{print NF}')
846 if [[ -z $DISKSARRAY ]]; then
851 if (( $DISK_ARRAY_NUM == 1 )); then
852 while ((j
< MAX_PARTITIONS
)); do
853 parted
$DEV_DSKDIR/$DISK -s rm $j \
855 if (( $?
== 1 )); then
856 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
857 if (( $?
== 1 )); then
858 log_note
"Partitions for $DISK should be deleted"
860 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
864 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
865 if (( $?
== 0 )); then
866 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
872 for disk
in `echo $DISKSARRAY`; do
873 while ((j
< MAX_PARTITIONS
)); do
874 parted
$DEV_DSKDIR/$disk -s rm $j > /dev
/null
2>&1
875 if (( $?
== 1 )); then
876 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
877 if (( $?
== 1 )); then
878 log_note
"Partitions for $disk should be deleted"
880 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
884 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
885 if (( $?
== 0 )); then
886 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
899 # Get the end cyl of the given slice
901 function get_endslice
#<disk> <slice>
905 if [[ -z $disk ||
-z $slice ]] ; then
906 log_fail
"The disk name or slice number is unspecified."
910 endcyl
=$
(parted
-s $DEV_DSKDIR/$disk -- unit cyl print | \
911 grep "part${slice}" | \
914 ((endcyl
= (endcyl
+ 1)))
916 disk
=${disk#/dev/dsk/}
917 disk
=${disk#/dev/rdsk/}
921 ratio
=$
(prtvtoc
/dev
/rdsk
/${disk}s2 | \
922 grep "sectors\/cylinder" | \
925 if ((ratio
== 0)); then
929 typeset
-i endcyl
=$
(prtvtoc
-h /dev
/rdsk
/${disk}s2 |
930 nawk
-v token
="$slice" '{if ($1==token) print $6}')
932 ((endcyl
= (endcyl
+ 1) / ratio
))
940 # Given a size,disk and total slice number, this function formats the
941 # disk slices from 0 to the total slice number with the same specified
944 function partition_disk
#<slice_size> <whole_disk_name> <total_slices>
947 typeset slice_size
=$1
949 typeset total_slices
=$3
952 zero_partitions
$disk_name
953 while ((i
< $total_slices)); do
960 set_partition
$i "$cyl" $slice_size $disk_name
961 cyl
=$
(get_endslice
$disk_name $i)
967 # This function continues to write to a filenum number of files into dirnum
968 # number of directories until either file_write returns an error or the
969 # maximum number of files per directory have been written.
972 # fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data]
974 # Return value: 0 on success
978 # destdir: is the directory where everything is to be created under
979 # dirnum: the maximum number of subdirectories to use, -1 no limit
980 # filenum: the maximum number of files per subdirectory
981 # bytes: number of bytes to write
982 # num_writes: numer of types to write out bytes
983 # data: the data that will be written
986 # file_fs /testdir 20 25 1024 256 0
988 # Note: bytes * num_writes equals the size of the testfile
990 function fill_fs
# destdir dirnum filenum bytes num_writes data
992 typeset destdir
=${1:-$TESTDIR}
993 typeset
-i dirnum
=${2:-50}
994 typeset
-i filenum
=${3:-50}
995 typeset
-i bytes
=${4:-8192}
996 typeset
-i num_writes
=${5:-10240}
997 typeset
-i data
=${6:-0}
1000 typeset
-i idirnum
=0
1004 log_must mkdir
-p $destdir/$idirnum
1005 while (($odirnum > 0)); do
1006 if ((dirnum
>= 0 && idirnum
>= dirnum
)); then
1010 file_write
-o create
-f $destdir/$idirnum/$TESTFILE.
$fn \
1011 -b $bytes -c $num_writes -d $data
1013 if (($retval != 0)); then
1017 if (($fn >= $filenum)); then
1019 ((idirnum
= idirnum
+ 1))
1020 log_must mkdir
-p $destdir/$idirnum
1029 # Simple function to get the specified property. If unable to
1030 # get the property then exits.
1032 # Note property is in 'parsable' format (-p)
1034 function get_prop
# property dataset
1040 prop_val
=$
(zfs get
-pH -o value
$prop $dataset 2>/dev
/null
)
1041 if [[ $?
-ne 0 ]]; then
1042 log_note
"Unable to get $prop property for dataset " \
1052 # Simple function to get the specified property of pool. If unable to
1053 # get the property then exits.
1055 # Note property is in 'parsable' format (-p)
1057 function get_pool_prop
# property pool
1063 if poolexists
$pool ; then
1064 prop_val
=$
(zpool get
-pH $prop $pool 2>/dev
/null |
tail -1 | \
1066 if [[ $?
-ne 0 ]]; then
1067 log_note
"Unable to get $prop property for pool " \
1072 log_note
"Pool $pool not exists."
1080 # Return 0 if a pool exists; $? otherwise
1088 if [[ -z $pool ]]; then
1089 log_note
"No pool name given."
1093 zpool get name
"$pool" > /dev
/null
2>&1
1097 # Return 0 if all the specified datasets exist; $? otherwise
1100 function datasetexists
1102 if (($# == 0)); then
1103 log_note
"No dataset name given."
1107 while (($# > 0)); do
1108 zfs get name
$1 > /dev
/null
2>&1 || \
1116 # return 0 if none of the specified datasets exists, otherwise return 1.
1119 function datasetnonexists
1121 if (($# == 0)); then
1122 log_note
"No dataset name given."
1126 while (($# > 0)); do
1127 zfs list
-H -t filesystem
,snapshot
,volume
$1 > /dev
/null
2>&1 \
1136 # Given a mountpoint, or a dataset name, determine if it is shared via NFS.
1138 # Returns 0 if shared, 1 otherwise.
1145 if [[ $fs != "/"* ]] ; then
1146 if datasetnonexists
"$fs" ; then
1149 mtpt
=$
(get_prop mountpoint
"$fs")
1151 none|legacy|
-) return 1
1160 for mtpt
in `share | awk '{print $1}'` ; do
1161 if [[ $mtpt == $fs ]] ; then
1168 for mtpt
in `share | awk '{print $2}'` ; do
1169 if [[ $mtpt == $fs ]] ; then
1174 typeset stat
=$
(svcs
-H -o STA nfs
/server
:default
)
1175 if [[ $stat != "ON" ]]; then
1176 log_note
"Current nfs/server status: $stat"
1183 # Given a dataset name determine if it is shared via SMB.
1185 # Returns 0 if shared, 1 otherwise.
1187 function is_shared_smb
1192 if datasetnonexists
"$fs" ; then
1195 fs
=$
(echo $fs |
sed 's@/@_@g')
1199 for mtpt
in `net usershare list | awk '{print $1}'` ; do
1200 if [[ $mtpt == $fs ]] ; then
1206 log_unsupported
"Currently unsupported by the test framework"
1212 # Given a mountpoint, determine if it is not shared via NFS.
1214 # Returns 0 if not shared, 1 otherwise.
1221 if (($?
== 0)); then
1229 # Given a dataset determine if it is not shared via SMB.
1231 # Returns 0 if not shared, 1 otherwise.
1233 function not_shared_smb
1238 if (($?
== 0)); then
1246 # Helper function to unshare a mountpoint.
1248 function unshare_fs
#fs
1252 is_shared
$fs || is_shared_smb
$fs
1253 if (($?
== 0)); then
1254 log_must zfs unshare
$fs
1261 # Helper function to share a NFS mountpoint.
1263 function share_nfs
#fs
1269 if (($?
!= 0)); then
1270 log_must share
"*:$fs"
1274 if (($?
!= 0)); then
1275 log_must share
-F nfs
$fs
1283 # Helper function to unshare a NFS mountpoint.
1285 function unshare_nfs
#fs
1291 if (($?
== 0)); then
1292 log_must unshare
-u "*:$fs"
1296 if (($?
== 0)); then
1297 log_must unshare
-F nfs
$fs
1305 # Helper function to show NFS shares.
1307 function showshares_nfs
1319 # Helper function to show SMB shares.
1321 function showshares_smb
1333 # Check NFS server status and trigger it online.
1335 function setup_nfs_server
1337 # Cannot share directory in non-global zone.
1339 if ! is_global_zone
; then
1340 log_note
"Cannot trigger NFS server by sharing in LZ."
1345 log_note
"NFS server must started prior to running test framework."
1349 typeset nfs_fmri
="svc:/network/nfs/server:default"
1350 if [[ $
(svcs
-Ho STA
$nfs_fmri) != "ON" ]]; then
1352 # Only really sharing operation can enable NFS server
1353 # to online permanently.
1355 typeset dummy
=/tmp
/dummy
1357 if [[ -d $dummy ]]; then
1358 log_must
rm -rf $dummy
1361 log_must mkdir
$dummy
1362 log_must share
$dummy
1365 # Waiting for fmri's status to be the final status.
1366 # Otherwise, in transition, an asterisk (*) is appended for
1367 # instances, unshare will reverse status to 'DIS' again.
1369 # Waiting for 1's at least.
1373 while [[ timeout
-ne 0 && $
(svcs
-Ho STA
$nfs_fmri) == *'*' ]]
1380 log_must unshare
$dummy
1381 log_must
rm -rf $dummy
1384 log_note
"Current NFS status: '$(svcs -Ho STA,FMRI $nfs_fmri)'"
1388 # To verify whether calling process is in global zone
1390 # Return 0 if in global zone, 1 in non-global zone
1392 function is_global_zone
1397 typeset cur_zone
=$
(zonename
2>/dev
/null
)
1398 if [[ $cur_zone != "global" ]]; then
1406 # Verify whether test is permitted to run from
1407 # global zone, local zone, or both
1409 # $1 zone limit, could be "global", "local", or "both"(no limit)
1411 # Return 0 if permitted, otherwise exit with log_unsupported
1413 function verify_runnable
# zone limit
1417 [[ -z $limit ]] && return 0
1419 if is_global_zone
; then
1423 local) log_unsupported
"Test is unable to run from "\
1426 *) log_note
"Warning: unknown limit $limit - " \
1434 global
) log_unsupported
"Test is unable to run from "\
1437 *) log_note
"Warning: unknown limit $limit - " \
1448 # Return 0 if create successfully or the pool exists; $? otherwise
1449 # Note: In local zones, this function should return 0 silently.
1452 # $2-n - [keyword] devs_list
1454 function create_pool
#pool devs_list
1456 typeset pool
=${1%%/*}
1460 if [[ -z $pool ]]; then
1461 log_note
"Missing pool name."
1465 if poolexists
$pool ; then
1469 if is_global_zone
; then
1470 [[ -d /$pool ]] && rm -rf /$pool
1471 log_must zpool create
-f $pool $@
1477 # Return 0 if destroy successfully or the pool exists; $? otherwise
1478 # Note: In local zones, this function should return 0 silently.
1481 # Destroy pool with the given parameters.
1483 function destroy_pool
#pool
1485 typeset pool
=${1%%/*}
1488 if [[ -z $pool ]]; then
1489 log_note
"No pool name given."
1493 if is_global_zone
; then
1494 if poolexists
"$pool" ; then
1495 mtpt
=$
(get_prop mountpoint
"$pool")
1497 # At times, syseventd activity can cause attempts to
1498 # destroy a pool to fail with EBUSY. We retry a few
1499 # times allowing failures before requiring the destroy
1501 typeset
-i wait_time
=10 ret
=1 count
=0
1503 while [[ $ret -ne 0 ]]; do
1504 $must zpool destroy
-f $pool
1506 [[ $ret -eq 0 ]] && break
1507 log_note
"zpool destroy failed with $ret"
1508 [[ count
++ -ge 7 ]] && must
=log_must
1513 log_must
rm -rf $mtpt
1515 log_note
"Pool does not exist. ($pool)"
1524 # Firstly, create a pool with 5 datasets. Then, create a single zone and
1525 # export the 5 datasets to it. In addition, we also add a ZFS filesystem
1526 # and a zvol device to the zone.
1529 # $2 zone root directory prefix
1532 function zfs_zones_setup
#zone_name zone_root zone_ip
1534 typeset zone_name
=${1:-$(hostname)-z}
1535 typeset zone_root
=${2:-"/zone_root"}
1536 typeset zone_ip
=${3:-"10.1.1.10"}
1537 typeset prefix_ctr
=$ZONE_CTR
1538 typeset pool_name
=$ZONE_POOL
1542 # Create pool and 5 container within it
1544 [[ -d /$pool_name ]] && rm -rf /$pool_name
1545 log_must zpool create
-f $pool_name $DISKS
1546 while ((i
< cntctr
)); do
1547 log_must zfs create
$pool_name/$prefix_ctr$i
1552 log_must zfs create
-V 1g
$pool_name/zone_zvol
1556 # If current system support slog, add slog device for pool
1558 if verify_slog_support
; then
1559 typeset sdevs
="/var/tmp/sdev1 /var/tmp/sdev2"
1560 log_must mkfile
$MINVDEVSIZE $sdevs
1561 log_must zpool add
$pool_name log mirror
$sdevs
1564 # this isn't supported just yet.
1565 # Create a filesystem. In order to add this to
1566 # the zone, it must have it's mountpoint set to 'legacy'
1567 # log_must zfs create $pool_name/zfs_filesystem
1568 # log_must zfs set mountpoint=legacy $pool_name/zfs_filesystem
1570 [[ -d $zone_root ]] && \
1571 log_must
rm -rf $zone_root/$zone_name
1572 [[ ! -d $zone_root ]] && \
1573 log_must mkdir
-p -m 0700 $zone_root/$zone_name
1575 # Create zone configure file and configure the zone
1577 typeset zone_conf
=/tmp
/zone_conf.$$
1578 echo "create" > $zone_conf
1579 echo "set zonepath=$zone_root/$zone_name" >> $zone_conf
1580 echo "set autoboot=true" >> $zone_conf
1582 while ((i
< cntctr
)); do
1583 echo "add dataset" >> $zone_conf
1584 echo "set name=$pool_name/$prefix_ctr$i" >> \
1586 echo "end" >> $zone_conf
1590 # add our zvol to the zone
1591 echo "add device" >> $zone_conf
1592 echo "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf
1593 echo "end" >> $zone_conf
1595 # add a corresponding zvol rdsk to the zone
1596 echo "add device" >> $zone_conf
1597 echo "set match=$ZVOL_RDEVDIR/$pool_name/zone_zvol" >> $zone_conf
1598 echo "end" >> $zone_conf
1600 # once it's supported, we'll add our filesystem to the zone
1601 # echo "add fs" >> $zone_conf
1602 # echo "set type=zfs" >> $zone_conf
1603 # echo "set special=$pool_name/zfs_filesystem" >> $zone_conf
1604 # echo "set dir=/export/zfs_filesystem" >> $zone_conf
1605 # echo "end" >> $zone_conf
1607 echo "verify" >> $zone_conf
1608 echo "commit" >> $zone_conf
1609 log_must zonecfg
-z $zone_name -f $zone_conf
1610 log_must
rm -f $zone_conf
1613 zoneadm
-z $zone_name install
1614 if (($?
== 0)); then
1615 log_note
"SUCCESS: zoneadm -z $zone_name install"
1617 log_fail
"FAIL: zoneadm -z $zone_name install"
1620 # Install sysidcfg file
1622 typeset sysidcfg
=$zone_root/$zone_name/root
/etc
/sysidcfg
1623 echo "system_locale=C" > $sysidcfg
1624 echo "terminal=dtterm" >> $sysidcfg
1625 echo "network_interface=primary {" >> $sysidcfg
1626 echo "hostname=$zone_name" >> $sysidcfg
1627 echo "}" >> $sysidcfg
1628 echo "name_service=NONE" >> $sysidcfg
1629 echo "root_password=mo791xfZ/SFiw" >> $sysidcfg
1630 echo "security_policy=NONE" >> $sysidcfg
1631 echo "timezone=US/Eastern" >> $sysidcfg
1634 log_must zoneadm
-z $zone_name boot
1638 # Reexport TESTPOOL & TESTPOOL(1-4)
1640 function reexport_pool
1645 while ((i
< cntctr
)); do
1647 TESTPOOL
=$ZONE_POOL/$ZONE_CTR$i
1648 if ! ismounted
$TESTPOOL; then
1649 log_must zfs mount
$TESTPOOL
1652 eval TESTPOOL
$i=$ZONE_POOL/$ZONE_CTR$i
1653 if eval ! ismounted \
$TESTPOOL$i; then
1654 log_must
eval zfs mount \
$TESTPOOL$i
1662 # Verify a given disk or pool state
1664 # Return 0 is pool/disk matches expected state, 1 otherwise
1666 function check_state
# pool disk state{online,offline,degraded}
1669 typeset disk
=${2#$DEV_DSKDIR/}
1672 [[ -z $pool ]] ||
[[ -z $state ]] \
1673 && log_fail
"Arguments invalid or missing"
1675 if [[ -z $disk ]]; then
1676 #check pool state only
1677 zpool get
-H -o value health
$pool \
1678 |
grep -i "$state" > /dev
/null
2>&1
1680 zpool status
-v $pool |
grep "$disk" \
1681 |
grep -i "$state" > /dev
/null
2>&1
1688 # Cause a scan of all scsi host adapters by default
1690 # $1 optional host number
1692 function scan_scsi_hosts
1694 typeset hostnum
=${1}
1697 if [[ -z $hostnum ]]; then
1698 for host in /sys
/class
/scsi_host
/host*; do
1699 log_must
eval "echo '- - -' > $host/scan"
1703 "echo /sys/class/scsi_host/host$hostnum/scan" \
1706 "echo '- - -' > /sys/class/scsi_host/host$hostnum/scan"
1711 # Wait for newly created block devices to have their minors created.
1713 function block_device_wait
1722 # Online or offline a disk on the system
1724 # First checks state of disk. Test will fail if disk is not properly onlined
1725 # or offlined. Online is a full rescan of SCSI disks by echoing to every
1728 function on_off_disk
# disk state{online,offline} host
1734 [[ -z $disk ]] ||
[[ -z $state ]] && \
1735 log_fail
"Arguments invalid or missing"
1738 if [[ $state == "offline" ]] && ( is_mpath_device
$disk ); then
1739 dm_name
="$(readlink $DEV_DSKDIR/$disk \
1740 | nawk -F / '{print $2}')"
1741 slave
="$(ls /sys/block/${dm_name}/slaves \
1742 | nawk '{print $1}')"
1743 while [[ -n $slave ]]; do
1744 #check if disk is online
1745 lsscsi |
egrep $slave > /dev
/null
1746 if (($?
== 0)); then
1747 slave_dir
="/sys/block/${dm_name}"
1748 slave_dir
+="/slaves/${slave}/device"
1749 ss
="${slave_dir}/state"
1750 sd
="${slave_dir}/delete"
1751 log_must
eval "echo 'offline' > ${ss}"
1752 log_must
eval "echo '1' > ${sd}"
1753 lsscsi |
egrep $slave > /dev
/null
1754 if (($?
== 0)); then
1755 log_fail
"Offlining" \
1759 slave
="$(ls /sys/block/$dm_name/slaves \
1760 2>/dev/null | nawk '{print $1}')"
1762 elif [[ $state == "offline" ]] && ( is_real_device
$disk ); then
1763 #check if disk is online
1764 lsscsi |
egrep $disk > /dev
/null
1765 if (($?
== 0)); then
1766 dev_state
="/sys/block/$disk/device/state"
1767 dev_delete
="/sys/block/$disk/device/delete"
1768 log_must
eval "echo 'offline' > ${dev_state}"
1769 log_must
eval "echo '1' > ${dev_delete}"
1770 lsscsi |
egrep $disk > /dev
/null
1771 if (($?
== 0)); then
1772 log_fail
"Offlining $disk" \
1776 log_note
"$disk is already offline"
1778 elif [[ $state == "online" ]]; then
1779 #force a full rescan
1780 scan_scsi_hosts
$host
1782 if is_mpath_device
$disk; then
1783 dm_name
="$(readlink $DEV_DSKDIR/$disk \
1784 | nawk -F / '{print $2}')"
1785 slave
="$(ls /sys/block/$dm_name/slaves \
1786 | nawk '{print $1}')"
1787 lsscsi |
egrep $slave > /dev
/null
1788 if (($?
!= 0)); then
1789 log_fail
"Onlining $disk failed"
1791 elif is_real_device
$disk; then
1792 lsscsi |
egrep $disk > /dev
/null
1793 if (($?
!= 0)); then
1794 log_fail
"Onlining $disk failed"
1797 log_fail
"$disk is not a real dev"
1800 log_fail
"$disk failed to $state"
1806 # Get the mountpoint of snapshot
1807 # For the snapshot use <mp_filesystem>/.zfs/snapshot/<snap>
1810 function snapshot_mountpoint
1812 typeset dataset
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
1814 if [[ $dataset != *@
* ]]; then
1815 log_fail
"Error name of snapshot '$dataset'."
1818 typeset fs
=${dataset%@*}
1819 typeset snap
=${dataset#*@}
1821 if [[ -z $fs ||
-z $snap ]]; then
1822 log_fail
"Error name of snapshot '$dataset'."
1825 echo $
(get_prop mountpoint
$fs)/.zfs
/snapshot
/$snap
1829 # Given a device and 'ashift' value verify it's correctly set on every label
1831 function verify_ashift
# device ashift
1836 zdb
-e -lll $device |
awk -v ashift
=$ashift '/ashift: / {
1852 # Given a pool and file system, this function will verify the file system
1853 # using the zdb internal tool. Note that the pool is exported and imported
1854 # to ensure it has consistent state.
1856 function verify_filesys
# pool filesystem dir
1859 typeset filesys
="$2"
1860 typeset zdbout
="/tmp/zdbout.$$"
1865 typeset search_path
=""
1867 log_note
"Calling zdb to verify filesystem '$filesys'"
1868 zfs unmount
-a > /dev
/null
2>&1
1869 log_must zpool
export $pool
1871 if [[ -n $dirs ]] ; then
1872 for dir
in $dirs ; do
1873 search_path
="$search_path -d $dir"
1877 log_must zpool import
$search_path $pool
1879 zdb
-cudi $filesys > $zdbout 2>&1
1880 if [[ $?
!= 0 ]]; then
1881 log_note
"Output: zdb -cudi $filesys"
1883 log_fail
"zdb detected errors with: '$filesys'"
1886 log_must zfs mount
-a
1887 log_must
rm -rf $zdbout
1891 # Given a pool, and this function list all disks in the pool
1893 function get_disklist
# pool
1897 disklist
=$
(zpool iostat
-v $1 | nawk
'(NR >4) {print $1}' | \
1898 grep -v "\-\-\-\-\-" | \
1899 egrep -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
1905 # Given a pool, and this function list all disks in the pool with their full
1906 # path (like "/dev/sda" instead of "sda").
1908 function get_disklist_fullpath
# pool
1917 # This function kills a given list of processes after a time period. We use
1918 # this in the stress tests instead of STF_TIMEOUT so that we can have processes
1919 # run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT
1920 # would be listed as FAIL, which we don't want : we're happy with stress tests
1921 # running for a certain amount of time, then finishing.
1923 # @param $1 the time in seconds after which we should terminate these processes
1924 # @param $2..$n the processes we wish to terminate.
1926 function stress_timeout
1928 typeset
-i TIMEOUT
=$1
1932 log_note
"Waiting for child processes($cpids). " \
1933 "It could last dozens of minutes, please be patient ..."
1934 log_must
sleep $TIMEOUT
1936 log_note
"Killing child processes after ${TIMEOUT} stress timeout."
1938 for pid
in $cpids; do
1939 ps
-p $pid > /dev
/null
2>&1
1940 if (($?
== 0)); then
1941 log_must
kill -USR1 $pid
1947 # Verify a given hotspare disk is inuse or avail
1949 # Return 0 is pool/disk matches expected state, 1 otherwise
1951 function check_hotspare_state
# pool disk state{inuse,avail}
1954 typeset disk
=${2#$DEV_DSKDIR/}
1957 cur_state
=$
(get_device_state
$pool $disk "spares")
1959 if [[ $state != ${cur_state} ]]; then
1966 # Verify a given slog disk is inuse or avail
1968 # Return 0 is pool/disk matches expected state, 1 otherwise
1970 function check_slog_state
# pool disk state{online,offline,unavail}
1973 typeset disk
=${2#$DEV_DSKDIR/}
1976 cur_state
=$
(get_device_state
$pool $disk "logs")
1978 if [[ $state != ${cur_state} ]]; then
1985 # Verify a given vdev disk is inuse or avail
1987 # Return 0 is pool/disk matches expected state, 1 otherwise
1989 function check_vdev_state
# pool disk state{online,offline,unavail}
1992 typeset disk
=${2#$/DEV_DSKDIR/}
1995 cur_state
=$
(get_device_state
$pool $disk)
1997 if [[ $state != ${cur_state} ]]; then
2004 # Check the output of 'zpool status -v <pool>',
2005 # and to see if the content of <token> contain the <keyword> specified.
2007 # Return 0 is contain, 1 otherwise
2009 function check_pool_status
# pool token keyword
2015 zpool status
-v "$pool" 2>/dev
/null | nawk
-v token
="$token:" '
2016 ($1==token) {print $0}' \
2017 |
grep -i "$keyword" > /dev
/null
2>&1
2023 # These 5 following functions are instance of check_pool_status()
2024 # is_pool_resilvering - to check if the pool is resilver in progress
2025 # is_pool_resilvered - to check if the pool is resilver completed
2026 # is_pool_scrubbing - to check if the pool is scrub in progress
2027 # is_pool_scrubbed - to check if the pool is scrub completed
2028 # is_pool_scrub_stopped - to check if the pool is scrub stopped
2030 function is_pool_resilvering
#pool
2032 check_pool_status
"$1" "scan" "resilver in progress since "
2036 function is_pool_resilvered
#pool
2038 check_pool_status
"$1" "scan" "resilvered "
2042 function is_pool_scrubbing
#pool
2044 check_pool_status
"$1" "scan" "scrub in progress since "
2048 function is_pool_scrubbed
#pool
2050 check_pool_status
"$1" "scan" "scrub repaired"
2054 function is_pool_scrub_stopped
#pool
2056 check_pool_status
"$1" "scan" "scrub canceled"
2061 # Use create_pool()/destroy_pool() to clean up the information in
2062 # in the given disk to avoid slice overlapping.
2064 function cleanup_devices
#vdevs
2066 typeset pool
="foopool$$"
2068 if poolexists
$pool ; then
2072 create_pool
$pool $@
2079 # A function to find and locate free disks on a system or from given
2080 # disks as the parameter. It works by locating disks that are in use
2081 # as swap devices and dump devices, and also disks listed in /etc/vfstab
2083 # $@ given disks to find which are free, default is all disks in
2086 # @return a string containing the list of available disks
2090 # Trust provided list, no attempt is made to locate unused devices.
2097 sfi
=/tmp
/swaplist.$$
2098 dmpi
=/tmp
/dumpdev.$$
2099 max_finddisksnum
=${MAX_FINDDISKSNUM:-6}
2102 dumpadm
> $dmpi 2>/dev
/null
2104 # write an awk script that can process the output of format
2105 # to produce a list of disks we know about. Note that we have
2106 # to escape "$2" so that the shell doesn't interpret it while
2107 # we're creating the awk script.
2108 # -------------------
2109 cat > /tmp
/find_disks.
awk <<EOF
2118 if (searchdisks && \$2 !~ "^$"){
2124 /^AVAILABLE DISK SELECTIONS:/{
2128 #---------------------
2130 chmod 755 /tmp
/find_disks.
awk
2131 disks
=${@:-$(echo "" | format -e 2>/dev/null | /tmp/find_disks.awk)}
2132 rm /tmp
/find_disks.
awk
2135 for disk
in $disks; do
2137 grep "${disk}[sp]" /etc
/mnttab
>/dev
/null
2138 (($?
== 0)) && continue
2140 grep "${disk}[sp]" $sfi >/dev
/null
2141 (($?
== 0)) && continue
2142 # check for dump device
2143 grep "${disk}[sp]" $dmpi >/dev
/null
2144 (($?
== 0)) && continue
2145 # check to see if this disk hasn't been explicitly excluded
2146 # by a user-set environment variable
2147 echo "${ZFS_HOST_DEVICES_IGNORE}" |
grep "${disk}" > /dev
/null
2148 (($?
== 0)) && continue
2149 unused_candidates
="$unused_candidates $disk"
2154 # now just check to see if those disks do actually exist
2155 # by looking for a device pointing to the first slice in
2156 # each case. limit the number to max_finddisksnum
2158 for disk
in $unused_candidates; do
2159 if [ -b $DEV_DSKDIR/${disk}s0
]; then
2160 if [ $count -lt $max_finddisksnum ]; then
2161 unused
="$unused $disk"
2162 # do not impose limit if $@ is provided
2163 [[ -z $@
]] && ((count
= count
+ 1))
2168 # finally, return our disk list
2173 # Add specified user to specified group
2177 # $3 base of the homedir (optional)
2179 function add_user
#<group_name> <user_name> <basedir>
2183 typeset basedir
=${3:-"/var/tmp"}
2185 if ((${#gname} == 0 ||
${#uname} == 0)); then
2186 log_fail
"group name or user name are not defined."
2189 log_must useradd
-g $gname -d $basedir/$uname -m $uname
2190 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.profile
2191 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.bash_profile
2192 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.login
2194 # Add new users to the same group and the command line utils.
2195 # This allows them to be run out of the original users home
2196 # directory as long as it permissioned to be group readable.
2198 cmd_group
=$
(stat
--format="%G" $
(which zfs
))
2199 log_must usermod
-a -G $cmd_group $uname
2206 # Delete the specified user.
2209 # $2 base of the homedir (optional)
2211 function del_user
#<logname> <basedir>
2214 typeset basedir
=${2:-"/var/tmp"}
2216 if ((${#user} == 0)); then
2217 log_fail
"login name is necessary."
2220 if id
$user > /dev
/null
2>&1; then
2221 log_must userdel
$user
2224 [[ -d $basedir/$user ]] && rm -fr $basedir/$user
2230 # Select valid gid and create specified group.
2234 function add_group
#<group_name>
2238 if ((${#group} == 0)); then
2239 log_fail
"group name is necessary."
2242 # Assign 100 as the base gid, a larger value is selected for
2243 # Linux because for many distributions 1000 and under are reserved.
2246 groupadd
$group > /dev
/null
2>&1
2256 groupadd
-g $gid $group > /dev
/null
2>&1
2260 # The gid is not unique
2269 # Delete the specified group.
2273 function del_group
#<group_name>
2276 if ((${#grp} == 0)); then
2277 log_fail
"group name is necessary."
2281 getent group
$grp > /dev
/null
2>&1
2284 # Group does not exist.
2286 # Name already exists as a group name
2287 0) log_must groupdel
$grp ;;
2291 groupmod
-n $grp $grp > /dev
/null
2>&1
2294 # Group does not exist.
2296 # Name already exists as a group name
2297 9) log_must groupdel
$grp ;;
2306 # This function will return true if it's safe to destroy the pool passed
2307 # as argument 1. It checks for pools based on zvols and files, and also
2308 # files contained in a pool that may have a different mountpoint.
2310 function safe_to_destroy_pool
{ # $1 the pool name
2313 typeset DONT_DESTROY
=""
2315 # We check that by deleting the $1 pool, we're not
2316 # going to pull the rug out from other pools. Do this
2317 # by looking at all other pools, ensuring that they
2318 # aren't built from files or zvols contained in this pool.
2320 for pool
in $
(zpool list
-H -o name
)
2324 # this is a list of the top-level directories in each of the
2325 # files that make up the path to the files the pool is based on
2326 FILEPOOL
=$
(zpool status
-v $pool |
grep /$1/ | \
2329 # this is a list of the zvols that make up the pool
2330 ZVOLPOOL
=$
(zpool status
-v $pool |
grep "$ZVOL_DEVDIR/$1$" \
2333 # also want to determine if it's a file-based pool using an
2334 # alternate mountpoint...
2335 POOL_FILE_DIRS
=$
(zpool status
-v $pool | \
2336 grep / |
awk '{print $1}' | \
2337 awk -F/ '{print $2}' |
grep -v "dev")
2339 for pooldir
in $POOL_FILE_DIRS
2341 OUTPUT
=$
(zfs list
-H -r -o mountpoint
$1 | \
2342 grep "${pooldir}$" |
awk '{print $1}')
2344 ALTMOUNTPOOL
="${ALTMOUNTPOOL}${OUTPUT}"
2348 if [ ! -z "$ZVOLPOOL" ]
2351 log_note
"Pool $pool is built from $ZVOLPOOL on $1"
2354 if [ ! -z "$FILEPOOL" ]
2357 log_note
"Pool $pool is built from $FILEPOOL on $1"
2360 if [ ! -z "$ALTMOUNTPOOL" ]
2363 log_note
"Pool $pool is built from $ALTMOUNTPOOL on $1"
2367 if [ -z "${DONT_DESTROY}" ]
2371 log_note
"Warning: it is not safe to destroy $1!"
2377 # Get the available ZFS compression options
2378 # $1 option type zfs_set|zfs_compress
2380 function get_compress_opts
2382 typeset COMPRESS_OPTS
2383 typeset GZIP_OPTS
="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \
2384 gzip-6 gzip-7 gzip-8 gzip-9"
2386 if [[ $1 == "zfs_compress" ]] ; then
2387 COMPRESS_OPTS
="on lzjb"
2388 elif [[ $1 == "zfs_set" ]] ; then
2389 COMPRESS_OPTS
="on off lzjb"
2391 typeset valid_opts
="$COMPRESS_OPTS"
2392 zfs get
2>&1 |
grep gzip >/dev
/null
2>&1
2393 if [[ $?
-eq 0 ]]; then
2394 valid_opts
="$valid_opts $GZIP_OPTS"
2400 # Verify zfs operation with -p option work as expected
2401 # $1 operation, value could be create, clone or rename
2402 # $2 dataset type, value could be fs or vol
2404 # $4 new dataset name
2406 function verify_opt_p_ops
2411 typeset newdataset
=$4
2413 if [[ $datatype != "fs" && $datatype != "vol" ]]; then
2414 log_fail
"$datatype is not supported."
2417 # check parameters accordingly
2422 if [[ $datatype == "vol" ]]; then
2423 ops
="create -V $VOLSIZE"
2427 if [[ -z $newdataset ]]; then
2428 log_fail
"newdataset should not be empty" \
2431 log_must datasetexists
$dataset
2432 log_must snapexists
$dataset
2435 if [[ -z $newdataset ]]; then
2436 log_fail
"newdataset should not be empty" \
2439 log_must datasetexists
$dataset
2440 log_mustnot snapexists
$dataset
2443 log_fail
"$ops is not supported."
2447 # make sure the upper level filesystem does not exist
2448 if datasetexists
${newdataset%/*} ; then
2449 log_must zfs destroy
-rRf ${newdataset%/*}
2452 # without -p option, operation will fail
2453 log_mustnot zfs
$ops $dataset $newdataset
2454 log_mustnot datasetexists
$newdataset ${newdataset%/*}
2456 # with -p option, operation should succeed
2457 log_must zfs
$ops -p $dataset $newdataset
2460 if ! datasetexists
$newdataset ; then
2461 log_fail
"-p option does not work for $ops"
2464 # when $ops is create or clone, redo the operation still return zero
2465 if [[ $ops != "rename" ]]; then
2466 log_must zfs
$ops -p $dataset $newdataset
2473 # Get configuration of pool
2483 if ! poolexists
"$pool" ; then
2486 alt_root
=$
(zpool list
-H $pool |
awk '{print $NF}')
2487 if [[ $alt_root == "-" ]]; then
2488 value
=$
(zdb
-C $pool |
grep "$config:" |
awk -F: \
2491 value
=$
(zdb
-e $pool |
grep "$config:" |
awk -F: \
2494 if [[ -n $value ]] ; then
2504 # Privated function. Random select one of items from arguments.
2509 function _random_get
2516 ((ind
= RANDOM
% cnt
+ 1))
2518 typeset ret
=$
(echo "$str" | cut
-f $ind -d ' ')
2523 # Random select one of item from arguments which include NONE string
2525 function random_get_with_non
2530 _random_get
"$cnt" "$@"
2534 # Random select one of item from arguments which doesn't include NONE string
2538 _random_get
"$#" "$@"
2542 # Detect if the current system support slog
2544 function verify_slog_support
2546 typeset dir
=/tmp
/disk.$$
2552 mkfile
$MINVDEVSIZE $vdev $sdev
2555 if ! zpool create
-n $pool $vdev log
$sdev > /dev
/null
2>&1; then
2564 # The function will generate a dataset name with specific length
2565 # $1, the length of the name
2566 # $2, the base string to construct the name
2568 function gen_dataset_name
2571 typeset basestr
="$2"
2572 typeset
-i baselen
=${#basestr}
2576 if ((len
% baselen
== 0)); then
2577 ((iter
= len
/ baselen
))
2579 ((iter
= len
/ baselen
+ 1))
2581 while ((iter
> 0)); do
2582 l_name
="${l_name}$basestr"
2591 # Get cksum tuple of dataset
2594 # sample zdb output:
2595 # Dataset data/test [ZPL], ID 355, cr_txg 2413856, 31.0K, 7 objects, rootbp
2596 # DVA[0]=<0:803046400:200> DVA[1]=<0:81199000:200> [L0 DMU objset] fletcher4
2597 # lzjb LE contiguous unique double size=800L/200P birth=2413856L/2413856P
2598 # fill=7 cksum=11ce125712:643a9c18ee2:125e25238fca0:254a3f74b59744
2599 function datasetcksum
2603 cksum=$
(zdb
-vvv $1 |
grep "^Dataset $1 \[" |
grep "cksum" \
2604 |
awk -F= '{print $7}')
2615 cksum=$
(cksum $1 |
awk '{print $1}')
2620 # Get the given disk/slice state from the specific field of the pool
2622 function get_device_state
#pool disk field("", "spares","logs")
2625 typeset disk
=${2#$DEV_DSKDIR/}
2626 typeset field
=${3:-$pool}
2628 state
=$
(zpool status
-v "$pool" 2>/dev
/null | \
2629 nawk
-v device
=$disk -v pool
=$pool -v field
=$field \
2630 'BEGIN {startconfig=0; startfield=0; }
2631 /config:/ {startconfig=1}
2632 (startconfig==1) && ($1==field) {startfield=1; next;}
2633 (startfield==1) && ($1==device) {print $2; exit;}
2635 ($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}')
2641 # print the given directory filesystem type
2649 if [[ -z $dir ]]; then
2650 log_fail
"Usage: get_fstype <directory>"
2657 df
-n $dir |
awk '{print $3}'
2661 # Given a disk, label it to VTOC regardless what label was on the disk
2667 if [[ -z $disk ]]; then
2668 log_fail
"The disk name is unspecified."
2670 typeset label_file
=/var
/tmp
/labelvtoc.$$
2671 typeset arch
=$
(uname
-p)
2674 log_note
"Currently unsupported by the test framework"
2678 if [[ $arch == "i386" ]]; then
2679 echo "label" > $label_file
2680 echo "0" >> $label_file
2681 echo "" >> $label_file
2682 echo "q" >> $label_file
2683 echo "q" >> $label_file
2685 fdisk
-B $disk >/dev
/null
2>&1
2686 # wait a while for fdisk finishes
2688 elif [[ $arch == "sparc" ]]; then
2689 echo "label" > $label_file
2690 echo "0" >> $label_file
2691 echo "" >> $label_file
2692 echo "" >> $label_file
2693 echo "" >> $label_file
2694 echo "q" >> $label_file
2696 log_fail
"unknown arch type"
2699 format
-e -s -d $disk -f $label_file
2700 typeset
-i ret_val
=$?
2703 # wait the format to finish
2706 if ((ret_val
!= 0)); then
2707 log_fail
"unable to label $disk as VTOC."
2714 # check if the system was installed as zfsroot or not
2715 # return: 0 ture, otherwise false
2719 df
-n / |
grep zfs
> /dev
/null
2>&1
2724 # get the root filesystem name if it's zfsroot system.
2726 # return: root filesystem name
2732 rootfs
=$
(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \
2735 if [[ -z "$rootfs" ]]; then
2736 log_fail
"Can not get rootfs"
2738 zfs list
$rootfs > /dev
/null
2>&1
2739 if (($?
== 0)); then
2742 log_fail
"This is not a zfsroot system."
2747 # get the rootfs's pool name
2751 function get_rootpool
2757 rootfs
=$
(awk '{if ($2 == "/" && $3 =="zfs") print $1}' \
2760 if [[ -z "$rootfs" ]]; then
2761 log_fail
"Can not get rootpool"
2763 zfs list
$rootfs > /dev
/null
2>&1
2764 if (($?
== 0)); then
2765 rootpool
=`echo $rootfs | awk -F\/ '{print $1}'`
2768 log_fail
"This is not a zfsroot system."
2773 # Check if the given device is physical device
2775 function is_physical_device
#device
2777 typeset device
=${1#$DEV_DSKDIR}
2778 device
=${device#$DEV_RDSKDIR}
2781 [[ -b "$DEV_DSKDIR/$device" ]] && \
2782 [[ -f /sys
/module
/loop
/parameters
/max_part
]]
2785 echo $device |
egrep "^c[0-F]+([td][0-F]+)+$" > /dev
/null
2>&1
2791 # Check if the given device is a real device (ie SCSI device)
2793 function is_real_device
#disk
2796 [[ -z $disk ]] && log_fail
"No argument for disk given."
2799 lsblk
$DEV_RDSKDIR/$disk -o TYPE
2>/dev
/null | \
2800 egrep disk
>/dev
/null
2806 # Check if the given device is a loop device
2808 function is_loop_device
#disk
2811 [[ -z $disk ]] && log_fail
"No argument for disk given."
2814 lsblk
$DEV_RDSKDIR/$disk -o TYPE
2>/dev
/null | \
2815 egrep loop
>/dev
/null
2821 # Check if the given device is a multipath device and if there is a sybolic
2822 # link to a device mapper and to a disk
2823 # Currently no support for dm devices alone without multipath
2825 function is_mpath_device
#disk
2828 [[ -z $disk ]] && log_fail
"No argument for disk given."
2831 lsblk
$DEV_MPATHDIR/$disk -o TYPE
2>/dev
/null | \
2832 egrep mpath
>/dev
/null
2833 if (($?
== 0)); then
2834 readlink
$DEV_MPATHDIR/$disk > /dev
/null
2>&1
2842 # Set the slice prefix for disk partitioning depending
2843 # on whether the device is a real, multipath, or loop device.
2844 # Currently all disks have to be of the same type, so only
2845 # checks first disk to determine slice prefix.
2847 function set_slice_prefix
2853 while (( i
< $DISK_ARRAY_NUM )); do
2854 disk
="$(echo $DISKS | nawk '{print $(i + 1)}')"
2855 if ( is_mpath_device
$disk ) && [[ -z $
(echo $disk |
awk 'substr($1,18,1)\
2856 ~ /^[[:digit:]]+$/') ]] ||
( is_real_device
$disk ); then
2857 export SLICE_PREFIX
=""
2859 elif ( is_mpath_device
$disk || is_loop_device \
2861 export SLICE_PREFIX
="p"
2864 log_fail
"$disk not supported for partitioning."
2872 # Set the directory path of the listed devices in $DISK_ARRAY_NUM
2873 # Currently all disks have to be of the same type, so only
2874 # checks first disk to determine device directory
2875 # default = /dev (linux)
2876 # real disk = /dev (linux)
2877 # multipath device = /dev/mapper (linux)
2879 function set_device_dir
2885 while (( i
< $DISK_ARRAY_NUM )); do
2886 disk
="$(echo $DISKS | nawk '{print $(i + 1)}')"
2887 if is_mpath_device
$disk; then
2888 export DEV_DSKDIR
=$DEV_MPATHDIR
2891 export DEV_DSKDIR
=$DEV_RDSKDIR
2897 export DEV_DSKDIR
=$DEV_RDSKDIR
2902 # Get the directory path of given device
2904 function get_device_dir
#device
2908 if ! $
(is_physical_device
$device) ; then
2909 if [[ $device != "/" ]]; then
2912 if [[ -b "$DEV_DSKDIR/$device" ]]; then
2913 device
="$DEV_DSKDIR"
2922 # Get persistent name for given disk
2924 function get_persistent_disk_name
#device
2930 if is_real_device
$device; then
2931 dev_id
="$(udevadm info -q all -n $DEV_DSKDIR/$device \
2932 | egrep disk/by-id | nawk '{print $2; exit}' \
2933 | nawk -F / '{print $3}')"
2935 elif is_mpath_device
$device; then
2936 dev_id
="$(udevadm info -q all -n $DEV_DSKDIR/$device \
2937 | egrep disk/by-id/dm-uuid \
2938 | nawk '{print $2; exit}' \
2939 | nawk -F / '{print $3}')"
2950 # Load scsi_debug module with specified parameters
2952 function load_scsi_debug
# dev_size_mb add_host num_tgts max_luns
2959 [[ -z $devsize ]] ||
[[ -z $hosts ]] ||
[[ -z $tgts ]] || \
2960 [[ -z $luns ]] && log_fail
"Arguments invalid or missing"
2963 modprobe
-n scsi_debug
2964 if (($?
!= 0)); then
2965 log_unsupported
"Platform does not have scsi_debug"
2968 lsmod |
egrep scsi_debug
> /dev
/null
2969 if (($?
== 0)); then
2970 log_fail
"scsi_debug module already installed"
2972 log_must modprobe scsi_debug dev_size_mb
=$devsize \
2973 add_host
=$hosts num_tgts
=$tgts max_luns
=$luns
2975 lsscsi |
egrep scsi_debug
> /dev
/null
2976 if (($?
== 1)); then
2977 log_fail
"scsi_debug module install failed"
2984 # Get the package name
2986 function get_package_name
2988 typeset dirpath
=${1:-$STC_NAME}
2990 echo "SUNWstc-${dirpath}" |
/usr
/bin
/sed -e "s/\//-/g"
2994 # Get the word numbers from a string separated by white space
2996 function get_word_count
3002 # To verify if the require numbers of disks is given
3004 function verify_disk_count
3006 typeset
-i min
=${2:-1}
3008 typeset
-i count
=$
(get_word_count
"$1")
3010 if ((count
< min
)); then
3011 log_untested
"A minimum of $min disks is required to run." \
3012 " You specified $count disk(s)"
3016 function ds_is_volume
3018 typeset
type=$
(get_prop
type $1)
3019 [[ $type = "volume" ]] && return 0
3023 function ds_is_filesystem
3025 typeset
type=$
(get_prop
type $1)
3026 [[ $type = "filesystem" ]] && return 0
3030 function ds_is_snapshot
3032 typeset
type=$
(get_prop
type $1)
3033 [[ $type = "snapshot" ]] && return 0
3038 # Check if Trusted Extensions are installed and enabled
3040 function is_te_enabled
3042 svcs
-H -o state labeld
2>/dev
/null |
grep "enabled"
3043 if (($?
!= 0)); then
3050 # Utility function to determine if a system has multiple cpus.
3056 (($
(psrinfo |
wc -l) > 1))
3062 function get_cpu_freq
3065 lscpu |
awk '/CPU MHz/ { print $3 }'
3067 psrinfo
-v 0 |
awk '/processor operates at/ {print $6}'
3071 # Run the given command as the user provided.
3077 log_note
"user:$user $@"
3078 eval su
- \
$user -c \"$@
\" > /tmp
/out
2>/tmp
/err
3083 # Check if the pool contains the specified vdevs
3088 # Return 0 if the vdevs are contained in the pool, 1 if any of the specified
3089 # vdevs is not in the pool, and 2 if pool name is missing.
3091 function vdevs_in_pool
3096 if [[ -z $pool ]]; then
3097 log_note
"Missing pool name."
3103 typeset tmpfile
=$
(mktemp
)
3104 zpool list
-Hv "$pool" >$tmpfile
3106 grep -w ${vdev##*/} $tmpfile >/dev
/null
2>&1
3107 [[ $?
-ne 0 ]] && return 1
3121 max
=$
(echo $
((max
> i ? max
: i
)))
3133 min
=$
(echo $
((min
< i ? min
: i
)))
3140 # Generate a random number between 1 and the argument.
3145 echo $
(( ($RANDOM % $max) + 1 ))
3148 # Write data that can be compressed into a directory
3149 function write_compressible
3153 typeset nfiles
=${3:-1}
3154 typeset bs
=${4:-1024k}
3155 typeset fname
=${5:-file}
3157 [[ -d $dir ]] || log_fail
"No directory: $dir"
3159 # Under Linux fio is not currently used since its behavior can
3160 # differ significantly across versions. This includes missing
3161 # command line options and cases where the --buffer_compress_*
3162 # options fail to behave as expected.
3164 typeset file_bytes
=$
(to_bytes
$megs)
3165 typeset bs_bytes
=4096
3166 typeset blocks
=$
(($file_bytes / $bs_bytes))
3168 for (( i
= 0; i
< $nfiles; i
++ )); do
3169 truncate
-s $file_bytes $dir/$fname.
$i
3171 # Write every third block to get 66% compression.
3172 for (( j
= 0; j
< $blocks; j
+= 3 )); do
3173 dd if=/dev
/urandom of
=$dir/$fname.
$i \
3174 seek
=$j bs
=$bs_bytes count
=1 \
3175 conv
=notrunc
>/dev
/null
2>&1
3179 log_must
eval "fio \
3184 --buffer_compress_percentage=66 \
3185 --buffer_compress_chunk=4096 \
3192 --filename_format='$fname.\$jobnum' >/dev/null"
3201 [[ -e $pathname ]] || log_fail
"No such file or directory: $pathname"
3202 objnum
=$
(stat
-c %i
$pathname)
3207 # Sync data to the pool
3210 # $2 boolean to force uberblock (and config including zpool cache file) update
3212 function sync_pool
#pool <force>
3214 typeset pool
=${1:-$TESTPOOL}
3215 typeset force
=${2:-false}
3217 if [[ $force == true
]]; then
3218 log_must zpool sync
-f $pool
3220 log_must zpool sync
$pool
3227 # Wait for zpool 'freeing' property drops to zero.
3231 function wait_freeing
#pool
3233 typeset pool
=${1:-$TESTPOOL}
3235 [[ "0" == "$(zpool list -Ho freeing $pool)" ]] && break
3241 # Wait for every device replace operation to complete
3245 function wait_replacing
#pool
3247 typeset pool
=${1:-$TESTPOOL}
3249 [[ "" == "$(zpool status $pool |
3250 awk '/replacing-[0-9]+/ {print $1}')" ]] && break
3256 # Check if ZED is currently running, if not start ZED.
3261 # ZEDLET_DIR=/var/tmp/zed
3262 if [[ ! -d $ZEDLET_DIR ]]; then
3263 log_must mkdir
$ZEDLET_DIR
3266 # Verify the ZED is not already running.
3267 pgrep
-x zed
> /dev
/null
3268 if (($?
== 0)); then
3269 log_fail
"ZED already running"
3272 # ZEDLETDIR=</etc/zfs/zed.d | ${SRCDIR}/cmd/zed/zed.d>
3273 log_must
cp ${ZEDLETDIR}/all-syslog.sh
$ZEDLET_DIR
3275 log_note
"Starting ZED"
3276 # run ZED in the background and redirect foreground logging
3278 log_must
eval "zed -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid" \
3279 "-s $ZEDLET_DIR/state 2>${ZEDLET_DIR}/zedlog &"
3289 if [[ -f ${ZEDLET_DIR}/zed.pid
]]; then
3290 zedpid
=$
(cat ${ZEDLET_DIR}/zed.pid
)
3291 log_must
kill $zedpid
3293 log_must
rm -f ${ZEDLET_DIR}/all-syslog.sh
3294 log_must
rm -f ${ZEDLET_DIR}/zed.pid
3295 log_must
rm -f ${ZEDLET_DIR}/zedlog
3296 log_must
rm -f ${ZEDLET_DIR}/state
3297 log_must
rmdir $ZEDLET_DIR
3302 # Check is provided device is being active used as a swap device.
3304 function is_swap_inuse
3308 if [[ -z $device ]] ; then
3309 log_note
"No device specified."
3314 swapon
-s |
grep -w $
(readlink
-f $device) > /dev
/null
2>&1
3316 swap
-l |
grep -w $device > /dev
/null
2>&1
3323 # Setup a swap device using the provided device.
3330 log_must mkswap
$swapdev > /dev
/null
2>&1
3331 log_must swapon
$swapdev
3333 log_must swap
-a $swapdev
3340 # Cleanup a swap device on the provided device.
3342 function swap_cleanup
3346 if is_swap_inuse
$swapdev; then
3348 log_must swapoff
$swapdev
3350 log_must swap
-d $swapdev