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.
31 .
${STF_TOOLS}/include
/logapi.shlib
34 # Apply constrained path when available. This is required since the
35 # PATH may have been modified by sudo's secure_path behavior.
37 if [ -n "$STF_PATH" ]; then
41 # Determine if this is a Linux test system
43 # Return 0 if platform Linux, 1 if otherwise
47 if [[ $
(uname
-o) == "GNU/Linux" ]]; then
54 # Determine if this is a 32-bit system
56 # Return 0 if platform is 32-bit, 1 if otherwise
60 if [[ $
(getconf LONG_BIT
) == "32" ]]; then
67 # Determine if kmemleak is enabled
69 # Return 0 if kmemleak is enabled, 1 if otherwise
73 if is_linux
&& [[ -e /sys
/kernel
/debug
/kmemleak
]]; then
80 # Determine whether a dataset is mounted
83 # $2 filesystem type; optional - defaulted to zfs
85 # Return 0 if dataset is mounted; 1 if unmounted; 2 on error
90 [[ -z $fstype ]] && fstype
=zfs
91 typeset out dir name ret
95 if [[ "$1" == "/"* ]] ; then
96 for out
in $
(zfs mount |
awk '{print $2}'); do
97 [[ $1 == $out ]] && return 0
100 for out
in $
(zfs mount |
awk '{print $1}'); do
101 [[ $1 == $out ]] && return 0
106 out
=$
(df
-F $fstype $1 2>/dev
/null
)
108 (($ret != 0)) && return $ret
116 [[ "$1" == "$dir" ||
"$1" == "$name" ]] && return 0
119 out
=$
(df
-t $fstype $1 2>/dev
/null
)
123 if [[ -L "$ZVOL_DEVDIR/$1" ]]; then
124 link
=$
(readlink
-f $ZVOL_DEVDIR/$1)
125 [[ -n "$link" ]] && \
126 mount |
grep -q "^$link" && \
135 # Return 0 if a dataset is mounted; 1 otherwise
138 # $2 filesystem type; optional - defaulted to zfs
143 (($?
== 0)) && return 0
147 # Return 0 if a dataset is unmounted; 1 otherwise
150 # $2 filesystem type; optional - defaulted to zfs
155 (($?
== 1)) && return 0
165 echo $1 |
sed "s/,/ /g"
168 function default_setup
170 default_setup_noexit
"$@"
176 # Given a list of disks, setup storage pools and datasets.
178 function default_setup_noexit
183 log_note begin default_setup_noexit
185 if is_global_zone
; then
186 if poolexists
$TESTPOOL ; then
187 destroy_pool
$TESTPOOL
189 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
190 log_must zpool create
-f $TESTPOOL $disklist
195 rm -rf $TESTDIR || log_unresolved Could not remove
$TESTDIR
196 mkdir
-p $TESTDIR || log_unresolved Could not create
$TESTDIR
198 log_must zfs create
$TESTPOOL/$TESTFS
199 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
201 if [[ -n $container ]]; then
202 rm -rf $TESTDIR1 || \
203 log_unresolved Could not remove
$TESTDIR1
204 mkdir
-p $TESTDIR1 || \
205 log_unresolved Could not create
$TESTDIR1
207 log_must zfs create
$TESTPOOL/$TESTCTR
208 log_must zfs
set canmount
=off
$TESTPOOL/$TESTCTR
209 log_must zfs create
$TESTPOOL/$TESTCTR/$TESTFS1
210 log_must zfs
set mountpoint
=$TESTDIR1 \
211 $TESTPOOL/$TESTCTR/$TESTFS1
214 if [[ -n $volume ]]; then
215 if is_global_zone
; then
216 log_must zfs create
-V $VOLSIZE $TESTPOOL/$TESTVOL
219 log_must zfs create
$TESTPOOL/$TESTVOL
225 # Given a list of disks, setup a storage pool, file system and
228 function default_container_setup
232 default_setup
"$disklist" "true"
236 # Given a list of disks, setup a storage pool,file system
239 function default_volume_setup
243 default_setup
"$disklist" "" "true"
247 # Given a list of disks, setup a storage pool,file system,
248 # a container and a volume.
250 function default_container_volume_setup
254 default_setup
"$disklist" "true" "true"
258 # Create a snapshot on a filesystem or volume. Defaultly create a snapshot on
261 # $1 Existing filesystem or volume name. Default, $TESTFS
262 # $2 snapshot name. Default, $TESTSNAP
264 function create_snapshot
266 typeset fs_vol
=${1:-$TESTFS}
267 typeset snap
=${2:-$TESTSNAP}
269 [[ -z $fs_vol ]] && log_fail
"Filesystem or volume's name is undefined."
270 [[ -z $snap ]] && log_fail
"Snapshot's name is undefined."
272 if snapexists
$fs_vol@
$snap; then
273 log_fail
"$fs_vol@$snap already exists."
275 datasetexists
$fs_vol || \
276 log_fail
"$fs_vol must exist."
278 log_must zfs snapshot
$fs_vol@
$snap
282 # Create a clone from a snapshot, default clone name is $TESTCLONE.
284 # $1 Existing snapshot, $TESTPOOL/$TESTFS@$TESTSNAP is default.
285 # $2 Clone name, $TESTPOOL/$TESTCLONE is default.
287 function create_clone
# snapshot clone
289 typeset snap
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
290 typeset clone
=${2:-$TESTPOOL/$TESTCLONE}
293 log_fail
"Snapshot name is undefined."
295 log_fail
"Clone name is undefined."
297 log_must zfs clone
$snap $clone
301 # Create a bookmark of the given snapshot. Defaultly create a bookmark on
304 # $1 Existing filesystem or volume name. Default, $TESTFS
305 # $2 Existing snapshot name. Default, $TESTSNAP
306 # $3 bookmark name. Default, $TESTBKMARK
308 function create_bookmark
310 typeset fs_vol
=${1:-$TESTFS}
311 typeset snap
=${2:-$TESTSNAP}
312 typeset bkmark
=${3:-$TESTBKMARK}
314 [[ -z $fs_vol ]] && log_fail
"Filesystem or volume's name is undefined."
315 [[ -z $snap ]] && log_fail
"Snapshot's name is undefined."
316 [[ -z $bkmark ]] && log_fail
"Bookmark's name is undefined."
318 if bkmarkexists
$fs_vol#$bkmark; then
319 log_fail
"$fs_vol#$bkmark already exists."
321 datasetexists
$fs_vol || \
322 log_fail
"$fs_vol must exist."
323 snapexists
$fs_vol@
$snap || \
324 log_fail
"$fs_vol@$snap must exist."
326 log_must zfs bookmark
$fs_vol@
$snap $fs_vol#$bkmark
329 function default_mirror_setup
331 default_mirror_setup_noexit
$1 $2 $3
337 # Given a pair of disks, set up a storage pool and dataset for the mirror
338 # @parameters: $1 the primary side of the mirror
339 # $2 the secondary side of the mirror
340 # @uses: ZPOOL ZFS TESTPOOL TESTFS
341 function default_mirror_setup_noexit
343 readonly func
="default_mirror_setup_noexit"
347 [[ -z $primary ]] && \
348 log_fail
"$func: No parameters passed"
349 [[ -z $secondary ]] && \
350 log_fail
"$func: No secondary partition passed"
351 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
352 log_must zpool create
-f $TESTPOOL mirror $@
353 log_must zfs create
$TESTPOOL/$TESTFS
354 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
358 # create a number of mirrors.
359 # We create a number($1) of 2 way mirrors using the pairs of disks named
360 # on the command line. These mirrors are *not* mounted
361 # @parameters: $1 the number of mirrors to create
362 # $... the devices to use to create the mirrors on
363 # @uses: ZPOOL ZFS TESTPOOL
364 function setup_mirrors
366 typeset
-i nmirrors
=$1
369 while ((nmirrors
> 0)); do
370 log_must
test -n "$1" -a -n "$2"
371 [[ -d /$TESTPOOL$nmirrors ]] && rm -rf /$TESTPOOL$nmirrors
372 log_must zpool create
-f $TESTPOOL$nmirrors mirror
$1 $2
374 ((nmirrors
= nmirrors
- 1))
379 # create a number of raidz pools.
380 # We create a number($1) of 2 raidz pools using the pairs of disks named
381 # on the command line. These pools are *not* mounted
382 # @parameters: $1 the number of pools to create
383 # $... the devices to use to create the pools on
384 # @uses: ZPOOL ZFS TESTPOOL
385 function setup_raidzs
387 typeset
-i nraidzs
=$1
390 while ((nraidzs
> 0)); do
391 log_must
test -n "$1" -a -n "$2"
392 [[ -d /$TESTPOOL$nraidzs ]] && rm -rf /$TESTPOOL$nraidzs
393 log_must zpool create
-f $TESTPOOL$nraidzs raidz
$1 $2
395 ((nraidzs
= nraidzs
- 1))
400 # Destroy the configured testpool mirrors.
401 # the mirrors are of the form ${TESTPOOL}{number}
402 # @uses: ZPOOL ZFS TESTPOOL
403 function destroy_mirrors
405 default_cleanup_noexit
411 # Given a minimum of two disks, set up a storage pool and dataset for the raid-z
412 # $1 the list of disks
414 function default_raidz_setup
416 typeset disklist
="$*"
417 disks
=(${disklist[*]})
419 if [[ ${#disks[*]} -lt 2 ]]; then
420 log_fail
"A raid-z requires a minimum of two disks."
423 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
424 log_must zpool create
-f $TESTPOOL raidz
$1 $2 $3
425 log_must zfs create
$TESTPOOL/$TESTFS
426 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
432 # Common function used to cleanup storage pools and datasets.
434 # Invoked at the start of the test suite to ensure the system
435 # is in a known state, and also at the end of each set of
436 # sub-tests to ensure errors from one set of tests doesn't
437 # impact the execution of the next set.
439 function default_cleanup
441 default_cleanup_noexit
446 function default_cleanup_noexit
451 # Destroying the pool will also destroy any
452 # filesystems it contains.
454 if is_global_zone
; then
455 zfs unmount
-a > /dev
/null
2>&1
456 exclude
=`eval echo \"'(${KEEP})'\"`
457 ALL_POOLS
=$
(zpool list
-H -o name \
458 |
grep -v "$NO_POOLS" |
egrep -v "$exclude")
459 # Here, we loop through the pools we're allowed to
460 # destroy, only destroying them if it's safe to do
462 while [ ! -z ${ALL_POOLS} ]
464 for pool
in ${ALL_POOLS}
466 if safe_to_destroy_pool
$pool ;
470 ALL_POOLS
=$
(zpool list
-H -o name \
471 |
grep -v "$NO_POOLS" \
472 |
egrep -v "$exclude")
479 for fs
in $
(zfs list
-H -o name \
480 |
grep "^$ZONE_POOL/$ZONE_CTR[01234]/"); do
481 datasetexists
$fs && \
482 log_must zfs destroy
-Rf $fs
485 # Need cleanup here to avoid garbage dir left.
486 for fs
in $
(zfs list
-H -o name
); do
487 [[ $fs == /$ZONE_POOL ]] && continue
488 [[ -d $fs ]] && log_must
rm -rf $fs/*
492 # Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to
495 for fs
in $
(zfs list
-H -o name
); do
496 if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then
497 log_must zfs
set reservation
=none
$fs
498 log_must zfs
set recordsize
=128K
$fs
499 log_must zfs
set mountpoint
=/$fs $fs
501 enc
=$
(get_prop encryption
$fs)
502 if [[ $?
-ne 0 ]] ||
[[ -z "$enc" ]] || \
503 [[ "$enc" == "off" ]]; then
504 log_must zfs
set checksum
=on
$fs
506 log_must zfs
set compression
=off
$fs
507 log_must zfs
set atime
=on
$fs
508 log_must zfs
set devices
=off
$fs
509 log_must zfs
set exec=on
$fs
510 log_must zfs
set setuid
=on
$fs
511 log_must zfs
set readonly=off
$fs
512 log_must zfs
set snapdir
=hidden
$fs
513 log_must zfs
set aclmode
=groupmask
$fs
514 log_must zfs
set aclinherit
=secure
$fs
519 [[ -d $TESTDIR ]] && \
520 log_must
rm -rf $TESTDIR
523 if is_mpath_device
$disk1; then
530 # Common function used to cleanup storage pools, file systems
533 function default_container_cleanup
535 if ! is_global_zone
; then
539 ismounted
$TESTPOOL/$TESTCTR/$TESTFS1
541 log_must zfs unmount
$TESTPOOL/$TESTCTR/$TESTFS1
543 datasetexists
$TESTPOOL/$TESTCTR/$TESTFS1 && \
544 log_must zfs destroy
-R $TESTPOOL/$TESTCTR/$TESTFS1
546 datasetexists
$TESTPOOL/$TESTCTR && \
547 log_must zfs destroy
-Rf $TESTPOOL/$TESTCTR
549 [[ -e $TESTDIR1 ]] && \
550 log_must
rm -rf $TESTDIR1 > /dev
/null
2>&1
556 # Common function used to cleanup snapshot of file system or volume. Default to
557 # delete the file system's snapshot
561 function destroy_snapshot
563 typeset snap
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
565 if ! snapexists
$snap; then
566 log_fail
"'$snap' does not existed."
570 # For the sake of the value which come from 'get_prop' is not equal
571 # to the really mountpoint when the snapshot is unmounted. So, firstly
572 # check and make sure this snapshot's been mounted in current system.
575 if ismounted
$snap; then
576 mtpt
=$
(get_prop mountpoint
$snap)
578 log_fail
"get_prop mountpoint $snap failed."
581 log_must zfs destroy
$snap
582 [[ $mtpt != "" && -d $mtpt ]] && \
583 log_must
rm -rf $mtpt
587 # Common function used to cleanup clone.
591 function destroy_clone
593 typeset clone
=${1:-$TESTPOOL/$TESTCLONE}
595 if ! datasetexists
$clone; then
596 log_fail
"'$clone' does not existed."
599 # With the same reason in destroy_snapshot
601 if ismounted
$clone; then
602 mtpt
=$
(get_prop mountpoint
$clone)
604 log_fail
"get_prop mountpoint $clone failed."
607 log_must zfs destroy
$clone
608 [[ $mtpt != "" && -d $mtpt ]] && \
609 log_must
rm -rf $mtpt
613 # Common function used to cleanup bookmark of file system or volume. Default
614 # to delete the file system's bookmark.
618 function destroy_bookmark
620 typeset bkmark
=${1:-$TESTPOOL/$TESTFS#$TESTBKMARK}
622 if ! bkmarkexists
$bkmark; then
623 log_fail
"'$bkmarkp' does not existed."
626 log_must zfs destroy
$bkmark
629 # Return 0 if a snapshot exists; $? otherwise
635 zfs list
-H -t snapshot
"$1" > /dev
/null
2>&1
640 # Return 0 if a bookmark exists; $? otherwise
644 function bkmarkexists
646 zfs list
-H -t bookmark
"$1" > /dev
/null
2>&1
651 # Set a property to a certain value on a dataset.
652 # Sets a property of the dataset to the value as passed in.
654 # $1 dataset who's property is being set
656 # $3 value to set property to
658 # 0 if the property could be set.
659 # non-zero otherwise.
662 function dataset_setprop
664 typeset fn
=dataset_setprop
667 log_note
"$fn: Insufficient parameters (need 3, had $#)"
671 output
=$
(zfs
set $2=$3 $1 2>&1)
674 log_note
"Setting property on $1 failed."
675 log_note
"property $2=$3"
676 log_note
"Return Code: $rv"
677 log_note
"Output: $output"
684 # Assign suite defined dataset properties.
685 # This function is used to apply the suite's defined default set of
686 # properties to a dataset.
687 # @parameters: $1 dataset to use
688 # @uses: ZFS COMPRESSION_PROP CHECKSUM_PROP
690 # 0 if the dataset has been altered.
691 # 1 if no pool name was passed in.
692 # 2 if the dataset could not be found.
693 # 3 if the dataset could not have it's properties set.
695 function dataset_set_defaultproperties
699 [[ -z $dataset ]] && return 1
703 for confset
in $
(zfs list
); do
704 if [[ $dataset = $confset ]]; then
709 [[ $found -eq 0 ]] && return 2
710 if [[ -n $COMPRESSION_PROP ]]; then
711 dataset_setprop
$dataset compression
$COMPRESSION_PROP || \
713 log_note
"Compression set to '$COMPRESSION_PROP' on $dataset"
715 if [[ -n $CHECKSUM_PROP ]]; then
716 dataset_setprop
$dataset checksum
$CHECKSUM_PROP || \
718 log_note
"Checksum set to '$CHECKSUM_PROP' on $dataset"
724 # Check a numeric assertion
725 # @parameter: $@ the assertion to check
726 # @output: big loud notice if assertion failed
731 (($@
)) || log_fail
"$@"
735 # Function to format partition size of a disk
736 # Given a disk cxtxdx reduces all partitions
739 function zero_partitions
#<whole_disk_name>
745 log_must parted
$DEV_DSKDIR/$diskname -s -- mklabel gpt
747 for i
in 0 1 3 4 5 6 7
749 set_partition
$i "" 0mb
$diskname
755 # Given a slice, size and disk, this function
756 # formats the slice to the specified size.
757 # Size should be specified with units as per
758 # the `format` command requirements eg. 100mb 3gb
760 # NOTE: This entire interface is problematic for the Linux parted utilty
761 # which requires the end of the partition to be specified. It would be
762 # best to retire this interface and replace it with something more flexible.
763 # At the moment a best effort is made.
765 function set_partition
#<slice_num> <slice_start> <size_plus_units> <whole_disk_name>
767 typeset
-i slicenum
=$1
771 [[ -z $slicenum ||
-z $size ||
-z $disk ]] && \
772 log_fail
"The slice, size or disk name is unspecified."
775 typeset size_mb
=${size%%[mMgG]}
777 size_mb
=${size_mb%%[mMgG][bB]}
778 if [[ ${size:1:1} == 'g' ]]; then
779 ((size_mb
= size_mb
* 1024))
782 # Create GPT partition table when setting slice 0 or
783 # when the device doesn't already contain a GPT label.
784 parted
$DEV_DSKDIR/$disk -s -- print
1 >/dev
/null
786 if [[ $slicenum -eq 0 ||
$ret_val -ne 0 ]]; then
787 log_must parted
$DEV_DSKDIR/$disk -s -- mklabel gpt
790 # When no start is given align on the first cylinder.
791 if [[ -z "$start" ]]; then
795 # Determine the cylinder size for the device and using
796 # that calculate the end offset in cylinders.
797 typeset
-i cly_size_kb
=0
798 cly_size_kb
=$
(parted
-m $DEV_DSKDIR/$disk -s -- \
799 unit cyl print |
head -3 |
tail -1 | \
800 awk -F '[:k.]' '{print $4}')
801 ((end
= (size_mb
* 1024 / cly_size_kb
) + start
))
803 log_must parted
$DEV_DSKDIR/$disk -s -- \
804 mkpart part
$slicenum ${start}cyl
${end}cyl
806 blockdev
--rereadpt $DEV_DSKDIR/$disk 2>/dev
/null
809 typeset format_file
=/var
/tmp
/format_in.$$
811 echo "partition" >$format_file
812 echo "$slicenum" >> $format_file
813 echo "" >> $format_file
814 echo "" >> $format_file
815 echo "$start" >> $format_file
816 echo "$size" >> $format_file
817 echo "label" >> $format_file
818 echo "" >> $format_file
819 echo "q" >> $format_file
820 echo "q" >> $format_file
822 format
-e -s -d $disk -f $format_file
827 [[ $ret_val -ne 0 ]] && \
828 log_fail
"Unable to format $disk slice $slicenum to $size"
833 # Delete all partitions on all disks - this is specifically for the use of multipath
834 # devices which currently can only be used in the test suite as raw/un-partitioned
835 # devices (ie a zpool cannot be created on a whole mpath device that has partitions)
837 function delete_partitions
841 if [[ -z $DISK_ARRAY_NUM ]]; then
842 DISK_ARRAY_NUM
=$
(echo ${DISKS} | nawk
'{print NF}')
844 if [[ -z $DISKSARRAY ]]; then
849 if (( $DISK_ARRAY_NUM == 1 )); then
850 while ((j
< MAX_PARTITIONS
)); do
851 parted
$DEV_DSKDIR/$DISK -s rm $j \
853 if (( $?
== 1 )); then
854 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
855 if (( $?
== 1 )); then
856 log_note
"Partitions for $DISK should be deleted"
858 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
862 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
863 if (( $?
== 0 )); then
864 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
870 for disk
in `echo $DISKSARRAY`; do
871 while ((j
< MAX_PARTITIONS
)); do
872 parted
$DEV_DSKDIR/$disk -s rm $j > /dev
/null
2>&1
873 if (( $?
== 1 )); then
874 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
875 if (( $?
== 1 )); then
876 log_note
"Partitions for $disk should be deleted"
878 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
882 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
883 if (( $?
== 0 )); then
884 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
897 # Get the end cyl of the given slice
899 function get_endslice
#<disk> <slice>
903 if [[ -z $disk ||
-z $slice ]] ; then
904 log_fail
"The disk name or slice number is unspecified."
908 endcyl
=$
(parted
-s $DEV_DSKDIR/$disk -- unit cyl print | \
909 grep "part${slice}" | \
912 ((endcyl
= (endcyl
+ 1)))
914 disk
=${disk#/dev/dsk/}
915 disk
=${disk#/dev/rdsk/}
919 ratio
=$
(prtvtoc
/dev
/rdsk
/${disk}s2 | \
920 grep "sectors\/cylinder" | \
923 if ((ratio
== 0)); then
927 typeset
-i endcyl
=$
(prtvtoc
-h /dev
/rdsk
/${disk}s2 |
928 nawk
-v token
="$slice" '{if ($1==token) print $6}')
930 ((endcyl
= (endcyl
+ 1) / ratio
))
938 # Given a size,disk and total slice number, this function formats the
939 # disk slices from 0 to the total slice number with the same specified
942 function partition_disk
#<slice_size> <whole_disk_name> <total_slices>
945 typeset slice_size
=$1
947 typeset total_slices
=$3
950 zero_partitions
$disk_name
951 while ((i
< $total_slices)); do
958 set_partition
$i "$cyl" $slice_size $disk_name
959 cyl
=$
(get_endslice
$disk_name $i)
965 # This function continues to write to a filenum number of files into dirnum
966 # number of directories until either file_write returns an error or the
967 # maximum number of files per directory have been written.
970 # fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data]
972 # Return value: 0 on success
976 # destdir: is the directory where everything is to be created under
977 # dirnum: the maximum number of subdirectories to use, -1 no limit
978 # filenum: the maximum number of files per subdirectory
979 # bytes: number of bytes to write
980 # num_writes: numer of types to write out bytes
981 # data: the data that will be written
984 # file_fs /testdir 20 25 1024 256 0
986 # Note: bytes * num_writes equals the size of the testfile
988 function fill_fs
# destdir dirnum filenum bytes num_writes data
990 typeset destdir
=${1:-$TESTDIR}
991 typeset
-i dirnum
=${2:-50}
992 typeset
-i filenum
=${3:-50}
993 typeset
-i bytes
=${4:-8192}
994 typeset
-i num_writes
=${5:-10240}
995 typeset
-i data
=${6:-0}
1002 log_must mkdir
-p $destdir/$idirnum
1003 while (($odirnum > 0)); do
1004 if ((dirnum
>= 0 && idirnum
>= dirnum
)); then
1008 file_write
-o create
-f $destdir/$idirnum/$TESTFILE.
$fn \
1009 -b $bytes -c $num_writes -d $data
1011 if (($retval != 0)); then
1015 if (($fn >= $filenum)); then
1017 ((idirnum
= idirnum
+ 1))
1018 log_must mkdir
-p $destdir/$idirnum
1027 # Simple function to get the specified property. If unable to
1028 # get the property then exits.
1030 # Note property is in 'parsable' format (-p)
1032 function get_prop
# property dataset
1038 prop_val
=$
(zfs get
-pH -o value
$prop $dataset 2>/dev
/null
)
1039 if [[ $?
-ne 0 ]]; then
1040 log_note
"Unable to get $prop property for dataset " \
1050 # Simple function to get the specified property of pool. If unable to
1051 # get the property then exits.
1053 # Note property is in 'parsable' format (-p)
1055 function get_pool_prop
# property pool
1061 if poolexists
$pool ; then
1062 prop_val
=$
(zpool get
-pH $prop $pool 2>/dev
/null |
tail -1 | \
1064 if [[ $?
-ne 0 ]]; then
1065 log_note
"Unable to get $prop property for pool " \
1070 log_note
"Pool $pool not exists."
1078 # Return 0 if a pool exists; $? otherwise
1086 if [[ -z $pool ]]; then
1087 log_note
"No pool name given."
1091 zpool get name
"$pool" > /dev
/null
2>&1
1095 # Return 0 if all the specified datasets exist; $? otherwise
1098 function datasetexists
1100 if (($# == 0)); then
1101 log_note
"No dataset name given."
1105 while (($# > 0)); do
1106 zfs get name
$1 > /dev
/null
2>&1 || \
1114 # return 0 if none of the specified datasets exists, otherwise return 1.
1117 function datasetnonexists
1119 if (($# == 0)); then
1120 log_note
"No dataset name given."
1124 while (($# > 0)); do
1125 zfs list
-H -t filesystem
,snapshot
,volume
$1 > /dev
/null
2>&1 \
1134 # Given a mountpoint, or a dataset name, determine if it is shared via NFS.
1136 # Returns 0 if shared, 1 otherwise.
1143 if [[ $fs != "/"* ]] ; then
1144 if datasetnonexists
"$fs" ; then
1147 mtpt
=$
(get_prop mountpoint
"$fs")
1149 none|legacy|
-) return 1
1158 for mtpt
in `share | awk '{print $1}'` ; do
1159 if [[ $mtpt == $fs ]] ; then
1166 for mtpt
in `share | awk '{print $2}'` ; do
1167 if [[ $mtpt == $fs ]] ; then
1172 typeset stat
=$
(svcs
-H -o STA nfs
/server
:default
)
1173 if [[ $stat != "ON" ]]; then
1174 log_note
"Current nfs/server status: $stat"
1181 # Given a dataset name determine if it is shared via SMB.
1183 # Returns 0 if shared, 1 otherwise.
1185 function is_shared_smb
1190 if datasetnonexists
"$fs" ; then
1193 fs
=$
(echo $fs |
sed 's@/@_@g')
1197 for mtpt
in `net usershare list | awk '{print $1}'` ; do
1198 if [[ $mtpt == $fs ]] ; then
1204 log_unsupported
"Currently unsupported by the test framework"
1210 # Given a mountpoint, determine if it is not shared via NFS.
1212 # Returns 0 if not shared, 1 otherwise.
1219 if (($?
== 0)); then
1227 # Given a dataset determine if it is not shared via SMB.
1229 # Returns 0 if not shared, 1 otherwise.
1231 function not_shared_smb
1236 if (($?
== 0)); then
1244 # Helper function to unshare a mountpoint.
1246 function unshare_fs
#fs
1250 is_shared
$fs || is_shared_smb
$fs
1251 if (($?
== 0)); then
1252 log_must zfs unshare
$fs
1259 # Helper function to share a NFS mountpoint.
1261 function share_nfs
#fs
1267 if (($?
!= 0)); then
1268 log_must share
"*:$fs"
1272 if (($?
!= 0)); then
1273 log_must share
-F nfs
$fs
1281 # Helper function to unshare a NFS mountpoint.
1283 function unshare_nfs
#fs
1289 if (($?
== 0)); then
1290 log_must unshare
-u "*:$fs"
1294 if (($?
== 0)); then
1295 log_must unshare
-F nfs
$fs
1303 # Helper function to show NFS shares.
1305 function showshares_nfs
1317 # Helper function to show SMB shares.
1319 function showshares_smb
1331 # Check NFS server status and trigger it online.
1333 function setup_nfs_server
1335 # Cannot share directory in non-global zone.
1337 if ! is_global_zone
; then
1338 log_note
"Cannot trigger NFS server by sharing in LZ."
1343 log_note
"NFS server must started prior to running test framework."
1347 typeset nfs_fmri
="svc:/network/nfs/server:default"
1348 if [[ $
(svcs
-Ho STA
$nfs_fmri) != "ON" ]]; then
1350 # Only really sharing operation can enable NFS server
1351 # to online permanently.
1353 typeset dummy
=/tmp
/dummy
1355 if [[ -d $dummy ]]; then
1356 log_must
rm -rf $dummy
1359 log_must mkdir
$dummy
1360 log_must share
$dummy
1363 # Waiting for fmri's status to be the final status.
1364 # Otherwise, in transition, an asterisk (*) is appended for
1365 # instances, unshare will reverse status to 'DIS' again.
1367 # Waiting for 1's at least.
1371 while [[ timeout
-ne 0 && $
(svcs
-Ho STA
$nfs_fmri) == *'*' ]]
1378 log_must unshare
$dummy
1379 log_must
rm -rf $dummy
1382 log_note
"Current NFS status: '$(svcs -Ho STA,FMRI $nfs_fmri)'"
1386 # To verify whether calling process is in global zone
1388 # Return 0 if in global zone, 1 in non-global zone
1390 function is_global_zone
1395 typeset cur_zone
=$
(zonename
2>/dev
/null
)
1396 if [[ $cur_zone != "global" ]]; then
1404 # Verify whether test is permitted to run from
1405 # global zone, local zone, or both
1407 # $1 zone limit, could be "global", "local", or "both"(no limit)
1409 # Return 0 if permitted, otherwise exit with log_unsupported
1411 function verify_runnable
# zone limit
1415 [[ -z $limit ]] && return 0
1417 if is_global_zone
; then
1421 local) log_unsupported
"Test is unable to run from "\
1424 *) log_note
"Warning: unknown limit $limit - " \
1432 global
) log_unsupported
"Test is unable to run from "\
1435 *) log_note
"Warning: unknown limit $limit - " \
1446 # Return 0 if create successfully or the pool exists; $? otherwise
1447 # Note: In local zones, this function should return 0 silently.
1450 # $2-n - [keyword] devs_list
1452 function create_pool
#pool devs_list
1454 typeset pool
=${1%%/*}
1458 if [[ -z $pool ]]; then
1459 log_note
"Missing pool name."
1463 if poolexists
$pool ; then
1467 if is_global_zone
; then
1468 [[ -d /$pool ]] && rm -rf /$pool
1469 log_must zpool create
-f $pool $@
1475 # Return 0 if destroy successfully or the pool exists; $? otherwise
1476 # Note: In local zones, this function should return 0 silently.
1479 # Destroy pool with the given parameters.
1481 function destroy_pool
#pool
1483 typeset pool
=${1%%/*}
1486 if [[ -z $pool ]]; then
1487 log_note
"No pool name given."
1491 if is_global_zone
; then
1492 if poolexists
"$pool" ; then
1493 mtpt
=$
(get_prop mountpoint
"$pool")
1495 # At times, syseventd activity can cause attempts to
1496 # destroy a pool to fail with EBUSY. We retry a few
1497 # times allowing failures before requiring the destroy
1499 typeset
-i wait_time
=10 ret
=1 count
=0
1501 while [[ $ret -ne 0 ]]; do
1502 $must zpool destroy
-f $pool
1504 [[ $ret -eq 0 ]] && break
1505 log_note
"zpool destroy failed with $ret"
1506 [[ count
++ -ge 7 ]] && must
=log_must
1511 log_must
rm -rf $mtpt
1513 log_note
"Pool does not exist. ($pool)"
1522 # Firstly, create a pool with 5 datasets. Then, create a single zone and
1523 # export the 5 datasets to it. In addition, we also add a ZFS filesystem
1524 # and a zvol device to the zone.
1527 # $2 zone root directory prefix
1530 function zfs_zones_setup
#zone_name zone_root zone_ip
1532 typeset zone_name
=${1:-$(hostname)-z}
1533 typeset zone_root
=${2:-"/zone_root"}
1534 typeset zone_ip
=${3:-"10.1.1.10"}
1535 typeset prefix_ctr
=$ZONE_CTR
1536 typeset pool_name
=$ZONE_POOL
1540 # Create pool and 5 container within it
1542 [[ -d /$pool_name ]] && rm -rf /$pool_name
1543 log_must zpool create
-f $pool_name $DISKS
1544 while ((i
< cntctr
)); do
1545 log_must zfs create
$pool_name/$prefix_ctr$i
1550 log_must zfs create
-V 1g
$pool_name/zone_zvol
1554 # If current system support slog, add slog device for pool
1556 if verify_slog_support
; then
1557 typeset sdevs
="/var/tmp/sdev1 /var/tmp/sdev2"
1558 log_must mkfile
$MINVDEVSIZE $sdevs
1559 log_must zpool add
$pool_name log mirror
$sdevs
1562 # this isn't supported just yet.
1563 # Create a filesystem. In order to add this to
1564 # the zone, it must have it's mountpoint set to 'legacy'
1565 # log_must zfs create $pool_name/zfs_filesystem
1566 # log_must zfs set mountpoint=legacy $pool_name/zfs_filesystem
1568 [[ -d $zone_root ]] && \
1569 log_must
rm -rf $zone_root/$zone_name
1570 [[ ! -d $zone_root ]] && \
1571 log_must mkdir
-p -m 0700 $zone_root/$zone_name
1573 # Create zone configure file and configure the zone
1575 typeset zone_conf
=/tmp
/zone_conf.$$
1576 echo "create" > $zone_conf
1577 echo "set zonepath=$zone_root/$zone_name" >> $zone_conf
1578 echo "set autoboot=true" >> $zone_conf
1580 while ((i
< cntctr
)); do
1581 echo "add dataset" >> $zone_conf
1582 echo "set name=$pool_name/$prefix_ctr$i" >> \
1584 echo "end" >> $zone_conf
1588 # add our zvol to the zone
1589 echo "add device" >> $zone_conf
1590 echo "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf
1591 echo "end" >> $zone_conf
1593 # add a corresponding zvol rdsk to the zone
1594 echo "add device" >> $zone_conf
1595 echo "set match=$ZVOL_RDEVDIR/$pool_name/zone_zvol" >> $zone_conf
1596 echo "end" >> $zone_conf
1598 # once it's supported, we'll add our filesystem to the zone
1599 # echo "add fs" >> $zone_conf
1600 # echo "set type=zfs" >> $zone_conf
1601 # echo "set special=$pool_name/zfs_filesystem" >> $zone_conf
1602 # echo "set dir=/export/zfs_filesystem" >> $zone_conf
1603 # echo "end" >> $zone_conf
1605 echo "verify" >> $zone_conf
1606 echo "commit" >> $zone_conf
1607 log_must zonecfg
-z $zone_name -f $zone_conf
1608 log_must
rm -f $zone_conf
1611 zoneadm
-z $zone_name install
1612 if (($?
== 0)); then
1613 log_note
"SUCCESS: zoneadm -z $zone_name install"
1615 log_fail
"FAIL: zoneadm -z $zone_name install"
1618 # Install sysidcfg file
1620 typeset sysidcfg
=$zone_root/$zone_name/root
/etc
/sysidcfg
1621 echo "system_locale=C" > $sysidcfg
1622 echo "terminal=dtterm" >> $sysidcfg
1623 echo "network_interface=primary {" >> $sysidcfg
1624 echo "hostname=$zone_name" >> $sysidcfg
1625 echo "}" >> $sysidcfg
1626 echo "name_service=NONE" >> $sysidcfg
1627 echo "root_password=mo791xfZ/SFiw" >> $sysidcfg
1628 echo "security_policy=NONE" >> $sysidcfg
1629 echo "timezone=US/Eastern" >> $sysidcfg
1632 log_must zoneadm
-z $zone_name boot
1636 # Reexport TESTPOOL & TESTPOOL(1-4)
1638 function reexport_pool
1643 while ((i
< cntctr
)); do
1645 TESTPOOL
=$ZONE_POOL/$ZONE_CTR$i
1646 if ! ismounted
$TESTPOOL; then
1647 log_must zfs mount
$TESTPOOL
1650 eval TESTPOOL
$i=$ZONE_POOL/$ZONE_CTR$i
1651 if eval ! ismounted \
$TESTPOOL$i; then
1652 log_must
eval zfs mount \
$TESTPOOL$i
1660 # Verify a given disk or pool state
1662 # Return 0 is pool/disk matches expected state, 1 otherwise
1664 function check_state
# pool disk state{online,offline,degraded}
1667 typeset disk
=${2#$DEV_DSKDIR/}
1670 [[ -z $pool ]] ||
[[ -z $state ]] \
1671 && log_fail
"Arguments invalid or missing"
1673 if [[ -z $disk ]]; then
1674 #check pool state only
1675 zpool get
-H -o value health
$pool \
1676 |
grep -i "$state" > /dev
/null
2>&1
1678 zpool status
-v $pool |
grep "$disk" \
1679 |
grep -i "$state" > /dev
/null
2>&1
1686 # Cause a scan of all scsi host adapters by default
1688 # $1 optional host number
1690 function scan_scsi_hosts
1692 typeset hostnum
=${1}
1695 if [[ -z $hostnum ]]; then
1696 for host in /sys
/class
/scsi_host
/host*; do
1697 log_must
eval "echo '- - -' > $host/scan"
1701 "echo /sys/class/scsi_host/host$hostnum/scan" \
1704 "echo '- - -' > /sys/class/scsi_host/host$hostnum/scan"
1709 # Wait for newly created block devices to have their minors created.
1711 function block_device_wait
1720 # Online or offline a disk on the system
1722 # First checks state of disk. Test will fail if disk is not properly onlined
1723 # or offlined. Online is a full rescan of SCSI disks by echoing to every
1726 function on_off_disk
# disk state{online,offline} host
1732 [[ -z $disk ]] ||
[[ -z $state ]] && \
1733 log_fail
"Arguments invalid or missing"
1736 if [[ $state == "offline" ]] && ( is_mpath_device
$disk ); then
1737 dm_name
="$(readlink $DEV_DSKDIR/$disk \
1738 | nawk -F / '{print $2}')"
1739 slave
="$(ls /sys/block/${dm_name}/slaves \
1740 | nawk '{print $1}')"
1741 while [[ -n $slave ]]; do
1742 #check if disk is online
1743 lsscsi |
egrep $slave > /dev
/null
1744 if (($?
== 0)); then
1745 slave_dir
="/sys/block/${dm_name}"
1746 slave_dir
+="/slaves/${slave}/device"
1747 ss
="${slave_dir}/state"
1748 sd
="${slave_dir}/delete"
1749 log_must
eval "echo 'offline' > ${ss}"
1750 log_must
eval "echo '1' > ${sd}"
1751 lsscsi |
egrep $slave > /dev
/null
1752 if (($?
== 0)); then
1753 log_fail
"Offlining" \
1757 slave
="$(ls /sys/block/$dm_name/slaves \
1758 2>/dev/null | nawk '{print $1}')"
1760 elif [[ $state == "offline" ]] && ( is_real_device
$disk ); then
1761 #check if disk is online
1762 lsscsi |
egrep $disk > /dev
/null
1763 if (($?
== 0)); then
1764 dev_state
="/sys/block/$disk/device/state"
1765 dev_delete
="/sys/block/$disk/device/delete"
1766 log_must
eval "echo 'offline' > ${dev_state}"
1767 log_must
eval "echo '1' > ${dev_delete}"
1768 lsscsi |
egrep $disk > /dev
/null
1769 if (($?
== 0)); then
1770 log_fail
"Offlining $disk" \
1774 log_note
"$disk is already offline"
1776 elif [[ $state == "online" ]]; then
1777 #force a full rescan
1778 scan_scsi_hosts
$host
1780 if is_mpath_device
$disk; then
1781 dm_name
="$(readlink $DEV_DSKDIR/$disk \
1782 | nawk -F / '{print $2}')"
1783 slave
="$(ls /sys/block/$dm_name/slaves \
1784 | nawk '{print $1}')"
1785 lsscsi |
egrep $slave > /dev
/null
1786 if (($?
!= 0)); then
1787 log_fail
"Onlining $disk failed"
1789 elif is_real_device
$disk; then
1790 lsscsi |
egrep $disk > /dev
/null
1791 if (($?
!= 0)); then
1792 log_fail
"Onlining $disk failed"
1795 log_fail
"$disk is not a real dev"
1798 log_fail
"$disk failed to $state"
1804 # Get the mountpoint of snapshot
1805 # For the snapshot use <mp_filesystem>/.zfs/snapshot/<snap>
1808 function snapshot_mountpoint
1810 typeset dataset
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
1812 if [[ $dataset != *@
* ]]; then
1813 log_fail
"Error name of snapshot '$dataset'."
1816 typeset fs
=${dataset%@*}
1817 typeset snap
=${dataset#*@}
1819 if [[ -z $fs ||
-z $snap ]]; then
1820 log_fail
"Error name of snapshot '$dataset'."
1823 echo $
(get_prop mountpoint
$fs)/.zfs
/snapshot
/$snap
1827 # Given a pool and file system, this function will verify the file system
1828 # using the zdb internal tool. Note that the pool is exported and imported
1829 # to ensure it has consistent state.
1831 function verify_filesys
# pool filesystem dir
1834 typeset filesys
="$2"
1835 typeset zdbout
="/tmp/zdbout.$$"
1840 typeset search_path
=""
1842 log_note
"Calling zdb to verify filesystem '$filesys'"
1843 zfs unmount
-a > /dev
/null
2>&1
1844 log_must zpool
export $pool
1846 if [[ -n $dirs ]] ; then
1847 for dir
in $dirs ; do
1848 search_path
="$search_path -d $dir"
1852 log_must zpool import
$search_path $pool
1854 zdb
-cudi $filesys > $zdbout 2>&1
1855 if [[ $?
!= 0 ]]; then
1856 log_note
"Output: zdb -cudi $filesys"
1858 log_fail
"zdb detected errors with: '$filesys'"
1861 log_must zfs mount
-a
1862 log_must
rm -rf $zdbout
1866 # Given a pool, and this function list all disks in the pool
1868 function get_disklist
# pool
1872 disklist
=$
(zpool iostat
-v $1 | nawk
'(NR >4) {print $1}' | \
1873 grep -v "\-\-\-\-\-" | \
1874 egrep -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
1880 # Given a pool, and this function list all disks in the pool with their full
1881 # path (like "/dev/sda" instead of "sda").
1883 function get_disklist_fullpath
# pool
1892 # This function kills a given list of processes after a time period. We use
1893 # this in the stress tests instead of STF_TIMEOUT so that we can have processes
1894 # run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT
1895 # would be listed as FAIL, which we don't want : we're happy with stress tests
1896 # running for a certain amount of time, then finishing.
1898 # @param $1 the time in seconds after which we should terminate these processes
1899 # @param $2..$n the processes we wish to terminate.
1901 function stress_timeout
1903 typeset
-i TIMEOUT
=$1
1907 log_note
"Waiting for child processes($cpids). " \
1908 "It could last dozens of minutes, please be patient ..."
1909 log_must
sleep $TIMEOUT
1911 log_note
"Killing child processes after ${TIMEOUT} stress timeout."
1913 for pid
in $cpids; do
1914 ps
-p $pid > /dev
/null
2>&1
1915 if (($?
== 0)); then
1916 log_must
kill -USR1 $pid
1922 # Verify a given hotspare disk is inuse or avail
1924 # Return 0 is pool/disk matches expected state, 1 otherwise
1926 function check_hotspare_state
# pool disk state{inuse,avail}
1929 typeset disk
=${2#$DEV_DSKDIR/}
1932 cur_state
=$
(get_device_state
$pool $disk "spares")
1934 if [[ $state != ${cur_state} ]]; then
1941 # Verify a given slog disk is inuse or avail
1943 # Return 0 is pool/disk matches expected state, 1 otherwise
1945 function check_slog_state
# pool disk state{online,offline,unavail}
1948 typeset disk
=${2#$DEV_DSKDIR/}
1951 cur_state
=$
(get_device_state
$pool $disk "logs")
1953 if [[ $state != ${cur_state} ]]; then
1960 # Verify a given vdev disk is inuse or avail
1962 # Return 0 is pool/disk matches expected state, 1 otherwise
1964 function check_vdev_state
# pool disk state{online,offline,unavail}
1967 typeset disk
=${2#$/DEV_DSKDIR/}
1970 cur_state
=$
(get_device_state
$pool $disk)
1972 if [[ $state != ${cur_state} ]]; then
1979 # Check the output of 'zpool status -v <pool>',
1980 # and to see if the content of <token> contain the <keyword> specified.
1982 # Return 0 is contain, 1 otherwise
1984 function check_pool_status
# pool token keyword
1990 zpool status
-v "$pool" 2>/dev
/null | nawk
-v token
="$token:" '
1991 ($1==token) {print $0}' \
1992 |
grep -i "$keyword" > /dev
/null
2>&1
1998 # These 5 following functions are instance of check_pool_status()
1999 # is_pool_resilvering - to check if the pool is resilver in progress
2000 # is_pool_resilvered - to check if the pool is resilver completed
2001 # is_pool_scrubbing - to check if the pool is scrub in progress
2002 # is_pool_scrubbed - to check if the pool is scrub completed
2003 # is_pool_scrub_stopped - to check if the pool is scrub stopped
2005 function is_pool_resilvering
#pool
2007 check_pool_status
"$1" "scan" "resilver in progress since "
2011 function is_pool_resilvered
#pool
2013 check_pool_status
"$1" "scan" "resilvered "
2017 function is_pool_scrubbing
#pool
2019 check_pool_status
"$1" "scan" "scrub in progress since "
2023 function is_pool_scrubbed
#pool
2025 check_pool_status
"$1" "scan" "scrub repaired"
2029 function is_pool_scrub_stopped
#pool
2031 check_pool_status
"$1" "scan" "scrub canceled"
2036 # Use create_pool()/destroy_pool() to clean up the information in
2037 # in the given disk to avoid slice overlapping.
2039 function cleanup_devices
#vdevs
2041 typeset pool
="foopool$$"
2043 if poolexists
$pool ; then
2047 create_pool
$pool $@
2054 # Verify the rsh connectivity to each remote host in RHOSTS.
2056 # Return 0 if remote host is accessible; otherwise 1.
2057 # $1 remote host name
2060 function verify_rsh_connect
#rhost, username
2064 typeset rsh_cmd
="rsh -n"
2067 getent hosts
$rhost >/dev
/null
2>&1
2068 if (($?
!= 0)); then
2069 log_note
"$rhost cannot be found from" \
2070 "administrative database."
2074 ping $rhost 3 >/dev
/null
2>&1
2075 if (($?
!= 0)); then
2076 log_note
"$rhost is not reachable."
2080 if ((${#username} != 0)); then
2081 rsh_cmd
="$rsh_cmd -l $username"
2082 cur_user
="given user \"$username\""
2084 cur_user
="current user \"`logname`\""
2087 if ! $rsh_cmd $rhost true
; then
2088 log_note
"rsh to $rhost is not accessible" \
2097 # Verify the remote host connection via rsh after rebooting
2100 function verify_remote
2105 # The following loop waits for the remote system rebooting.
2106 # Each iteration will wait for 150 seconds. there are
2107 # total 5 iterations, so the total timeout value will
2108 # be 12.5 minutes for the system rebooting. This number
2109 # is an approxiate number.
2112 while ! verify_rsh_connect
$rhost; do
2114 ((count
= count
+ 1))
2115 if ((count
> 5)); then
2123 # Replacement function for /usr/bin/rsh. This function will include
2124 # the /usr/bin/rsh and meanwhile return the execution status of the
2127 # $1 usrname passing down to -l option of /usr/bin/rsh
2128 # $2 remote machine hostname
2129 # $3... command string
2143 err_file
=/tmp
/${rhost}.$$.err
2144 if ((${#ruser} == 0)); then
2147 rsh_str
="rsh -n -l $ruser"
2150 $rsh_str $rhost /bin
/ksh
-c "'$cmd_str; \
2151 print -u 2 \"status=\$?\"'" \
2152 >/dev
/null
2>$err_file
2154 if (($ret != 0)); then
2156 rm -f $std_file $err_file
2157 log_fail
"rsh itself failed with exit code $ret..."
2160 ret
=$
(grep -v 'print -u 2' $err_file |
grep 'status=' | \
2162 (($ret != 0)) && cat $err_file >&2
2164 rm -f $err_file >/dev
/null
2>&1
2169 # Get the SUNWstc-fs-zfs package installation path in a remote host
2170 # $1 remote host name
2172 function get_remote_pkgpath
2177 pkgpath
=$
(rsh -n $rhost "pkginfo -l SUNWstc-fs-zfs | grep BASEDIR: |\
2184 # A function to find and locate free disks on a system or from given
2185 # disks as the parameter. It works by locating disks that are in use
2186 # as swap devices and dump devices, and also disks listed in /etc/vfstab
2188 # $@ given disks to find which are free, default is all disks in
2191 # @return a string containing the list of available disks
2195 # Trust provided list, no attempt is made to locate unused devices.
2202 sfi
=/tmp
/swaplist.$$
2203 dmpi
=/tmp
/dumpdev.$$
2204 max_finddisksnum
=${MAX_FINDDISKSNUM:-6}
2207 dumpadm
> $dmpi 2>/dev
/null
2209 # write an awk script that can process the output of format
2210 # to produce a list of disks we know about. Note that we have
2211 # to escape "$2" so that the shell doesn't interpret it while
2212 # we're creating the awk script.
2213 # -------------------
2214 cat > /tmp
/find_disks.
awk <<EOF
2223 if (searchdisks && \$2 !~ "^$"){
2229 /^AVAILABLE DISK SELECTIONS:/{
2233 #---------------------
2235 chmod 755 /tmp
/find_disks.
awk
2236 disks
=${@:-$(echo "" | format -e 2>/dev/null | /tmp/find_disks.awk)}
2237 rm /tmp
/find_disks.
awk
2240 for disk
in $disks; do
2242 grep "${disk}[sp]" /etc
/mnttab
>/dev
/null
2243 (($?
== 0)) && continue
2245 grep "${disk}[sp]" $sfi >/dev
/null
2246 (($?
== 0)) && continue
2247 # check for dump device
2248 grep "${disk}[sp]" $dmpi >/dev
/null
2249 (($?
== 0)) && continue
2250 # check to see if this disk hasn't been explicitly excluded
2251 # by a user-set environment variable
2252 echo "${ZFS_HOST_DEVICES_IGNORE}" |
grep "${disk}" > /dev
/null
2253 (($?
== 0)) && continue
2254 unused_candidates
="$unused_candidates $disk"
2259 # now just check to see if those disks do actually exist
2260 # by looking for a device pointing to the first slice in
2261 # each case. limit the number to max_finddisksnum
2263 for disk
in $unused_candidates; do
2264 if [ -b $DEV_DSKDIR/${disk}s0
]; then
2265 if [ $count -lt $max_finddisksnum ]; then
2266 unused
="$unused $disk"
2267 # do not impose limit if $@ is provided
2268 [[ -z $@
]] && ((count
= count
+ 1))
2273 # finally, return our disk list
2278 # Add specified user to specified group
2282 # $3 base of the homedir (optional)
2284 function add_user
#<group_name> <user_name> <basedir>
2288 typeset basedir
=${3:-"/var/tmp"}
2290 if ((${#gname} == 0 ||
${#uname} == 0)); then
2291 log_fail
"group name or user name are not defined."
2294 log_must useradd
-g $gname -d $basedir/$uname -m $uname
2295 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.profile
2296 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.bash_profile
2297 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.login
2299 # Add new users to the same group and the command line utils.
2300 # This allows them to be run out of the original users home
2301 # directory as long as it permissioned to be group readable.
2303 cmd_group
=$
(stat
--format="%G" $
(which zfs
))
2304 log_must usermod
-a -G $cmd_group $uname
2311 # Delete the specified user.
2314 # $2 base of the homedir (optional)
2316 function del_user
#<logname> <basedir>
2319 typeset basedir
=${2:-"/var/tmp"}
2321 if ((${#user} == 0)); then
2322 log_fail
"login name is necessary."
2325 if id
$user > /dev
/null
2>&1; then
2326 log_must userdel
$user
2329 [[ -d $basedir/$user ]] && rm -fr $basedir/$user
2335 # Select valid gid and create specified group.
2339 function add_group
#<group_name>
2343 if ((${#group} == 0)); then
2344 log_fail
"group name is necessary."
2347 # Assign 100 as the base gid, a larger value is selected for
2348 # Linux because for many distributions 1000 and under are reserved.
2351 groupadd
$group > /dev
/null
2>&1
2361 groupadd
-g $gid $group > /dev
/null
2>&1
2365 # The gid is not unique
2374 # Delete the specified group.
2378 function del_group
#<group_name>
2381 if ((${#grp} == 0)); then
2382 log_fail
"group name is necessary."
2386 getent group
$grp > /dev
/null
2>&1
2389 # Group does not exist.
2391 # Name already exists as a group name
2392 0) log_must groupdel
$grp ;;
2396 groupmod
-n $grp $grp > /dev
/null
2>&1
2399 # Group does not exist.
2401 # Name already exists as a group name
2402 9) log_must groupdel
$grp ;;
2411 # This function will return true if it's safe to destroy the pool passed
2412 # as argument 1. It checks for pools based on zvols and files, and also
2413 # files contained in a pool that may have a different mountpoint.
2415 function safe_to_destroy_pool
{ # $1 the pool name
2418 typeset DONT_DESTROY
=""
2420 # We check that by deleting the $1 pool, we're not
2421 # going to pull the rug out from other pools. Do this
2422 # by looking at all other pools, ensuring that they
2423 # aren't built from files or zvols contained in this pool.
2425 for pool
in $
(zpool list
-H -o name
)
2429 # this is a list of the top-level directories in each of the
2430 # files that make up the path to the files the pool is based on
2431 FILEPOOL
=$
(zpool status
-v $pool |
grep /$1/ | \
2434 # this is a list of the zvols that make up the pool
2435 ZVOLPOOL
=$
(zpool status
-v $pool |
grep "$ZVOL_DEVDIR/$1$" \
2438 # also want to determine if it's a file-based pool using an
2439 # alternate mountpoint...
2440 POOL_FILE_DIRS
=$
(zpool status
-v $pool | \
2441 grep / |
awk '{print $1}' | \
2442 awk -F/ '{print $2}' |
grep -v "dev")
2444 for pooldir
in $POOL_FILE_DIRS
2446 OUTPUT
=$
(zfs list
-H -r -o mountpoint
$1 | \
2447 grep "${pooldir}$" |
awk '{print $1}')
2449 ALTMOUNTPOOL
="${ALTMOUNTPOOL}${OUTPUT}"
2453 if [ ! -z "$ZVOLPOOL" ]
2456 log_note
"Pool $pool is built from $ZVOLPOOL on $1"
2459 if [ ! -z "$FILEPOOL" ]
2462 log_note
"Pool $pool is built from $FILEPOOL on $1"
2465 if [ ! -z "$ALTMOUNTPOOL" ]
2468 log_note
"Pool $pool is built from $ALTMOUNTPOOL on $1"
2472 if [ -z "${DONT_DESTROY}" ]
2476 log_note
"Warning: it is not safe to destroy $1!"
2482 # Get the available ZFS compression options
2483 # $1 option type zfs_set|zfs_compress
2485 function get_compress_opts
2487 typeset COMPRESS_OPTS
2488 typeset GZIP_OPTS
="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \
2489 gzip-6 gzip-7 gzip-8 gzip-9"
2491 if [[ $1 == "zfs_compress" ]] ; then
2492 COMPRESS_OPTS
="on lzjb"
2493 elif [[ $1 == "zfs_set" ]] ; then
2494 COMPRESS_OPTS
="on off lzjb"
2496 typeset valid_opts
="$COMPRESS_OPTS"
2497 zfs get
2>&1 |
grep gzip >/dev
/null
2>&1
2498 if [[ $?
-eq 0 ]]; then
2499 valid_opts
="$valid_opts $GZIP_OPTS"
2505 # Verify zfs operation with -p option work as expected
2506 # $1 operation, value could be create, clone or rename
2507 # $2 dataset type, value could be fs or vol
2509 # $4 new dataset name
2511 function verify_opt_p_ops
2516 typeset newdataset
=$4
2518 if [[ $datatype != "fs" && $datatype != "vol" ]]; then
2519 log_fail
"$datatype is not supported."
2522 # check parameters accordingly
2527 if [[ $datatype == "vol" ]]; then
2528 ops
="create -V $VOLSIZE"
2532 if [[ -z $newdataset ]]; then
2533 log_fail
"newdataset should not be empty" \
2536 log_must datasetexists
$dataset
2537 log_must snapexists
$dataset
2540 if [[ -z $newdataset ]]; then
2541 log_fail
"newdataset should not be empty" \
2544 log_must datasetexists
$dataset
2545 log_mustnot snapexists
$dataset
2548 log_fail
"$ops is not supported."
2552 # make sure the upper level filesystem does not exist
2553 if datasetexists
${newdataset%/*} ; then
2554 log_must zfs destroy
-rRf ${newdataset%/*}
2557 # without -p option, operation will fail
2558 log_mustnot zfs
$ops $dataset $newdataset
2559 log_mustnot datasetexists
$newdataset ${newdataset%/*}
2561 # with -p option, operation should succeed
2562 log_must zfs
$ops -p $dataset $newdataset
2565 if ! datasetexists
$newdataset ; then
2566 log_fail
"-p option does not work for $ops"
2569 # when $ops is create or clone, redo the operation still return zero
2570 if [[ $ops != "rename" ]]; then
2571 log_must zfs
$ops -p $dataset $newdataset
2578 # Get configuration of pool
2588 if ! poolexists
"$pool" ; then
2591 alt_root
=$
(zpool list
-H $pool |
awk '{print $NF}')
2592 if [[ $alt_root == "-" ]]; then
2593 value
=$
(zdb
-C $pool |
grep "$config:" |
awk -F: \
2596 value
=$
(zdb
-e $pool |
grep "$config:" |
awk -F: \
2599 if [[ -n $value ]] ; then
2609 # Privated function. Random select one of items from arguments.
2614 function _random_get
2621 ((ind
= RANDOM
% cnt
+ 1))
2623 typeset ret
=$
(echo "$str" | cut
-f $ind -d ' ')
2628 # Random select one of item from arguments which include NONE string
2630 function random_get_with_non
2635 _random_get
"$cnt" "$@"
2639 # Random select one of item from arguments which doesn't include NONE string
2643 _random_get
"$#" "$@"
2647 # Detect if the current system support slog
2649 function verify_slog_support
2651 typeset dir
=/tmp
/disk.$$
2657 mkfile
$MINVDEVSIZE $vdev $sdev
2660 if ! zpool create
-n $pool $vdev log
$sdev > /dev
/null
2>&1; then
2669 # The function will generate a dataset name with specific length
2670 # $1, the length of the name
2671 # $2, the base string to construct the name
2673 function gen_dataset_name
2676 typeset basestr
="$2"
2677 typeset
-i baselen
=${#basestr}
2681 if ((len
% baselen
== 0)); then
2682 ((iter
= len
/ baselen
))
2684 ((iter
= len
/ baselen
+ 1))
2686 while ((iter
> 0)); do
2687 l_name
="${l_name}$basestr"
2696 # Get cksum tuple of dataset
2699 # sample zdb output:
2700 # Dataset data/test [ZPL], ID 355, cr_txg 2413856, 31.0K, 7 objects, rootbp
2701 # DVA[0]=<0:803046400:200> DVA[1]=<0:81199000:200> [L0 DMU objset] fletcher4
2702 # lzjb LE contiguous unique double size=800L/200P birth=2413856L/2413856P
2703 # fill=7 cksum=11ce125712:643a9c18ee2:125e25238fca0:254a3f74b59744
2704 function datasetcksum
2708 cksum=$
(zdb
-vvv $1 |
grep "^Dataset $1 \[" |
grep "cksum" \
2709 |
awk -F= '{print $7}')
2720 cksum=$
(cksum $1 |
awk '{print $1}')
2725 # Get the given disk/slice state from the specific field of the pool
2727 function get_device_state
#pool disk field("", "spares","logs")
2730 typeset disk
=${2#$DEV_DSKDIR/}
2731 typeset field
=${3:-$pool}
2733 state
=$
(zpool status
-v "$pool" 2>/dev
/null | \
2734 nawk
-v device
=$disk -v pool
=$pool -v field
=$field \
2735 'BEGIN {startconfig=0; startfield=0; }
2736 /config:/ {startconfig=1}
2737 (startconfig==1) && ($1==field) {startfield=1; next;}
2738 (startfield==1) && ($1==device) {print $2; exit;}
2740 ($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}')
2746 # print the given directory filesystem type
2754 if [[ -z $dir ]]; then
2755 log_fail
"Usage: get_fstype <directory>"
2762 df
-n $dir |
awk '{print $3}'
2766 # Given a disk, label it to VTOC regardless what label was on the disk
2772 if [[ -z $disk ]]; then
2773 log_fail
"The disk name is unspecified."
2775 typeset label_file
=/var
/tmp
/labelvtoc.$$
2776 typeset arch
=$
(uname
-p)
2779 log_note
"Currently unsupported by the test framework"
2783 if [[ $arch == "i386" ]]; then
2784 echo "label" > $label_file
2785 echo "0" >> $label_file
2786 echo "" >> $label_file
2787 echo "q" >> $label_file
2788 echo "q" >> $label_file
2790 fdisk
-B $disk >/dev
/null
2>&1
2791 # wait a while for fdisk finishes
2793 elif [[ $arch == "sparc" ]]; then
2794 echo "label" > $label_file
2795 echo "0" >> $label_file
2796 echo "" >> $label_file
2797 echo "" >> $label_file
2798 echo "" >> $label_file
2799 echo "q" >> $label_file
2801 log_fail
"unknown arch type"
2804 format
-e -s -d $disk -f $label_file
2805 typeset
-i ret_val
=$?
2808 # wait the format to finish
2811 if ((ret_val
!= 0)); then
2812 log_fail
"unable to label $disk as VTOC."
2819 # check if the system was installed as zfsroot or not
2820 # return: 0 ture, otherwise false
2824 df
-n / |
grep zfs
> /dev
/null
2>&1
2829 # get the root filesystem name if it's zfsroot system.
2831 # return: root filesystem name
2835 rootfs
=$
(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \
2837 if [[ -z "$rootfs" ]]; then
2838 log_fail
"Can not get rootfs"
2840 zfs list
$rootfs > /dev
/null
2>&1
2841 if (($?
== 0)); then
2844 log_fail
"This is not a zfsroot system."
2849 # get the rootfs's pool name
2853 function get_rootpool
2857 rootfs
=$
(awk '{if ($2 == "/" && $3 =="zfs") print $1}' \
2859 if [[ -z "$rootfs" ]]; then
2860 log_fail
"Can not get rootpool"
2862 zfs list
$rootfs > /dev
/null
2>&1
2863 if (($?
== 0)); then
2864 rootpool
=`echo $rootfs | awk -F\/ '{print $1}'`
2867 log_fail
"This is not a zfsroot system."
2872 # Check if the given device is physical device
2874 function is_physical_device
#device
2876 typeset device
=${1#$DEV_DSKDIR}
2877 device
=${device#$DEV_RDSKDIR}
2880 [[ -b "$DEV_DSKDIR/$device" ]] && \
2881 [[ -f /sys
/module
/loop
/parameters
/max_part
]]
2884 echo $device |
egrep "^c[0-F]+([td][0-F]+)+$" > /dev
/null
2>&1
2890 # Check if the given device is a real device (ie SCSI device)
2892 function is_real_device
#disk
2895 [[ -z $disk ]] && log_fail
"No argument for disk given."
2898 lsblk
$DEV_RDSKDIR/$disk -o TYPE
2>/dev
/null | \
2899 egrep disk
>/dev
/null
2905 # Check if the given device is a loop device
2907 function is_loop_device
#disk
2910 [[ -z $disk ]] && log_fail
"No argument for disk given."
2913 lsblk
$DEV_RDSKDIR/$disk -o TYPE
2>/dev
/null | \
2914 egrep loop
>/dev
/null
2920 # Check if the given device is a multipath device and if there is a sybolic
2921 # link to a device mapper and to a disk
2922 # Currently no support for dm devices alone without multipath
2924 function is_mpath_device
#disk
2927 [[ -z $disk ]] && log_fail
"No argument for disk given."
2930 lsblk
$DEV_MPATHDIR/$disk -o TYPE
2>/dev
/null | \
2931 egrep mpath
>/dev
/null
2932 if (($?
== 0)); then
2933 readlink
$DEV_MPATHDIR/$disk > /dev
/null
2>&1
2941 # Set the slice prefix for disk partitioning depending
2942 # on whether the device is a real, multipath, or loop device.
2943 # Currently all disks have to be of the same type, so only
2944 # checks first disk to determine slice prefix.
2946 function set_slice_prefix
2952 while (( i
< $DISK_ARRAY_NUM )); do
2953 disk
="$(echo $DISKS | nawk '{print $(i + 1)}')"
2954 if ( is_mpath_device
$disk ) && [[ -z $
(echo $disk |
awk 'substr($1,18,1)\
2955 ~ /^[[:digit:]]+$/') ]] ||
( is_real_device
$disk ); then
2956 export SLICE_PREFIX
=""
2958 elif ( is_mpath_device
$disk || is_loop_device \
2960 export SLICE_PREFIX
="p"
2963 log_fail
"$disk not supported for partitioning."
2971 # Set the directory path of the listed devices in $DISK_ARRAY_NUM
2972 # Currently all disks have to be of the same type, so only
2973 # checks first disk to determine device directory
2974 # default = /dev (linux)
2975 # real disk = /dev (linux)
2976 # multipath device = /dev/mapper (linux)
2978 function set_device_dir
2984 while (( i
< $DISK_ARRAY_NUM )); do
2985 disk
="$(echo $DISKS | nawk '{print $(i + 1)}')"
2986 if is_mpath_device
$disk; then
2987 export DEV_DSKDIR
=$DEV_MPATHDIR
2990 export DEV_DSKDIR
=$DEV_RDSKDIR
2996 export DEV_DSKDIR
=$DEV_RDSKDIR
3001 # Get the directory path of given device
3003 function get_device_dir
#device
3007 if ! $
(is_physical_device
$device) ; then
3008 if [[ $device != "/" ]]; then
3011 if [[ -b "$DEV_DSKDIR/$device" ]]; then
3012 device
="$DEV_DSKDIR"
3021 # Get persistent name for given disk
3023 function get_persistent_disk_name
#device
3029 if is_real_device
$device; then
3030 dev_id
="$(udevadm info -q all -n $DEV_DSKDIR/$device \
3031 | egrep disk/by-id | nawk '{print $2; exit}' \
3032 | nawk -F / '{print $3}')"
3034 elif is_mpath_device
$device; then
3035 dev_id
="$(udevadm info -q all -n $DEV_DSKDIR/$device \
3036 | egrep disk/by-id/dm-uuid \
3037 | nawk '{print $2; exit}' \
3038 | nawk -F / '{print $3}')"
3049 # Load scsi_debug module with specified parameters
3051 function load_scsi_debug
# dev_size_mb add_host num_tgts max_luns
3058 [[ -z $devsize ]] ||
[[ -z $hosts ]] ||
[[ -z $tgts ]] || \
3059 [[ -z $luns ]] && log_fail
"Arguments invalid or missing"
3062 modprobe
-n scsi_debug
3063 if (($?
!= 0)); then
3064 log_unsupported
"Platform does not have scsi_debug"
3067 lsmod |
egrep scsi_debug
> /dev
/null
3068 if (($?
== 0)); then
3069 log_fail
"scsi_debug module already installed"
3071 log_must modprobe scsi_debug dev_size_mb
=$devsize \
3072 add_host
=$hosts num_tgts
=$tgts max_luns
=$luns
3074 lsscsi |
egrep scsi_debug
> /dev
/null
3075 if (($?
== 1)); then
3076 log_fail
"scsi_debug module install failed"
3083 # Get the package name
3085 function get_package_name
3087 typeset dirpath
=${1:-$STC_NAME}
3089 echo "SUNWstc-${dirpath}" |
/usr
/bin
/sed -e "s/\//-/g"
3093 # Get the word numbers from a string separated by white space
3095 function get_word_count
3101 # To verify if the require numbers of disks is given
3103 function verify_disk_count
3105 typeset
-i min
=${2:-1}
3107 typeset
-i count
=$
(get_word_count
"$1")
3109 if ((count
< min
)); then
3110 log_untested
"A minimum of $min disks is required to run." \
3111 " You specified $count disk(s)"
3115 function ds_is_volume
3117 typeset
type=$
(get_prop
type $1)
3118 [[ $type = "volume" ]] && return 0
3122 function ds_is_filesystem
3124 typeset
type=$
(get_prop
type $1)
3125 [[ $type = "filesystem" ]] && return 0
3129 function ds_is_snapshot
3131 typeset
type=$
(get_prop
type $1)
3132 [[ $type = "snapshot" ]] && return 0
3137 # Check if Trusted Extensions are installed and enabled
3139 function is_te_enabled
3141 svcs
-H -o state labeld
2>/dev
/null |
grep "enabled"
3142 if (($?
!= 0)); then
3149 # Utility function to determine if a system has multiple cpus.
3155 (($
(psrinfo |
wc -l) > 1))
3161 function get_cpu_freq
3164 lscpu |
awk '/CPU MHz/ { print $3 }'
3166 psrinfo
-v 0 |
awk '/processor operates at/ {print $6}'
3170 # Run the given command as the user provided.
3176 log_note
"user:$user $@"
3177 eval su
- \
$user -c \"$@
\" > /tmp
/out
2>/tmp
/err
3182 # Check if the pool contains the specified vdevs
3187 # Return 0 if the vdevs are contained in the pool, 1 if any of the specified
3188 # vdevs is not in the pool, and 2 if pool name is missing.
3190 function vdevs_in_pool
3195 if [[ -z $pool ]]; then
3196 log_note
"Missing pool name."
3202 typeset tmpfile
=$
(mktemp
)
3203 zpool list
-Hv "$pool" >$tmpfile
3205 grep -w ${vdev##*/} $tmpfile >/dev
/null
2>&1
3206 [[ $?
-ne 0 ]] && return 1
3220 max
=$
(echo $
((max
> i ? max
: i
)))
3232 min
=$
(echo $
((min
< i ? min
: i
)))
3239 # Synchronize all the data in pool
3243 function sync_pool
#pool
3245 typeset pool
=${1:-$TESTPOOL}
3249 # Flush all the pool data.
3251 zpool scrub
$pool >/dev
/null
2>&1
3253 (( $ret != 0 )) && \
3254 log_fail
"zpool scrub $pool failed."
3256 while ! is_pool_scrubbed
$pool; do
3257 if is_pool_resilvered
$pool ; then
3258 log_fail
"$pool should not be resilver completed."
3265 # Wait for zpool 'freeing' property drops to zero.
3269 function wait_freeing
#pool
3271 typeset pool
=${1:-$TESTPOOL}
3273 [[ "0" == "$(zpool list -Ho freeing $pool)" ]] && break
3279 # Check if ZED is currently running, if not start ZED.
3284 # ZEDLET_DIR=/var/tmp/zed
3285 if [[ ! -d $ZEDLET_DIR ]]; then
3286 log_must mkdir
$ZEDLET_DIR
3289 # Verify the ZED is not already running.
3290 pgrep
-x zed
> /dev
/null
3291 if (($?
== 0)); then
3292 log_fail
"ZED already running"
3295 # ZEDLETDIR=</etc/zfs/zed.d | ${SRCDIR}/cmd/zed/zed.d>
3296 log_must
cp ${ZEDLETDIR}/all-syslog.sh
$ZEDLET_DIR
3298 log_note
"Starting ZED"
3299 # run ZED in the background and redirect foreground logging
3301 log_must
eval "zed -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid" \
3302 "-s $ZEDLET_DIR/state 2>${ZEDLET_DIR}/zedlog &"
3312 if [[ -f ${ZEDLET_DIR}/zed.pid
]]; then
3313 zedpid
=$
(cat ${ZEDLET_DIR}/zed.pid
)
3314 log_must
kill $zedpid
3316 log_must
rm -f ${ZEDLET_DIR}/all-syslog.sh
3317 log_must
rm -f ${ZEDLET_DIR}/zed.pid
3318 log_must
rm -f ${ZEDLET_DIR}/zedlog
3319 log_must
rm -f ${ZEDLET_DIR}/state
3320 log_must
rmdir $ZEDLET_DIR