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.
30 # Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
33 .
${STF_TOOLS}/include
/logapi.shlib
34 .
${STF_SUITE}/include
/math.shlib
35 .
${STF_SUITE}/include
/blkdev.shlib
38 # Apply constrained path when available. This is required since the
39 # PATH may have been modified by sudo's secure_path behavior.
41 if [ -n "$STF_PATH" ]; then
45 # Linux kernel version comparison function
47 # $1 Linux version ("4.10", "2.6.32") or blank for installed Linux version
49 # Used for comparison: if [ $(linux_version) -ge $(linux_version "2.6.32") ]
51 function linux_version
55 [[ -z "$ver" ]] && ver
=$
(uname
-r |
grep -Eo "^[0-9]+\.[0-9]+\.[0-9]+")
57 typeset version
=$
(echo $ver | cut
-d '.' -f 1)
58 typeset major
=$
(echo $ver | cut
-d '.' -f 2)
59 typeset minor
=$
(echo $ver | cut
-d '.' -f 3)
61 [[ -z "$version" ]] && version
=0
62 [[ -z "$major" ]] && major
=0
63 [[ -z "$minor" ]] && minor
=0
65 echo $
((version
* 10000 + major
* 100 + minor
))
68 # Determine if this is a Linux test system
70 # Return 0 if platform Linux, 1 if otherwise
74 if [[ $
(uname
-o) == "GNU/Linux" ]]; then
81 # Determine if this is a 32-bit system
83 # Return 0 if platform is 32-bit, 1 if otherwise
87 if [[ $
(getconf LONG_BIT
) == "32" ]]; then
94 # Determine if kmemleak is enabled
96 # Return 0 if kmemleak is enabled, 1 if otherwise
100 if is_linux
&& [[ -e /sys
/kernel
/debug
/kmemleak
]]; then
107 # Determine whether a dataset is mounted
110 # $2 filesystem type; optional - defaulted to zfs
112 # Return 0 if dataset is mounted; 1 if unmounted; 2 on error
117 [[ -z $fstype ]] && fstype
=zfs
118 typeset out dir name ret
122 if [[ "$1" == "/"* ]] ; then
123 for out
in $
(zfs mount |
awk '{print $2}'); do
124 [[ $1 == $out ]] && return 0
127 for out
in $
(zfs mount |
awk '{print $1}'); do
128 [[ $1 == $out ]] && return 0
133 out
=$
(df
-F $fstype $1 2>/dev
/null
)
135 (($ret != 0)) && return $ret
143 [[ "$1" == "$dir" ||
"$1" == "$name" ]] && return 0
146 out
=$
(df
-t $fstype $1 2>/dev
/null
)
150 if [[ -L "$ZVOL_DEVDIR/$1" ]]; then
151 link
=$
(readlink
-f $ZVOL_DEVDIR/$1)
152 [[ -n "$link" ]] && \
153 mount |
grep -q "^$link" && \
162 # Return 0 if a dataset is mounted; 1 otherwise
165 # $2 filesystem type; optional - defaulted to zfs
170 (($?
== 0)) && return 0
174 # Return 0 if a dataset is unmounted; 1 otherwise
177 # $2 filesystem type; optional - defaulted to zfs
182 (($?
== 1)) && return 0
192 echo $1 |
sed "s/,/ /g"
195 function default_setup
197 default_setup_noexit
"$@"
203 # Given a list of disks, setup storage pools and datasets.
205 function default_setup_noexit
210 log_note begin default_setup_noexit
212 if is_global_zone
; then
213 if poolexists
$TESTPOOL ; then
214 destroy_pool
$TESTPOOL
216 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
217 log_must zpool create
-f $TESTPOOL $disklist
222 rm -rf $TESTDIR || log_unresolved Could not remove
$TESTDIR
223 mkdir
-p $TESTDIR || log_unresolved Could not create
$TESTDIR
225 log_must zfs create
$TESTPOOL/$TESTFS
226 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
228 if [[ -n $container ]]; then
229 rm -rf $TESTDIR1 || \
230 log_unresolved Could not remove
$TESTDIR1
231 mkdir
-p $TESTDIR1 || \
232 log_unresolved Could not create
$TESTDIR1
234 log_must zfs create
$TESTPOOL/$TESTCTR
235 log_must zfs
set canmount
=off
$TESTPOOL/$TESTCTR
236 log_must zfs create
$TESTPOOL/$TESTCTR/$TESTFS1
237 log_must zfs
set mountpoint
=$TESTDIR1 \
238 $TESTPOOL/$TESTCTR/$TESTFS1
241 if [[ -n $volume ]]; then
242 if is_global_zone
; then
243 log_must zfs create
-V $VOLSIZE $TESTPOOL/$TESTVOL
246 log_must zfs create
$TESTPOOL/$TESTVOL
252 # Given a list of disks, setup a storage pool, file system and
255 function default_container_setup
259 default_setup
"$disklist" "true"
263 # Given a list of disks, setup a storage pool,file system
266 function default_volume_setup
270 default_setup
"$disklist" "" "true"
274 # Given a list of disks, setup a storage pool,file system,
275 # a container and a volume.
277 function default_container_volume_setup
281 default_setup
"$disklist" "true" "true"
285 # Create a snapshot on a filesystem or volume. Defaultly create a snapshot on
288 # $1 Existing filesystem or volume name. Default, $TESTPOOL/$TESTFS
289 # $2 snapshot name. Default, $TESTSNAP
291 function create_snapshot
293 typeset fs_vol
=${1:-$TESTPOOL/$TESTFS}
294 typeset snap
=${2:-$TESTSNAP}
296 [[ -z $fs_vol ]] && log_fail
"Filesystem or volume's name is undefined."
297 [[ -z $snap ]] && log_fail
"Snapshot's name is undefined."
299 if snapexists
$fs_vol@
$snap; then
300 log_fail
"$fs_vol@$snap already exists."
302 datasetexists
$fs_vol || \
303 log_fail
"$fs_vol must exist."
305 log_must zfs snapshot
$fs_vol@
$snap
309 # Create a clone from a snapshot, default clone name is $TESTCLONE.
311 # $1 Existing snapshot, $TESTPOOL/$TESTFS@$TESTSNAP is default.
312 # $2 Clone name, $TESTPOOL/$TESTCLONE is default.
314 function create_clone
# snapshot clone
316 typeset snap
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
317 typeset clone
=${2:-$TESTPOOL/$TESTCLONE}
320 log_fail
"Snapshot name is undefined."
322 log_fail
"Clone name is undefined."
324 log_must zfs clone
$snap $clone
328 # Create a bookmark of the given snapshot. Defaultly create a bookmark on
331 # $1 Existing filesystem or volume name. Default, $TESTFS
332 # $2 Existing snapshot name. Default, $TESTSNAP
333 # $3 bookmark name. Default, $TESTBKMARK
335 function create_bookmark
337 typeset fs_vol
=${1:-$TESTFS}
338 typeset snap
=${2:-$TESTSNAP}
339 typeset bkmark
=${3:-$TESTBKMARK}
341 [[ -z $fs_vol ]] && log_fail
"Filesystem or volume's name is undefined."
342 [[ -z $snap ]] && log_fail
"Snapshot's name is undefined."
343 [[ -z $bkmark ]] && log_fail
"Bookmark's name is undefined."
345 if bkmarkexists
$fs_vol#$bkmark; then
346 log_fail
"$fs_vol#$bkmark already exists."
348 datasetexists
$fs_vol || \
349 log_fail
"$fs_vol must exist."
350 snapexists
$fs_vol@
$snap || \
351 log_fail
"$fs_vol@$snap must exist."
353 log_must zfs bookmark
$fs_vol@
$snap $fs_vol#$bkmark
357 # Create a temporary clone result of an interrupted resumable 'zfs receive'
358 # $1 Destination filesystem name. Must not exist, will be created as the result
359 # of this function along with its %recv temporary clone
360 # $2 Source filesystem name. Must not exist, will be created and destroyed
362 function create_recv_clone
365 typeset sendfs
="${2:-$TESTPOOL/create_recv_clone}"
366 typeset snap
="$sendfs@snap1"
367 typeset incr
="$sendfs@snap2"
368 typeset mountpoint
="$TESTDIR/create_recv_clone"
369 typeset sendfile
="$TESTDIR/create_recv_clone.zsnap"
371 [[ -z $recvfs ]] && log_fail
"Recv filesystem's name is undefined."
373 datasetexists
$recvfs && log_fail
"Recv filesystem must not exist."
374 datasetexists
$sendfs && log_fail
"Send filesystem must not exist."
376 log_must zfs create
-o mountpoint
="$mountpoint" $sendfs
377 log_must zfs snapshot
$snap
378 log_must
eval "zfs send $snap | zfs recv -u $recvfs"
379 log_must mkfile
1m
"$mountpoint/data"
380 log_must zfs snapshot
$incr
381 log_must
eval "zfs send -i $snap $incr | dd bs=10K count=1 > $sendfile"
382 log_mustnot
eval "zfs recv -su $recvfs < $sendfile"
383 destroy_dataset
"$sendfs" "-r"
384 log_must
rm -f "$sendfile"
386 if [[ $
(get_prop
'inconsistent' "$recvfs/%recv") -ne 1 ]]; then
387 log_fail
"Error creating temporary $recvfs/%recv clone"
391 function default_mirror_setup
393 default_mirror_setup_noexit
$1 $2 $3
399 # Given a pair of disks, set up a storage pool and dataset for the mirror
400 # @parameters: $1 the primary side of the mirror
401 # $2 the secondary side of the mirror
402 # @uses: ZPOOL ZFS TESTPOOL TESTFS
403 function default_mirror_setup_noexit
405 readonly func
="default_mirror_setup_noexit"
409 [[ -z $primary ]] && \
410 log_fail
"$func: No parameters passed"
411 [[ -z $secondary ]] && \
412 log_fail
"$func: No secondary partition passed"
413 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
414 log_must zpool create
-f $TESTPOOL mirror $@
415 log_must zfs create
$TESTPOOL/$TESTFS
416 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
420 # create a number of mirrors.
421 # We create a number($1) of 2 way mirrors using the pairs of disks named
422 # on the command line. These mirrors are *not* mounted
423 # @parameters: $1 the number of mirrors to create
424 # $... the devices to use to create the mirrors on
425 # @uses: ZPOOL ZFS TESTPOOL
426 function setup_mirrors
428 typeset
-i nmirrors
=$1
431 while ((nmirrors
> 0)); do
432 log_must
test -n "$1" -a -n "$2"
433 [[ -d /$TESTPOOL$nmirrors ]] && rm -rf /$TESTPOOL$nmirrors
434 log_must zpool create
-f $TESTPOOL$nmirrors mirror
$1 $2
436 ((nmirrors
= nmirrors
- 1))
441 # create a number of raidz pools.
442 # We create a number($1) of 2 raidz pools using the pairs of disks named
443 # on the command line. These pools are *not* mounted
444 # @parameters: $1 the number of pools to create
445 # $... the devices to use to create the pools on
446 # @uses: ZPOOL ZFS TESTPOOL
447 function setup_raidzs
449 typeset
-i nraidzs
=$1
452 while ((nraidzs
> 0)); do
453 log_must
test -n "$1" -a -n "$2"
454 [[ -d /$TESTPOOL$nraidzs ]] && rm -rf /$TESTPOOL$nraidzs
455 log_must zpool create
-f $TESTPOOL$nraidzs raidz
$1 $2
457 ((nraidzs
= nraidzs
- 1))
462 # Destroy the configured testpool mirrors.
463 # the mirrors are of the form ${TESTPOOL}{number}
464 # @uses: ZPOOL ZFS TESTPOOL
465 function destroy_mirrors
467 default_cleanup_noexit
473 # Given a minimum of two disks, set up a storage pool and dataset for the raid-z
474 # $1 the list of disks
476 function default_raidz_setup
478 typeset disklist
="$*"
479 disks
=(${disklist[*]})
481 if [[ ${#disks[*]} -lt 2 ]]; then
482 log_fail
"A raid-z requires a minimum of two disks."
485 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
486 log_must zpool create
-f $TESTPOOL raidz
$disklist
487 log_must zfs create
$TESTPOOL/$TESTFS
488 log_must zfs
set mountpoint
=$TESTDIR $TESTPOOL/$TESTFS
494 # Common function used to cleanup storage pools and datasets.
496 # Invoked at the start of the test suite to ensure the system
497 # is in a known state, and also at the end of each set of
498 # sub-tests to ensure errors from one set of tests doesn't
499 # impact the execution of the next set.
501 function default_cleanup
503 default_cleanup_noexit
509 # Utility function used to list all available pool names.
511 # NOTE: $KEEP is a variable containing pool names, separated by a newline
512 # character, that must be excluded from the returned list.
514 function get_all_pools
516 zpool list
-H -o name |
grep -Fvx "$KEEP" |
grep -v "$NO_POOLS"
519 function default_cleanup_noexit
523 # Destroying the pool will also destroy any
524 # filesystems it contains.
526 if is_global_zone
; then
527 zfs unmount
-a > /dev
/null
2>&1
528 ALL_POOLS
=$
(get_all_pools
)
529 # Here, we loop through the pools we're allowed to
530 # destroy, only destroying them if it's safe to do
532 while [ ! -z ${ALL_POOLS} ]
534 for pool
in ${ALL_POOLS}
536 if safe_to_destroy_pool
$pool ;
540 ALL_POOLS
=$
(get_all_pools
)
547 for fs
in $
(zfs list
-H -o name \
548 |
grep "^$ZONE_POOL/$ZONE_CTR[01234]/"); do
549 destroy_dataset
"$fs" "-Rf"
552 # Need cleanup here to avoid garbage dir left.
553 for fs
in $
(zfs list
-H -o name
); do
554 [[ $fs == /$ZONE_POOL ]] && continue
555 [[ -d $fs ]] && log_must
rm -rf $fs/*
559 # Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to
562 for fs
in $
(zfs list
-H -o name
); do
563 if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then
564 log_must zfs
set reservation
=none
$fs
565 log_must zfs
set recordsize
=128K
$fs
566 log_must zfs
set mountpoint
=/$fs $fs
568 enc
=$
(get_prop encryption
$fs)
569 if [[ $?
-ne 0 ]] ||
[[ -z "$enc" ]] || \
570 [[ "$enc" == "off" ]]; then
571 log_must zfs
set checksum
=on
$fs
573 log_must zfs
set compression
=off
$fs
574 log_must zfs
set atime
=on
$fs
575 log_must zfs
set devices
=off
$fs
576 log_must zfs
set exec=on
$fs
577 log_must zfs
set setuid
=on
$fs
578 log_must zfs
set readonly=off
$fs
579 log_must zfs
set snapdir
=hidden
$fs
580 log_must zfs
set aclmode
=groupmask
$fs
581 log_must zfs
set aclinherit
=secure
$fs
586 [[ -d $TESTDIR ]] && \
587 log_must
rm -rf $TESTDIR
590 if is_mpath_device
$disk1; then
597 # Common function used to cleanup storage pools, file systems
600 function default_container_cleanup
602 if ! is_global_zone
; then
606 ismounted
$TESTPOOL/$TESTCTR/$TESTFS1
608 log_must zfs unmount
$TESTPOOL/$TESTCTR/$TESTFS1
610 destroy_dataset
"$TESTPOOL/$TESTCTR/$TESTFS1" "-R"
611 destroy_dataset
"$TESTPOOL/$TESTCTR" "-Rf"
613 [[ -e $TESTDIR1 ]] && \
614 log_must
rm -rf $TESTDIR1 > /dev
/null
2>&1
620 # Common function used to cleanup snapshot of file system or volume. Default to
621 # delete the file system's snapshot
625 function destroy_snapshot
627 typeset snap
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
629 if ! snapexists
$snap; then
630 log_fail
"'$snap' does not existed."
634 # For the sake of the value which come from 'get_prop' is not equal
635 # to the really mountpoint when the snapshot is unmounted. So, firstly
636 # check and make sure this snapshot's been mounted in current system.
639 if ismounted
$snap; then
640 mtpt
=$
(get_prop mountpoint
$snap)
642 log_fail
"get_prop mountpoint $snap failed."
645 destroy_dataset
"$snap"
646 [[ $mtpt != "" && -d $mtpt ]] && \
647 log_must
rm -rf $mtpt
651 # Common function used to cleanup clone.
655 function destroy_clone
657 typeset clone
=${1:-$TESTPOOL/$TESTCLONE}
659 if ! datasetexists
$clone; then
660 log_fail
"'$clone' does not existed."
663 # With the same reason in destroy_snapshot
665 if ismounted
$clone; then
666 mtpt
=$
(get_prop mountpoint
$clone)
668 log_fail
"get_prop mountpoint $clone failed."
671 destroy_dataset
"$clone"
672 [[ $mtpt != "" && -d $mtpt ]] && \
673 log_must
rm -rf $mtpt
677 # Common function used to cleanup bookmark of file system or volume. Default
678 # to delete the file system's bookmark.
682 function destroy_bookmark
684 typeset bkmark
=${1:-$TESTPOOL/$TESTFS#$TESTBKMARK}
686 if ! bkmarkexists
$bkmark; then
687 log_fail
"'$bkmarkp' does not existed."
690 destroy_dataset
"$bkmark"
693 # Return 0 if a snapshot exists; $? otherwise
699 zfs list
-H -t snapshot
"$1" > /dev
/null
2>&1
704 # Return 0 if a bookmark exists; $? otherwise
708 function bkmarkexists
710 zfs list
-H -t bookmark
"$1" > /dev
/null
2>&1
715 # Set a property to a certain value on a dataset.
716 # Sets a property of the dataset to the value as passed in.
718 # $1 dataset who's property is being set
720 # $3 value to set property to
722 # 0 if the property could be set.
723 # non-zero otherwise.
726 function dataset_setprop
728 typeset fn
=dataset_setprop
731 log_note
"$fn: Insufficient parameters (need 3, had $#)"
735 output
=$
(zfs
set $2=$3 $1 2>&1)
738 log_note
"Setting property on $1 failed."
739 log_note
"property $2=$3"
740 log_note
"Return Code: $rv"
741 log_note
"Output: $output"
748 # Assign suite defined dataset properties.
749 # This function is used to apply the suite's defined default set of
750 # properties to a dataset.
751 # @parameters: $1 dataset to use
752 # @uses: ZFS COMPRESSION_PROP CHECKSUM_PROP
754 # 0 if the dataset has been altered.
755 # 1 if no pool name was passed in.
756 # 2 if the dataset could not be found.
757 # 3 if the dataset could not have it's properties set.
759 function dataset_set_defaultproperties
763 [[ -z $dataset ]] && return 1
767 for confset
in $
(zfs list
); do
768 if [[ $dataset = $confset ]]; then
773 [[ $found -eq 0 ]] && return 2
774 if [[ -n $COMPRESSION_PROP ]]; then
775 dataset_setprop
$dataset compression
$COMPRESSION_PROP || \
777 log_note
"Compression set to '$COMPRESSION_PROP' on $dataset"
779 if [[ -n $CHECKSUM_PROP ]]; then
780 dataset_setprop
$dataset checksum
$CHECKSUM_PROP || \
782 log_note
"Checksum set to '$CHECKSUM_PROP' on $dataset"
788 # Check a numeric assertion
789 # @parameter: $@ the assertion to check
790 # @output: big loud notice if assertion failed
795 (($@
)) || log_fail
"$@"
799 # Function to format partition size of a disk
800 # Given a disk cxtxdx reduces all partitions
803 function zero_partitions
#<whole_disk_name>
809 log_must parted
$DEV_DSKDIR/$diskname -s -- mklabel gpt
811 for i
in 0 1 3 4 5 6 7
813 log_must set_partition
$i "" 0mb
$diskname
821 # Given a slice, size and disk, this function
822 # formats the slice to the specified size.
823 # Size should be specified with units as per
824 # the `format` command requirements eg. 100mb 3gb
826 # NOTE: This entire interface is problematic for the Linux parted utilty
827 # which requires the end of the partition to be specified. It would be
828 # best to retire this interface and replace it with something more flexible.
829 # At the moment a best effort is made.
831 function set_partition
#<slice_num> <slice_start> <size_plus_units> <whole_disk_name>
833 typeset
-i slicenum
=$1
837 [[ -z $slicenum ||
-z $size ||
-z $disk ]] && \
838 log_fail
"The slice, size or disk name is unspecified."
841 typeset size_mb
=${size%%[mMgG]}
843 size_mb
=${size_mb%%[mMgG][bB]}
844 if [[ ${size:1:1} == 'g' ]]; then
845 ((size_mb
= size_mb
* 1024))
848 # Create GPT partition table when setting slice 0 or
849 # when the device doesn't already contain a GPT label.
850 parted
$DEV_DSKDIR/$disk -s -- print
1 >/dev
/null
852 if [[ $slicenum -eq 0 ||
$ret_val -ne 0 ]]; then
853 parted
$DEV_DSKDIR/$disk -s -- mklabel gpt
854 if [[ $?
-ne 0 ]]; then
855 log_note
"Failed to create GPT partition table on $disk"
860 # When no start is given align on the first cylinder.
861 if [[ -z "$start" ]]; then
865 # Determine the cylinder size for the device and using
866 # that calculate the end offset in cylinders.
867 typeset
-i cly_size_kb
=0
868 cly_size_kb
=$
(parted
-m $DEV_DSKDIR/$disk -s -- \
869 unit cyl print |
head -3 |
tail -1 | \
870 awk -F '[:k.]' '{print $4}')
871 ((end
= (size_mb
* 1024 / cly_size_kb
) + start
))
873 parted
$DEV_DSKDIR/$disk -s -- \
874 mkpart part
$slicenum ${start}cyl
${end}cyl
875 if [[ $?
-ne 0 ]]; then
876 log_note
"Failed to create partition $slicenum on $disk"
880 blockdev
--rereadpt $DEV_DSKDIR/$disk 2>/dev
/null
883 typeset format_file
=/var
/tmp
/format_in.$$
885 echo "partition" >$format_file
886 echo "$slicenum" >> $format_file
887 echo "" >> $format_file
888 echo "" >> $format_file
889 echo "$start" >> $format_file
890 echo "$size" >> $format_file
891 echo "label" >> $format_file
892 echo "" >> $format_file
893 echo "q" >> $format_file
894 echo "q" >> $format_file
896 format
-e -s -d $disk -f $format_file
901 if [[ $ret_val -ne 0 ]]; then
902 log_note
"Unable to format $disk slice $slicenum to $size"
909 # Delete all partitions on all disks - this is specifically for the use of multipath
910 # devices which currently can only be used in the test suite as raw/un-partitioned
911 # devices (ie a zpool cannot be created on a whole mpath device that has partitions)
913 function delete_partitions
917 if [[ -z $DISK_ARRAY_NUM ]]; then
918 DISK_ARRAY_NUM
=$
(echo ${DISKS} | nawk
'{print NF}')
920 if [[ -z $DISKSARRAY ]]; then
925 if (( $DISK_ARRAY_NUM == 1 )); then
926 while ((j
< MAX_PARTITIONS
)); do
927 parted
$DEV_DSKDIR/$DISK -s rm $j \
929 if (( $?
== 1 )); then
930 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
931 if (( $?
== 1 )); then
932 log_note
"Partitions for $DISK should be deleted"
934 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
938 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
939 if (( $?
== 0 )); then
940 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
946 for disk
in `echo $DISKSARRAY`; do
947 while ((j
< MAX_PARTITIONS
)); do
948 parted
$DEV_DSKDIR/$disk -s rm $j > /dev
/null
2>&1
949 if (( $?
== 1 )); then
950 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
951 if (( $?
== 1 )); then
952 log_note
"Partitions for $disk should be deleted"
954 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
958 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
959 if (( $?
== 0 )); then
960 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
973 # Get the end cyl of the given slice
975 function get_endslice
#<disk> <slice>
979 if [[ -z $disk ||
-z $slice ]] ; then
980 log_fail
"The disk name or slice number is unspecified."
984 endcyl
=$
(parted
-s $DEV_DSKDIR/$disk -- unit cyl print | \
985 grep "part${slice}" | \
988 ((endcyl
= (endcyl
+ 1)))
990 disk
=${disk#/dev/dsk/}
991 disk
=${disk#/dev/rdsk/}
995 ratio
=$
(prtvtoc
/dev
/rdsk
/${disk}s2 | \
996 grep "sectors\/cylinder" | \
999 if ((ratio
== 0)); then
1003 typeset
-i endcyl
=$
(prtvtoc
-h /dev
/rdsk
/${disk}s2 |
1004 nawk
-v token
="$slice" '{if ($1==token) print $6}')
1006 ((endcyl
= (endcyl
+ 1) / ratio
))
1014 # Given a size,disk and total slice number, this function formats the
1015 # disk slices from 0 to the total slice number with the same specified
1018 function partition_disk
#<slice_size> <whole_disk_name> <total_slices>
1021 typeset slice_size
=$1
1022 typeset disk_name
=$2
1023 typeset total_slices
=$3
1026 zero_partitions
$disk_name
1027 while ((i
< $total_slices)); do
1034 log_must set_partition
$i "$cyl" $slice_size $disk_name
1035 cyl
=$
(get_endslice
$disk_name $i)
1041 # This function continues to write to a filenum number of files into dirnum
1042 # number of directories until either file_write returns an error or the
1043 # maximum number of files per directory have been written.
1046 # fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data]
1048 # Return value: 0 on success
1052 # destdir: is the directory where everything is to be created under
1053 # dirnum: the maximum number of subdirectories to use, -1 no limit
1054 # filenum: the maximum number of files per subdirectory
1055 # bytes: number of bytes to write
1056 # num_writes: numer of types to write out bytes
1057 # data: the data that will be written
1060 # file_fs /testdir 20 25 1024 256 0
1062 # Note: bytes * num_writes equals the size of the testfile
1064 function fill_fs
# destdir dirnum filenum bytes num_writes data
1066 typeset destdir
=${1:-$TESTDIR}
1067 typeset
-i dirnum
=${2:-50}
1068 typeset
-i filenum
=${3:-50}
1069 typeset
-i bytes
=${4:-8192}
1070 typeset
-i num_writes
=${5:-10240}
1071 typeset
-i data
=${6:-0}
1073 typeset
-i odirnum
=1
1074 typeset
-i idirnum
=0
1078 log_must mkdir
-p $destdir/$idirnum
1079 while (($odirnum > 0)); do
1080 if ((dirnum
>= 0 && idirnum
>= dirnum
)); then
1084 file_write
-o create
-f $destdir/$idirnum/$TESTFILE.
$fn \
1085 -b $bytes -c $num_writes -d $data
1087 if (($retval != 0)); then
1091 if (($fn >= $filenum)); then
1093 ((idirnum
= idirnum
+ 1))
1094 log_must mkdir
-p $destdir/$idirnum
1103 # Simple function to get the specified property. If unable to
1104 # get the property then exits.
1106 # Note property is in 'parsable' format (-p)
1108 function get_prop
# property dataset
1114 prop_val
=$
(zfs get
-pH -o value
$prop $dataset 2>/dev
/null
)
1115 if [[ $?
-ne 0 ]]; then
1116 log_note
"Unable to get $prop property for dataset " \
1126 # Simple function to get the specified property of pool. If unable to
1127 # get the property then exits.
1129 # Note property is in 'parsable' format (-p)
1131 function get_pool_prop
# property pool
1137 if poolexists
$pool ; then
1138 prop_val
=$
(zpool get
-pH $prop $pool 2>/dev
/null |
tail -1 | \
1140 if [[ $?
-ne 0 ]]; then
1141 log_note
"Unable to get $prop property for pool " \
1146 log_note
"Pool $pool not exists."
1154 # Return 0 if a pool exists; $? otherwise
1162 if [[ -z $pool ]]; then
1163 log_note
"No pool name given."
1167 zpool get name
"$pool" > /dev
/null
2>&1
1171 # Return 0 if all the specified datasets exist; $? otherwise
1174 function datasetexists
1176 if (($# == 0)); then
1177 log_note
"No dataset name given."
1181 while (($# > 0)); do
1182 zfs get name
$1 > /dev
/null
2>&1 || \
1190 # return 0 if none of the specified datasets exists, otherwise return 1.
1193 function datasetnonexists
1195 if (($# == 0)); then
1196 log_note
"No dataset name given."
1200 while (($# > 0)); do
1201 zfs list
-H -t filesystem
,snapshot
,volume
$1 > /dev
/null
2>&1 \
1210 # Given a mountpoint, or a dataset name, determine if it is shared via NFS.
1212 # Returns 0 if shared, 1 otherwise.
1219 if [[ $fs != "/"* ]] ; then
1220 if datasetnonexists
"$fs" ; then
1223 mtpt
=$
(get_prop mountpoint
"$fs")
1225 none|legacy|
-) return 1
1234 for mtpt
in `share | awk '{print $1}'` ; do
1235 if [[ $mtpt == $fs ]] ; then
1242 for mtpt
in `share | awk '{print $2}'` ; do
1243 if [[ $mtpt == $fs ]] ; then
1248 typeset stat
=$
(svcs
-H -o STA nfs
/server
:default
)
1249 if [[ $stat != "ON" ]]; then
1250 log_note
"Current nfs/server status: $stat"
1257 # Given a dataset name determine if it is shared via SMB.
1259 # Returns 0 if shared, 1 otherwise.
1261 function is_shared_smb
1266 if datasetnonexists
"$fs" ; then
1269 fs
=$
(echo $fs |
sed 's@/@_@g')
1273 for mtpt
in `net usershare list | awk '{print $1}'` ; do
1274 if [[ $mtpt == $fs ]] ; then
1280 log_unsupported
"Currently unsupported by the test framework"
1286 # Given a mountpoint, determine if it is not shared via NFS.
1288 # Returns 0 if not shared, 1 otherwise.
1295 if (($?
== 0)); then
1303 # Given a dataset determine if it is not shared via SMB.
1305 # Returns 0 if not shared, 1 otherwise.
1307 function not_shared_smb
1312 if (($?
== 0)); then
1320 # Helper function to unshare a mountpoint.
1322 function unshare_fs
#fs
1326 is_shared
$fs || is_shared_smb
$fs
1327 if (($?
== 0)); then
1328 log_must zfs unshare
$fs
1335 # Helper function to share a NFS mountpoint.
1337 function share_nfs
#fs
1343 if (($?
!= 0)); then
1344 log_must share
"*:$fs"
1348 if (($?
!= 0)); then
1349 log_must share
-F nfs
$fs
1357 # Helper function to unshare a NFS mountpoint.
1359 function unshare_nfs
#fs
1365 if (($?
== 0)); then
1366 log_must unshare
-u "*:$fs"
1370 if (($?
== 0)); then
1371 log_must unshare
-F nfs
$fs
1379 # Helper function to show NFS shares.
1381 function showshares_nfs
1393 # Helper function to show SMB shares.
1395 function showshares_smb
1407 # Check NFS server status and trigger it online.
1409 function setup_nfs_server
1411 # Cannot share directory in non-global zone.
1413 if ! is_global_zone
; then
1414 log_note
"Cannot trigger NFS server by sharing in LZ."
1420 # Re-synchronize /var/lib/nfs/etab with /etc/exports and
1421 # /etc/exports.d./* to provide a clean test environment.
1425 log_note
"NFS server must be started prior to running ZTS."
1429 typeset nfs_fmri
="svc:/network/nfs/server:default"
1430 if [[ $
(svcs
-Ho STA
$nfs_fmri) != "ON" ]]; then
1432 # Only really sharing operation can enable NFS server
1433 # to online permanently.
1435 typeset dummy
=/tmp
/dummy
1437 if [[ -d $dummy ]]; then
1438 log_must
rm -rf $dummy
1441 log_must mkdir
$dummy
1442 log_must share
$dummy
1445 # Waiting for fmri's status to be the final status.
1446 # Otherwise, in transition, an asterisk (*) is appended for
1447 # instances, unshare will reverse status to 'DIS' again.
1449 # Waiting for 1's at least.
1453 while [[ timeout
-ne 0 && $
(svcs
-Ho STA
$nfs_fmri) == *'*' ]]
1460 log_must unshare
$dummy
1461 log_must
rm -rf $dummy
1464 log_note
"Current NFS status: '$(svcs -Ho STA,FMRI $nfs_fmri)'"
1468 # To verify whether calling process is in global zone
1470 # Return 0 if in global zone, 1 in non-global zone
1472 function is_global_zone
1477 typeset cur_zone
=$
(zonename
2>/dev
/null
)
1478 if [[ $cur_zone != "global" ]]; then
1486 # Verify whether test is permitted to run from
1487 # global zone, local zone, or both
1489 # $1 zone limit, could be "global", "local", or "both"(no limit)
1491 # Return 0 if permitted, otherwise exit with log_unsupported
1493 function verify_runnable
# zone limit
1497 [[ -z $limit ]] && return 0
1499 if is_global_zone
; then
1503 local) log_unsupported
"Test is unable to run from "\
1506 *) log_note
"Warning: unknown limit $limit - " \
1514 global
) log_unsupported
"Test is unable to run from "\
1517 *) log_note
"Warning: unknown limit $limit - " \
1528 # Return 0 if create successfully or the pool exists; $? otherwise
1529 # Note: In local zones, this function should return 0 silently.
1532 # $2-n - [keyword] devs_list
1534 function create_pool
#pool devs_list
1536 typeset pool
=${1%%/*}
1540 if [[ -z $pool ]]; then
1541 log_note
"Missing pool name."
1545 if poolexists
$pool ; then
1549 if is_global_zone
; then
1550 [[ -d /$pool ]] && rm -rf /$pool
1551 log_must zpool create
-f $pool $@
1557 # Return 0 if destroy successfully or the pool exists; $? otherwise
1558 # Note: In local zones, this function should return 0 silently.
1561 # Destroy pool with the given parameters.
1563 function destroy_pool
#pool
1565 typeset pool
=${1%%/*}
1568 if [[ -z $pool ]]; then
1569 log_note
"No pool name given."
1573 if is_global_zone
; then
1574 if poolexists
"$pool" ; then
1575 mtpt
=$
(get_prop mountpoint
"$pool")
1577 # At times, syseventd/udev activity can cause attempts
1578 # to destroy a pool to fail with EBUSY. We retry a few
1579 # times allowing failures before requiring the destroy
1581 log_must_busy zpool destroy
-f $pool
1584 log_must
rm -rf $mtpt
1586 log_note
"Pool does not exist. ($pool)"
1594 # Return 0 if destroy successfully or the dataset exists; $? otherwise
1595 # Note: In local zones, this function should return 0 silently.
1598 # $2 - custom arguments for zfs destroy
1599 # Destroy dataset with the given parameters.
1601 function destroy_dataset
#dataset #args
1605 typeset args
=${2:-""}
1607 if [[ -z $dataset ]]; then
1608 log_note
"No dataset name given."
1612 if is_global_zone
; then
1613 if datasetexists
"$dataset" ; then
1614 mtpt
=$
(get_prop mountpoint
"$dataset")
1615 log_must_busy zfs destroy
$args $dataset
1618 log_must
rm -rf $mtpt
1620 log_note
"Dataset does not exist. ($dataset)"
1629 # Firstly, create a pool with 5 datasets. Then, create a single zone and
1630 # export the 5 datasets to it. In addition, we also add a ZFS filesystem
1631 # and a zvol device to the zone.
1634 # $2 zone root directory prefix
1637 function zfs_zones_setup
#zone_name zone_root zone_ip
1639 typeset zone_name
=${1:-$(hostname)-z}
1640 typeset zone_root
=${2:-"/zone_root"}
1641 typeset zone_ip
=${3:-"10.1.1.10"}
1642 typeset prefix_ctr
=$ZONE_CTR
1643 typeset pool_name
=$ZONE_POOL
1647 # Create pool and 5 container within it
1649 [[ -d /$pool_name ]] && rm -rf /$pool_name
1650 log_must zpool create
-f $pool_name $DISKS
1651 while ((i
< cntctr
)); do
1652 log_must zfs create
$pool_name/$prefix_ctr$i
1657 log_must zfs create
-V 1g
$pool_name/zone_zvol
1661 # If current system support slog, add slog device for pool
1663 if verify_slog_support
; then
1664 typeset sdevs
="$TEST_BASE_DIR/sdev1 $TEST_BASE_DIR/sdev2"
1665 log_must mkfile
$MINVDEVSIZE $sdevs
1666 log_must zpool add
$pool_name log mirror
$sdevs
1669 # this isn't supported just yet.
1670 # Create a filesystem. In order to add this to
1671 # the zone, it must have it's mountpoint set to 'legacy'
1672 # log_must zfs create $pool_name/zfs_filesystem
1673 # log_must zfs set mountpoint=legacy $pool_name/zfs_filesystem
1675 [[ -d $zone_root ]] && \
1676 log_must
rm -rf $zone_root/$zone_name
1677 [[ ! -d $zone_root ]] && \
1678 log_must mkdir
-p -m 0700 $zone_root/$zone_name
1680 # Create zone configure file and configure the zone
1682 typeset zone_conf
=/tmp
/zone_conf.$$
1683 echo "create" > $zone_conf
1684 echo "set zonepath=$zone_root/$zone_name" >> $zone_conf
1685 echo "set autoboot=true" >> $zone_conf
1687 while ((i
< cntctr
)); do
1688 echo "add dataset" >> $zone_conf
1689 echo "set name=$pool_name/$prefix_ctr$i" >> \
1691 echo "end" >> $zone_conf
1695 # add our zvol to the zone
1696 echo "add device" >> $zone_conf
1697 echo "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf
1698 echo "end" >> $zone_conf
1700 # add a corresponding zvol rdsk to the zone
1701 echo "add device" >> $zone_conf
1702 echo "set match=$ZVOL_RDEVDIR/$pool_name/zone_zvol" >> $zone_conf
1703 echo "end" >> $zone_conf
1705 # once it's supported, we'll add our filesystem to the zone
1706 # echo "add fs" >> $zone_conf
1707 # echo "set type=zfs" >> $zone_conf
1708 # echo "set special=$pool_name/zfs_filesystem" >> $zone_conf
1709 # echo "set dir=/export/zfs_filesystem" >> $zone_conf
1710 # echo "end" >> $zone_conf
1712 echo "verify" >> $zone_conf
1713 echo "commit" >> $zone_conf
1714 log_must zonecfg
-z $zone_name -f $zone_conf
1715 log_must
rm -f $zone_conf
1718 zoneadm
-z $zone_name install
1719 if (($?
== 0)); then
1720 log_note
"SUCCESS: zoneadm -z $zone_name install"
1722 log_fail
"FAIL: zoneadm -z $zone_name install"
1725 # Install sysidcfg file
1727 typeset sysidcfg
=$zone_root/$zone_name/root
/etc
/sysidcfg
1728 echo "system_locale=C" > $sysidcfg
1729 echo "terminal=dtterm" >> $sysidcfg
1730 echo "network_interface=primary {" >> $sysidcfg
1731 echo "hostname=$zone_name" >> $sysidcfg
1732 echo "}" >> $sysidcfg
1733 echo "name_service=NONE" >> $sysidcfg
1734 echo "root_password=mo791xfZ/SFiw" >> $sysidcfg
1735 echo "security_policy=NONE" >> $sysidcfg
1736 echo "timezone=US/Eastern" >> $sysidcfg
1739 log_must zoneadm
-z $zone_name boot
1743 # Reexport TESTPOOL & TESTPOOL(1-4)
1745 function reexport_pool
1750 while ((i
< cntctr
)); do
1752 TESTPOOL
=$ZONE_POOL/$ZONE_CTR$i
1753 if ! ismounted
$TESTPOOL; then
1754 log_must zfs mount
$TESTPOOL
1757 eval TESTPOOL
$i=$ZONE_POOL/$ZONE_CTR$i
1758 if eval ! ismounted \
$TESTPOOL$i; then
1759 log_must
eval zfs mount \
$TESTPOOL$i
1767 # Verify a given disk or pool state
1769 # Return 0 is pool/disk matches expected state, 1 otherwise
1771 function check_state
# pool disk state{online,offline,degraded}
1774 typeset disk
=${2#$DEV_DSKDIR/}
1777 [[ -z $pool ]] ||
[[ -z $state ]] \
1778 && log_fail
"Arguments invalid or missing"
1780 if [[ -z $disk ]]; then
1781 #check pool state only
1782 zpool get
-H -o value health
$pool \
1783 |
grep -i "$state" > /dev
/null
2>&1
1785 zpool status
-v $pool |
grep "$disk" \
1786 |
grep -i "$state" > /dev
/null
2>&1
1793 # Get the mountpoint of snapshot
1794 # For the snapshot use <mp_filesystem>/.zfs/snapshot/<snap>
1797 function snapshot_mountpoint
1799 typeset dataset
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
1801 if [[ $dataset != *@
* ]]; then
1802 log_fail
"Error name of snapshot '$dataset'."
1805 typeset fs
=${dataset%@*}
1806 typeset snap
=${dataset#*@}
1808 if [[ -z $fs ||
-z $snap ]]; then
1809 log_fail
"Error name of snapshot '$dataset'."
1812 echo $
(get_prop mountpoint
$fs)/.zfs
/snapshot
/$snap
1816 # Given a device and 'ashift' value verify it's correctly set on every label
1818 function verify_ashift
# device ashift
1823 zdb
-e -lll $device |
awk -v ashift
=$ashift '/ashift: / {
1839 # Given a pool and file system, this function will verify the file system
1840 # using the zdb internal tool. Note that the pool is exported and imported
1841 # to ensure it has consistent state.
1843 function verify_filesys
# pool filesystem dir
1846 typeset filesys
="$2"
1847 typeset zdbout
="/tmp/zdbout.$$"
1852 typeset search_path
=""
1854 log_note
"Calling zdb to verify filesystem '$filesys'"
1855 zfs unmount
-a > /dev
/null
2>&1
1856 log_must zpool
export $pool
1858 if [[ -n $dirs ]] ; then
1859 for dir
in $dirs ; do
1860 search_path
="$search_path -d $dir"
1864 log_must zpool import
$search_path $pool
1866 zdb
-cudi $filesys > $zdbout 2>&1
1867 if [[ $?
!= 0 ]]; then
1868 log_note
"Output: zdb -cudi $filesys"
1870 log_fail
"zdb detected errors with: '$filesys'"
1873 log_must zfs mount
-a
1874 log_must
rm -rf $zdbout
1878 # Given a pool, and this function list all disks in the pool
1880 function get_disklist
# pool
1884 disklist
=$
(zpool iostat
-v $1 | nawk
'(NR >4) {print $1}' | \
1885 grep -v "\-\-\-\-\-" | \
1886 egrep -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
1892 # Given a pool, and this function list all disks in the pool with their full
1893 # path (like "/dev/sda" instead of "sda").
1895 function get_disklist_fullpath
# pool
1904 # This function kills a given list of processes after a time period. We use
1905 # this in the stress tests instead of STF_TIMEOUT so that we can have processes
1906 # run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT
1907 # would be listed as FAIL, which we don't want : we're happy with stress tests
1908 # running for a certain amount of time, then finishing.
1910 # @param $1 the time in seconds after which we should terminate these processes
1911 # @param $2..$n the processes we wish to terminate.
1913 function stress_timeout
1915 typeset
-i TIMEOUT
=$1
1919 log_note
"Waiting for child processes($cpids). " \
1920 "It could last dozens of minutes, please be patient ..."
1921 log_must
sleep $TIMEOUT
1923 log_note
"Killing child processes after ${TIMEOUT} stress timeout."
1925 for pid
in $cpids; do
1926 ps
-p $pid > /dev
/null
2>&1
1927 if (($?
== 0)); then
1928 log_must
kill -USR1 $pid
1934 # Verify a given hotspare disk is inuse or avail
1936 # Return 0 is pool/disk matches expected state, 1 otherwise
1938 function check_hotspare_state
# pool disk state{inuse,avail}
1941 typeset disk
=${2#$DEV_DSKDIR/}
1944 cur_state
=$
(get_device_state
$pool $disk "spares")
1946 if [[ $state != ${cur_state} ]]; then
1953 # Wait until a hotspare transitions to a given state or times out.
1955 # Return 0 when pool/disk matches expected state, 1 on timeout.
1957 function wait_hotspare_state
# pool disk state timeout
1960 typeset disk
=${2#$/DEV_DSKDIR/}
1962 typeset timeout
=${4:-60}
1965 while [[ $i -lt $timeout ]]; do
1966 if check_hotspare_state
$pool $disk $state; then
1978 # Verify a given slog disk is inuse or avail
1980 # Return 0 is pool/disk matches expected state, 1 otherwise
1982 function check_slog_state
# pool disk state{online,offline,unavail}
1985 typeset disk
=${2#$DEV_DSKDIR/}
1988 cur_state
=$
(get_device_state
$pool $disk "logs")
1990 if [[ $state != ${cur_state} ]]; then
1997 # Verify a given vdev disk is inuse or avail
1999 # Return 0 is pool/disk matches expected state, 1 otherwise
2001 function check_vdev_state
# pool disk state{online,offline,unavail}
2004 typeset disk
=${2#$/DEV_DSKDIR/}
2007 cur_state
=$
(get_device_state
$pool $disk)
2009 if [[ $state != ${cur_state} ]]; then
2016 # Wait until a vdev transitions to a given state or times out.
2018 # Return 0 when pool/disk matches expected state, 1 on timeout.
2020 function wait_vdev_state
# pool disk state timeout
2023 typeset disk
=${2#$/DEV_DSKDIR/}
2025 typeset timeout
=${4:-60}
2028 while [[ $i -lt $timeout ]]; do
2029 if check_vdev_state
$pool $disk $state; then
2041 # Check the output of 'zpool status -v <pool>',
2042 # and to see if the content of <token> contain the <keyword> specified.
2044 # Return 0 is contain, 1 otherwise
2046 function check_pool_status
# pool token keyword <verbose>
2051 typeset verbose
=${4:-false}
2053 scan
=$
(zpool status
-v "$pool" 2>/dev
/null | nawk
-v token
="$token:" '
2054 ($1==token) {print $0}')
2055 if [[ $verbose == true
]]; then
2058 echo $scan |
grep -i "$keyword" > /dev
/null
2>&1
2064 # These 6 following functions are instance of check_pool_status()
2065 # is_pool_resilvering - to check if the pool is resilver in progress
2066 # is_pool_resilvered - to check if the pool is resilver completed
2067 # is_pool_scrubbing - to check if the pool is scrub in progress
2068 # is_pool_scrubbed - to check if the pool is scrub completed
2069 # is_pool_scrub_stopped - to check if the pool is scrub stopped
2070 # is_pool_scrub_paused - to check if the pool has scrub paused
2072 function is_pool_resilvering
#pool <verbose>
2074 check_pool_status
"$1" "scan" "resilver in progress since " $2
2078 function is_pool_resilvered
#pool <verbose>
2080 check_pool_status
"$1" "scan" "resilvered " $2
2084 function is_pool_scrubbing
#pool <verbose>
2086 check_pool_status
"$1" "scan" "scrub in progress since " $2
2090 function is_pool_scrubbed
#pool <verbose>
2092 check_pool_status
"$1" "scan" "scrub repaired" $2
2096 function is_pool_scrub_stopped
#pool <verbose>
2098 check_pool_status
"$1" "scan" "scrub canceled" $2
2102 function is_pool_scrub_paused
#pool <verbose>
2104 check_pool_status
"$1" "scan" "scrub paused since " $2
2109 # Use create_pool()/destroy_pool() to clean up the information in
2110 # in the given disk to avoid slice overlapping.
2112 function cleanup_devices
#vdevs
2114 typeset pool
="foopool$$"
2116 if poolexists
$pool ; then
2120 create_pool
$pool $@
2127 # A function to find and locate free disks on a system or from given
2128 # disks as the parameter. It works by locating disks that are in use
2129 # as swap devices and dump devices, and also disks listed in /etc/vfstab
2131 # $@ given disks to find which are free, default is all disks in
2134 # @return a string containing the list of available disks
2138 # Trust provided list, no attempt is made to locate unused devices.
2145 sfi
=/tmp
/swaplist.$$
2146 dmpi
=/tmp
/dumpdev.$$
2147 max_finddisksnum
=${MAX_FINDDISKSNUM:-6}
2150 dumpadm
> $dmpi 2>/dev
/null
2152 # write an awk script that can process the output of format
2153 # to produce a list of disks we know about. Note that we have
2154 # to escape "$2" so that the shell doesn't interpret it while
2155 # we're creating the awk script.
2156 # -------------------
2157 cat > /tmp
/find_disks.
awk <<EOF
2166 if (searchdisks && \$2 !~ "^$"){
2172 /^AVAILABLE DISK SELECTIONS:/{
2176 #---------------------
2178 chmod 755 /tmp
/find_disks.
awk
2179 disks
=${@:-$(echo "" | format -e 2>/dev/null | /tmp/find_disks.awk)}
2180 rm /tmp
/find_disks.
awk
2183 for disk
in $disks; do
2185 grep "${disk}[sp]" /etc
/mnttab
>/dev
/null
2186 (($?
== 0)) && continue
2188 grep "${disk}[sp]" $sfi >/dev
/null
2189 (($?
== 0)) && continue
2190 # check for dump device
2191 grep "${disk}[sp]" $dmpi >/dev
/null
2192 (($?
== 0)) && continue
2193 # check to see if this disk hasn't been explicitly excluded
2194 # by a user-set environment variable
2195 echo "${ZFS_HOST_DEVICES_IGNORE}" |
grep "${disk}" > /dev
/null
2196 (($?
== 0)) && continue
2197 unused_candidates
="$unused_candidates $disk"
2202 # now just check to see if those disks do actually exist
2203 # by looking for a device pointing to the first slice in
2204 # each case. limit the number to max_finddisksnum
2206 for disk
in $unused_candidates; do
2207 if [ -b $DEV_DSKDIR/${disk}s0
]; then
2208 if [ $count -lt $max_finddisksnum ]; then
2209 unused
="$unused $disk"
2210 # do not impose limit if $@ is provided
2211 [[ -z $@
]] && ((count
= count
+ 1))
2216 # finally, return our disk list
2221 # Add specified user to specified group
2225 # $3 base of the homedir (optional)
2227 function add_user
#<group_name> <user_name> <basedir>
2231 typeset basedir
=${3:-"/var/tmp"}
2233 if ((${#gname} == 0 ||
${#uname} == 0)); then
2234 log_fail
"group name or user name are not defined."
2237 log_must useradd
-g $gname -d $basedir/$uname -m $uname
2238 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.profile
2239 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.bash_profile
2240 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.login
2242 # Add new users to the same group and the command line utils.
2243 # This allows them to be run out of the original users home
2244 # directory as long as it permissioned to be group readable.
2246 cmd_group
=$
(stat
--format="%G" $
(which zfs
))
2247 log_must usermod
-a -G $cmd_group $uname
2254 # Delete the specified user.
2257 # $2 base of the homedir (optional)
2259 function del_user
#<logname> <basedir>
2262 typeset basedir
=${2:-"/var/tmp"}
2264 if ((${#user} == 0)); then
2265 log_fail
"login name is necessary."
2268 if id
$user > /dev
/null
2>&1; then
2269 log_must_retry
"currently used" 5 userdel
$user
2272 [[ -d $basedir/$user ]] && rm -fr $basedir/$user
2278 # Select valid gid and create specified group.
2282 function add_group
#<group_name>
2286 if ((${#group} == 0)); then
2287 log_fail
"group name is necessary."
2290 # Assign 100 as the base gid, a larger value is selected for
2291 # Linux because for many distributions 1000 and under are reserved.
2294 groupadd
$group > /dev
/null
2>&1
2304 groupadd
-g $gid $group > /dev
/null
2>&1
2308 # The gid is not unique
2317 # Delete the specified group.
2321 function del_group
#<group_name>
2324 if ((${#grp} == 0)); then
2325 log_fail
"group name is necessary."
2329 getent group
$grp > /dev
/null
2>&1
2332 # Group does not exist.
2334 # Name already exists as a group name
2335 0) log_must groupdel
$grp ;;
2339 groupmod
-n $grp $grp > /dev
/null
2>&1
2342 # Group does not exist.
2344 # Name already exists as a group name
2345 9) log_must groupdel
$grp ;;
2354 # This function will return true if it's safe to destroy the pool passed
2355 # as argument 1. It checks for pools based on zvols and files, and also
2356 # files contained in a pool that may have a different mountpoint.
2358 function safe_to_destroy_pool
{ # $1 the pool name
2361 typeset DONT_DESTROY
=""
2363 # We check that by deleting the $1 pool, we're not
2364 # going to pull the rug out from other pools. Do this
2365 # by looking at all other pools, ensuring that they
2366 # aren't built from files or zvols contained in this pool.
2368 for pool
in $
(zpool list
-H -o name
)
2372 # this is a list of the top-level directories in each of the
2373 # files that make up the path to the files the pool is based on
2374 FILEPOOL
=$
(zpool status
-v $pool |
grep /$1/ | \
2377 # this is a list of the zvols that make up the pool
2378 ZVOLPOOL
=$
(zpool status
-v $pool |
grep "$ZVOL_DEVDIR/$1$" \
2381 # also want to determine if it's a file-based pool using an
2382 # alternate mountpoint...
2383 POOL_FILE_DIRS
=$
(zpool status
-v $pool | \
2384 grep / |
awk '{print $1}' | \
2385 awk -F/ '{print $2}' |
grep -v "dev")
2387 for pooldir
in $POOL_FILE_DIRS
2389 OUTPUT
=$
(zfs list
-H -r -o mountpoint
$1 | \
2390 grep "${pooldir}$" |
awk '{print $1}')
2392 ALTMOUNTPOOL
="${ALTMOUNTPOOL}${OUTPUT}"
2396 if [ ! -z "$ZVOLPOOL" ]
2399 log_note
"Pool $pool is built from $ZVOLPOOL on $1"
2402 if [ ! -z "$FILEPOOL" ]
2405 log_note
"Pool $pool is built from $FILEPOOL on $1"
2408 if [ ! -z "$ALTMOUNTPOOL" ]
2411 log_note
"Pool $pool is built from $ALTMOUNTPOOL on $1"
2415 if [ -z "${DONT_DESTROY}" ]
2419 log_note
"Warning: it is not safe to destroy $1!"
2425 # Get the available ZFS compression options
2426 # $1 option type zfs_set|zfs_compress
2428 function get_compress_opts
2430 typeset COMPRESS_OPTS
2431 typeset GZIP_OPTS
="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \
2432 gzip-6 gzip-7 gzip-8 gzip-9"
2434 if [[ $1 == "zfs_compress" ]] ; then
2435 COMPRESS_OPTS
="on lzjb"
2436 elif [[ $1 == "zfs_set" ]] ; then
2437 COMPRESS_OPTS
="on off lzjb"
2439 typeset valid_opts
="$COMPRESS_OPTS"
2440 zfs get
2>&1 |
grep gzip >/dev
/null
2>&1
2441 if [[ $?
-eq 0 ]]; then
2442 valid_opts
="$valid_opts $GZIP_OPTS"
2448 # Verify zfs operation with -p option work as expected
2449 # $1 operation, value could be create, clone or rename
2450 # $2 dataset type, value could be fs or vol
2452 # $4 new dataset name
2454 function verify_opt_p_ops
2459 typeset newdataset
=$4
2461 if [[ $datatype != "fs" && $datatype != "vol" ]]; then
2462 log_fail
"$datatype is not supported."
2465 # check parameters accordingly
2470 if [[ $datatype == "vol" ]]; then
2471 ops
="create -V $VOLSIZE"
2475 if [[ -z $newdataset ]]; then
2476 log_fail
"newdataset should not be empty" \
2479 log_must datasetexists
$dataset
2480 log_must snapexists
$dataset
2483 if [[ -z $newdataset ]]; then
2484 log_fail
"newdataset should not be empty" \
2487 log_must datasetexists
$dataset
2488 log_mustnot snapexists
$dataset
2491 log_fail
"$ops is not supported."
2495 # make sure the upper level filesystem does not exist
2496 destroy_dataset
"${newdataset%/*}" "-rRf"
2498 # without -p option, operation will fail
2499 log_mustnot zfs
$ops $dataset $newdataset
2500 log_mustnot datasetexists
$newdataset ${newdataset%/*}
2502 # with -p option, operation should succeed
2503 log_must zfs
$ops -p $dataset $newdataset
2506 if ! datasetexists
$newdataset ; then
2507 log_fail
"-p option does not work for $ops"
2510 # when $ops is create or clone, redo the operation still return zero
2511 if [[ $ops != "rename" ]]; then
2512 log_must zfs
$ops -p $dataset $newdataset
2519 # Get configuration of pool
2529 if ! poolexists
"$pool" ; then
2532 alt_root
=$
(zpool list
-H $pool |
awk '{print $NF}')
2533 if [[ $alt_root == "-" ]]; then
2534 value
=$
(zdb
-C $pool |
grep "$config:" |
awk -F: \
2537 value
=$
(zdb
-e $pool |
grep "$config:" |
awk -F: \
2540 if [[ -n $value ]] ; then
2550 # Privated function. Random select one of items from arguments.
2555 function _random_get
2562 ((ind
= RANDOM
% cnt
+ 1))
2564 typeset ret
=$
(echo "$str" | cut
-f $ind -d ' ')
2569 # Random select one of item from arguments which include NONE string
2571 function random_get_with_non
2576 _random_get
"$cnt" "$@"
2580 # Random select one of item from arguments which doesn't include NONE string
2584 _random_get
"$#" "$@"
2588 # Detect if the current system support slog
2590 function verify_slog_support
2592 typeset dir
=$TEST_BASE_DIR/disk.$$
2598 mkfile
$MINVDEVSIZE $vdev $sdev
2601 if ! zpool create
-n $pool $vdev log
$sdev > /dev
/null
2>&1; then
2610 # The function will generate a dataset name with specific length
2611 # $1, the length of the name
2612 # $2, the base string to construct the name
2614 function gen_dataset_name
2617 typeset basestr
="$2"
2618 typeset
-i baselen
=${#basestr}
2622 if ((len
% baselen
== 0)); then
2623 ((iter
= len
/ baselen
))
2625 ((iter
= len
/ baselen
+ 1))
2627 while ((iter
> 0)); do
2628 l_name
="${l_name}$basestr"
2637 # Get cksum tuple of dataset
2640 # sample zdb output:
2641 # Dataset data/test [ZPL], ID 355, cr_txg 2413856, 31.0K, 7 objects, rootbp
2642 # DVA[0]=<0:803046400:200> DVA[1]=<0:81199000:200> [L0 DMU objset] fletcher4
2643 # lzjb LE contiguous unique double size=800L/200P birth=2413856L/2413856P
2644 # fill=7 cksum=11ce125712:643a9c18ee2:125e25238fca0:254a3f74b59744
2645 function datasetcksum
2649 cksum=$
(zdb
-vvv $1 |
grep "^Dataset $1 \[" |
grep "cksum" \
2650 |
awk -F= '{print $7}')
2661 cksum=$
(cksum $1 |
awk '{print $1}')
2666 # Get the given disk/slice state from the specific field of the pool
2668 function get_device_state
#pool disk field("", "spares","logs")
2671 typeset disk
=${2#$DEV_DSKDIR/}
2672 typeset field
=${3:-$pool}
2674 state
=$
(zpool status
-v "$pool" 2>/dev
/null | \
2675 nawk
-v device
=$disk -v pool
=$pool -v field
=$field \
2676 'BEGIN {startconfig=0; startfield=0; }
2677 /config:/ {startconfig=1}
2678 (startconfig==1) && ($1==field) {startfield=1; next;}
2679 (startfield==1) && ($1==device) {print $2; exit;}
2681 ($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}')
2687 # print the given directory filesystem type
2695 if [[ -z $dir ]]; then
2696 log_fail
"Usage: get_fstype <directory>"
2703 df
-n $dir |
awk '{print $3}'
2707 # Given a disk, label it to VTOC regardless what label was on the disk
2713 if [[ -z $disk ]]; then
2714 log_fail
"The disk name is unspecified."
2716 typeset label_file
=/var
/tmp
/labelvtoc.$$
2717 typeset arch
=$
(uname
-p)
2720 log_note
"Currently unsupported by the test framework"
2724 if [[ $arch == "i386" ]]; then
2725 echo "label" > $label_file
2726 echo "0" >> $label_file
2727 echo "" >> $label_file
2728 echo "q" >> $label_file
2729 echo "q" >> $label_file
2731 fdisk
-B $disk >/dev
/null
2>&1
2732 # wait a while for fdisk finishes
2734 elif [[ $arch == "sparc" ]]; then
2735 echo "label" > $label_file
2736 echo "0" >> $label_file
2737 echo "" >> $label_file
2738 echo "" >> $label_file
2739 echo "" >> $label_file
2740 echo "q" >> $label_file
2742 log_fail
"unknown arch type"
2745 format
-e -s -d $disk -f $label_file
2746 typeset
-i ret_val
=$?
2749 # wait the format to finish
2752 if ((ret_val
!= 0)); then
2753 log_fail
"unable to label $disk as VTOC."
2760 # check if the system was installed as zfsroot or not
2761 # return: 0 ture, otherwise false
2765 df
-n / |
grep zfs
> /dev
/null
2>&1
2770 # get the root filesystem name if it's zfsroot system.
2772 # return: root filesystem name
2778 rootfs
=$
(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \
2781 if [[ -z "$rootfs" ]]; then
2782 log_fail
"Can not get rootfs"
2784 zfs list
$rootfs > /dev
/null
2>&1
2785 if (($?
== 0)); then
2788 log_fail
"This is not a zfsroot system."
2793 # get the rootfs's pool name
2797 function get_rootpool
2803 rootfs
=$
(awk '{if ($2 == "/" && $3 =="zfs") print $1}' \
2806 if [[ -z "$rootfs" ]]; then
2807 log_fail
"Can not get rootpool"
2809 zfs list
$rootfs > /dev
/null
2>&1
2810 if (($?
== 0)); then
2811 rootpool
=`echo $rootfs | awk -F\/ '{print $1}'`
2814 log_fail
"This is not a zfsroot system."
2819 # Get the package name
2821 function get_package_name
2823 typeset dirpath
=${1:-$STC_NAME}
2825 echo "SUNWstc-${dirpath}" |
/usr
/bin
/sed -e "s/\//-/g"
2829 # Get the word numbers from a string separated by white space
2831 function get_word_count
2837 # To verify if the require numbers of disks is given
2839 function verify_disk_count
2841 typeset
-i min
=${2:-1}
2843 typeset
-i count
=$
(get_word_count
"$1")
2845 if ((count
< min
)); then
2846 log_untested
"A minimum of $min disks is required to run." \
2847 " You specified $count disk(s)"
2851 function ds_is_volume
2853 typeset
type=$
(get_prop
type $1)
2854 [[ $type = "volume" ]] && return 0
2858 function ds_is_filesystem
2860 typeset
type=$
(get_prop
type $1)
2861 [[ $type = "filesystem" ]] && return 0
2865 function ds_is_snapshot
2867 typeset
type=$
(get_prop
type $1)
2868 [[ $type = "snapshot" ]] && return 0
2873 # Check if Trusted Extensions are installed and enabled
2875 function is_te_enabled
2877 svcs
-H -o state labeld
2>/dev
/null |
grep "enabled"
2878 if (($?
!= 0)); then
2885 # Utility function to determine if a system has multiple cpus.
2891 (($
(psrinfo |
wc -l) > 1))
2897 function get_cpu_freq
2900 lscpu |
awk '/CPU MHz/ { print $3 }'
2902 psrinfo
-v 0 |
awk '/processor operates at/ {print $6}'
2906 # Run the given command as the user provided.
2912 log_note
"user:$user $@"
2913 eval su
- \
$user -c \"$@
\" > /tmp
/out
2>/tmp
/err
2918 # Check if the pool contains the specified vdevs
2923 # Return 0 if the vdevs are contained in the pool, 1 if any of the specified
2924 # vdevs is not in the pool, and 2 if pool name is missing.
2926 function vdevs_in_pool
2931 if [[ -z $pool ]]; then
2932 log_note
"Missing pool name."
2938 typeset tmpfile
=$
(mktemp
)
2939 zpool list
-Hv "$pool" >$tmpfile
2941 grep -w ${vdev##*/} $tmpfile >/dev
/null
2>&1
2942 [[ $?
-ne 0 ]] && return 1
2956 max
=$
(echo $
((max
> i ? max
: i
)))
2968 min
=$
(echo $
((min
< i ? min
: i
)))
2975 # Generate a random number between 1 and the argument.
2980 echo $
(( ($RANDOM % $max) + 1 ))
2983 # Write data that can be compressed into a directory
2984 function write_compressible
2988 typeset nfiles
=${3:-1}
2989 typeset bs
=${4:-1024k}
2990 typeset fname
=${5:-file}
2992 [[ -d $dir ]] || log_fail
"No directory: $dir"
2994 # Under Linux fio is not currently used since its behavior can
2995 # differ significantly across versions. This includes missing
2996 # command line options and cases where the --buffer_compress_*
2997 # options fail to behave as expected.
2999 typeset file_bytes
=$
(to_bytes
$megs)
3000 typeset bs_bytes
=4096
3001 typeset blocks
=$
(($file_bytes / $bs_bytes))
3003 for (( i
= 0; i
< $nfiles; i
++ )); do
3004 truncate
-s $file_bytes $dir/$fname.
$i
3006 # Write every third block to get 66% compression.
3007 for (( j
= 0; j
< $blocks; j
+= 3 )); do
3008 dd if=/dev
/urandom of
=$dir/$fname.
$i \
3009 seek
=$j bs
=$bs_bytes count
=1 \
3010 conv
=notrunc
>/dev
/null
2>&1
3014 log_must
eval "fio \
3019 --buffer_compress_percentage=66 \
3020 --buffer_compress_chunk=4096 \
3027 --filename_format='$fname.\$jobnum' >/dev/null"
3036 [[ -e $pathname ]] || log_fail
"No such file or directory: $pathname"
3037 objnum
=$
(stat
-c %i
$pathname)
3042 # Sync data to the pool
3045 # $2 boolean to force uberblock (and config including zpool cache file) update
3047 function sync_pool
#pool <force>
3049 typeset pool
=${1:-$TESTPOOL}
3050 typeset force
=${2:-false}
3052 if [[ $force == true
]]; then
3053 log_must zpool sync
-f $pool
3055 log_must zpool sync
$pool
3062 # Wait for zpool 'freeing' property drops to zero.
3066 function wait_freeing
#pool
3068 typeset pool
=${1:-$TESTPOOL}
3070 [[ "0" == "$(zpool list -Ho freeing $pool)" ]] && break
3076 # Wait for every device replace operation to complete
3080 function wait_replacing
#pool
3082 typeset pool
=${1:-$TESTPOOL}
3084 [[ "" == "$(zpool status $pool |
3085 awk '/replacing-[0-9]+/ {print $1}')" ]] && break
3091 # Wait for a pool to be scrubbed
3094 # $2 number of seconds to wait (optional)
3096 # Returns true when pool has been scrubbed, or false if there's a timeout or if
3097 # no scrub was done.
3099 function wait_scrubbed
3101 typeset pool
=${1:-$TESTPOOL}
3102 typeset iter
=${2:-10}
3103 for i
in {1..
$iter} ; do
3104 if is_pool_scrubbed
$pool ; then
3112 # Backup the zed.rc in our test directory so that we can edit it for our test.
3114 # Returns: Backup file name. You will need to pass this to zed_rc_restore().
3115 function zed_rc_backup
3117 zedrc_backup
="$(mktemp)"
3118 cp $ZEDLET_DIR/zed.rc
$zedrc_backup
3122 function zed_rc_restore
3124 mv $1 $ZEDLET_DIR/zed.rc
3128 # Setup custom environment for the ZED.
3130 # $@ Optional list of zedlets to run under zed.
3137 if [[ ! -d $ZEDLET_DIR ]]; then
3138 log_must mkdir
$ZEDLET_DIR
3141 if [[ ! -e $VDEVID_CONF ]]; then
3142 log_must
touch $VDEVID_CONF
3145 if [[ -e $VDEVID_CONF_ETC ]]; then
3146 log_fail
"Must not have $VDEVID_CONF_ETC file present on system"
3150 # Create a symlink for /etc/zfs/vdev_id.conf file.
3151 log_must
ln -s $VDEVID_CONF $VDEVID_CONF_ETC
3153 # Setup minimal ZED configuration. Individual test cases should
3154 # add additional ZEDLETs as needed for their specific test.
3155 log_must
cp ${ZEDLET_ETC_DIR}/zed.rc
$ZEDLET_DIR
3156 log_must
cp ${ZEDLET_ETC_DIR}/zed-functions.sh
$ZEDLET_DIR
3158 # Scripts must only be user writable.
3159 if [[ -n "$EXTRA_ZEDLETS" ]] ; then
3160 saved_umask
=$
(umask)
3162 for i
in $EXTRA_ZEDLETS ; do
3163 log_must
cp ${ZEDLET_LIBEXEC_DIR}/$i $ZEDLET_DIR
3165 log_must
umask $saved_umask
3168 # Customize the zed.rc file to enable the full debug log.
3169 log_must
sed -i '/\#ZED_DEBUG_LOG=.*/d' $ZEDLET_DIR/zed.rc
3170 echo "ZED_DEBUG_LOG=$ZED_DEBUG_LOG" >>$ZEDLET_DIR/zed.rc
3175 # Cleanup custom ZED environment.
3177 # $@ Optional list of zedlets to remove from our test zed.d directory.
3178 function zed_cleanup
3185 log_must
rm -f ${ZEDLET_DIR}/zed.rc
3186 log_must
rm -f ${ZEDLET_DIR}/zed-functions.sh
3187 log_must
rm -f ${ZEDLET_DIR}/all-syslog.sh
3188 log_must
rm -f ${ZEDLET_DIR}/all-debug.sh
3189 log_must
rm -f ${ZEDLET_DIR}/state
3191 if [[ -n "$EXTRA_ZEDLETS" ]] ; then
3192 for i
in $EXTRA_ZEDLETS ; do
3193 log_must
rm -f ${ZEDLET_DIR}/$i
3196 log_must
rm -f $ZED_LOG
3197 log_must
rm -f $ZED_DEBUG_LOG
3198 log_must
rm -f $VDEVID_CONF_ETC
3199 log_must
rm -f $VDEVID_CONF
3204 # Check if ZED is currently running, if not start ZED.
3212 # ZEDLET_DIR=/var/tmp/zed
3213 if [[ ! -d $ZEDLET_DIR ]]; then
3214 log_must mkdir
$ZEDLET_DIR
3217 # Verify the ZED is not already running.
3218 pgrep
-x zed
> /dev
/null
3219 if (($?
== 0)); then
3220 log_fail
"ZED already running"
3223 log_note
"Starting ZED"
3224 # run ZED in the background and redirect foreground logging
3225 # output to $ZED_LOG.
3226 log_must truncate
-s 0 $ZED_DEBUG_LOG
3227 log_must
eval "zed -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid -P $PATH" \
3228 "-s $ZEDLET_DIR/state 2>$ZED_LOG &"
3242 log_note
"Stopping ZED"
3243 if [[ -f ${ZEDLET_DIR}/zed.pid
]]; then
3244 zedpid
=$
(cat ${ZEDLET_DIR}/zed.pid
)
3246 while ps
-p $zedpid > /dev
/null
; do
3249 rm -f ${ZEDLET_DIR}/zed.pid
3257 function zed_events_drain
3259 while [ $
(zpool events
-H |
wc -l) -ne 0 ]; do
3261 zpool events
-c >/dev
/null
3265 # Set a variable in zed.rc to something, un-commenting it in the process.
3275 eval sed -i $cmd $ZEDLET_DIR/zed.rc
3278 echo "$var=$val" >> $ZEDLET_DIR/zed.rc
3283 # Check is provided device is being active used as a swap device.
3285 function is_swap_inuse
3289 if [[ -z $device ]] ; then
3290 log_note
"No device specified."
3295 swapon
-s |
grep -w $
(readlink
-f $device) > /dev
/null
2>&1
3297 swap
-l |
grep -w $device > /dev
/null
2>&1
3304 # Setup a swap device using the provided device.
3311 log_must
eval "mkswap $swapdev > /dev/null 2>&1"
3312 log_must swapon
$swapdev
3314 log_must swap
-a $swapdev
3321 # Cleanup a swap device on the provided device.
3323 function swap_cleanup
3327 if is_swap_inuse
$swapdev; then
3329 log_must swapoff
$swapdev
3331 log_must swap
-d $swapdev
3339 # Set a global system tunable (64-bit value)
3344 function set_tunable64
3346 set_tunable_impl
"$1" "$2" Z
3350 # Set a global system tunable (32-bit value)
3355 function set_tunable32
3357 set_tunable_impl
"$1" "$2" W
3360 function set_tunable_impl
3362 typeset tunable
="$1"
3364 typeset mdb_cmd
="$3"
3365 typeset module
="${4:-zfs}"
3367 [[ -z "$tunable" ]] && return 1
3368 [[ -z "$value" ]] && return 1
3369 [[ -z "$mdb_cmd" ]] && return 1
3373 typeset zfs_tunables
="/sys/module/$module/parameters"
3374 [[ -w "$zfs_tunables/$tunable" ]] ||
return 1
3375 echo -n "$value" > "$zfs_tunables/$tunable"
3379 [[ "$module" -eq "zfs" ]] ||
return 1
3380 echo "${tunable}/${mdb_cmd}0t${value}" | mdb
-kw
3387 # Get a global system tunable
3391 function get_tunable
3393 get_tunable_impl
"$1"
3396 function get_tunable_impl
3398 typeset tunable
="$1"
3399 typeset module
="${2:-zfs}"
3401 [[ -z "$tunable" ]] && return 1
3405 typeset zfs_tunables
="/sys/module/$module/parameters"
3406 [[ -f "$zfs_tunables/$tunable" ]] ||
return 1
3407 cat $zfs_tunables/$tunable
3411 [[ "$module" -eq "zfs" ]] ||
return 1