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 log_must zfs destroy
-r $sendfs
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 datasetexists
$fs && \
550 log_must zfs destroy
-Rf $fs
553 # Need cleanup here to avoid garbage dir left.
554 for fs
in $
(zfs list
-H -o name
); do
555 [[ $fs == /$ZONE_POOL ]] && continue
556 [[ -d $fs ]] && log_must
rm -rf $fs/*
560 # Reset the $ZONE_POOL/$ZONE_CTR[01234] file systems property to
563 for fs
in $
(zfs list
-H -o name
); do
564 if [[ $fs == $ZONE_POOL/$ZONE_CTR[01234] ]]; then
565 log_must zfs
set reservation
=none
$fs
566 log_must zfs
set recordsize
=128K
$fs
567 log_must zfs
set mountpoint
=/$fs $fs
569 enc
=$
(get_prop encryption
$fs)
570 if [[ $?
-ne 0 ]] ||
[[ -z "$enc" ]] || \
571 [[ "$enc" == "off" ]]; then
572 log_must zfs
set checksum
=on
$fs
574 log_must zfs
set compression
=off
$fs
575 log_must zfs
set atime
=on
$fs
576 log_must zfs
set devices
=off
$fs
577 log_must zfs
set exec=on
$fs
578 log_must zfs
set setuid
=on
$fs
579 log_must zfs
set readonly=off
$fs
580 log_must zfs
set snapdir
=hidden
$fs
581 log_must zfs
set aclmode
=groupmask
$fs
582 log_must zfs
set aclinherit
=secure
$fs
587 [[ -d $TESTDIR ]] && \
588 log_must
rm -rf $TESTDIR
591 if is_mpath_device
$disk1; then
598 # Common function used to cleanup storage pools, file systems
601 function default_container_cleanup
603 if ! is_global_zone
; then
607 ismounted
$TESTPOOL/$TESTCTR/$TESTFS1
609 log_must zfs unmount
$TESTPOOL/$TESTCTR/$TESTFS1
611 datasetexists
$TESTPOOL/$TESTCTR/$TESTFS1 && \
612 log_must zfs destroy
-R $TESTPOOL/$TESTCTR/$TESTFS1
614 datasetexists
$TESTPOOL/$TESTCTR && \
615 log_must zfs destroy
-Rf $TESTPOOL/$TESTCTR
617 [[ -e $TESTDIR1 ]] && \
618 log_must
rm -rf $TESTDIR1 > /dev
/null
2>&1
624 # Common function used to cleanup snapshot of file system or volume. Default to
625 # delete the file system's snapshot
629 function destroy_snapshot
631 typeset snap
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
633 if ! snapexists
$snap; then
634 log_fail
"'$snap' does not existed."
638 # For the sake of the value which come from 'get_prop' is not equal
639 # to the really mountpoint when the snapshot is unmounted. So, firstly
640 # check and make sure this snapshot's been mounted in current system.
643 if ismounted
$snap; then
644 mtpt
=$
(get_prop mountpoint
$snap)
646 log_fail
"get_prop mountpoint $snap failed."
649 log_must zfs destroy
$snap
650 [[ $mtpt != "" && -d $mtpt ]] && \
651 log_must
rm -rf $mtpt
655 # Common function used to cleanup clone.
659 function destroy_clone
661 typeset clone
=${1:-$TESTPOOL/$TESTCLONE}
663 if ! datasetexists
$clone; then
664 log_fail
"'$clone' does not existed."
667 # With the same reason in destroy_snapshot
669 if ismounted
$clone; then
670 mtpt
=$
(get_prop mountpoint
$clone)
672 log_fail
"get_prop mountpoint $clone failed."
675 log_must zfs destroy
$clone
676 [[ $mtpt != "" && -d $mtpt ]] && \
677 log_must
rm -rf $mtpt
681 # Common function used to cleanup bookmark of file system or volume. Default
682 # to delete the file system's bookmark.
686 function destroy_bookmark
688 typeset bkmark
=${1:-$TESTPOOL/$TESTFS#$TESTBKMARK}
690 if ! bkmarkexists
$bkmark; then
691 log_fail
"'$bkmarkp' does not existed."
694 log_must zfs destroy
$bkmark
697 # Return 0 if a snapshot exists; $? otherwise
703 zfs list
-H -t snapshot
"$1" > /dev
/null
2>&1
708 # Return 0 if a bookmark exists; $? otherwise
712 function bkmarkexists
714 zfs list
-H -t bookmark
"$1" > /dev
/null
2>&1
719 # Set a property to a certain value on a dataset.
720 # Sets a property of the dataset to the value as passed in.
722 # $1 dataset who's property is being set
724 # $3 value to set property to
726 # 0 if the property could be set.
727 # non-zero otherwise.
730 function dataset_setprop
732 typeset fn
=dataset_setprop
735 log_note
"$fn: Insufficient parameters (need 3, had $#)"
739 output
=$
(zfs
set $2=$3 $1 2>&1)
742 log_note
"Setting property on $1 failed."
743 log_note
"property $2=$3"
744 log_note
"Return Code: $rv"
745 log_note
"Output: $output"
752 # Assign suite defined dataset properties.
753 # This function is used to apply the suite's defined default set of
754 # properties to a dataset.
755 # @parameters: $1 dataset to use
756 # @uses: ZFS COMPRESSION_PROP CHECKSUM_PROP
758 # 0 if the dataset has been altered.
759 # 1 if no pool name was passed in.
760 # 2 if the dataset could not be found.
761 # 3 if the dataset could not have it's properties set.
763 function dataset_set_defaultproperties
767 [[ -z $dataset ]] && return 1
771 for confset
in $
(zfs list
); do
772 if [[ $dataset = $confset ]]; then
777 [[ $found -eq 0 ]] && return 2
778 if [[ -n $COMPRESSION_PROP ]]; then
779 dataset_setprop
$dataset compression
$COMPRESSION_PROP || \
781 log_note
"Compression set to '$COMPRESSION_PROP' on $dataset"
783 if [[ -n $CHECKSUM_PROP ]]; then
784 dataset_setprop
$dataset checksum
$CHECKSUM_PROP || \
786 log_note
"Checksum set to '$CHECKSUM_PROP' on $dataset"
792 # Check a numeric assertion
793 # @parameter: $@ the assertion to check
794 # @output: big loud notice if assertion failed
799 (($@
)) || log_fail
"$@"
803 # Function to format partition size of a disk
804 # Given a disk cxtxdx reduces all partitions
807 function zero_partitions
#<whole_disk_name>
813 log_must parted
$DEV_DSKDIR/$diskname -s -- mklabel gpt
815 for i
in 0 1 3 4 5 6 7
817 log_must set_partition
$i "" 0mb
$diskname
825 # Given a slice, size and disk, this function
826 # formats the slice to the specified size.
827 # Size should be specified with units as per
828 # the `format` command requirements eg. 100mb 3gb
830 # NOTE: This entire interface is problematic for the Linux parted utilty
831 # which requires the end of the partition to be specified. It would be
832 # best to retire this interface and replace it with something more flexible.
833 # At the moment a best effort is made.
835 function set_partition
#<slice_num> <slice_start> <size_plus_units> <whole_disk_name>
837 typeset
-i slicenum
=$1
841 [[ -z $slicenum ||
-z $size ||
-z $disk ]] && \
842 log_fail
"The slice, size or disk name is unspecified."
845 typeset size_mb
=${size%%[mMgG]}
847 size_mb
=${size_mb%%[mMgG][bB]}
848 if [[ ${size:1:1} == 'g' ]]; then
849 ((size_mb
= size_mb
* 1024))
852 # Create GPT partition table when setting slice 0 or
853 # when the device doesn't already contain a GPT label.
854 parted
$DEV_DSKDIR/$disk -s -- print
1 >/dev
/null
856 if [[ $slicenum -eq 0 ||
$ret_val -ne 0 ]]; then
857 parted
$DEV_DSKDIR/$disk -s -- mklabel gpt
858 if [[ $?
-ne 0 ]]; then
859 log_note
"Failed to create GPT partition table on $disk"
864 # When no start is given align on the first cylinder.
865 if [[ -z "$start" ]]; then
869 # Determine the cylinder size for the device and using
870 # that calculate the end offset in cylinders.
871 typeset
-i cly_size_kb
=0
872 cly_size_kb
=$
(parted
-m $DEV_DSKDIR/$disk -s -- \
873 unit cyl print |
head -3 |
tail -1 | \
874 awk -F '[:k.]' '{print $4}')
875 ((end
= (size_mb
* 1024 / cly_size_kb
) + start
))
877 parted
$DEV_DSKDIR/$disk -s -- \
878 mkpart part
$slicenum ${start}cyl
${end}cyl
879 if [[ $?
-ne 0 ]]; then
880 log_note
"Failed to create partition $slicenum on $disk"
884 blockdev
--rereadpt $DEV_DSKDIR/$disk 2>/dev
/null
887 typeset format_file
=/var
/tmp
/format_in.$$
889 echo "partition" >$format_file
890 echo "$slicenum" >> $format_file
891 echo "" >> $format_file
892 echo "" >> $format_file
893 echo "$start" >> $format_file
894 echo "$size" >> $format_file
895 echo "label" >> $format_file
896 echo "" >> $format_file
897 echo "q" >> $format_file
898 echo "q" >> $format_file
900 format
-e -s -d $disk -f $format_file
905 if [[ $ret_val -ne 0 ]]; then
906 log_note
"Unable to format $disk slice $slicenum to $size"
913 # Delete all partitions on all disks - this is specifically for the use of multipath
914 # devices which currently can only be used in the test suite as raw/un-partitioned
915 # devices (ie a zpool cannot be created on a whole mpath device that has partitions)
917 function delete_partitions
921 if [[ -z $DISK_ARRAY_NUM ]]; then
922 DISK_ARRAY_NUM
=$
(echo ${DISKS} | nawk
'{print NF}')
924 if [[ -z $DISKSARRAY ]]; then
929 if (( $DISK_ARRAY_NUM == 1 )); then
930 while ((j
< MAX_PARTITIONS
)); do
931 parted
$DEV_DSKDIR/$DISK -s rm $j \
933 if (( $?
== 1 )); then
934 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
935 if (( $?
== 1 )); then
936 log_note
"Partitions for $DISK should be deleted"
938 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
942 lsblk |
egrep ${DISK}${SLICE_PREFIX}${j} > /dev
/null
943 if (( $?
== 0 )); then
944 log_fail
"Partition for ${DISK}${SLICE_PREFIX}${j} not deleted"
950 for disk
in `echo $DISKSARRAY`; do
951 while ((j
< MAX_PARTITIONS
)); do
952 parted
$DEV_DSKDIR/$disk -s rm $j > /dev
/null
2>&1
953 if (( $?
== 1 )); then
954 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
955 if (( $?
== 1 )); then
956 log_note
"Partitions for $disk should be deleted"
958 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
962 lsblk |
egrep ${disk}${SLICE_PREFIX}${j} > /dev
/null
963 if (( $?
== 0 )); then
964 log_fail
"Partition for ${disk}${SLICE_PREFIX}${j} not deleted"
977 # Get the end cyl of the given slice
979 function get_endslice
#<disk> <slice>
983 if [[ -z $disk ||
-z $slice ]] ; then
984 log_fail
"The disk name or slice number is unspecified."
988 endcyl
=$
(parted
-s $DEV_DSKDIR/$disk -- unit cyl print | \
989 grep "part${slice}" | \
992 ((endcyl
= (endcyl
+ 1)))
994 disk
=${disk#/dev/dsk/}
995 disk
=${disk#/dev/rdsk/}
999 ratio
=$
(prtvtoc
/dev
/rdsk
/${disk}s2 | \
1000 grep "sectors\/cylinder" | \
1003 if ((ratio
== 0)); then
1007 typeset
-i endcyl
=$
(prtvtoc
-h /dev
/rdsk
/${disk}s2 |
1008 nawk
-v token
="$slice" '{if ($1==token) print $6}')
1010 ((endcyl
= (endcyl
+ 1) / ratio
))
1018 # Given a size,disk and total slice number, this function formats the
1019 # disk slices from 0 to the total slice number with the same specified
1022 function partition_disk
#<slice_size> <whole_disk_name> <total_slices>
1025 typeset slice_size
=$1
1026 typeset disk_name
=$2
1027 typeset total_slices
=$3
1030 zero_partitions
$disk_name
1031 while ((i
< $total_slices)); do
1038 log_must set_partition
$i "$cyl" $slice_size $disk_name
1039 cyl
=$
(get_endslice
$disk_name $i)
1045 # This function continues to write to a filenum number of files into dirnum
1046 # number of directories until either file_write returns an error or the
1047 # maximum number of files per directory have been written.
1050 # fill_fs [destdir] [dirnum] [filenum] [bytes] [num_writes] [data]
1052 # Return value: 0 on success
1056 # destdir: is the directory where everything is to be created under
1057 # dirnum: the maximum number of subdirectories to use, -1 no limit
1058 # filenum: the maximum number of files per subdirectory
1059 # bytes: number of bytes to write
1060 # num_writes: numer of types to write out bytes
1061 # data: the data that will be written
1064 # file_fs /testdir 20 25 1024 256 0
1066 # Note: bytes * num_writes equals the size of the testfile
1068 function fill_fs
# destdir dirnum filenum bytes num_writes data
1070 typeset destdir
=${1:-$TESTDIR}
1071 typeset
-i dirnum
=${2:-50}
1072 typeset
-i filenum
=${3:-50}
1073 typeset
-i bytes
=${4:-8192}
1074 typeset
-i num_writes
=${5:-10240}
1075 typeset
-i data
=${6:-0}
1077 typeset
-i odirnum
=1
1078 typeset
-i idirnum
=0
1082 log_must mkdir
-p $destdir/$idirnum
1083 while (($odirnum > 0)); do
1084 if ((dirnum
>= 0 && idirnum
>= dirnum
)); then
1088 file_write
-o create
-f $destdir/$idirnum/$TESTFILE.
$fn \
1089 -b $bytes -c $num_writes -d $data
1091 if (($retval != 0)); then
1095 if (($fn >= $filenum)); then
1097 ((idirnum
= idirnum
+ 1))
1098 log_must mkdir
-p $destdir/$idirnum
1107 # Simple function to get the specified property. If unable to
1108 # get the property then exits.
1110 # Note property is in 'parsable' format (-p)
1112 function get_prop
# property dataset
1118 prop_val
=$
(zfs get
-pH -o value
$prop $dataset 2>/dev
/null
)
1119 if [[ $?
-ne 0 ]]; then
1120 log_note
"Unable to get $prop property for dataset " \
1130 # Simple function to get the specified property of pool. If unable to
1131 # get the property then exits.
1133 # Note property is in 'parsable' format (-p)
1135 function get_pool_prop
# property pool
1141 if poolexists
$pool ; then
1142 prop_val
=$
(zpool get
-pH $prop $pool 2>/dev
/null |
tail -1 | \
1144 if [[ $?
-ne 0 ]]; then
1145 log_note
"Unable to get $prop property for pool " \
1150 log_note
"Pool $pool not exists."
1158 # Return 0 if a pool exists; $? otherwise
1166 if [[ -z $pool ]]; then
1167 log_note
"No pool name given."
1171 zpool get name
"$pool" > /dev
/null
2>&1
1175 # Return 0 if all the specified datasets exist; $? otherwise
1178 function datasetexists
1180 if (($# == 0)); then
1181 log_note
"No dataset name given."
1185 while (($# > 0)); do
1186 zfs get name
$1 > /dev
/null
2>&1 || \
1194 # return 0 if none of the specified datasets exists, otherwise return 1.
1197 function datasetnonexists
1199 if (($# == 0)); then
1200 log_note
"No dataset name given."
1204 while (($# > 0)); do
1205 zfs list
-H -t filesystem
,snapshot
,volume
$1 > /dev
/null
2>&1 \
1214 # Given a mountpoint, or a dataset name, determine if it is shared via NFS.
1216 # Returns 0 if shared, 1 otherwise.
1223 if [[ $fs != "/"* ]] ; then
1224 if datasetnonexists
"$fs" ; then
1227 mtpt
=$
(get_prop mountpoint
"$fs")
1229 none|legacy|
-) return 1
1238 for mtpt
in `share | awk '{print $1}'` ; do
1239 if [[ $mtpt == $fs ]] ; then
1246 for mtpt
in `share | awk '{print $2}'` ; do
1247 if [[ $mtpt == $fs ]] ; then
1252 typeset stat
=$
(svcs
-H -o STA nfs
/server
:default
)
1253 if [[ $stat != "ON" ]]; then
1254 log_note
"Current nfs/server status: $stat"
1261 # Given a dataset name determine if it is shared via SMB.
1263 # Returns 0 if shared, 1 otherwise.
1265 function is_shared_smb
1270 if datasetnonexists
"$fs" ; then
1273 fs
=$
(echo $fs |
sed 's@/@_@g')
1277 for mtpt
in `net usershare list | awk '{print $1}'` ; do
1278 if [[ $mtpt == $fs ]] ; then
1284 log_unsupported
"Currently unsupported by the test framework"
1290 # Given a mountpoint, determine if it is not shared via NFS.
1292 # Returns 0 if not shared, 1 otherwise.
1299 if (($?
== 0)); then
1307 # Given a dataset determine if it is not shared via SMB.
1309 # Returns 0 if not shared, 1 otherwise.
1311 function not_shared_smb
1316 if (($?
== 0)); then
1324 # Helper function to unshare a mountpoint.
1326 function unshare_fs
#fs
1330 is_shared
$fs || is_shared_smb
$fs
1331 if (($?
== 0)); then
1332 log_must zfs unshare
$fs
1339 # Helper function to share a NFS mountpoint.
1341 function share_nfs
#fs
1347 if (($?
!= 0)); then
1348 log_must share
"*:$fs"
1352 if (($?
!= 0)); then
1353 log_must share
-F nfs
$fs
1361 # Helper function to unshare a NFS mountpoint.
1363 function unshare_nfs
#fs
1369 if (($?
== 0)); then
1370 log_must unshare
-u "*:$fs"
1374 if (($?
== 0)); then
1375 log_must unshare
-F nfs
$fs
1383 # Helper function to show NFS shares.
1385 function showshares_nfs
1397 # Helper function to show SMB shares.
1399 function showshares_smb
1411 # Check NFS server status and trigger it online.
1413 function setup_nfs_server
1415 # Cannot share directory in non-global zone.
1417 if ! is_global_zone
; then
1418 log_note
"Cannot trigger NFS server by sharing in LZ."
1423 log_note
"NFS server must started prior to running test framework."
1427 typeset nfs_fmri
="svc:/network/nfs/server:default"
1428 if [[ $
(svcs
-Ho STA
$nfs_fmri) != "ON" ]]; then
1430 # Only really sharing operation can enable NFS server
1431 # to online permanently.
1433 typeset dummy
=/tmp
/dummy
1435 if [[ -d $dummy ]]; then
1436 log_must
rm -rf $dummy
1439 log_must mkdir
$dummy
1440 log_must share
$dummy
1443 # Waiting for fmri's status to be the final status.
1444 # Otherwise, in transition, an asterisk (*) is appended for
1445 # instances, unshare will reverse status to 'DIS' again.
1447 # Waiting for 1's at least.
1451 while [[ timeout
-ne 0 && $
(svcs
-Ho STA
$nfs_fmri) == *'*' ]]
1458 log_must unshare
$dummy
1459 log_must
rm -rf $dummy
1462 log_note
"Current NFS status: '$(svcs -Ho STA,FMRI $nfs_fmri)'"
1466 # To verify whether calling process is in global zone
1468 # Return 0 if in global zone, 1 in non-global zone
1470 function is_global_zone
1475 typeset cur_zone
=$
(zonename
2>/dev
/null
)
1476 if [[ $cur_zone != "global" ]]; then
1484 # Verify whether test is permitted to run from
1485 # global zone, local zone, or both
1487 # $1 zone limit, could be "global", "local", or "both"(no limit)
1489 # Return 0 if permitted, otherwise exit with log_unsupported
1491 function verify_runnable
# zone limit
1495 [[ -z $limit ]] && return 0
1497 if is_global_zone
; then
1501 local) log_unsupported
"Test is unable to run from "\
1504 *) log_note
"Warning: unknown limit $limit - " \
1512 global
) log_unsupported
"Test is unable to run from "\
1515 *) log_note
"Warning: unknown limit $limit - " \
1526 # Return 0 if create successfully or the pool exists; $? otherwise
1527 # Note: In local zones, this function should return 0 silently.
1530 # $2-n - [keyword] devs_list
1532 function create_pool
#pool devs_list
1534 typeset pool
=${1%%/*}
1538 if [[ -z $pool ]]; then
1539 log_note
"Missing pool name."
1543 if poolexists
$pool ; then
1547 if is_global_zone
; then
1548 [[ -d /$pool ]] && rm -rf /$pool
1549 log_must zpool create
-f $pool $@
1555 # Return 0 if destroy successfully or the pool exists; $? otherwise
1556 # Note: In local zones, this function should return 0 silently.
1559 # Destroy pool with the given parameters.
1561 function destroy_pool
#pool
1563 typeset pool
=${1%%/*}
1566 if [[ -z $pool ]]; then
1567 log_note
"No pool name given."
1571 if is_global_zone
; then
1572 if poolexists
"$pool" ; then
1573 mtpt
=$
(get_prop mountpoint
"$pool")
1575 # At times, syseventd/udev activity can cause attempts
1576 # to destroy a pool to fail with EBUSY. We retry a few
1577 # times allowing failures before requiring the destroy
1579 log_must_busy zpool destroy
-f $pool
1582 log_must
rm -rf $mtpt
1584 log_note
"Pool does not exist. ($pool)"
1593 # Firstly, create a pool with 5 datasets. Then, create a single zone and
1594 # export the 5 datasets to it. In addition, we also add a ZFS filesystem
1595 # and a zvol device to the zone.
1598 # $2 zone root directory prefix
1601 function zfs_zones_setup
#zone_name zone_root zone_ip
1603 typeset zone_name
=${1:-$(hostname)-z}
1604 typeset zone_root
=${2:-"/zone_root"}
1605 typeset zone_ip
=${3:-"10.1.1.10"}
1606 typeset prefix_ctr
=$ZONE_CTR
1607 typeset pool_name
=$ZONE_POOL
1611 # Create pool and 5 container within it
1613 [[ -d /$pool_name ]] && rm -rf /$pool_name
1614 log_must zpool create
-f $pool_name $DISKS
1615 while ((i
< cntctr
)); do
1616 log_must zfs create
$pool_name/$prefix_ctr$i
1621 log_must zfs create
-V 1g
$pool_name/zone_zvol
1625 # If current system support slog, add slog device for pool
1627 if verify_slog_support
; then
1628 typeset sdevs
="$TEST_BASE_DIR/sdev1 $TEST_BASE_DIR/sdev2"
1629 log_must mkfile
$MINVDEVSIZE $sdevs
1630 log_must zpool add
$pool_name log mirror
$sdevs
1633 # this isn't supported just yet.
1634 # Create a filesystem. In order to add this to
1635 # the zone, it must have it's mountpoint set to 'legacy'
1636 # log_must zfs create $pool_name/zfs_filesystem
1637 # log_must zfs set mountpoint=legacy $pool_name/zfs_filesystem
1639 [[ -d $zone_root ]] && \
1640 log_must
rm -rf $zone_root/$zone_name
1641 [[ ! -d $zone_root ]] && \
1642 log_must mkdir
-p -m 0700 $zone_root/$zone_name
1644 # Create zone configure file and configure the zone
1646 typeset zone_conf
=/tmp
/zone_conf.$$
1647 echo "create" > $zone_conf
1648 echo "set zonepath=$zone_root/$zone_name" >> $zone_conf
1649 echo "set autoboot=true" >> $zone_conf
1651 while ((i
< cntctr
)); do
1652 echo "add dataset" >> $zone_conf
1653 echo "set name=$pool_name/$prefix_ctr$i" >> \
1655 echo "end" >> $zone_conf
1659 # add our zvol to the zone
1660 echo "add device" >> $zone_conf
1661 echo "set match=/dev/zvol/dsk/$pool_name/zone_zvol" >> $zone_conf
1662 echo "end" >> $zone_conf
1664 # add a corresponding zvol rdsk to the zone
1665 echo "add device" >> $zone_conf
1666 echo "set match=$ZVOL_RDEVDIR/$pool_name/zone_zvol" >> $zone_conf
1667 echo "end" >> $zone_conf
1669 # once it's supported, we'll add our filesystem to the zone
1670 # echo "add fs" >> $zone_conf
1671 # echo "set type=zfs" >> $zone_conf
1672 # echo "set special=$pool_name/zfs_filesystem" >> $zone_conf
1673 # echo "set dir=/export/zfs_filesystem" >> $zone_conf
1674 # echo "end" >> $zone_conf
1676 echo "verify" >> $zone_conf
1677 echo "commit" >> $zone_conf
1678 log_must zonecfg
-z $zone_name -f $zone_conf
1679 log_must
rm -f $zone_conf
1682 zoneadm
-z $zone_name install
1683 if (($?
== 0)); then
1684 log_note
"SUCCESS: zoneadm -z $zone_name install"
1686 log_fail
"FAIL: zoneadm -z $zone_name install"
1689 # Install sysidcfg file
1691 typeset sysidcfg
=$zone_root/$zone_name/root
/etc
/sysidcfg
1692 echo "system_locale=C" > $sysidcfg
1693 echo "terminal=dtterm" >> $sysidcfg
1694 echo "network_interface=primary {" >> $sysidcfg
1695 echo "hostname=$zone_name" >> $sysidcfg
1696 echo "}" >> $sysidcfg
1697 echo "name_service=NONE" >> $sysidcfg
1698 echo "root_password=mo791xfZ/SFiw" >> $sysidcfg
1699 echo "security_policy=NONE" >> $sysidcfg
1700 echo "timezone=US/Eastern" >> $sysidcfg
1703 log_must zoneadm
-z $zone_name boot
1707 # Reexport TESTPOOL & TESTPOOL(1-4)
1709 function reexport_pool
1714 while ((i
< cntctr
)); do
1716 TESTPOOL
=$ZONE_POOL/$ZONE_CTR$i
1717 if ! ismounted
$TESTPOOL; then
1718 log_must zfs mount
$TESTPOOL
1721 eval TESTPOOL
$i=$ZONE_POOL/$ZONE_CTR$i
1722 if eval ! ismounted \
$TESTPOOL$i; then
1723 log_must
eval zfs mount \
$TESTPOOL$i
1731 # Verify a given disk or pool state
1733 # Return 0 is pool/disk matches expected state, 1 otherwise
1735 function check_state
# pool disk state{online,offline,degraded}
1738 typeset disk
=${2#$DEV_DSKDIR/}
1741 [[ -z $pool ]] ||
[[ -z $state ]] \
1742 && log_fail
"Arguments invalid or missing"
1744 if [[ -z $disk ]]; then
1745 #check pool state only
1746 zpool get
-H -o value health
$pool \
1747 |
grep -i "$state" > /dev
/null
2>&1
1749 zpool status
-v $pool |
grep "$disk" \
1750 |
grep -i "$state" > /dev
/null
2>&1
1757 # Get the mountpoint of snapshot
1758 # For the snapshot use <mp_filesystem>/.zfs/snapshot/<snap>
1761 function snapshot_mountpoint
1763 typeset dataset
=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
1765 if [[ $dataset != *@
* ]]; then
1766 log_fail
"Error name of snapshot '$dataset'."
1769 typeset fs
=${dataset%@*}
1770 typeset snap
=${dataset#*@}
1772 if [[ -z $fs ||
-z $snap ]]; then
1773 log_fail
"Error name of snapshot '$dataset'."
1776 echo $
(get_prop mountpoint
$fs)/.zfs
/snapshot
/$snap
1780 # Given a device and 'ashift' value verify it's correctly set on every label
1782 function verify_ashift
# device ashift
1787 zdb
-e -lll $device |
awk -v ashift
=$ashift '/ashift: / {
1803 # Given a pool and file system, this function will verify the file system
1804 # using the zdb internal tool. Note that the pool is exported and imported
1805 # to ensure it has consistent state.
1807 function verify_filesys
# pool filesystem dir
1810 typeset filesys
="$2"
1811 typeset zdbout
="/tmp/zdbout.$$"
1816 typeset search_path
=""
1818 log_note
"Calling zdb to verify filesystem '$filesys'"
1819 zfs unmount
-a > /dev
/null
2>&1
1820 log_must zpool
export $pool
1822 if [[ -n $dirs ]] ; then
1823 for dir
in $dirs ; do
1824 search_path
="$search_path -d $dir"
1828 log_must zpool import
$search_path $pool
1830 zdb
-cudi $filesys > $zdbout 2>&1
1831 if [[ $?
!= 0 ]]; then
1832 log_note
"Output: zdb -cudi $filesys"
1834 log_fail
"zdb detected errors with: '$filesys'"
1837 log_must zfs mount
-a
1838 log_must
rm -rf $zdbout
1842 # Given a pool, and this function list all disks in the pool
1844 function get_disklist
# pool
1848 disklist
=$
(zpool iostat
-v $1 | nawk
'(NR >4) {print $1}' | \
1849 grep -v "\-\-\-\-\-" | \
1850 egrep -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
1856 # Given a pool, and this function list all disks in the pool with their full
1857 # path (like "/dev/sda" instead of "sda").
1859 function get_disklist_fullpath
# pool
1868 # This function kills a given list of processes after a time period. We use
1869 # this in the stress tests instead of STF_TIMEOUT so that we can have processes
1870 # run for a fixed amount of time, yet still pass. Tests that hit STF_TIMEOUT
1871 # would be listed as FAIL, which we don't want : we're happy with stress tests
1872 # running for a certain amount of time, then finishing.
1874 # @param $1 the time in seconds after which we should terminate these processes
1875 # @param $2..$n the processes we wish to terminate.
1877 function stress_timeout
1879 typeset
-i TIMEOUT
=$1
1883 log_note
"Waiting for child processes($cpids). " \
1884 "It could last dozens of minutes, please be patient ..."
1885 log_must
sleep $TIMEOUT
1887 log_note
"Killing child processes after ${TIMEOUT} stress timeout."
1889 for pid
in $cpids; do
1890 ps
-p $pid > /dev
/null
2>&1
1891 if (($?
== 0)); then
1892 log_must
kill -USR1 $pid
1898 # Verify a given hotspare disk is inuse or avail
1900 # Return 0 is pool/disk matches expected state, 1 otherwise
1902 function check_hotspare_state
# pool disk state{inuse,avail}
1905 typeset disk
=${2#$DEV_DSKDIR/}
1908 cur_state
=$
(get_device_state
$pool $disk "spares")
1910 if [[ $state != ${cur_state} ]]; then
1917 # Wait until a hotspare transitions to a given state or times out.
1919 # Return 0 when pool/disk matches expected state, 1 on timeout.
1921 function wait_hotspare_state
# pool disk state timeout
1924 typeset disk
=${2#$/DEV_DSKDIR/}
1926 typeset timeout
=${4:-60}
1929 while [[ $i -lt $timeout ]]; do
1930 if check_hotspare_state
$pool $disk $state; then
1942 # Verify a given slog disk is inuse or avail
1944 # Return 0 is pool/disk matches expected state, 1 otherwise
1946 function check_slog_state
# pool disk state{online,offline,unavail}
1949 typeset disk
=${2#$DEV_DSKDIR/}
1952 cur_state
=$
(get_device_state
$pool $disk "logs")
1954 if [[ $state != ${cur_state} ]]; then
1961 # Verify a given vdev disk is inuse or avail
1963 # Return 0 is pool/disk matches expected state, 1 otherwise
1965 function check_vdev_state
# pool disk state{online,offline,unavail}
1968 typeset disk
=${2#$/DEV_DSKDIR/}
1971 cur_state
=$
(get_device_state
$pool $disk)
1973 if [[ $state != ${cur_state} ]]; then
1980 # Wait until a vdev transitions to a given state or times out.
1982 # Return 0 when pool/disk matches expected state, 1 on timeout.
1984 function wait_vdev_state
# pool disk state timeout
1987 typeset disk
=${2#$/DEV_DSKDIR/}
1989 typeset timeout
=${4:-60}
1992 while [[ $i -lt $timeout ]]; do
1993 if check_vdev_state
$pool $disk $state; then
2005 # Check the output of 'zpool status -v <pool>',
2006 # and to see if the content of <token> contain the <keyword> specified.
2008 # Return 0 is contain, 1 otherwise
2010 function check_pool_status
# pool token keyword <verbose>
2015 typeset verbose
=${4:-false}
2017 scan
=$
(zpool status
-v "$pool" 2>/dev
/null | nawk
-v token
="$token:" '
2018 ($1==token) {print $0}')
2019 if [[ $verbose == true
]]; then
2022 echo $scan |
grep -i "$keyword" > /dev
/null
2>&1
2028 # These 6 following functions are instance of check_pool_status()
2029 # is_pool_resilvering - to check if the pool is resilver in progress
2030 # is_pool_resilvered - to check if the pool is resilver completed
2031 # is_pool_scrubbing - to check if the pool is scrub in progress
2032 # is_pool_scrubbed - to check if the pool is scrub completed
2033 # is_pool_scrub_stopped - to check if the pool is scrub stopped
2034 # is_pool_scrub_paused - to check if the pool has scrub paused
2036 function is_pool_resilvering
#pool <verbose>
2038 check_pool_status
"$1" "scan" "resilver in progress since " $2
2042 function is_pool_resilvered
#pool <verbose>
2044 check_pool_status
"$1" "scan" "resilvered " $2
2048 function is_pool_scrubbing
#pool <verbose>
2050 check_pool_status
"$1" "scan" "scrub in progress since " $2
2054 function is_pool_scrubbed
#pool <verbose>
2056 check_pool_status
"$1" "scan" "scrub repaired" $2
2060 function is_pool_scrub_stopped
#pool <verbose>
2062 check_pool_status
"$1" "scan" "scrub canceled" $2
2066 function is_pool_scrub_paused
#pool <verbose>
2068 check_pool_status
"$1" "scan" "scrub paused since " $2
2073 # Use create_pool()/destroy_pool() to clean up the information in
2074 # in the given disk to avoid slice overlapping.
2076 function cleanup_devices
#vdevs
2078 typeset pool
="foopool$$"
2080 if poolexists
$pool ; then
2084 create_pool
$pool $@
2091 # A function to find and locate free disks on a system or from given
2092 # disks as the parameter. It works by locating disks that are in use
2093 # as swap devices and dump devices, and also disks listed in /etc/vfstab
2095 # $@ given disks to find which are free, default is all disks in
2098 # @return a string containing the list of available disks
2102 # Trust provided list, no attempt is made to locate unused devices.
2109 sfi
=/tmp
/swaplist.$$
2110 dmpi
=/tmp
/dumpdev.$$
2111 max_finddisksnum
=${MAX_FINDDISKSNUM:-6}
2114 dumpadm
> $dmpi 2>/dev
/null
2116 # write an awk script that can process the output of format
2117 # to produce a list of disks we know about. Note that we have
2118 # to escape "$2" so that the shell doesn't interpret it while
2119 # we're creating the awk script.
2120 # -------------------
2121 cat > /tmp
/find_disks.
awk <<EOF
2130 if (searchdisks && \$2 !~ "^$"){
2136 /^AVAILABLE DISK SELECTIONS:/{
2140 #---------------------
2142 chmod 755 /tmp
/find_disks.
awk
2143 disks
=${@:-$(echo "" | format -e 2>/dev/null | /tmp/find_disks.awk)}
2144 rm /tmp
/find_disks.
awk
2147 for disk
in $disks; do
2149 grep "${disk}[sp]" /etc
/mnttab
>/dev
/null
2150 (($?
== 0)) && continue
2152 grep "${disk}[sp]" $sfi >/dev
/null
2153 (($?
== 0)) && continue
2154 # check for dump device
2155 grep "${disk}[sp]" $dmpi >/dev
/null
2156 (($?
== 0)) && continue
2157 # check to see if this disk hasn't been explicitly excluded
2158 # by a user-set environment variable
2159 echo "${ZFS_HOST_DEVICES_IGNORE}" |
grep "${disk}" > /dev
/null
2160 (($?
== 0)) && continue
2161 unused_candidates
="$unused_candidates $disk"
2166 # now just check to see if those disks do actually exist
2167 # by looking for a device pointing to the first slice in
2168 # each case. limit the number to max_finddisksnum
2170 for disk
in $unused_candidates; do
2171 if [ -b $DEV_DSKDIR/${disk}s0
]; then
2172 if [ $count -lt $max_finddisksnum ]; then
2173 unused
="$unused $disk"
2174 # do not impose limit if $@ is provided
2175 [[ -z $@
]] && ((count
= count
+ 1))
2180 # finally, return our disk list
2185 # Add specified user to specified group
2189 # $3 base of the homedir (optional)
2191 function add_user
#<group_name> <user_name> <basedir>
2195 typeset basedir
=${3:-"/var/tmp"}
2197 if ((${#gname} == 0 ||
${#uname} == 0)); then
2198 log_fail
"group name or user name are not defined."
2201 log_must useradd
-g $gname -d $basedir/$uname -m $uname
2202 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.profile
2203 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.bash_profile
2204 echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.login
2206 # Add new users to the same group and the command line utils.
2207 # This allows them to be run out of the original users home
2208 # directory as long as it permissioned to be group readable.
2210 cmd_group
=$
(stat
--format="%G" $
(which zfs
))
2211 log_must usermod
-a -G $cmd_group $uname
2218 # Delete the specified user.
2221 # $2 base of the homedir (optional)
2223 function del_user
#<logname> <basedir>
2226 typeset basedir
=${2:-"/var/tmp"}
2228 if ((${#user} == 0)); then
2229 log_fail
"login name is necessary."
2232 if id
$user > /dev
/null
2>&1; then
2233 log_must_retry
"currently used" 5 userdel
$user
2236 [[ -d $basedir/$user ]] && rm -fr $basedir/$user
2242 # Select valid gid and create specified group.
2246 function add_group
#<group_name>
2250 if ((${#group} == 0)); then
2251 log_fail
"group name is necessary."
2254 # Assign 100 as the base gid, a larger value is selected for
2255 # Linux because for many distributions 1000 and under are reserved.
2258 groupadd
$group > /dev
/null
2>&1
2268 groupadd
-g $gid $group > /dev
/null
2>&1
2272 # The gid is not unique
2281 # Delete the specified group.
2285 function del_group
#<group_name>
2288 if ((${#grp} == 0)); then
2289 log_fail
"group name is necessary."
2293 getent group
$grp > /dev
/null
2>&1
2296 # Group does not exist.
2298 # Name already exists as a group name
2299 0) log_must groupdel
$grp ;;
2303 groupmod
-n $grp $grp > /dev
/null
2>&1
2306 # Group does not exist.
2308 # Name already exists as a group name
2309 9) log_must groupdel
$grp ;;
2318 # This function will return true if it's safe to destroy the pool passed
2319 # as argument 1. It checks for pools based on zvols and files, and also
2320 # files contained in a pool that may have a different mountpoint.
2322 function safe_to_destroy_pool
{ # $1 the pool name
2325 typeset DONT_DESTROY
=""
2327 # We check that by deleting the $1 pool, we're not
2328 # going to pull the rug out from other pools. Do this
2329 # by looking at all other pools, ensuring that they
2330 # aren't built from files or zvols contained in this pool.
2332 for pool
in $
(zpool list
-H -o name
)
2336 # this is a list of the top-level directories in each of the
2337 # files that make up the path to the files the pool is based on
2338 FILEPOOL
=$
(zpool status
-v $pool |
grep /$1/ | \
2341 # this is a list of the zvols that make up the pool
2342 ZVOLPOOL
=$
(zpool status
-v $pool |
grep "$ZVOL_DEVDIR/$1$" \
2345 # also want to determine if it's a file-based pool using an
2346 # alternate mountpoint...
2347 POOL_FILE_DIRS
=$
(zpool status
-v $pool | \
2348 grep / |
awk '{print $1}' | \
2349 awk -F/ '{print $2}' |
grep -v "dev")
2351 for pooldir
in $POOL_FILE_DIRS
2353 OUTPUT
=$
(zfs list
-H -r -o mountpoint
$1 | \
2354 grep "${pooldir}$" |
awk '{print $1}')
2356 ALTMOUNTPOOL
="${ALTMOUNTPOOL}${OUTPUT}"
2360 if [ ! -z "$ZVOLPOOL" ]
2363 log_note
"Pool $pool is built from $ZVOLPOOL on $1"
2366 if [ ! -z "$FILEPOOL" ]
2369 log_note
"Pool $pool is built from $FILEPOOL on $1"
2372 if [ ! -z "$ALTMOUNTPOOL" ]
2375 log_note
"Pool $pool is built from $ALTMOUNTPOOL on $1"
2379 if [ -z "${DONT_DESTROY}" ]
2383 log_note
"Warning: it is not safe to destroy $1!"
2389 # Get the available ZFS compression options
2390 # $1 option type zfs_set|zfs_compress
2392 function get_compress_opts
2394 typeset COMPRESS_OPTS
2395 typeset GZIP_OPTS
="gzip gzip-1 gzip-2 gzip-3 gzip-4 gzip-5 \
2396 gzip-6 gzip-7 gzip-8 gzip-9"
2398 if [[ $1 == "zfs_compress" ]] ; then
2399 COMPRESS_OPTS
="on lzjb"
2400 elif [[ $1 == "zfs_set" ]] ; then
2401 COMPRESS_OPTS
="on off lzjb"
2403 typeset valid_opts
="$COMPRESS_OPTS"
2404 zfs get
2>&1 |
grep gzip >/dev
/null
2>&1
2405 if [[ $?
-eq 0 ]]; then
2406 valid_opts
="$valid_opts $GZIP_OPTS"
2412 # Verify zfs operation with -p option work as expected
2413 # $1 operation, value could be create, clone or rename
2414 # $2 dataset type, value could be fs or vol
2416 # $4 new dataset name
2418 function verify_opt_p_ops
2423 typeset newdataset
=$4
2425 if [[ $datatype != "fs" && $datatype != "vol" ]]; then
2426 log_fail
"$datatype is not supported."
2429 # check parameters accordingly
2434 if [[ $datatype == "vol" ]]; then
2435 ops
="create -V $VOLSIZE"
2439 if [[ -z $newdataset ]]; then
2440 log_fail
"newdataset should not be empty" \
2443 log_must datasetexists
$dataset
2444 log_must snapexists
$dataset
2447 if [[ -z $newdataset ]]; then
2448 log_fail
"newdataset should not be empty" \
2451 log_must datasetexists
$dataset
2452 log_mustnot snapexists
$dataset
2455 log_fail
"$ops is not supported."
2459 # make sure the upper level filesystem does not exist
2460 if datasetexists
${newdataset%/*} ; then
2461 log_must zfs destroy
-rRf ${newdataset%/*}
2464 # without -p option, operation will fail
2465 log_mustnot zfs
$ops $dataset $newdataset
2466 log_mustnot datasetexists
$newdataset ${newdataset%/*}
2468 # with -p option, operation should succeed
2469 log_must zfs
$ops -p $dataset $newdataset
2472 if ! datasetexists
$newdataset ; then
2473 log_fail
"-p option does not work for $ops"
2476 # when $ops is create or clone, redo the operation still return zero
2477 if [[ $ops != "rename" ]]; then
2478 log_must zfs
$ops -p $dataset $newdataset
2485 # Get configuration of pool
2495 if ! poolexists
"$pool" ; then
2498 alt_root
=$
(zpool list
-H $pool |
awk '{print $NF}')
2499 if [[ $alt_root == "-" ]]; then
2500 value
=$
(zdb
-C $pool |
grep "$config:" |
awk -F: \
2503 value
=$
(zdb
-e $pool |
grep "$config:" |
awk -F: \
2506 if [[ -n $value ]] ; then
2516 # Privated function. Random select one of items from arguments.
2521 function _random_get
2528 ((ind
= RANDOM
% cnt
+ 1))
2530 typeset ret
=$
(echo "$str" | cut
-f $ind -d ' ')
2535 # Random select one of item from arguments which include NONE string
2537 function random_get_with_non
2542 _random_get
"$cnt" "$@"
2546 # Random select one of item from arguments which doesn't include NONE string
2550 _random_get
"$#" "$@"
2554 # Detect if the current system support slog
2556 function verify_slog_support
2558 typeset dir
=$TEST_BASE_DIR/disk.$$
2564 mkfile
$MINVDEVSIZE $vdev $sdev
2567 if ! zpool create
-n $pool $vdev log
$sdev > /dev
/null
2>&1; then
2576 # The function will generate a dataset name with specific length
2577 # $1, the length of the name
2578 # $2, the base string to construct the name
2580 function gen_dataset_name
2583 typeset basestr
="$2"
2584 typeset
-i baselen
=${#basestr}
2588 if ((len
% baselen
== 0)); then
2589 ((iter
= len
/ baselen
))
2591 ((iter
= len
/ baselen
+ 1))
2593 while ((iter
> 0)); do
2594 l_name
="${l_name}$basestr"
2603 # Get cksum tuple of dataset
2606 # sample zdb output:
2607 # Dataset data/test [ZPL], ID 355, cr_txg 2413856, 31.0K, 7 objects, rootbp
2608 # DVA[0]=<0:803046400:200> DVA[1]=<0:81199000:200> [L0 DMU objset] fletcher4
2609 # lzjb LE contiguous unique double size=800L/200P birth=2413856L/2413856P
2610 # fill=7 cksum=11ce125712:643a9c18ee2:125e25238fca0:254a3f74b59744
2611 function datasetcksum
2615 cksum=$
(zdb
-vvv $1 |
grep "^Dataset $1 \[" |
grep "cksum" \
2616 |
awk -F= '{print $7}')
2627 cksum=$
(cksum $1 |
awk '{print $1}')
2632 # Get the given disk/slice state from the specific field of the pool
2634 function get_device_state
#pool disk field("", "spares","logs")
2637 typeset disk
=${2#$DEV_DSKDIR/}
2638 typeset field
=${3:-$pool}
2640 state
=$
(zpool status
-v "$pool" 2>/dev
/null | \
2641 nawk
-v device
=$disk -v pool
=$pool -v field
=$field \
2642 'BEGIN {startconfig=0; startfield=0; }
2643 /config:/ {startconfig=1}
2644 (startconfig==1) && ($1==field) {startfield=1; next;}
2645 (startfield==1) && ($1==device) {print $2; exit;}
2647 ($1==field || $1 ~ "^spares$" || $1 ~ "^logs$") {startfield=0}')
2653 # print the given directory filesystem type
2661 if [[ -z $dir ]]; then
2662 log_fail
"Usage: get_fstype <directory>"
2669 df
-n $dir |
awk '{print $3}'
2673 # Given a disk, label it to VTOC regardless what label was on the disk
2679 if [[ -z $disk ]]; then
2680 log_fail
"The disk name is unspecified."
2682 typeset label_file
=/var
/tmp
/labelvtoc.$$
2683 typeset arch
=$
(uname
-p)
2686 log_note
"Currently unsupported by the test framework"
2690 if [[ $arch == "i386" ]]; then
2691 echo "label" > $label_file
2692 echo "0" >> $label_file
2693 echo "" >> $label_file
2694 echo "q" >> $label_file
2695 echo "q" >> $label_file
2697 fdisk
-B $disk >/dev
/null
2>&1
2698 # wait a while for fdisk finishes
2700 elif [[ $arch == "sparc" ]]; then
2701 echo "label" > $label_file
2702 echo "0" >> $label_file
2703 echo "" >> $label_file
2704 echo "" >> $label_file
2705 echo "" >> $label_file
2706 echo "q" >> $label_file
2708 log_fail
"unknown arch type"
2711 format
-e -s -d $disk -f $label_file
2712 typeset
-i ret_val
=$?
2715 # wait the format to finish
2718 if ((ret_val
!= 0)); then
2719 log_fail
"unable to label $disk as VTOC."
2726 # check if the system was installed as zfsroot or not
2727 # return: 0 ture, otherwise false
2731 df
-n / |
grep zfs
> /dev
/null
2>&1
2736 # get the root filesystem name if it's zfsroot system.
2738 # return: root filesystem name
2744 rootfs
=$
(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \
2747 if [[ -z "$rootfs" ]]; then
2748 log_fail
"Can not get rootfs"
2750 zfs list
$rootfs > /dev
/null
2>&1
2751 if (($?
== 0)); then
2754 log_fail
"This is not a zfsroot system."
2759 # get the rootfs's pool name
2763 function get_rootpool
2769 rootfs
=$
(awk '{if ($2 == "/" && $3 =="zfs") print $1}' \
2772 if [[ -z "$rootfs" ]]; then
2773 log_fail
"Can not get rootpool"
2775 zfs list
$rootfs > /dev
/null
2>&1
2776 if (($?
== 0)); then
2777 rootpool
=`echo $rootfs | awk -F\/ '{print $1}'`
2780 log_fail
"This is not a zfsroot system."
2785 # Get the package name
2787 function get_package_name
2789 typeset dirpath
=${1:-$STC_NAME}
2791 echo "SUNWstc-${dirpath}" |
/usr
/bin
/sed -e "s/\//-/g"
2795 # Get the word numbers from a string separated by white space
2797 function get_word_count
2803 # To verify if the require numbers of disks is given
2805 function verify_disk_count
2807 typeset
-i min
=${2:-1}
2809 typeset
-i count
=$
(get_word_count
"$1")
2811 if ((count
< min
)); then
2812 log_untested
"A minimum of $min disks is required to run." \
2813 " You specified $count disk(s)"
2817 function ds_is_volume
2819 typeset
type=$
(get_prop
type $1)
2820 [[ $type = "volume" ]] && return 0
2824 function ds_is_filesystem
2826 typeset
type=$
(get_prop
type $1)
2827 [[ $type = "filesystem" ]] && return 0
2831 function ds_is_snapshot
2833 typeset
type=$
(get_prop
type $1)
2834 [[ $type = "snapshot" ]] && return 0
2839 # Check if Trusted Extensions are installed and enabled
2841 function is_te_enabled
2843 svcs
-H -o state labeld
2>/dev
/null |
grep "enabled"
2844 if (($?
!= 0)); then
2851 # Utility function to determine if a system has multiple cpus.
2857 (($
(psrinfo |
wc -l) > 1))
2863 function get_cpu_freq
2866 lscpu |
awk '/CPU MHz/ { print $3 }'
2868 psrinfo
-v 0 |
awk '/processor operates at/ {print $6}'
2872 # Run the given command as the user provided.
2878 log_note
"user:$user $@"
2879 eval su
- \
$user -c \"$@
\" > /tmp
/out
2>/tmp
/err
2884 # Check if the pool contains the specified vdevs
2889 # Return 0 if the vdevs are contained in the pool, 1 if any of the specified
2890 # vdevs is not in the pool, and 2 if pool name is missing.
2892 function vdevs_in_pool
2897 if [[ -z $pool ]]; then
2898 log_note
"Missing pool name."
2904 typeset tmpfile
=$
(mktemp
)
2905 zpool list
-Hv "$pool" >$tmpfile
2907 grep -w ${vdev##*/} $tmpfile >/dev
/null
2>&1
2908 [[ $?
-ne 0 ]] && return 1
2922 max
=$
(echo $
((max
> i ? max
: i
)))
2934 min
=$
(echo $
((min
< i ? min
: i
)))
2941 # Generate a random number between 1 and the argument.
2946 echo $
(( ($RANDOM % $max) + 1 ))
2949 # Write data that can be compressed into a directory
2950 function write_compressible
2954 typeset nfiles
=${3:-1}
2955 typeset bs
=${4:-1024k}
2956 typeset fname
=${5:-file}
2958 [[ -d $dir ]] || log_fail
"No directory: $dir"
2960 # Under Linux fio is not currently used since its behavior can
2961 # differ significantly across versions. This includes missing
2962 # command line options and cases where the --buffer_compress_*
2963 # options fail to behave as expected.
2965 typeset file_bytes
=$
(to_bytes
$megs)
2966 typeset bs_bytes
=4096
2967 typeset blocks
=$
(($file_bytes / $bs_bytes))
2969 for (( i
= 0; i
< $nfiles; i
++ )); do
2970 truncate
-s $file_bytes $dir/$fname.
$i
2972 # Write every third block to get 66% compression.
2973 for (( j
= 0; j
< $blocks; j
+= 3 )); do
2974 dd if=/dev
/urandom of
=$dir/$fname.
$i \
2975 seek
=$j bs
=$bs_bytes count
=1 \
2976 conv
=notrunc
>/dev
/null
2>&1
2980 log_must
eval "fio \
2985 --buffer_compress_percentage=66 \
2986 --buffer_compress_chunk=4096 \
2993 --filename_format='$fname.\$jobnum' >/dev/null"
3002 [[ -e $pathname ]] || log_fail
"No such file or directory: $pathname"
3003 objnum
=$
(stat
-c %i
$pathname)
3008 # Sync data to the pool
3011 # $2 boolean to force uberblock (and config including zpool cache file) update
3013 function sync_pool
#pool <force>
3015 typeset pool
=${1:-$TESTPOOL}
3016 typeset force
=${2:-false}
3018 if [[ $force == true
]]; then
3019 log_must zpool sync
-f $pool
3021 log_must zpool sync
$pool
3028 # Wait for zpool 'freeing' property drops to zero.
3032 function wait_freeing
#pool
3034 typeset pool
=${1:-$TESTPOOL}
3036 [[ "0" == "$(zpool list -Ho freeing $pool)" ]] && break
3042 # Wait for every device replace operation to complete
3046 function wait_replacing
#pool
3048 typeset pool
=${1:-$TESTPOOL}
3050 [[ "" == "$(zpool status $pool |
3051 awk '/replacing-[0-9]+/ {print $1}')" ]] && break
3057 # Wait for a pool to be scrubbed
3060 # $2 number of seconds to wait (optional)
3062 # Returns true when pool has been scrubbed, or false if there's a timeout or if
3063 # no scrub was done.
3065 function wait_scrubbed
3067 typeset pool
=${1:-$TESTPOOL}
3068 typeset iter
=${2:-10}
3069 for i
in {1..
$iter} ; do
3070 if is_pool_scrubbed
$pool ; then
3079 # Setup custom environment for the ZED.
3081 # $@ Optional list of zedlets to run under zed.
3088 if [[ ! -d $ZEDLET_DIR ]]; then
3089 log_must mkdir
$ZEDLET_DIR
3092 if [[ ! -e $VDEVID_CONF ]]; then
3093 log_must
touch $VDEVID_CONF
3096 if [[ -e $VDEVID_CONF_ETC ]]; then
3097 log_fail
"Must not have $VDEVID_CONF_ETC file present on system"
3101 # Create a symlink for /etc/zfs/vdev_id.conf file.
3102 log_must
ln -s $VDEVID_CONF $VDEVID_CONF_ETC
3104 # Setup minimal ZED configuration. Individual test cases should
3105 # add additional ZEDLETs as needed for their specific test.
3106 log_must
cp ${ZEDLET_ETC_DIR}/zed.rc
$ZEDLET_DIR
3107 log_must
cp ${ZEDLET_ETC_DIR}/zed-functions.sh
$ZEDLET_DIR
3109 # Scripts must only be user writable.
3110 if [[ -n "$EXTRA_ZEDLETS" ]] ; then
3111 saved_umask
=$
(umask)
3113 for i
in $EXTRA_ZEDLETS ; do
3114 log_must
cp ${ZEDLET_LIBEXEC_DIR}/$i $ZEDLET_DIR
3116 log_must
umask $saved_umask
3119 # Customize the zed.rc file to enable the full debug log.
3120 log_must
sed -i '/\#ZED_DEBUG_LOG=.*/d' $ZEDLET_DIR/zed.rc
3121 echo "ZED_DEBUG_LOG=$ZED_DEBUG_LOG" >>$ZEDLET_DIR/zed.rc
3126 # Cleanup custom ZED environment.
3128 # $@ Optional list of zedlets to remove from our test zed.d directory.
3129 function zed_cleanup
3136 log_must
rm -f ${ZEDLET_DIR}/zed.rc
3137 log_must
rm -f ${ZEDLET_DIR}/zed-functions.sh
3138 log_must
rm -f ${ZEDLET_DIR}/all-syslog.sh
3139 log_must
rm -f ${ZEDLET_DIR}/all-debug.sh
3140 log_must
rm -f ${ZEDLET_DIR}/state
3142 if [[ -n "$EXTRA_ZEDLETS" ]] ; then
3143 for i
in $EXTRA_ZEDLETS ; do
3144 log_must
rm -f ${ZEDLET_DIR}/$i
3147 log_must
rm -f $ZED_LOG
3148 log_must
rm -f $ZED_DEBUG_LOG
3149 log_must
rm -f $VDEVID_CONF_ETC
3150 log_must
rm -f $VDEVID_CONF
3155 # Check if ZED is currently running, if not start ZED.
3163 # ZEDLET_DIR=/var/tmp/zed
3164 if [[ ! -d $ZEDLET_DIR ]]; then
3165 log_must mkdir
$ZEDLET_DIR
3168 # Verify the ZED is not already running.
3169 pgrep
-x zed
> /dev
/null
3170 if (($?
== 0)); then
3171 log_fail
"ZED already running"
3174 log_note
"Starting ZED"
3175 # run ZED in the background and redirect foreground logging
3176 # output to $ZED_LOG.
3177 log_must truncate
-s 0 $ZED_DEBUG_LOG
3178 log_must
eval "zed -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid -P $PATH" \
3179 "-s $ZEDLET_DIR/state 2>$ZED_LOG &"
3193 log_note
"Stopping ZED"
3194 if [[ -f ${ZEDLET_DIR}/zed.pid
]]; then
3195 zedpid
=$
(cat ${ZEDLET_DIR}/zed.pid
)
3197 while ps
-p $zedpid > /dev
/null
; do
3200 rm -f ${ZEDLET_DIR}/zed.pid
3208 function zed_events_drain
3210 while [ $
(zpool events
-H |
wc -l) -ne 0 ]; do
3212 zpool events
-c >/dev
/null
3217 # Check is provided device is being active used as a swap device.
3219 function is_swap_inuse
3223 if [[ -z $device ]] ; then
3224 log_note
"No device specified."
3229 swapon
-s |
grep -w $
(readlink
-f $device) > /dev
/null
2>&1
3231 swap
-l |
grep -w $device > /dev
/null
2>&1
3238 # Setup a swap device using the provided device.
3245 log_must
eval "mkswap $swapdev > /dev/null 2>&1"
3246 log_must swapon
$swapdev
3248 log_must swap
-a $swapdev
3255 # Cleanup a swap device on the provided device.
3257 function swap_cleanup
3261 if is_swap_inuse
$swapdev; then
3263 log_must swapoff
$swapdev
3265 log_must swap
-d $swapdev
3273 # Set a global system tunable (64-bit value)
3278 function set_tunable64
3280 set_tunable_impl
"$1" "$2" Z
3284 # Set a global system tunable (32-bit value)
3289 function set_tunable32
3291 set_tunable_impl
"$1" "$2" W
3294 function set_tunable_impl
3296 typeset tunable
="$1"
3298 typeset mdb_cmd
="$3"
3299 typeset module
="${4:-zfs}"
3301 [[ -z "$tunable" ]] && return 1
3302 [[ -z "$value" ]] && return 1
3303 [[ -z "$mdb_cmd" ]] && return 1
3307 typeset zfs_tunables
="/sys/module/$module/parameters"
3308 [[ -w "$zfs_tunables/$tunable" ]] ||
return 1
3309 echo -n "$value" > "$zfs_tunables/$tunable"
3313 [[ "$module" -eq "zfs" ]] ||
return 1
3314 echo "${tunable}/${mdb_cmd}0t${value}" | mdb
-kw
3321 # Get a global system tunable
3325 function get_tunable
3327 get_tunable_impl
"$1"
3330 function get_tunable_impl
3332 typeset tunable
="$1"
3333 typeset module
="${2:-zfs}"
3335 [[ -z "$tunable" ]] && return 1
3339 typeset zfs_tunables
="/sys/module/$module/parameters"
3340 [[ -f "$zfs_tunables/$tunable" ]] ||
return 1
3341 cat $zfs_tunables/$tunable
3345 [[ "$module" -eq "zfs" ]] ||
return 1