Lines Matching +full:function +full:- +full:group
1 # SPDX-License-Identifier: CDDL-1.0
10 # or https://opensource.org/licenses/CDDL-1.0.
30 # Copyright (c) 2017, Open-E Inc. All rights reserved.
46 PWD="$(readlink -f $PWD)"
53 if [ -n "$STF_PATH" ]; then
58 # Generic dot version comparison function
62 function compare_version_gte
64 [ "$(printf "$1\n$2" | sort -V | tail -n1)" = "$1" ]
67 # Helper function used by linux_version() and freebsd_version()
70 function kernel_version
74 [ -z "$ver" ] && case "$UNAME" in
78 # RHEL7: 3.10.0-1160.108.1.el7.x86_64
79 # Fedora 37: 6.5.12-100.fc37.x86_64
80 # Debian 12.6: 6.1.0-22-amd64
81 ver=$(uname -r | grep -Eo "^[0-9]+\.[0-9]+\.[0-9]+")
84 # FreeBSD version numbers are X.Y-BRANCH-pZ. Depending on
85 # branch, -pZ may not be present, but this is typically only
86 # on pre-release or true .0 releases, so can be assumed 0
89 # 13.2-RELEASE-p4
90 # 14.1-RELEASE
91 # 15.0-CURRENT
92 ver=$(uname -r | \
93 grep -Eo "[0-9]+\.[0-9]+(-[A-Z0-9]+-p[0-9]+)?" | \
94 sed -E "s/-[^-]+-p/./")
103 IFS='.' read -r version major minor _ <<<"$ver"
105 [ -z "$version" ] && version=0
106 [ -z "$major" ] && major=0
107 [ -z "$minor" ] && minor=0
112 # Linux kernel version comparison function
116 # Used for comparison: if [ $(linux_version) -ge $(linux_version "2.6.32") ]
117 function linux_version {
121 # FreeBSD version comparison function
125 # Used for comparison: if [ $(freebsd_version) -ge $(freebsd_version "13.2") ]
126 function freebsd_version {
134 function is_linux
142 function is_illumos
151 function is_freebsd
156 # Determine if this is a 32-bit system
158 # Return 0 if platform is 32-bit, 1 if otherwise
160 function is_32bit
169 function is_kmemleak
171 is_linux && [ -e /sys/kernel/debug/kmemleak ]
177 # $2 filesystem type; optional - defaulted to zfs
181 function ismounted
184 [[ -z $fstype ]] && fstype=zfs
190 ! zfs mount | awk -v fs="$1" '$2 == fs {exit 1}'
192 ! zfs mount | awk -v ds="$1" '$1 == ds {exit 1}'
197 mount -pt $fstype | while read dev dir _t _flags; do
201 out=$(df -F $fstype $1 2>/dev/null) || return
213 df -t $fstype $1 > /dev/null 2>&1
216 if [[ -L "$ZVOL_DEVDIR/$1" ]]; then
217 link=$(readlink -f $ZVOL_DEVDIR/$1)
218 [[ -n "$link" ]] && \
219 mount | grep -q "^$link" && \
232 # $2 filesystem type; optional - defaulted to zfs
234 function mounted
242 # $2 filesystem type; optional - defaulted to zfs
244 function unmounted
249 function default_setup
256 function default_setup_no_mountpoint
266 function default_setup_noexit
278 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
279 log_must zpool create -f $TESTPOOL $disklist
284 rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR
285 mkdir -p $TESTDIR || log_unresolved Could not create $TESTDIR
288 if [[ -z $no_mountpoint ]]; then
292 if [[ -n $container ]]; then
293 rm -rf $TESTDIR1 || \
295 mkdir -p $TESTDIR1 || \
301 if [[ -z $no_mountpoint ]]; then
307 if [[ -n $volume ]]; then
309 log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL
321 function default_container_setup
332 function default_volume_setup
343 function default_container_volume_setup
357 function create_snapshot
359 typeset fs_vol=${1:-$TESTPOOL/$TESTFS}
360 typeset snap=${2:-$TESTSNAP}
362 [[ -z $fs_vol ]] && log_fail "Filesystem or volume's name is undefined."
363 [[ -z $snap ]] && log_fail "Snapshot's name is undefined."
380 function create_clone # snapshot clone
382 typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
383 typeset clone=${2:-$TESTPOOL/$TESTCLONE}
385 [[ -z $snap ]] && \
387 [[ -z $clone ]] && \
401 function create_bookmark
403 typeset fs_vol=${1:-$TESTFS}
404 typeset snap=${2:-$TESTSNAP}
405 typeset bkmark=${3:-$TESTBKMARK}
407 [[ -z $fs_vol ]] && log_fail "Filesystem or volume's name is undefined."
408 [[ -z $snap ]] && log_fail "Snapshot's name is undefined."
409 [[ -z $bkmark ]] && log_fail "Bookmark's name is undefined."
425 # of this function along with its %recv temporary clone
428 function create_recv_clone
431 typeset sendfs="${2:-$TESTPOOL/create_recv_clone}"
437 [[ -z $recvfs ]] && log_fail "Recv filesystem's name is undefined."
442 log_must zfs create -o compression=off -o mountpoint="$mountpoint" $sendfs
444 log_must eval "zfs send $snap | zfs recv -u $recvfs"
447 log_must eval "zfs send -i $snap $incr | dd bs=10K count=1 \
449 log_mustnot eval "zfs recv -su $recvfs < $sendfile"
450 destroy_dataset "$sendfs" "-r"
451 log_must rm -f "$sendfile"
453 if [[ $(get_prop 'inconsistent' "$recvfs/%recv") -ne 1 ]]; then
458 function default_mirror_setup
470 function default_mirror_setup_noexit
476 [[ -z $primary ]] && \
478 [[ -z $secondary ]] && \
480 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
481 log_must zpool create -f $TESTPOOL mirror $@
490 function destroy_mirrors
497 function default_raidz_setup
505 # Given a minimum of two disks, set up a storage pool and dataset for the raid-z
508 function default_raidz_setup_noexit
513 if [[ ${#disks[*]} -lt 2 ]]; then
514 log_fail "A raid-z requires a minimum of two disks."
517 [[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
518 log_must zpool create -f $TESTPOOL raidz $disklist
524 # Common function used to cleanup storage pools and datasets.
528 # sub-tests to ensure errors from one set of tests doesn't
531 function default_cleanup
539 # Utility function used to list all available pool names.
544 function get_all_pools
546 zpool list -H -o name | grep -Fvx "$KEEP" | grep -v "$NO_POOLS"
549 function default_cleanup_noexit
557 zfs unmount -a > /dev/null 2>&1
562 while [ ! -z ${ALL_POOLS} ]
574 zfs mount -a
577 for fs in $(zfs list -H -o name \
579 destroy_dataset "$fs" "-Rf"
583 for fs in $(zfs list -H -o name); do
585 [[ -d $fs ]] && log_must rm -rf $fs/*
592 for fs in $(zfs list -H -o name); do
598 if [ -z "$enc" ] || [ "$enc" = "off" ]; then
614 [[ -d $TESTDIR ]] && \
615 log_must rm -rf $TESTDIR
622 rm -f $TEST_BASE_DIR/{err,out}
627 # Common function used to cleanup storage pools, file systems
630 function default_container_cleanup
639 destroy_dataset "$TESTPOOL/$TESTCTR/$TESTFS1" "-R"
640 destroy_dataset "$TESTPOOL/$TESTCTR" "-Rf"
642 [[ -e $TESTDIR1 ]] && \
643 log_must rm -rf $TESTDIR1
649 # Common function used to cleanup snapshot of file system or volume. Default to
654 function destroy_snapshot
656 typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
673 [[ $mtpt != "" && -d $mtpt ]] && \
674 log_must rm -rf $mtpt
678 # Common function used to cleanup clone.
682 function destroy_clone
684 typeset clone=${1:-$TESTPOOL/$TESTCLONE}
697 [[ $mtpt != "" && -d $mtpt ]] && \
698 log_must rm -rf $mtpt
702 # Common function used to cleanup bookmark of file system or volume. Default
707 function destroy_bookmark
709 typeset bkmark=${1:-$TESTPOOL/$TESTFS#$TESTBKMARK}
720 # $1 - snapshot name
722 function snapexists
724 zfs list -H -t snapshot "$1" > /dev/null 2>&1
730 # $1 - bookmark name
732 function bkmarkexists
734 zfs list -H -t bookmark "$1" > /dev/null 2>&1
740 # $1 - hold tag
741 # $2 - snapshot name
743 function holdexists
745 ! zfs holds "$2" | awk -v t="$1" '$2 ~ t { exit 1 }'
757 # non-zero otherwise.
760 function dataset_setprop
787 function assert
793 # Function to format partition size of a disk
797 function zero_partitions #<whole_disk_name>
803 gpart destroy -F $diskname
806 DSK=$(echo $DSK | sed -e "s|//|/|g")
807 log_must parted $DSK -s -- mklabel gpt
808 blockdev --rereadpt $DSK 2>/dev/null
821 # Given a slice, size and disk, this function
832 function set_partition
834 typeset -i slicenum=$1
842 if [[ -z $size || -z $disk ]]; then
855 parted $disk -s -- print 1 >/dev/null
857 if [[ $slicenum -eq 0 || $ret_val -ne 0 ]]; then
858 if ! parted $disk -s -- mklabel gpt; then
865 if [[ -z "$start" ]]; then
871 typeset -i cly_size_kb=0
872 cly_size_kb=$(parted -m $disk -s -- unit cyl print |
873 awk -F '[:k.]' 'NR == 3 {print $4}')
876 parted $disk -s -- \
879 if [[ $ret_val -ne 0 ]]; then
884 blockdev --rereadpt $disk 2>/dev/null
888 if [[ -z $size || -z $disk ]]; then
893 if [[ $slicenum -eq 0 ]] || ! gpart show $disk >/dev/null 2>&1; then
894 gpart destroy -F $disk >/dev/null 2>&1
895 if ! gpart create -s GPT $disk; then
903 if [[ -n $start ]]; then
904 start="-b $start"
906 gpart add -t freebsd-zfs $start -s $size -i $index $disk
907 if [[ $ret_val -ne 0 ]]; then
915 if [[ -z $slicenum || -z $size || -z $disk ]]; then
932 format -e -s -d $disk -f $format_file
934 rm -f $format_file
938 if [[ $ret_val -ne 0 ]]; then
946 # Delete all partitions on all disks - this is specifically for the use of multipath
947 # devices which currently can only be used in the test suite as raw/un-partitioned
950 function delete_partitions
954 if [[ -z $DISKSARRAY ]]; then
959 typeset -i part
963 parted $DEV_DSKDIR/$disk -s rm $part > /dev/null 2>&1
964 if lsblk | grep -qF ${partition}; then
973 if gpart destroy -F $disk; then
985 function get_endslice #<disk> <slice>
989 if [[ -z $disk || -z $slice ]] ; then
995 endcyl=$(parted -s $DEV_DSKDIR/$disk -- unit cyl print | \
1004 awk -v slice=$slice '$3 == slice { print $1 + $2 }')
1011 typeset -i ratio=0
1019 typeset -i endcyl=$(prtvtoc -h /dev/rdsk/${disk}s2 |
1020 awk -v token="$slice" '$1 == token {print $6}')
1031 # Given a size,disk and total slice number, this function formats the
1035 function partition_disk #<slice_size> <whole_disk_name> <total_slices>
1037 typeset -i i=0
1058 # This function continues to write to a filenum number of files into dirnum
1070 # dirnum: the maximum number of subdirectories to use, -1 no limit
1081 function fill_fs # destdir dirnum filenum bytes num_writes data
1083 typeset destdir=${1:-$TESTDIR}
1084 typeset -i dirnum=${2:-50}
1085 typeset -i filenum=${3:-50}
1086 typeset -i bytes=${4:-8192}
1087 typeset -i num_writes=${5:-10240}
1088 typeset data=${6:-"R"}
1090 mkdir -p $destdir/{1..$dirnum}
1092 file_write -o create -f $f -b $bytes -c $num_writes -d $data \
1098 function get_prop # property dataset
1103 zfs get -Hpo value "$prop" "$dataset" || log_fail "zfs get $prop $dataset"
1107 function get_pool_prop # property pool
1112 zpool get -Hpo value "$prop" "$pool" || log_fail "zpool get $prop $pool"
1116 function get_vdev_prop
1122 zpool get -Hpo value "$prop" "$pool" "$vdev" || log_fail "zpool get $prop $pool $vdev"
1127 # $1 - pool name
1129 function poolexists
1133 if [[ -z $pool ]]; then
1143 # $1-n dataset name
1144 function datasetexists
1156 # $1-n dataset name
1157 function datasetnonexists
1165 zfs list -H -t filesystem,snapshot,volume $1 > /dev/null 2>&1 \
1176 # cf. https://github.com/openzfs/zfs/pull/13165#issuecomment-1059845807
1178 # Linux can have spaces (which are \OOO-escaped),
1180 function shares_can_have_whitespace
1185 function is_shared_freebsd
1189 pgrep -q mountd && showmount -E | grep -qx "$fs"
1192 function is_shared_illumos
1203 typeset stat=$(svcs -H -o STA nfs/server:default)
1211 function is_shared_linux
1214 ! exportfs -s | awk -v fs="${fs//\\/\\\\}" '/^\// && $1 == fs {exit 1}'
1222 function is_shared
1233 none|legacy|-) return 1
1248 function is_exported_illumos
1253 while read -r mtpt _; do
1260 function is_exported_freebsd
1265 while read -r mtpt _; do
1272 function is_exported_linux
1277 while read -r mtpt _; do
1286 # the os-specific NFS exports file.
1290 function is_exported
1301 none|legacy|-) return 1
1321 function is_shared_smb
1328 net usershare list | grep -xFq "${fs//[-\/]/_}"
1340 function not_shared
1350 function not_shared_smb
1356 # Helper function to unshare a mountpoint.
1358 function unshare_fs #fs
1368 # Helper function to share a NFS mountpoint.
1370 function share_nfs #fs
1382 read -r mountd < /var/run/mountd.pid
1384 log_must kill -s HUP "$mountd"
1387 log_must share -F nfs "$fs"
1395 # Helper function to unshare a NFS mountpoint.
1397 function unshare_nfs #fs
1405 log_must exportfs -u "*:$fs"
1409 read -r mountd < /var/run/mountd.pid
1410 awk -v fs="${fs//\\/\\\\}" '$1 != fs' /etc/zfs/exports > /etc/zfs/exports.$$
1412 log_must kill -s HUP "$mountd"
1415 log_must unshare -F nfs $fs
1423 # Helper function to show NFS shares.
1425 function showshares_nfs
1429 exportfs -v
1435 share -F nfs
1440 function check_nfs
1444 exportfs -s
1447 showmount -e
1458 function setup_nfs_server
1460 # Cannot share directory in non-global zone.
1469 # Re-synchronize /var/lib/nfs/etab with /etc/exports and
1472 log_must exportfs -r
1477 log_must kill -s HUP $(</var/run/mountd.pid)
1484 if [[ $(svcs -Ho STA $nfs_fmri) != "ON" ]]; then
1491 if [[ -d $dummy ]]; then
1492 log_must rm -rf $dummy
1507 while [[ timeout -ne 0 && $(svcs -Ho STA $nfs_fmri) == *'*' ]]
1511 ((timeout -= 1))
1515 log_must rm -rf $dummy
1518 log_note "Current NFS status: '$(svcs -Ho STA,FMRI $nfs_fmri)'"
1524 # Return 0 if in global zone, 1 in non-global zone
1526 function is_global_zone
1544 function verify_runnable # zone limit
1548 [[ -z $limit ]] && return 0
1557 *) log_note "Warning: unknown limit $limit - " \
1568 *) log_note "Warning: unknown limit $limit - " \
1580 # Note: In local zones, this function should return 0 silently.
1582 # $1 - pool name
1583 # $2-n - [keyword] devs_list
1585 function create_pool #pool devs_list
1591 if [[ -z $pool ]]; then
1601 [[ -d /$pool ]] && rm -rf /$pool
1602 log_must zpool create -f $pool $@
1609 # Note: In local zones, this function should return 0 silently.
1611 # $1 - pool name
1614 function destroy_pool #pool
1619 if [[ -z $pool ]]; then
1632 log_must_busy zpool destroy -f $pool
1634 [[ -d $mtpt ]] && \
1635 log_must rm -rf $mtpt
1647 # $1 - dataset name
1648 # $2-n - dataset options
1650 function create_dataset #dataset dataset_options
1656 if [[ -z $dataset ]]; then
1671 # Note: In local zones, this function should return 0 silently.
1673 # $1 - dataset name
1674 # $2 - custom arguments for zfs destroy
1677 function destroy_dataset # dataset [args]
1681 typeset args=${2:-""}
1683 if [[ -z $dataset ]]; then
1693 [ -d $mtpt ] && log_must rm -rf $mtpt
1704 # Reexport TESTPOOL & TESTPOOL(1-4)
1706 function reexport_pool
1708 typeset -i cntctr=5
1709 typeset -i i=0
1732 function check_state # pool disk state{online,offline,degraded}
1738 [[ -z $pool ]] || [[ -z $state ]] \
1741 if [[ -z $disk ]]; then
1743 zpool get -H -o value health $pool | grep -qi "$state"
1745 zpool status -v $pool | grep "$disk" | grep -qi "$state"
1754 function snapshot_mountpoint
1756 typeset dataset=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
1765 if [[ -z $fs || -z $snap ]]; then
1775 function verify_ashift # device ashift
1780 zdb -e -lll $device | awk -v ashift=$ashift '
1793 # Given a pool and file system, this function will verify the file system
1797 function verify_filesys # pool filesystem dir
1809 zfs unmount -a > /dev/null 2>&1
1812 if [[ -n $dirs ]] ; then
1814 search_path="$search_path -d $dir"
1820 if ! zdb -cudi $filesys > $zdbout 2>&1; then
1821 log_note "Output: zdb -cudi $filesys"
1823 rm -f $zdbout
1827 log_must zfs mount -a
1828 log_must rm -rf $zdbout
1834 function verify_pool
1836 typeset pool=${1:-$TESTPOOL}
1841 typeset -i cksum=$(zpool status $pool | awk '
1848 log_must zpool status -v
1854 # Given a pool, and this function list all disks in the pool
1856 function get_disklist # pool
1858 echo $(zpool iostat -v $1 | awk '(NR > 4) {print $1}' | \
1859 grep -vEe '^-----' -e "^(mirror|raidz[1-3]|draid[1-3]|spare|log|cache|special|dedup)|\-[0-9]$")
1863 # Given a pool, and this function list all disks in the pool with their full
1866 function get_disklist_fullpath # pool
1868 get_disklist "-P $1"
1874 # This function kills a given list of processes after a time period. We use
1883 function stress_timeout
1885 typeset -i TIMEOUT=$1
1896 ps -p $pid > /dev/null 2>&1 &&
1897 log_must kill -USR1 $pid
1906 function check_hotspare_state # pool disk state{inuse,avail}
1922 function wait_hotspare_state # pool disk state timeout
1927 typeset timeout=${4:-60}
1928 typeset -i i=0
1930 while [[ $i -lt $timeout ]]; do
1947 function check_vdev_state # pool disk state{online,offline,unavail,removed}
1963 function wait_vdev_state # pool disk state timeout
1968 typeset timeout=${4:-60}
1969 typeset -i i=0
1971 while [[ $i -lt $timeout ]]; do
1990 function wait_sit_out #pool vdev timeout
1992 typeset pool=${1:-$TESTPOOL}
1994 typeset timeout=${3:-300}
2006 # Check the output of 'zpool status -v <pool>',
2011 function check_pool_status # pool token keyword <verbose>
2016 typeset verbose=${4:-false}
2018 scan=$(zpool status -v "$pool" 2>/dev/null | awk -v token="$token:" '$1==token')
2022 echo $scan | grep -qi "$keyword"
2027 # is_pool_resilvering - to check if the pool resilver is in progress
2028 # is_pool_resilvered - to check if the pool resilver is completed
2029 # is_pool_scrubbing - to check if the pool scrub is in progress
2030 # is_pool_scrubbed - to check if the pool scrub is completed
2031 # is_pool_scrub_stopped - to check if the pool scrub is stopped
2032 # is_pool_scrub_paused - to check if the pool scrub has paused
2033 # is_pool_removing - to check if the pool removing is a vdev
2034 # is_pool_removed - to check if the pool remove is completed
2035 # is_pool_discarding - to check if the pool checkpoint is being discarded
2036 # is_pool_replacing - to check if the pool is performing a replacement
2038 function is_pool_resilvering #pool <verbose>
2041 "resilver[ ()0-9A-Za-z:_-]* in progress since" $2
2044 function is_pool_resilvered #pool <verbose>
2049 function is_pool_scrubbing #pool <verbose>
2054 function is_pool_error_scrubbing #pool <verbose>
2060 function is_pool_scrubbed #pool <verbose>
2065 function is_pool_scrub_stopped #pool <verbose>
2070 function is_pool_error_scrub_stopped #pool <verbose>
2076 function is_pool_scrub_paused #pool <verbose>
2081 function is_pool_error_scrub_paused #pool <verbose>
2087 function is_pool_removing #pool
2092 function is_pool_removed #pool
2097 function is_pool_discarding #pool
2101 function is_pool_replacing #pool
2103 zpool status "$1" | grep -qE 'replacing-[0-9]+'
2106 function wait_for_degraded
2109 typeset timeout=${2:-30}
2116 if ((SECONDS - t0 > $timeout)); then
2129 function cleanup_devices #vdevs
2145 # A function to find and locate free disks on a system or from given
2154 function find_disks
2165 max_finddisksnum=${MAX_FINDDISKSNUM:-6}
2167 swap -l > $sfi
2170 disks=${@:-$(echo "" | format -e 2>/dev/null | awk '
2192 grep -q "${disk}[sp]" /etc/mnttab && continue
2194 grep -q "${disk}[sp]" $sfi && continue
2196 grep -q "${disk}[sp]" $dmpi && continue
2198 # by a user-set environment variable
2199 echo "${ZFS_HOST_DEVICES_IGNORE}" | grep -q "${disk}" && continue
2210 [ $count -lt $max_finddisksnum ]; then
2213 [[ -z $@ ]] && ((count = count + 1))
2221 function add_user_freebsd #<group_name> <user_name> <basedir>
2223 typeset group=$1
2233 typeset -i uid=1000
2235 pw useradd -u $uid -g $group -d $basedir/$user -m -n $user
2258 function del_user_freebsd #<logname>
2270 # Select valid gid and create specified group.
2272 # $1 group name
2274 function add_group_freebsd #<group_name>
2276 typeset group=$1
2278 # See if the group already exists.
2279 if pw groupshow $group >/dev/null 2>&1; then
2284 typeset -i gid=1000
2286 pw groupadd -g $gid -n $group > /dev/null 2>&1
2294 log_fail "No user id available under 65000 for $group"
2300 # Delete the specified group.
2302 # $1 group name
2304 function del_group_freebsd #<group_name>
2306 typeset group=$1
2308 pw groupdel -n $group > /dev/null 2>&1
2310 # Group does not exist, or was deleted successfully.
2312 # Name already exists as a group name
2313 9) log_must pw groupdel $group ;;
2320 function add_user_illumos #<group_name> <user_name> <basedir>
2322 typeset group=$1
2326 log_must useradd -g $group -d $basedir/$user -m $user
2331 function del_user_illumos #<user_name>
2342 function add_group_illumos #<group_name>
2344 typeset group=$1
2346 typeset -i gid=100
2348 groupadd -g $gid $group > /dev/null 2>&1
2358 function del_group_illumos #<group_name>
2360 typeset group=$1
2362 groupmod -n $grp $grp > /dev/null 2>&1
2364 # Group does not exist.
2366 # Name already exists as a group name
2372 function add_user_linux #<group_name> <user_name> <basedir>
2374 typeset group=$1
2378 log_must useradd -g $group -d $basedir/$user -m $user
2380 # Add new users to the same group and the command line utils.
2382 # directory as long as it permissioned to be group readable.
2383 cmd_group=$(stat --format="%G" $(command -v zfs))
2384 log_must usermod -a -G $cmd_group $user
2389 function del_user_linux #<user_name>
2398 function add_group_linux #<group_name>
2400 typeset group=$1
2405 groupadd $group > /dev/null 2>&1
2413 function del_group_linux #<group_name>
2415 typeset group=$1
2417 getent group $group > /dev/null 2>&1
2419 # Group does not exist.
2421 # Name already exists as a group name
2422 0) log_must groupdel $group ;;
2430 # Add specified user to specified group
2432 # $1 group name
2436 function add_user #<group_name> <user_name> <basedir>
2438 typeset group=$1
2440 typeset basedir=${3:-"$TEST_BASE_DIR"}
2442 if ((${#group} == 0 || ${#user} == 0)); then
2443 log_fail "group name or user name are not defined."
2448 add_user_freebsd "$group" "$user" "$basedir"
2451 add_user_linux "$group" "$user" "$basedir"
2454 add_user_illumos "$group" "$user" "$basedir"
2467 function del_user #<logname> <basedir>
2470 typeset basedir=${2:-"$TEST_BASE_DIR"}
2488 [[ -d $basedir/$user ]] && rm -fr $basedir/$user
2494 # Select valid gid and create specified group.
2496 # $1 group name
2498 function add_group #<group_name>
2500 typeset group=$1
2502 if ((${#group} == 0)); then
2503 log_fail "group name is necessary."
2508 add_group_freebsd "$group"
2511 add_group_linux "$group"
2514 add_group_illumos "$group"
2522 # Delete the specified group.
2524 # $1 group name
2526 function del_group #<group_name>
2528 typeset group=$1
2530 if ((${#group} == 0)); then
2531 log_fail "group name is necessary."
2536 del_group_freebsd "$group"
2539 del_group_linux "$group"
2542 del_group_illumos "$group"
2550 # This function will return true if it's safe to destroy the pool passed
2554 function safe_to_destroy_pool { # $1 the pool name
2564 for pool in $(zpool list -H -o name)
2568 # this is a list of the top-level directories in each of the
2570 FILEPOOL=$(zpool status -v $pool | awk -v pool="/$1/" '$0 ~ pool {print $1}')
2573 ZVOLPOOL=$(zpool status -v $pool | awk -v zvols="$ZVOL_DEVDIR/$1$" '$0 ~ zvols {print $1}')
2575 # also want to determine if it's a file-based pool using an
2577 POOL_FILE_DIRS=$(zpool status -v $pool | \
2579 awk -F/ '!/dev/ {print $2}')
2583 OUTPUT=$(zfs list -H -r -o mountpoint $1 | \
2584 awk -v pd="${pooldir}$" '$0 ~ pd {print $1}')
2590 if [ ! -z "$ZVOLPOOL" ]
2596 if [ ! -z "$FILEPOOL" ]
2602 if [ ! -z "$ALTMOUNTPOOL" ]
2609 if [ -z "${DONT_DESTROY}" ]
2619 # Verify zfs operation with -p option work as expected
2625 function verify_opt_p_ops
2642 ops="create -V $VOLSIZE"
2646 if [[ -z $newdataset ]]; then
2654 if [[ -z $newdataset ]]; then
2666 destroy_dataset "${newdataset%/*}" "-rRf"
2668 # without -p option, operation will fail
2672 # with -p option, operation should succeed
2673 log_must zfs $ops -p $dataset $newdataset
2677 log_fail "-p option does not work for $ops"
2682 log_must zfs $ops -p $dataset $newdataset
2693 function get_config
2702 zdb -e $pool
2704 zdb -C $pool
2705 fi | awk -F: -v cfg="$config:" '$0 ~ cfg {sub(/^'\''/, $2); sub(/'\''$/, $2); print $2}'
2709 # Privated function. Random select one of items from arguments.
2712 # $2-n string
2714 function _random_get
2720 typeset -i ind
2723 echo "$str" | cut -f $ind -d ' '
2729 function random_get_with_non
2731 typeset -i cnt=$#
2740 function random_get
2746 # The function will generate a dataset name with specific length
2750 function gen_dataset_name
2752 typeset -i len=$1
2754 typeset -i baselen=${#basestr}
2755 typeset -i iter=0
2766 ((iter -= 1))
2781 function datasetcksum
2786 zdb -vvv $1 | awk -F= -v ds="^Dataset $1 "'\\[' '$0 ~ ds && /cksum/ {print $7}'
2792 function get_device_state #pool disk field("", "spares","logs")
2796 typeset field=${3:-$pool}
2798 zpool status -v "$pool" 2>/dev/null | \
2799 awk -v device=$disk -v pool=$pool -v field=$field \
2812 function get_rootfs
2817 rootfs=$(mount -p | awk '$2 == "/" && $3 == "zfs" {print $1}')
2822 if [[ -z "$rootfs" ]]; then
2837 function get_rootpool
2846 function verify_disk_count
2848 typeset -i min=${2:-1}
2850 typeset -i count=$(echo "$1" | wc -w)
2858 function ds_is_volume
2864 function ds_is_filesystem
2873 function is_te_enabled
2875 svcs -H -o state labeld 2>/dev/null | grep -q "enabled"
2878 # Return the number of CPUs (cross-platform)
2879 function get_num_cpus
2882 grep -c '^processor' /proc/cpuinfo
2884 sysctl -n kern.smp.cpus
2886 psrinfo | wc -l
2890 # Utility function to determine if a system has multiple cpus.
2891 function is_mp
2893 [[ $(get_num_cpus) -gt 1 ]]
2896 function get_cpu_freq
2901 sysctl -n hw.clockrate
2903 psrinfo -v 0 | awk '/processor operates at/ {print $6}'
2908 function user_run
2916 if ! sudo -Eu $user test -x $PATH ; then
2917 log_note "-------------------------------------------------"
2928 log_note "to a world-accessible location (like /tmp), and "
2935 log_note "-------------------------------------------------"
2941 sudo -Eu $user \
2959 function vdevs_in_pool
2964 if [[ -z $pool ]]; then
2972 # can't reference a mirror/raidz vdev using its ID (i.e mirror-0),
2975 zpool status -v "$pool" | grep -A 1000 "config:" >$tmpfile
2977 grep -wq ${vdev##*/} $tmpfile || return 1
2980 rm -f $tmpfile
2984 function get_max
2986 typeset -l i max=$1
2997 function write_compressible
3001 typeset nfiles=${3:-1}
3002 typeset bs=${4:-1024k}
3003 typeset fname=${5:-file}
3005 [[ -d $dir ]] || log_fail "No directory: $dir"
3009 # command line options and cases where the --buffer_compress_*
3017 truncate -s $file_bytes $dir/$fname.$i
3027 command -v fio > /dev/null || log_unsupported "fio missing"
3029 --name=job \
3030 --fallocate=0 \
3031 --minimal \
3032 --randrepeat=0 \
3033 --buffer_compress_percentage=66 \
3034 --buffer_compress_chunk=4096 \
3035 --directory="$dir" \
3036 --numjobs="$nfiles" \
3037 --nrfiles="$nfiles" \
3038 --rw=write \
3039 --bs="$bs" \
3040 --filesize="$megs" \
3041 "--filename_format='$fname.\$jobnum' >/dev/null"
3045 function get_objnum
3050 [[ -e $pathname ]] || log_fail "No such file or directory: $pathname"
3052 objnum=$(stat -f "%i" $pathname)
3054 objnum=$(stat -c %i $pathname)
3065 function sync_pool #pool <force>
3067 typeset pool=${1:-$TESTPOOL}
3068 typeset force=${2:-false}
3071 log_must zpool sync -f $pool
3084 function sync_all_pools #<force>
3086 typeset force=${1:-false}
3089 log_must zpool sync -f
3102 function wait_freeing #pool
3104 typeset pool=${1:-$TESTPOOL}
3106 [[ "0" == "$(zpool list -Ho freeing $pool)" ]] && break
3117 function wait_replacing #pool timeout
3119 typeset timeout=${2:-300}
3120 typeset pool=${1:-$TESTPOOL}
3132 function wait_scrubbed #pool timeout
3134 typeset timeout=${2:-300}
3135 typeset pool=${1:-$TESTPOOL}
3145 function zed_rc_backup
3152 function zed_rc_restore
3161 function zed_setup
3167 if [[ ! -d $ZEDLET_DIR ]]; then
3171 if [[ ! -e $VDEVID_CONF ]]; then
3175 if [[ -e $VDEVID_CONF_ETC ]]; then
3181 log_must ln -s $VDEVID_CONF $VDEVID_CONF_ETC
3186 log_must cp ${ZEDLET_ETC_DIR}/zed-functions.sh $ZEDLET_DIR
3189 if [[ -n "$EXTRA_ZEDLETS" ]] ; then
3199 log_must sed -i '/\#ZED_DEBUG_LOG=.*/d' $ZEDLET_DIR/zed.rc
3208 function zed_cleanup
3215 log_must rm -f ${ZEDLET_DIR}/$extra_zedlet
3217 …log_must rm -fd ${ZEDLET_DIR}/zed.rc ${ZEDLET_DIR}/zed-functions.sh ${ZEDLET_DIR}/all-syslog.sh ${…
3225 function zed_check
3230 zedpids="$(pgrep -x zed)"
3231 zedpids2="$(pgrep -x lt-zed)"
3238 function zed_start
3245 if [[ ! -d $ZEDLET_DIR ]]; then
3251 if [ -n "$zedpids" ]; then
3253 # is already running - usually this implies our test cases
3257 log_fail "ZED already running - ${zedpids}"
3262 log_must truncate -s 0 $ZED_DEBUG_LOG
3263 log_must eval "zed -vF -d $ZEDLET_DIR -P $PATH" \
3264 "-s $ZEDLET_DIR/state -j 1 2>$ZED_LOG &"
3273 function zed_stop
3282 [ ! -n "$zedpids" ] && break
3293 function zed_events_drain
3295 while [ $(zpool events -H | wc -l) -ne 0 ]; do
3297 zpool events -c >/dev/null
3301 # Set a variable in zed.rc to something, un-commenting it in the process.
3305 function zed_rc_set
3311 eval sed -i $cmd $ZEDLET_DIR/zed.rc
3321 function is_swap_inuse
3325 if [[ -z $device ]] ; then
3332 swapon -s | grep -wq $(readlink -f $device)
3335 swapctl -l | grep -wq $device
3338 swap -l | grep -wq $device
3346 function swap_setup
3356 log_must swapctl -a $swapdev
3359 log_must swap -a $swapdev
3369 function swap_cleanup
3379 log_must swap -d $swapdev
3387 # Set a global system tunable (64-bit value)
3392 function set_tunable64
3398 # Set a global system tunable (32-bit value)
3403 function set_tunable32
3408 function set_tunable_impl
3426 [[ -z "$value" ]] && return 1
3427 [[ -z "$mdb_cmd" ]] && return 1
3438 echo "${tunable}/${mdb_cmd}0t${value}" | mdb -kw
3443 function save_tunable
3446 [[ ! -d $TEST_BASE_DIR ]] && return 1
3447 [[ -e $TEST_BASE_DIR/tunable-$1 ]] && return 2
3448 echo "$(get_tunable """$1""")" > "$TEST_BASE_DIR"/tunable-"$1"
3452 function restore_tunable
3455 [[ ! -e $TEST_BASE_DIR/tunable-$1 ]] && return 1
3456 val="$(cat $TEST_BASE_DIR/tunable-"""$1""")"
3458 rm $TEST_BASE_DIR/tunable-$1
3467 function get_tunable
3472 function get_tunable_impl
3475 typeset module="${2:-zfs}"
3481 if [ -z "$check_only" ] ; then
3488 if [ -z "$check_only" ] ; then
3504 sysctl -n vfs.zfs.$tunable
3507 [[ "$module" -eq "zfs" ]] || return 1
3515 function tunable_exists
3524 function xxh128digest
3532 function cmp_xxh128 {
3541 function new_fs #<args>
3548 echo y | newfs -v "$@"
3553 function stat_size #<path>
3559 stat -f %z "$path"
3562 stat -c %s "$path"
3567 function stat_mtime #<path>
3573 stat -f %m "$path"
3576 stat -c %Y "$path"
3581 function stat_ctime #<path>
3587 stat -f %c "$path"
3590 stat -c %Z "$path"
3595 function stat_crtime #<path>
3601 stat -f %B "$path"
3604 stat -c %W "$path"
3609 function stat_generation #<path>
3618 stat -f %v "${path}"
3629 function faketty
3632 script -q /dev/null env "$@"
3634 script --return --quiet -c "$*" /dev/null
3641 function range_shuffle # begin end
3643 typeset -i begin=$1
3644 typeset -i end=$2
3646 seq ${begin} ${end} | sort -R
3650 # Cross-platform xattr helpers
3653 function get_xattr # name path
3660 getextattr -qq user "${name}" "${path}"
3663 attr -qg "${name}" "${path}"
3668 function set_xattr # name value path
3679 attr -qs "${name}" -V "${value}" "${path}"
3684 function set_xattr_stdin # name value
3691 setextattr -i user "${name}" "${path}"
3694 attr -qs "${name}" "${path}"
3699 function rm_xattr # name path
3706 rmextattr -q user "${name}" "${path}"
3709 attr -qr "${name}" "${path}"
3714 function ls_xattr # path
3720 lsextattr -qq user "${path}"
3723 attr -ql "${path}"
3728 function punch_hole # offset length file
3736 truncate -d -o $offset -l $length "$file"
3739 fallocate --punch-hole --offset $offset --length $length "$file"
3747 function zero_range # offset length file
3755 fallocate --zero-range --offset $offset --length $length "$file"
3764 # Wait for the specified arcstat to reach non-zero quiescence.
3768 function arcstat_quiescence # stat echo
3774 if [[ $echo -eq 0 ]]; then
3778 while $do_once || [ $stat1 -ne $stat2 ] || [ $stat2 -eq 0 ]; do
3785 if [[ $echo -eq 1 ]]; then
3790 function arcstat_quiescence_noecho # stat
3796 function arcstat_quiescence_echo # stat
3806 function wait_for_children #children
3814 if [ $child_exit -ne 0 ]; then
3825 # output and a non-zero error is returned.
3832 function directory_diff # dir_a dir_b
3836 zil_replay="${LIBTEST_DIFF_ZIL_REPLAY:-0}"
3840 if ! [ -d "$dir_a" -a -d "$dir_b" ]; then
3844 # Run rsync with --dry-run --itemize-changes to get something akin to diff
3848 # Also make sure to filter out non-user.* xattrs when comparing. On
3849 # SELinux-enabled systems the copied tree will probably have different
3851 args=("-nicaAHX" '--filter=-x! user.*' "--delete")
3853 # NOTE: Quite a few rsync builds do not support --crtimes which would be
3862 if rsync --version | grep -q "[, ] crtimes"; then
3863 args+=("--crtimes")
3865 log_note "This rsync package does not support --crtimes (-N)."
3869 # Unfortunately --no-times doesn't do what we want -- it will still tell
3873 if [ "$zil_replay" -eq 0 ]; then
3879 filter=("grep" "-v" '^\..[.Tt]\+ ')
3884 if [ -n "$diff" ]; then
3899 function replay_directory_diff # dir_a dir_b
3909 function push_coredump_pattern # dir
3911 ulimit -c unlimited
3919 sysctl -n kern.corefile
3924 coreadm -p "$1/core.%f"
3932 function pop_coredump_pattern
3934 [ -s "$1" ] || return 0
3938 { read -r pat; read -r pid; } < "$1"