From 7839c4b5e1e79e29f0df4ec9fe5e1e7182473e47 Mon Sep 17 00:00:00 2001 From: Matthew Macy Date: Wed, 18 Dec 2019 12:29:43 -0800 Subject: Update ZTS to work on FreeBSD Update the common ZTS scripts and individual test cases as needed in order to allow them to be run on FreeBSD. The high level goal is to provide compatibility wrappers whenever possible to minimize changes to individual test cases. Reviewed-by: Brian Behlendorf Reviewed-by: John Kennedy Signed-off-by: Matt Macy Signed-off-by: Ryan Moeller Closes #9692 --- tests/zfs-tests/cmd/Makefile.am | 14 +- tests/zfs-tests/cmd/mkfile/Makefile.am | 3 + tests/zfs-tests/cmd/mkfile/mkfile.c | 13 +- tests/zfs-tests/cmd/mkfiles/mkfiles.c | 4 + tests/zfs-tests/cmd/mktree/mktree.c | 4 + tests/zfs-tests/include/blkdev.shlib | 23 +- tests/zfs-tests/include/commands.cfg | 84 ++-- tests/zfs-tests/include/default.cfg.in | 16 +- tests/zfs-tests/include/libtest.shlib | 542 +++++++++++++++++---- tests/zfs-tests/include/properties.shlib | 9 +- .../functional/alloc_class/alloc_class_013_pos.ksh | 2 +- .../tests/functional/atime/atime_common.kshlib | 5 + .../tests/functional/bootfs/bootfs_006_pos.ksh | 2 +- .../channel_program/channel_common.kshlib | 22 +- .../channel_program/lua_core/tst.timeout.ksh | 2 +- .../synctask_core/tst.get_index_props.ksh | 3 +- .../synctask_core/tst.get_index_props.zcp | 13 +- .../tests/functional/chattr/chattr_001_pos.ksh | 33 +- .../tests/functional/checksum/filetest_001_pos.ksh | 10 + .../tests/functional/cli_root/zdb/zdb_003_pos.ksh | 9 + .../tests/functional/cli_root/zdb/zdb_004_pos.ksh | 25 +- .../tests/functional/cli_root/zdb/zdb_005_pos.ksh | 9 + .../tests/functional/cli_root/zfs/zfs_002_pos.ksh | 13 +- .../cli_root/zfs_copies/zfs_copies.kshlib | 20 +- .../cli_root/zfs_copies/zfs_copies_002_pos.ksh | 21 +- .../zfs_clone_livelist_condense_and_disable.ksh | 16 +- .../zfs_clone_livelist_condense_races.ksh | 29 +- .../cli_root/zfs_destroy/zfs_destroy.cfg | 17 + .../zfs_destroy/zfs_destroy_clone_livelist.ksh | 6 +- .../cli_root/zfs_destroy/zfs_destroy_common.kshlib | 7 +- .../zfs_destroy_dev_removal_condense.ksh | 15 +- .../tests/functional/cli_root/zfs_diff/socket.c | 1 + .../cli_root/zfs_diff/zfs_diff_timestamp.ksh | 6 +- .../cli_root/zfs_diff/zfs_diff_types.ksh | 15 +- .../cli_root/zfs_get/zfs_get_001_pos.ksh | 17 +- .../cli_root/zfs_get/zfs_get_002_pos.ksh | 16 +- .../cli_root/zfs_get/zfs_get_005_neg.ksh | 14 +- .../cli_root/zfs_get/zfs_get_008_pos.ksh | 11 +- .../cli_root/zfs_get/zfs_get_009_pos.ksh | 7 +- .../cli_root/zfs_mount/zfs_mount_005_pos.ksh | 8 +- .../cli_root/zfs_mount/zfs_mount_007_pos.ksh | 7 +- .../cli_root/zfs_mount/zfs_mount_010_neg.ksh | 2 +- .../cli_root/zfs_mount/zfs_mount_012_neg.ksh | 24 +- .../cli_root/zfs_mount/zfs_mount_all_fail.ksh | 20 +- .../cli_root/zfs_mount/zfs_mount_remount.ksh | 43 +- .../cli_root/zfs_mount/zfs_multi_mount.ksh | 7 +- .../zfs_receive/zfs_receive_raw_incremental.ksh | 2 +- .../zfs_rollback/zfs_rollback_common.kshlib | 3 +- .../cli_root/zfs_send/zfs_send_007_pos.ksh | 2 +- .../cli_root/zfs_send/zfs_send_sparse.ksh | 4 +- .../cli_root/zfs_set/checksum_001_pos.ksh | 5 +- .../cli_root/zfs_set/mountpoint_003_pos.ksh | 12 +- .../functional/cli_root/zfs_set/onoffs_001_pos.ksh | 7 +- .../cli_root/zfs_set/readonly_001_pos.ksh | 2 +- .../cli_root/zfs_set/zfs_set_keylocation.ksh | 9 +- .../functional/cli_root/zfs_sysfs/cleanup.ksh | 4 + .../tests/functional/cli_root/zfs_sysfs/setup.ksh | 4 + .../cli_root/zfs_unmount/zfs_unmount_008_neg.ksh | 2 +- .../functional/cli_root/zpool/zpool_002_pos.ksh | 4 + .../functional/cli_root/zpool/zpool_003_pos.ksh | 4 + .../cli_root/zpool_add/add_prop_ashift.ksh | 2 +- .../functional/cli_root/zpool_add/zpool_add.cfg | 2 +- .../functional/cli_root/zpool_add/zpool_add.kshlib | 13 +- .../cli_root/zpool_add/zpool_add_005_pos.ksh | 14 +- .../cli_root/zpool_create/zpool_create.shlib | 10 +- .../cli_root/zpool_create/zpool_create_002_pos.ksh | 4 +- .../cli_root/zpool_create/zpool_create_011_neg.ksh | 12 +- .../cli_root/zpool_create/zpool_create_014_neg.ksh | 2 +- .../functional/cli_root/zpool_get/zpool_get.cfg | 3 +- .../functional/cli_root/zpool_import/setup.ksh | 2 +- .../cli_root/zpool_import/zpool_import.cfg | 13 + .../cli_root/zpool_labelclear/labelclear.cfg | 13 +- .../functional/cli_root/zpool_remove/setup.ksh | 2 +- .../functional/cli_root/zpool_reopen/cleanup.ksh | 4 + .../cli_root/zpool_split/zpool_split_vdevs.ksh | 4 +- .../tests/functional/cli_user/misc/misc.cfg | 26 + .../functional/cli_user/misc/zfs_share_001_neg.ksh | 2 +- .../cli_user/misc/zfs_unshare_001_neg.ksh | 2 +- tests/zfs-tests/tests/functional/ctime/ctime.c | 6 + .../tests/functional/delegate/cleanup.ksh | 4 + .../functional/delegate/delegate_common.kshlib | 16 +- .../zfs-tests/tests/functional/delegate/setup.ksh | 5 + .../functional/delegate/zfs_allow_001_pos.ksh | 4 +- .../functional/delegate/zfs_allow_010_pos.ksh | 41 ++ .../functional/delegate/zfs_allow_012_neg.ksh | 6 + .../tests/functional/devices/devices_common.kshlib | 251 +++++++--- .../tests/functional/fault/auto_spare_002_pos.ksh | 7 +- .../tests/functional/fault/auto_spare_multiple.ksh | 7 +- .../tests/functional/fault/decompress_fault.ksh | 17 +- .../tests/functional/fault/decrypt_fault.ksh | 5 +- .../tests/functional/history/history_002_pos.ksh | 25 + .../tests/functional/history/history_007_pos.ksh | 2 +- .../tests/functional/inuse/inuse_001_pos.ksh | 4 +- .../tests/functional/inuse/inuse_003_pos.ksh | 6 +- .../tests/functional/inuse/inuse_004_pos.ksh | 3 + .../tests/functional/inuse/inuse_005_pos.ksh | 6 +- .../tests/functional/inuse/inuse_006_pos.ksh | 4 +- .../tests/functional/inuse/inuse_007_pos.ksh | 4 +- .../tests/functional/inuse/inuse_008_pos.ksh | 4 +- .../zfs-tests/tests/functional/migration/setup.ksh | 4 +- .../tests/functional/mount/umountall_001.ksh | 5 + .../functional/mv_files/mv_files_common.kshlib | 3 +- .../tests/functional/no_space/enospc_003_pos.ksh | 2 +- .../tests/functional/nopwrite/nopwrite_mtime.ksh | 8 + .../tests/functional/nopwrite/nopwrite_volume.ksh | 1 + .../tests/functional/privilege/cleanup.ksh | 2 +- .../functional/privilege/privilege_001_pos.ksh | 2 +- .../functional/privilege/privilege_002_pos.ksh | 2 +- .../zfs-tests/tests/functional/privilege/setup.ksh | 2 +- .../procfs/procfs_list_concurrent_readers.ksh | 2 +- tests/zfs-tests/tests/functional/procfs/setup.ksh | 4 - .../zfs-tests/tests/functional/quota/quota.kshlib | 2 + .../functional/redacted_send/redacted_holes.ksh | 4 +- .../tests/functional/removal/removal.kshlib | 2 +- .../functional/removal/removal_remap_deadlists.ksh | 2 +- .../tests/functional/rootpool/rootpool_007_pos.ksh | 9 +- .../zfs-tests/tests/functional/rootpool/setup.ksh | 2 +- .../zfs-tests/tests/functional/rsend/rsend.kshlib | 21 +- .../tests/functional/rsend/rsend_012_pos.ksh | 4 +- tests/zfs-tests/tests/functional/rsend/send-cD.ksh | 6 +- .../functional/rsend/send-c_embedded_blocks.ksh | 2 +- .../rsend/send-c_stream_size_estimate.ksh | 7 +- .../functional/rsend/send-cpL_varied_recsize.ksh | 8 +- .../functional/rsend/send-wDR_encrypted_zvol.ksh | 7 +- .../rsend/send_encrypted_truncated_files.ksh | 12 +- .../tests/functional/slog/slog_013_pos.ksh | 4 + .../tests/functional/slog/slog_014_pos.ksh | 2 +- .../tests/functional/slog/slog_015_neg.ksh | 11 +- .../tests/functional/slog/slog_replay_fs_001.ksh | 39 +- .../tests/functional/slog/slog_replay_volume.ksh | 36 +- .../tests/functional/snapshot/clone_001_pos.ksh | 10 + tests/zfs-tests/tests/functional/trim/setup.ksh | 19 +- .../functional/truncate/truncate_timestamps.ksh | 24 +- .../tests/functional/xattr/xattr_004_pos.ksh | 2 +- .../tests/functional/zvol/zvol_ENOSPC/setup.ksh | 3 +- .../tests/functional/zvol/zvol_common.shlib | 18 +- .../zvol/zvol_misc/zvol_misc_002_pos.ksh | 5 +- .../zvol/zvol_misc/zvol_misc_003_neg.ksh | 5 +- .../zvol/zvol_misc/zvol_misc_common.kshlib | 3 + .../zvol/zvol_misc/zvol_misc_rename_inuse.ksh | 2 +- .../tests/functional/zvol/zvol_swap/cleanup.ksh | 2 + .../zvol/zvol_swap/zvol_swap_003_pos.ksh | 2 +- .../zvol/zvol_swap/zvol_swap_005_pos.ksh | 4 +- .../zvol/zvol_swap/zvol_swap_006_pos.ksh | 4 +- 144 files changed, 1602 insertions(+), 528 deletions(-) (limited to 'tests') diff --git a/tests/zfs-tests/cmd/Makefile.am b/tests/zfs-tests/cmd/Makefile.am index 09c59f591..934587b1a 100644 --- a/tests/zfs-tests/cmd/Makefile.am +++ b/tests/zfs-tests/cmd/Makefile.am @@ -2,7 +2,6 @@ EXTRA_DIST = file_common.h SUBDIRS = \ chg_usr_exec \ - user_ns_exec \ devname2devid \ dir_rd_update \ file_check \ @@ -19,11 +18,16 @@ SUBDIRS = \ mmap_libaio \ mmapwrite \ nvlist_to_lua \ - randfree_file \ randwritecomp \ readmmap \ rename_dir \ rm_lnkcnt_zero_file \ - threadsappend \ - xattrtest \ - stride_dd + stride_dd \ + threadsappend + +if BUILD_LINUX +SUBDIRS += \ + randfree_file \ + user_ns_exec \ + xattrtest +endif diff --git a/tests/zfs-tests/cmd/mkfile/Makefile.am b/tests/zfs-tests/cmd/mkfile/Makefile.am index 016c67128..82672d1c3 100644 --- a/tests/zfs-tests/cmd/mkfile/Makefile.am +++ b/tests/zfs-tests/cmd/mkfile/Makefile.am @@ -4,3 +4,6 @@ pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/bin pkgexec_PROGRAMS = mkfile mkfile_SOURCES = mkfile.c +if BUILD_FREEBSD +mkfile_LDADD = -L/usr/local/lib -lintl +endif diff --git a/tests/zfs-tests/cmd/mkfile/mkfile.c b/tests/zfs-tests/cmd/mkfile/mkfile.c index 888af6db6..211d83c9e 100644 --- a/tests/zfs-tests/cmd/mkfile/mkfile.c +++ b/tests/zfs-tests/cmd/mkfile/mkfile.c @@ -137,8 +137,17 @@ main(int argc, char **argv) argv++; argc--; continue; - } - if (lseek(fd, (off_t)size-1, SEEK_SET) < 0) { + } else if (fchown(fd, getuid(), getgid()) < 0) { + saverr = errno; + (void) fprintf(stderr, gettext( + "Could not set owner/group of %s: %s\n"), + argv[1], strerror(saverr)); + (void) close(fd); + errors++; + argv++; + argc--; + continue; + } else if (lseek(fd, (off_t)size-1, SEEK_SET) < 0) { saverr = errno; (void) fprintf(stderr, gettext( "Could not seek to offset %ld in %s: %s\n"), diff --git a/tests/zfs-tests/cmd/mkfiles/mkfiles.c b/tests/zfs-tests/cmd/mkfiles/mkfiles.c index 62dee1627..32abfd0c3 100644 --- a/tests/zfs-tests/cmd/mkfiles/mkfiles.c +++ b/tests/zfs-tests/cmd/mkfiles/mkfiles.c @@ -55,6 +55,10 @@ main(int argc, char **argv) (void) fprintf(stderr, "Failed to create %s %s\n", buf, strerror(errno)); return (-4); + } else if (fchown(fd, getuid(), getgid()) < 0) { + (void) fprintf(stderr, "Failed to chown %s %s\n", buf, + strerror(errno)); + return (-5); } (void) close(fd); } diff --git a/tests/zfs-tests/cmd/mktree/mktree.c b/tests/zfs-tests/cmd/mktree/mktree.c index 02d4974d7..25b26c9e1 100644 --- a/tests/zfs-tests/cmd/mktree/mktree.c +++ b/tests/zfs-tests/cmd/mktree/mktree.c @@ -30,7 +30,9 @@ #include #include #include +#ifdef __linux__ #include +#endif #include #include #include @@ -176,11 +178,13 @@ crtfile(char *pname) exit(errno); } +#ifdef __linux__ if (fsetxattr(fd, "user.xattr", pbuf, 1024, 0) < 0) { (void) fprintf(stderr, "fsetxattr(fd, \"xattr\", pbuf, " "1024, 0) failed.\n[%d]: %s.\n", errno, strerror(errno)); exit(errno); } +#endif (void) close(fd); free(pbuf); diff --git a/tests/zfs-tests/include/blkdev.shlib b/tests/zfs-tests/include/blkdev.shlib index af3324683..758af09ad 100644 --- a/tests/zfs-tests/include/blkdev.shlib +++ b/tests/zfs-tests/include/blkdev.shlib @@ -79,6 +79,8 @@ function block_device_wait typeset local elapsed=$((SECONDS - start)) [[ $elapsed > 60 ]] && \ log_note udevadm settle time too long: $elapsed + elif is_freebsd; then + sleep 3 fi } @@ -94,6 +96,9 @@ function is_physical_device #device [[ -b "$DEV_DSKDIR/$device" ]] && \ [[ -f /sys/module/loop/parameters/max_part ]] return $? + elif is_freebsd; then + echo $device | grep -q -e '^a?da[0-9]*$' -e '^md[0-9]*$' > /dev/null 2>&1 + return $? else echo $device | egrep "^c[0-F]+([td][0-F]+)+$" > /dev/null 2>&1 return $? @@ -131,10 +136,17 @@ function is_loop_device #disk } # +# Linux: # Check if the given device is a multipath device and if there is a symbolic # link to a device mapper and to a disk # Currently no support for dm devices alone without multipath # +# FreeBSD: +# Check if the given device is a gmultipath device. +# +# Others: +# No multipath detection. +# function is_mpath_device #disk { typeset disk=$1 @@ -149,6 +161,10 @@ function is_mpath_device #disk else return $? fi + elif is_freebsd; then + test -b $DEV_MPATHDIR/$disk + else + false fi } @@ -178,6 +194,9 @@ function set_slice_prefix fi (( i = i + 1)) done + elif is_freebsd; then + export SLICE_PREFIX="p" + return 0 fi } @@ -218,7 +237,7 @@ function get_device_dir #device { typeset device=$1 - if ! $(is_physical_device $device) ; then + if ! is_freebsd && ! $(is_physical_device $device) ; then if [[ $device != "/" ]]; then device=${device%/*} fi @@ -459,7 +478,7 @@ function get_pool_devices #testpool #devdir typeset devdir=$2 typeset out="" - if is_linux; then + if is_linux || is_freebsd; then out=$(zpool status -P $testpool |grep ${devdir} | awk '{print $1}') out=$(echo $out | sed -e "s|${devdir}/||g" | tr '\n' ' ') fi diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg index 52758a1aa..6f41a3273 100644 --- a/tests/zfs-tests/include/commands.cfg +++ b/tests/zfs-tests/include/commands.cfg @@ -8,22 +8,17 @@ # Please keep the contents of each variable sorted for ease of reading # and maintenance. # -export SYSTEM_FILES='arp +export SYSTEM_FILES_COMMON='arp awk - attr base64 basename bc - blkid - blockdev bunzip2 bzcat cat - chattr chgrp chmod chown - cksum cmp cp cpio @@ -37,11 +32,8 @@ export SYSTEM_FILES='arp du echo egrep - exportfs expr - fallocate false - fdisk file find fio @@ -49,15 +41,10 @@ export SYSTEM_FILES='arp getconf getent getfacl - getfattr grep - groupadd - groupdel - groupmod gunzip gzip head - hostid hostname id iostat @@ -65,29 +52,16 @@ export SYSTEM_FILES='arp ksh ln logname - losetup ls - lsattr - lsblk - lscpu - lsmod - lsscsi - md5sum mkdir mknod - mkswap mktemp - modprobe mount - mpstat mv net - nproc od openssl - parted pax - perf pgrep ping pkill @@ -105,11 +79,8 @@ export SYSTEM_FILES='arp scp sed seq - setenforce setfacl - setfattr sh - sha256sum shuf sleep sort @@ -130,13 +101,9 @@ export SYSTEM_FILES='arp tr true truncate - udevadm umask umount uname - useradd - userdel - usermod uuidgen vmstat wait @@ -144,6 +111,55 @@ export SYSTEM_FILES='arp which xargs' +export SYSTEM_FILES_FREEBSD='chflags + compress + dumpon + fsck + gpart + md5 + mdconfig + mkfifo + newfs + pw + sha256 + swapctl + sysctl + uncompress' + +export SYSTEM_FILES_LINUX='attr + blkid + blockdev + chattr + cksum + exportfs + fallocate + fdisk + getfattr + groupadd + groupdel + groupmod + hostid + losetup + lsattr + lsblk + lscpu + lsmod + lsscsi + md5sum + mkswap + modprobe + mpstat + nproc + parted + perf + setenforce + setfattr + sha256sum + udevadm + useradd + userdel + usermod' + export ZFS_FILES='zdb zfs zhack diff --git a/tests/zfs-tests/include/default.cfg.in b/tests/zfs-tests/include/default.cfg.in index e1e2a7e91..52a03533c 100644 --- a/tests/zfs-tests/include/default.cfg.in +++ b/tests/zfs-tests/include/default.cfg.in @@ -143,7 +143,7 @@ export SPA_MINDEVSIZE=$((64 * 1024 * 1024)) # For iscsi target support export ISCSITGTFILE=/tmp/iscsitgt_file export ISCSITGT_FMRI=svc:/system/iscsitgt:default -if ! is_linux; then +if ! is_linux && ! is_freebsd; then export AUTO_SNAP=$(svcs -a | grep auto-snapshot | grep online | awk \ '{print $3}') fi @@ -184,6 +184,20 @@ if is_linux; then NEWFS_DEFAULT_FS="ext2" +elif is_freebsd; then + unpack_opts="xv" + pack_opts="cf" + verbose="v" + unpack_preserve="xpf" + pack_preserve="cpf" + + ZVOL_DEVDIR="/dev/zvol" + ZVOL_RDEVDIR="/dev/zvol" + DEV_DSKDIR="/dev" + DEV_RDSKDIR="/dev" + DEV_MPATHDIR="/dev/multipath" + + NEWFS_DEFAULT_FS="ufs" else unpack_opts="xv" pack_opts="cf" diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib index 9d6f3865c..5b5f3189c 100644 --- a/tests/zfs-tests/include/libtest.shlib +++ b/tests/zfs-tests/include/libtest.shlib @@ -92,6 +92,19 @@ function is_linux fi } +# Determine if this is a FreeBSD test system +# +# Return 0 if platform FreeBSD, 1 if otherwise + +function is_freebsd +{ + if [[ $(uname -o) == "FreeBSD" ]]; then + return 0 + else + return 1 + fi +} + # Determine if this is a 32-bit system # # Return 0 if platform is 32-bit, 1 if otherwise @@ -144,17 +157,23 @@ function ismounted fi ;; ufs|nfs) - out=$(df -F $fstype $1 2>/dev/null) - ret=$? - (($ret != 0)) && return $ret + if is_freebsd; then + mount -pt $fstype | while read dev dir _t _flags; do + [[ "$1" == "$dev" || "$1" == "$dir" ]] && return 0 + done + else + out=$(df -F $fstype $1 2>/dev/null) + ret=$? + (($ret != 0)) && return $ret - dir=${out%%\(*} - dir=${dir%% *} - name=${out##*\(} - name=${name%%\)*} - name=${name%% *} + dir=${out%%\(*} + dir=${dir%% *} + name=${out##*\(} + name=${name%%\)*} + name=${name%% *} - [[ "$1" == "$dir" || "$1" == "$name" ]] && return 0 + [[ "$1" == "$dir" || "$1" == "$name" ]] && return 0 + fi ;; ext*) out=$(df -t $fstype $1 2>/dev/null) @@ -881,7 +900,8 @@ function set_partition typeset size=$3 typeset disk=$4 - if is_linux; then + case "$(uname)" in + Linux) if [[ -z $size || -z $disk ]]; then log_fail "The size or disk name is unspecified." fi @@ -928,7 +948,36 @@ function set_partition blockdev --rereadpt $disk 2>/dev/null block_device_wait $disk - else + ;; + FreeBSD) + if [[ -z $size || -z $disk ]]; then + log_fail "The size or disk name is unspecified." + fi + [[ -n $DEV_DSKDIR ]] && disk=$DEV_DSKDIR/$disk + + if [[ $slicenum -eq 0 ]] || ! gpart show $disk >/dev/null 2>&1; then + gpart destroy -F $disk >/dev/null 2>&1 + gpart create -s GPT $disk + if [[ $? -ne 0 ]]; then + log_note "Failed to create GPT partition table on $disk" + return 1 + fi + fi + + typeset index=$((slicenum + 1)) + + if [[ -n $start ]]; then + start="-b $start" + fi + gpart add -t freebsd-zfs $start -s $size -i $index $disk + if [[ $ret_val -ne 0 ]]; then + log_note "Failed to create partition $slicenum on $disk" + return 1 + fi + + block_device_wait $disk + ;; + *) if [[ -z $slicenum || -z $size || -z $disk ]]; then log_fail "The slice, size or disk name is unspecified." fi @@ -949,7 +998,8 @@ function set_partition format -e -s -d $disk -f $format_file typeset ret_val=$? rm -f $format_file - fi + ;; + esac if [[ $ret_val -ne 0 ]]; then log_note "Unable to format $disk slice $slicenum to $size" @@ -984,6 +1034,14 @@ function delete_partitions fi done done + elif is_freebsd; then + for disk in $DISKSARRAY; do + if gpart destroy -F $disk; then + log_note "Partitions for ${disk} deleted" + else + log_fail "Partitions for ${disk} not deleted" + fi + done fi } @@ -998,13 +1056,22 @@ function get_endslice # log_fail "The disk name or slice number is unspecified." fi - if is_linux; then + case "$(uname)" in + Linux) endcyl=$(parted -s $DEV_DSKDIR/$disk -- unit cyl print | \ grep "part${slice}" | \ awk '{print $3}' | \ sed 's,cyl,,') ((endcyl = (endcyl + 1))) - else + ;; + FreeBSD) + disk=${disk#/dev/zvol/} + disk=${disk%p*} + slice=$((slice + 1)) + endcyl=$(gpart show $disk | \ + awk -v slice=$slice '$3 == slice { print $1 + $2 }') + ;; + *) disk=${disk#/dev/dsk/} disk=${disk#/dev/rdsk/} disk=${disk%s*} @@ -1022,7 +1089,8 @@ function get_endslice # nawk -v token="$slice" '{if ($1==token) print $6}') ((endcyl = (endcyl + 1) / ratio)) - fi + ;; + esac echo $endcyl } @@ -1441,7 +1509,7 @@ function setup_nfs_server return fi - if is_linux; then + if is_linux || is_freebsd; then # # Re-synchronize /var/lib/nfs/etab with /etc/exports and # /etc/exports.d./* to provide a clean test environment. @@ -1497,7 +1565,7 @@ function setup_nfs_server # function is_global_zone { - if is_linux; then + if is_linux || is_freebsd; then return 0 else typeset cur_zone=$(zonename 2>/dev/null) @@ -2244,7 +2312,7 @@ function cleanup_devices #vdevs function find_disks { # Trust provided list, no attempt is made to locate unused devices. - if is_linux; then + if is_linux || is_freebsd; then echo "$@" return fi @@ -2325,6 +2393,224 @@ EOF echo $unused } +function add_user_freebsd # +{ + typeset group=$1 + typeset user=$2 + typeset basedir=$3 + + # Check to see if the user exists. + if id $user > /dev/null 2>&1; then + return 0 + fi + + # Assign 1000 as the base uid + typeset -i uid=1000 + while true; do + typeset -i ret + pw useradd -u $uid -g $group -d $basedir/$user -m -n $user + ret=$? + case $ret in + 0) break ;; + # The uid is not unique + 65) ((uid += 1)) ;; + *) return 1 ;; + esac + if [[ $uid == 65000 ]]; then + log_fail "No user id available under 65000 for $user" + fi + done + + # Silence MOTD + touch $basedir/$user/.hushlogin + + return 0 +} + +# +# Delete the specified user. +# +# $1 login name +# +function del_user_freebsd # +{ + typeset user=$1 + + if id $user > /dev/null 2>&1; then + log_must pw userdel $user + fi + + return 0 +} + +# +# Select valid gid and create specified group. +# +# $1 group name +# +function add_group_freebsd # +{ + typeset group=$1 + + # See if the group already exists. + if pw groupshow $group >/dev/null 2>&1; then + return 0 + fi + + # Assign 1000 as the base gid + typeset -i gid=1000 + while true; do + pw groupadd -g $gid -n $group > /dev/null 2>&1 + typeset -i ret=$? + case $ret in + 0) return 0 ;; + # The gid is not unique + 65) ((gid += 1)) ;; + *) return 1 ;; + esac + if [[ $gid == 65000 ]]; then + log_fail "No user id available under 65000 for $group" + fi + done +} + +# +# Delete the specified group. +# +# $1 group name +# +function del_group_freebsd # +{ + typeset group=$1 + + pw groupdel -n $group > /dev/null 2>&1 + typeset -i ret=$? + case $ret in + # Group does not exist, or was deleted successfully. + 0|6|65) return 0 ;; + # Name already exists as a group name + 9) log_must pw groupdel $group ;; + *) return 1 ;; + esac + + return 0 +} + +function add_user_illumos # +{ + typeset group=$1 + typeset user=$2 + typeset basedir=$3 + + log_must useradd -g $group -d $basedir/$user -m $user + + return 0 +} + +function del_user_illumos # +{ + typeset user=$1 + + if id $user > /dev/null 2>&1; then + log_must_retry "currently used" 6 userdel $user + fi + + return 0 +} + +function add_group_illumos # +{ + typeset group=$1 + + typeset -i gid=100 + while true; do + groupadd -g $gid $group > /dev/null 2>&1 + typeset -i ret=$? + case $ret in + 0) return 0 ;; + # The gid is not unique + 4) ((gid += 1)) ;; + *) return 1 ;; + esac + done +} + +function del_group_illumos # +{ + typeset group=$1 + + groupmod -n $grp $grp > /dev/null 2>&1 + typeset -i ret=$? + case $ret in + # Group does not exist. + 6) return 0 ;; + # Name already exists as a group name + 9) log_must groupdel $grp ;; + *) return 1 ;; + esac +} + +function add_user_linux # +{ + typeset group=$1 + typeset user=$2 + typeset basedir=$3 + + log_must useradd -g $group -d $basedir/$user -m $user + + # Add new users to the same group and the command line utils. + # This allows them to be run out of the original users home + # directory as long as it permissioned to be group readable. + cmd_group=$(stat --format="%G" $(which zfs)) + log_must usermod -a -G $cmd_group $user + + return 0 +} + +function del_user_linux # +{ + typeset user=$1 + + if id $user > /dev/null 2>&1; then + log_must_retry "currently used" 6 userdel $user + fi + + return 0 +} + +function add_group_linux # +{ + typeset group=$1 + + # Assign 100 as the base gid, a larger value is selected for + # Linux because for many distributions 1000 and under are reserved. + while true; do + groupadd $group > /dev/null 2>&1 + typeset -i ret=$? + case $ret in + 0) return 0 ;; + *) return 1 ;; + esac + done +} + +function del_group_linux # +{ + typeset group=$1 + + getent group $group > /dev/null 2>&1 + typeset -i ret=$? + case $ret in + # Group does not exist. + 2) return 0 ;; + # Name already exists as a group name + 0) log_must groupdel $group ;; + *) return 1 ;; + esac + + return 0 +} + # # Add specified user to specified group # @@ -2334,26 +2620,29 @@ EOF # function add_user # { - typeset gname=$1 - typeset uname=$2 + typeset group=$1 + typeset user=$2 typeset basedir=${3:-"/var/tmp"} - if ((${#gname} == 0 || ${#uname} == 0)); then + if ((${#group} == 0 || ${#user} == 0)); then log_fail "group name or user name are not defined." fi - log_must useradd -g $gname -d $basedir/$uname -m $uname - echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.profile - echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.bash_profile - echo "export PATH=\"$STF_PATH\"" >>$basedir/$uname/.login + case $(uname) in + FreeBSD) + add_user_freebsd "$group" "$user" "$basedir" + ;; + Linux) + add_user_linux "$group" "$user" "$basedir" + ;; + *) + add_user_illumos "$group" "$user" "$basedir" + ;; + esac - # Add new users to the same group and the command line utils. - # This allows them to be run out of the original users home - # directory as long as it permissioned to be group readable. - if is_linux; then - cmd_group=$(stat --format="%G" $(which zfs)) - log_must usermod -a -G $cmd_group $uname - fi + echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.profile + echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.bash_profile + echo "export PATH=\"$STF_PATH\"" >>$basedir/$user/.login return 0 } @@ -2373,9 +2662,17 @@ function del_user # log_fail "login name is necessary." fi - if id $user > /dev/null 2>&1; then - log_must_retry "currently used" 6 userdel $user - fi + case $(uname) in + FreeBSD) + del_user_freebsd "$user" + ;; + Linux) + del_user_linux "$user" + ;; + *) + del_user_illumos "$user" + ;; + esac [[ -d $basedir/$user ]] && rm -fr $basedir/$user @@ -2395,30 +2692,19 @@ function add_group # log_fail "group name is necessary." fi - # Assign 100 as the base gid, a larger value is selected for - # Linux because for many distributions 1000 and under are reserved. - if is_linux; then - while true; do - groupadd $group > /dev/null 2>&1 - typeset -i ret=$? - case $ret in - 0) return 0 ;; - *) return 1 ;; - esac - done - else - typeset -i gid=100 - while true; do - groupadd -g $gid $group > /dev/null 2>&1 - typeset -i ret=$? - case $ret in - 0) return 0 ;; - # The gid is not unique - 4) ((gid += 1)) ;; - *) return 1 ;; - esac - done - fi + case $(uname) in + FreeBSD) + add_group_freebsd "$group" + ;; + Linux) + add_group_linux "$group" + ;; + *) + add_group_illumos "$group" + ;; + esac + + return 0 } # @@ -2428,32 +2714,23 @@ function add_group # # function del_group # { - typeset grp=$1 - if ((${#grp} == 0)); then + typeset group=$1 + + if ((${#group} == 0)); then log_fail "group name is necessary." fi - if is_linux; then - getent group $grp > /dev/null 2>&1 - typeset -i ret=$? - case $ret in - # Group does not exist. - 2) return 0 ;; - # Name already exists as a group name - 0) log_must groupdel $grp ;; - *) return 1 ;; - esac - else - groupmod -n $grp $grp > /dev/null 2>&1 - typeset -i ret=$? - case $ret in - # Group does not exist. - 6) return 0 ;; - # Name already exists as a group name - 9) log_must groupdel $grp ;; - *) return 1 ;; - esac - fi + case $(uname) in + FreeBSD) + del_group_freebsd "$group" + ;; + Linux) + del_group_linux "$group" + ;; + *) + del_group_illumos "$group" + ;; + esac return 0 } @@ -2800,7 +3077,7 @@ function labelvtoc typeset label_file=/var/tmp/labelvtoc.$$ typeset arch=$(uname -p) - if is_linux; then + if is_linux || is_freebsd; then log_note "Currently unsupported by the test framework" return 1 fi @@ -2858,7 +3135,9 @@ function get_rootfs { typeset rootfs="" - if ! is_linux; then + if is_freebsd; then + rootfs=$(mount -p | awk '$2 == "/" && $3 == "zfs" {print $1}') + elif ! is_linux; then rootfs=$(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \ /etc/mnttab) fi @@ -2883,7 +3162,9 @@ function get_rootpool typeset rootfs="" typeset rootpool="" - if ! is_linux; then + if is_freebsd; then + rootfs=$(mount -p | awk '$2 == "/" && $3 == "zfs" {print $1}') + elif ! is_linux; then rootfs=$(awk '{if ($2 == "/" && $3 =="zfs") print $1}' \ /etc/mnttab) fi @@ -2892,23 +3173,12 @@ function get_rootpool fi zfs list $rootfs > /dev/null 2>&1 if (($? == 0)); then - rootpool=`echo $rootfs | awk -F\/ '{print $1}'` - echo $rootpool + echo ${rootfs%%/*} else log_fail "This is not a zfsroot system." fi } -# -# Get the package name -# -function get_package_name -{ - typeset dirpath=${1:-$STC_NAME} - - echo "SUNWstc-${dirpath}" | /usr/bin/sed -e "s/\//-/g" -} - # # Get the word numbers from a string separated by white space # @@ -2971,6 +3241,8 @@ function is_mp { if is_linux; then (($(nproc) > 1)) + elif is_freebsd; then + sysctl -n kern.smp.cpus else (($(psrinfo | wc -l) > 1)) fi @@ -2982,6 +3254,8 @@ function get_cpu_freq { if is_linux; then lscpu | awk '/CPU MHz/ { print $3 }' + elif is_freebsd; then + cat /var/run/dmesg.boot | grep '^CPU:' | cut -d '(' -f 2 | cut -d ')' -f 1 else psrinfo -v 0 | awk '/processor operates at/ {print $6}' fi @@ -2994,8 +3268,13 @@ function user_run shift log_note "user:$user $@" - eval su - \$user -c \"$@\" > $TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err - return $? + if is_freebsd; then + eval "su \$user -c \"$@\"" > $TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err + return $? + else + eval su - \$user -c \"$@\" > $TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err + return $? + fi } # @@ -3121,7 +3400,11 @@ function get_objnum typeset objnum [[ -e $pathname ]] || log_fail "No such file or directory: $pathname" - objnum=$(stat -c %i $pathname) + if is_freebsd; then + objnum=$(stat -f "%i" $pathname) + else + objnum=$(stat -c %i $pathname) + fi echo $objnum } @@ -3214,7 +3497,7 @@ function zed_rc_restore function zed_setup { if ! is_linux; then - return + log_unsupported "No zed on $(uname)" fi if [[ ! -d $ZEDLET_DIR ]]; then @@ -3376,6 +3659,8 @@ function is_swap_inuse if is_linux; then swapon -s | grep -w $(readlink -f $device) > /dev/null 2>&1 + elif is_freebsd; then + swapctl -l | grep -w $device else swap -l | grep -w $device > /dev/null 2>&1 fi @@ -3393,6 +3678,8 @@ function swap_setup if is_linux; then log_must eval "mkswap $swapdev > /dev/null 2>&1" log_must swapon $swapdev + elif is_freebsd; then + log_must swapctl -a $swapdev else log_must swap -a $swapdev fi @@ -3410,6 +3697,8 @@ function swap_cleanup if is_swap_inuse $swapdev; then if is_linux; then log_must swapoff $swapdev + elif is_freebsd; then + log_must swapoff $swapdev else log_must swap -d $swapdev fi @@ -3458,6 +3747,10 @@ function set_tunable_impl cat >"$zfs_tunables/$tunable" <<<"$value" return $? ;; + FreeBSD) + sysctl vfs.zfs.$tunable=$value + return "$?" + ;; SunOS) [[ "$module" -eq "zfs" ]] || return 1 echo "${tunable}/${mdb_cmd}0t${value}" | mdb -kw @@ -3490,6 +3783,9 @@ function get_tunable_impl cat $zfs_tunables/$tunable return $? ;; + FreeBSD) + sysctl -n vfs.zfs.$tunable + ;; SunOS) [[ "$module" -eq "zfs" ]] || return 1 ;; @@ -3567,7 +3863,14 @@ function md5digest { typeset file=$1 - md5sum -b $file | awk '{ print $1 }' + case $(uname) in + FreeBSD) + md5 -q $file + ;; + *) + md5sum -b $file | awk '{ print $1 }' + ;; + esac } # @@ -3578,5 +3881,38 @@ function sha256digest { typeset file=$1 - sha256sum -b $file | awk '{ print $1 }' + case $(uname) in + FreeBSD) + sha256 -q $file + ;; + *) + sha256sum -b $file | awk '{ print $1 }' + ;; + esac +} + +function new_fs # +{ + case $(uname) in + FreeBSD) + newfs "$@" + ;; + *) + echo y | newfs -v "$@" + ;; + esac +} + +function stat_size # +{ + typeset path=$1 + + case $(uname) in + FreeBSD) + stat -f %z "$path" + ;; + *) + stat -c %s "$path" + ;; + esac } diff --git a/tests/zfs-tests/include/properties.shlib b/tests/zfs-tests/include/properties.shlib index f049f5193..cc37e769d 100644 --- a/tests/zfs-tests/include/properties.shlib +++ b/tests/zfs-tests/include/properties.shlib @@ -80,8 +80,13 @@ function get_rand_large_recsize # # Functions to toggle on/off properties # -typeset -a binary_props=('atime' 'devices' 'exec' 'readonly' 'setuid' 'xattr' - 'zoned') +typeset -a binary_props=('atime' 'devices' 'exec' 'readonly' 'setuid' 'xattr') + +if is_freebsd; then + binary_props+=('jailed') +else + binary_props+=('zoned') +fi if is_linux; then # Only older kernels support non-blocking mandatory locks diff --git a/tests/zfs-tests/tests/functional/alloc_class/alloc_class_013_pos.ksh b/tests/zfs-tests/tests/functional/alloc_class/alloc_class_013_pos.ksh index 22a8f1a97..2ce22a624 100755 --- a/tests/zfs-tests/tests/functional/alloc_class/alloc_class_013_pos.ksh +++ b/tests/zfs-tests/tests/functional/alloc_class/alloc_class_013_pos.ksh @@ -42,7 +42,7 @@ log_must display_status "$TESTPOOL" log_must zfs create -o dedup=on -V 2G $TESTPOOL/$TESTVOL -log_must echo y | newfs $ZVOL_DEVDIR/$TESTPOOL/$TESTVOL >/dev/null 2>&1 +log_must eval "new_fs $ZVOL_DEVDIR/$TESTPOOL/$TESTVOL >/dev/null 2>&1" sync_pool log_must zpool list -v $TESTPOOL diff --git a/tests/zfs-tests/tests/functional/atime/atime_common.kshlib b/tests/zfs-tests/tests/functional/atime/atime_common.kshlib index bd6c6dc39..90e2de067 100644 --- a/tests/zfs-tests/tests/functional/atime/atime_common.kshlib +++ b/tests/zfs-tests/tests/functional/atime/atime_common.kshlib @@ -47,6 +47,9 @@ function check_atime_updated if is_linux; then typeset before=$(stat -c %X $filename) sleep 2 + elif is_freebsd; then + typeset before=$(ls -luD "%Y-%m-%d %R.%s" $filename | awk '{print $7}') + sleep 2 else typeset before=$(ls -Eu $filename | awk '{print $7}') fi @@ -55,6 +58,8 @@ function check_atime_updated if is_linux; then typeset after=$(stat -c %X $filename) + elif is_freebsd; then + typeset after=$(ls -luD "%Y-%m-%d %R.%s" $filename | awk '{print $7}') else typeset after=$(ls -Eu $filename | awk '{print $7}') fi diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_006_pos.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_006_pos.ksh index e17c06bb5..d29fe7e89 100755 --- a/tests/zfs-tests/tests/functional/bootfs/bootfs_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/bootfs/bootfs_006_pos.ksh @@ -117,7 +117,7 @@ verify_bootfs $TESTPOOL log_must zpool create $TESTPOOL mirror $VDEV1 $VDEV2 spare $VDEV3 verify_bootfs $TESTPOOL -if is_linux; then +if is_linux || is_freebsd; then # stripe log_must zpool create $TESTPOOL $VDEV1 $VDEV2 verify_bootfs $TESTPOOL diff --git a/tests/zfs-tests/tests/functional/channel_program/channel_common.kshlib b/tests/zfs-tests/tests/functional/channel_program/channel_common.kshlib index 722a47755..a828ba290 100644 --- a/tests/zfs-tests/tests/functional/channel_program/channel_common.kshlib +++ b/tests/zfs-tests/tests/functional/channel_program/channel_common.kshlib @@ -141,24 +141,16 @@ function log_program_construct_args pool=$1 shift - # - # Catch HERE document if it exists and save it within our - # temp file. The reason we do this is that since the - # log_must_program wrapper calls zfs-program twice (once - # for open context and once for syncing) the HERE doc - # is consumed in the first invocation and the second one - # does not have a program to run. - # - test -s /dev/stdin && cat > $tmpin + infile=$1 + shift # - # If $tmpin has contents it means that we consumed a HERE - # doc and $1 currently holds "-" (a dash). If there is no - # HERE doc and $tmpin is empty, then we copy the contents - # of the original channel program to $tmpin. + # Copy the contents of the original channel program to $tmpin. # - [[ -s $tmpin ]] || cp $1 $tmpin - shift + # If $infile currently holds "-" (a dash) it means that we consume a + # HERE doc from stdin, otherwise $infile is a file path. + # + cat $infile > $tmpin lua_args=$@ diff --git a/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.timeout.ksh b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.timeout.ksh index 9256e8677..22ea37548 100755 --- a/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.timeout.ksh +++ b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.timeout.ksh @@ -37,7 +37,7 @@ function test_instr_limit error=$(zfs program -t $lim $TESTPOOL $ZCP_ROOT/lua_core/tst.timeout.zcp 2>&1) [[ $? -ne 0 ]] || log_fail "Channel program with limit $lim exited 0: $error" - instrs_run=$(echo $error | sed -n 's/.\+ \([0-9]*\) Lua instructions/\1/p') + instrs_run=$(echo $error | awk -F "chunk" '{print $2}' | awk '{print $1}') if [[ $instrs_run -lt $(( $lim - 100 )) ]]; then log_fail "Runtime (${instrs_run} instr) < limit (${lim} - 100 instr)" elif [[ $instrs_run -gt $(( $lim + 100 )) ]]; then diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_index_props.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_index_props.ksh index 6478fa654..eed3e0bce 100755 --- a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_index_props.ksh +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_index_props.ksh @@ -35,6 +35,7 @@ log_onexit cleanup log_must zfs create -o version=5 $fs create_snapshot $fs $TESTSNAP -log_must_program $TESTPOOL $ZCP_ROOT/synctask_core/tst.get_index_props.zcp $fs $snap +os=$(uname) +log_must_program $TESTPOOL $ZCP_ROOT/synctask_core/tst.get_index_props.zcp $fs $snap $os log_pass "Getting index props should work correctly." diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_index_props.zcp b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_index_props.zcp index e898cf86f..10ef8e7f8 100644 --- a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_index_props.zcp +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_index_props.zcp @@ -16,6 +16,7 @@ arg = ... fs = arg["argv"][1] snap = arg["argv"][2] +os = arg["argv"][3] props = {} @@ -26,7 +27,11 @@ props['checksum'] = {{'on', 'default'}, {nil, nil}} props['dedup'] = {{'off', 'default'}, {nil, nil}} props['compression'] = {{'off', 'default'}, {nil, nil}} props['snapdir'] = {{'hidden', 'default'}, {nil, nil}} -props['acltype'] = {{'off', 'default'}, {'off', 'default'}} +if os == "Linux" then + props['acltype'] = {{'off', 'default'}, {'off', 'default'}} +elseif os == "FreeBSD" then + props['aclmode'] = {{'discard', 'default'}, {'discard', 'default'}} +end props['aclinherit'] = {{'restricted','default'}, {nil, nil}} props['copies'] = {{'1', 'default'}, {nil, nil}} props['primarycache'] = {{'all', 'default'}, {'all', 'default'}} @@ -37,7 +42,11 @@ props['devices'] = {{'on', 'default'}, {'on', 'default'}} props['exec'] = {{'on', 'default'}, {'on', 'default'}} props['setuid'] = {{'on', 'default'}, {'on', 'default'}} props['readonly'] = {{'off', 'default'}, {nil, nil}} -props['zoned'] = {{'off', 'default'}, {nil, nil}} +if os == "FreeBSD" then + props['jailed'] = {{'off', 'default'}, {nil, nil}} +else + props['zoned'] = {{'off', 'default'}, {nil, nil}} +end props['vscan'] = {{'off', 'default'}, {nil, nil}} props['nbmand'] = {{'off', 'default'}, {'off', 'default'}} props['version'] = {{'5', nil}, {'5', nil}} diff --git a/tests/zfs-tests/tests/functional/chattr/chattr_001_pos.ksh b/tests/zfs-tests/tests/functional/chattr/chattr_001_pos.ksh index 4d66146d7..cb8c2ead5 100755 --- a/tests/zfs-tests/tests/functional/chattr/chattr_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/chattr/chattr_001_pos.ksh @@ -48,22 +48,37 @@ set -A files writable immutable append function cleanup { for i in ${files[*]}; do - log_must chattr -ia $TESTDIR/$i - log_must rm -f $TESTDIR/$i + if is_freebsd ; then + log_must chflags noschg $TESTDIR/$i + log_must rm -f $TESTDIR/$i + else + log_must chattr -ia $TESTDIR/$i + log_must rm -f $TESTDIR/$i + fi done } log_onexit cleanup -log_assert "Check whether chattr works as expected" +if is_freebsd ; then + log_assert "Check whether chflags works as expected" +else + log_assert "Check whether chattr works as expected" +fi log_must touch $TESTDIR/writable log_must touch $TESTDIR/immutable log_must touch $TESTDIR/append -log_must chattr -i $TESTDIR/writable -log_must chattr +i $TESTDIR/immutable -log_must chattr +a $TESTDIR/append +if is_freebsd ; then + log_must chflags noschg $TESTDIR/writable + log_must chflags schg $TESTDIR/immutable + log_must chflags sappnd $TESTDIR/append +else + log_must chattr -i $TESTDIR/writable + log_must chattr +i $TESTDIR/immutable + log_must chattr +a $TESTDIR/append +fi log_must eval "echo test > $TESTDIR/writable" log_must eval "echo test >> $TESTDIR/writable" @@ -72,4 +87,8 @@ log_mustnot eval "echo test >> $TESTDIR/immutable" log_mustnot eval "echo test > $TESTDIR/append" log_must eval "echo test >> $TESTDIR/append" -log_pass "chattr works as expected" +if is_freebsd ; then + log_pass "chflags works as expected" +else + log_pass "chattr works as expected" +fi diff --git a/tests/zfs-tests/tests/functional/checksum/filetest_001_pos.ksh b/tests/zfs-tests/tests/functional/checksum/filetest_001_pos.ksh index 27dad0726..4bee69c24 100755 --- a/tests/zfs-tests/tests/functional/checksum/filetest_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/checksum/filetest_001_pos.ksh @@ -75,6 +75,11 @@ firstvdev=${array[0]} typeset -i i=1 while [[ $i -lt ${#CHECKSUM_TYPES[*]} ]]; do type=${CHECKSUM_TYPES[i]} + # edonr not supported on FreeBSD + if is_freebsd && [[ "$type" == "edonr" ]] ; then + (( i = i + 1 )) + continue + fi log_must zfs set checksum=$type $TESTPOOL log_must file_write -o overwrite -f $TESTDIR/test_$type \ -b $WRITESZ -c 5 -d R @@ -96,6 +101,11 @@ log_assert "Test corrupting the files and seeing checksum errors" typeset -i j=1 while [[ $j -lt ${#CHECKSUM_TYPES[*]} ]]; do type=${CHECKSUM_TYPES[$j]} + # edonr not supported on FreeBSD + if is_freebsd && [[ "$type" == "edonr" ]] ; then + (( j = j + 1 )) + continue + fi log_must zfs set checksum=$type $TESTPOOL log_must file_write -o overwrite -f $TESTDIR/test_$type \ -b $WRITESZ -c 5 -d R diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_003_pos.ksh index 3c444ae98..36f1929dd 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_003_pos.ksh @@ -34,8 +34,17 @@ log_onexit cleanup function cleanup { datasetexists $TESTPOOL && destroy_pool $TESTPOOL + if is_freebsd ; then + log_must sysctl kern.geom.debugflags=$saved_debugflags + fi } +if is_freebsd ; then + # FreeBSD won't allow writing to an in-use device without this set + saved_debugflags=$(sysctl -n kern.geom.debugflags) + log_must sysctl kern.geom.debugflags=16 +fi + verify_runnable "global" verify_disk_count "$DISKS" 2 diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_004_pos.ksh index 91a5c9799..2adaf8fac 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_004_pos.ksh @@ -40,12 +40,25 @@ function cleanup for DISK in $DISKS; do zpool labelclear -f $DEV_RDSKDIR/$DISK done + if is_freebsd ; then + log_must sysctl kern.geom.debugflags=$saved_debugflags + fi } +if is_freebsd ; then + # FreeBSD won't allow writing to an in-use device without this set + saved_debugflags=$(sysctl -n kern.geom.debugflags) + log_must sysctl kern.geom.debugflags=16 +fi + verify_runnable "global" verify_disk_count "$DISKS" 2 set -A DISK $DISKS -WHOLE_DISK=${DISK[0]} +if is_freebsd ; then + WHOLE_DISK=/dev/${DISK[0]} +else + WHOLE_DISK=${DISK[0]} +fi default_mirror_setup_noexit $DISKS DEVS=$(get_pool_devices ${TESTPOOL} ${DEV_RDSKDIR}) @@ -57,10 +70,16 @@ log_must zpool export $TESTPOOL log_must dd if=$DEV_RDSKDIR/${DISK[0]} of=$DEV_RDSKDIR/${DISK[1]} bs=1K count=256 conv=notrunc -ubs=$(zdb -lu ${DISK[1]} | grep -e LABEL -e Uberblock -e 'labels = ') +if is_freebsd; then + DISK1="/dev/${DISK[1]}" +else + DISK1="${DISK[1]}" +fi + +ubs=$(zdb -lu ${DISK1} | grep -e LABEL -e Uberblock -e 'labels = ') log_note "vdev 1: ubs $ubs" -ub_dump_counts=$(zdb -lu ${DISK[1]} | \ +ub_dump_counts=$(zdb -lu ${DISK1} | \ awk ' /LABEL/ {label=$NF; blocks[label]=0}; /Uberblock/ {blocks[label]++}; END {print blocks[0],blocks[1],blocks[2],blocks[3]}') diff --git a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_005_pos.ksh index 49e237c70..74975dbb0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zdb/zdb_005_pos.ksh @@ -37,8 +37,17 @@ function cleanup { datasetexists $TESTPOOL && destroy_pool $TESTPOOL rm -f $TEMPFILE + if is_freebsd ; then + log_must sysctl kern.geom.debugflags=$saved_debugflags + fi } +if is_freebsd ; then + # FreeBSD won't allow writing to an in-use device without this set + saved_debugflags=$(sysctl -n kern.geom.debugflags) + log_must sysctl kern.geom.debugflags=16 +fi + verify_runnable "global" verify_disk_count "$DISKS" 2 diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh index 92382aa11..b475960c9 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh @@ -48,6 +48,10 @@ function cleanup { unset ZFS_ABORT + if is_freebsd && [[ -n $savedcorefile ]]; then + sysctl kern.corefile=$savedcorefile + fi + if [[ -d $corepath ]]; then rm -rf $corepath fi @@ -63,7 +67,9 @@ log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a " \ log_onexit cleanup # Preparation work for testing +savedcorefile="" corepath=$TESTDIR/core +corefile=$corepath/core.zfs if [[ -d $corepath ]]; then rm -rf $corepath fi @@ -91,9 +97,13 @@ typeset badparams=("" "create" "destroy" "snapshot" "rollback" "clone" \ if is_linux; then ulimit -c unlimited - echo "$corepath/core.zfs" >/proc/sys/kernel/core_pattern + echo "$corefile" >/proc/sys/kernel/core_pattern echo 0 >/proc/sys/kernel/core_uses_pid export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0" +elif is_freebsd; then + ulimit -c unlimited + savedcorefile=$(sysctl -n kern.corefile) + log_must sysctl kern.corefile=$corepath/core.%N else log_must coreadm -p ${corepath}/core.%f fi @@ -102,7 +112,6 @@ log_must export ZFS_ABORT=yes for subcmd in "${cmds[@]}" "${badparams[@]}"; do zfs $subcmd >/dev/null 2>&1 && log_fail "$subcmd passed incorrectly." - corefile=${corepath}/core.zfs if [[ ! -e $corefile ]]; then log_fail "zfs $subcmd cannot generate core file with " \ "ZFS_ABORT set." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib index b0ced58c9..c75318e5c 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib @@ -91,18 +91,32 @@ function do_vol_test case "$type" in "ext2") - log_must eval "echo y | newfs $vol_r_path >/dev/null 2>&1" + if is_freebsd; then + log_unsupported "ext2 test not implemented for freebsd" + fi + log_must eval "new_fs $vol_r_path >/dev/null 2>&1" log_must mount -o rw $vol_b_path $mntp ;; "ufs") if is_linux; then log_unsupported "ufs test not implemented for linux" fi - log_must eval "newfs $vol_r_path >/dev/null 2>&1" + log_must eval "new_fs $vol_r_path >/dev/null 2>&1" log_must mount $vol_b_path $mntp ;; "zfs") - log_must zpool create $TESTPOOL1 $vol_b_path + if is_freebsd; then + # Pool creation on zvols is forbidden by default. + # Save and restore the current setting. + typeset _saved=$(get_tunable vol.recursive) + log_must set_tunable64 vol.recursive 1 # Allow + zpool create $TESTPOOL1 $vol_b_path + typeset _zpool_create_result=$? + log_must set_tunable64 vol.recursive $_saved # Restore + log_must test $_zpool_create_result = 0 + else + log_must zpool create $TESTPOOL1 $vol_b_path + fi log_must zfs create $TESTPOOL1/$TESTFS1 ;; *) diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh index 11265cd5a..828837348 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh @@ -81,7 +81,7 @@ for val in 1 2 3; do done log_note "Verify 'ls -s' can correctly list the space charged." -if is_linux; then +if is_linux || is_freebsd; then blksize=1024 else blksize=512 @@ -94,16 +94,25 @@ done log_note "Verify df(1M) can correctly display the space charged." for val in 1 2 3; do - used=`df -F zfs -k /$TESTPOOL/fs_$val/$FILE | grep $TESTPOOL/fs_$val \ - | awk '{print $3}'` - (( used = used * 1024 )) # kb -> bytes + if is_freebsd; then + used=`df -m /$TESTPOOL/fs_$val | grep $TESTPOOL/fs_$val \ + | awk -v fs=fs_$val '$4 ~ fs {print $3}'` + else + used=`df -F zfs -k /$TESTPOOL/fs_$val/$FILE | grep $TESTPOOL/fs_$val \ + | awk '{print $3}'` + (( used = used * 1024 )) # kb -> bytes + fi check_used $used $val done log_note "Verify du(1) can correctly display the space charged." for val in 1 2 3; do - used=`du -k /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'` - (( used = used * 1024 )) # kb -> bytes + if is_freebsd; then + used=`du -h /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'` + else + used=`du -k /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'` + (( used = used * 1024 )) # kb -> bytes + fi check_used $used $val done diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_clone_livelist_condense_and_disable.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_clone_livelist_condense_and_disable.ksh index 7faf304db..13976e7c4 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_clone_livelist_condense_and_disable.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_clone_livelist_condense_and_disable.ksh @@ -36,9 +36,9 @@ function cleanup { log_must zfs destroy -Rf $TESTPOOL/$TESTFS1 # reset the livelist sublist size to the original value - set_tunable64 zfs_livelist_max_entries $ORIGINAL_MAX + set_tunable64 $LIVELIST_MAX_ENTRIES $ORIGINAL_MAX # reset the minimum percent shared to 75 - set_tunable32 zfs_livelist_min_percent_shared $ORIGINAL_MIN + set_tunable32 $LIVELIST_MIN_PERCENT_SHARED $ORIGINAL_MIN } function check_ll_len @@ -58,9 +58,9 @@ function test_condense { # set the max livelist entries to a small value to more easily # trigger a condense - set_tunable64 zfs_livelist_max_entries 20 + set_tunable64 $LIVELIST_MAX_ENTRIES 20 # set a small percent shared threshold so the livelist is not disabled - set_tunable32 zfs_livelist_min_percent_shared 10 + set_tunable32 $LIVELIST_MIN_PERCENT_SHARED 10 clone_dataset $TESTFS1 snap $TESTCLONE # sync between each write to make sure a new entry is created @@ -86,7 +86,7 @@ function test_condense function test_deactivated { # Threshold set to 50 percent - set_tunable32 zfs_livelist_min_percent_shared 50 + set_tunable32 $LIVELIST_MIN_PERCENT_SHARED 50 clone_dataset $TESTFS1 snap $TESTCLONE log_must mkfile 5m /$TESTPOOL/$TESTCLONE/$TESTFILE0 @@ -97,7 +97,7 @@ function test_deactivated log_must zfs destroy -R $TESTPOOL/$TESTCLONE # Threshold set to 20 percent - set_tunable32 zfs_livelist_min_percent_shared 20 + set_tunable32 $LIVELIST_MIN_PERCENT_SHARED 20 clone_dataset $TESTFS1 snap $TESTCLONE log_must mkfile 5m /$TESTPOOL/$TESTCLONE/$TESTFILE0 @@ -112,8 +112,8 @@ function test_deactivated log_must zfs destroy -R $TESTPOOL/$TESTCLONE } -ORIGINAL_MAX=$(get_tunable zfs_livelist_max_entries) -ORIGINAL_MIN=$(get_tunable zfs_livelist_min_percent_shared) +ORIGINAL_MAX=$(get_tunable $LIVELIST_MAX_ENTRIES) +ORIGINAL_MIN=$(get_tunable $LIVELIST_MIN_PERCENT_SHARED) log_onexit cleanup log_must zfs create $TESTPOOL/$TESTFS1 diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_clone_livelist_condense_races.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_clone_livelist_condense_races.ksh index 85692f889..4c99a05e0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_clone_livelist_condense_races.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_clone_livelist_condense_races.ksh @@ -32,15 +32,16 @@ # then export the pool. . $STF_SUITE/include/libtest.shlib +. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib function cleanup { log_must zfs destroy -Rf $TESTPOOL/$TESTFS1 # reset the livelist sublist size to the original value - set_tunable64 zfs_livelist_max_entries $ORIGINAL_MAX + set_tunable64 $LIVELIST_MAX_ENTRIES $ORIGINAL_MAX # reset the condense tests to 0 - set_tunable32 zfs_livelist_condense_zthr_pause 0 - set_tunable32 zfs_livelist_condense_sync_pause 0 + set_tunable32 $LIVELIST_CONDENSE_ZTHR_PAUSE 0 + set_tunable32 $LIVELIST_CONDENSE_SYNC_PAUSE 0 } function delete_race @@ -88,7 +89,7 @@ function disable_race log_must zfs destroy $TESTPOOL/$TESTCLONE } -ORIGINAL_MAX=$(get_tunable zfs_livelist_max_entries) +ORIGINAL_MAX=$(get_tunable $LIVELIST_MAX_ENTRIES) log_onexit cleanup @@ -98,19 +99,19 @@ log_must zpool sync $TESTPOOL log_must zfs snapshot $TESTPOOL/$TESTFS1@snap # Reduce livelist size to trigger condense more easily -set_tunable64 zfs_livelist_max_entries 20 +set_tunable64 $LIVELIST_MAX_ENTRIES 20 # Test cancellation path in the zthr -set_tunable32 zfs_livelist_condense_zthr_pause 1 -set_tunable32 zfs_livelist_condense_sync_pause 0 -disable_race "zfs_livelist_condense_zthr_cancel" -delete_race "zfs_livelist_condense_zthr_cancel" -export_race "zfs_livelist_condense_zthr_cancel" +set_tunable32 $LIVELIST_CONDENSE_ZTHR_PAUSE 1 +set_tunable32 $LIVELIST_CONDENSE_SYNC_PAUSE 0 +disable_race $LIVELIST_CONDENSE_ZTHR_CANCEL +delete_race $LIVELIST_CONDENSE_ZTHR_CANCEL +export_race $LIVELIST_CONDENSE_ZTHR_CANCEL # Test cancellation path in the synctask -set_tunable32 zfs_livelist_condense_zthr_pause 0 -set_tunable32 zfs_livelist_condense_sync_pause 1 -disable_race "zfs_livelist_condense_sync_cancel" -delete_race "zfs_livelist_condense_sync_cancel" +set_tunable32 $LIVELIST_CONDENSE_ZTHR_PAUSE 0 +set_tunable32 $LIVELIST_CONDENSE_SYNC_PAUSE 1 +disable_race $LIVELIST_CONDENSE_SYNC_CANCEL +delete_race $LIVELIST_CONDENSE_SYNC_CANCEL log_pass "Clone livelist condense race conditions passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg index a62739b07..4a7b8967d 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg @@ -37,3 +37,20 @@ export FSSNAP=$FS@$TESTSNAP export VOLSNAP=$VOL@$TESTSNAP export FSCLONE=$TESTPOOL/$TESTFSCLONE export VOLCLONE=$TESTPOOL/$TESTVOLCLONE +if is_freebsd; then + export LIVELIST_MAX_ENTRIES=livelist.max_entries + export LIVELIST_MIN_PERCENT_SHARED=livelist.min_percent_shared + export LIVELIST_CONDENSE_NEW_ALLOC=livelist.condense.new_alloc + export LIVELIST_CONDENSE_ZTHR_CANCEL=livelist.condense.zthr_cancel + export LIVELIST_CONDENSE_SYNC_CANCEL=livelist.condense.sync_cancel + export LIVELIST_CONDENSE_ZTHR_PAUSE=livelist.condense.zthr_pause + export LIVELIST_CONDENSE_SYNC_PAUSE=livelist.condense.sync_pause +else + export LIVELIST_MAX_ENTRIES=zfs_livelist_max_entries + export LIVELIST_MIN_PERCENT_SHARED=zfs_livelist_min_percent_shared + export LIVELIST_CONDENSE_NEW_ALLOC=zfs_livelist_condense_new_alloc + export LIVELIST_CONDENSE_ZTHR_CANCEL=zfs_livelist_condense_zthr_cancel + export LIVELIST_CONDENSE_SYNC_CANCEL=zfs_livelist_condense_sync_cancel + export LIVELIST_CONDENSE_ZTHR_PAUSE=zfs_livelist_condense_zthr_pause + export LIVELIST_CONDENSE_SYNC_PAUSE=zfs_livelist_condense_sync_pause +fi diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_clone_livelist.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_clone_livelist.ksh index c427e4bc4..d1cc92633 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_clone_livelist.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_clone_livelist.ksh @@ -40,7 +40,7 @@ function cleanup { datasetexists $TESTPOOL/$TESTFS1 && zfs destroy -R $TESTPOOL/$TESTFS1 # reset the livelist sublist size to its original value - set_tunable64 zfs_livelist_max_entries $ORIGINAL_MAX + set_tunable64 $LIVELIST_MAX_ENTRIES $ORIGINAL_MAX } function clone_write_file @@ -120,7 +120,7 @@ function test_promote log_must zfs destroy -R $TESTPOOL/$TESTCLONE } -ORIGINAL_MAX=$(get_tunable zfs_livelist_max_entries) +ORIGINAL_MAX=$(get_tunable $LIVELIST_MAX_ENTRIES) log_onexit cleanup log_must zfs create $TESTPOOL/$TESTFS1 @@ -128,7 +128,7 @@ log_must mkfile 20m /$TESTPOOL/$TESTFS1/atestfile log_must zfs snapshot $TESTPOOL/$TESTFS1@snap # set a small livelist entry size to more easily test multiple entry livelists -set_tunable64 zfs_livelist_max_entries 20 +set_tunable64 $LIVELIST_MAX_ENTRIES 20 test_one_empty test_one diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib index 31b880c1d..096c18f06 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib @@ -61,12 +61,7 @@ function setup_testenv #[dtst] log_must zfs create -V $VOLSIZE $VOL block_device_wait - echo "y" | newfs $ZVOL_DEVDIR/$VOL > /dev/null 2>&1 - if (( $? == 0 )); then - log_note "SUCCESS: newfs $ZVOL_DEVDIR/$VOL>/dev/null" - else - log_fail "newfs $ZVOL_DEVDIR/$VOL > /dev/null" - fi + log_must new_fs $ZVOL_DEVDIR/$VOL if [[ ! -d $TESTDIR1 ]]; then log_must mkdir $TESTDIR1 diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_dev_removal_condense.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_dev_removal_condense.ksh index e11a43f62..22a942d15 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_dev_removal_condense.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_dev_removal_condense.ksh @@ -32,20 +32,21 @@ . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/removal/removal.kshlib +. $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg function cleanup { poolexists $TESTPOOL2 && zpool destroy $TESTPOOL2 # reset livelist max size - set_tunable64 zfs_livelist_max_entries $ORIGINAL_MAX + set_tunable64 $LIVELIST_MAX_ENTRIES $ORIGINAL_MAX [[ -f $VIRTUAL_DISK1 ]] && log_must rm $VIRTUAL_DISK1 [[ -f $VIRTUAL_DISK2 ]] && log_must rm $VIRTUAL_DISK2 } log_onexit cleanup -ORIGINAL_MAX=$(get_tunable zfs_livelist_max_entries) -set_tunable64 zfs_livelist_max_entries 20 +ORIGINAL_MAX=$(get_tunable $LIVELIST_MAX_ENTRIES) +set_tunable64 $LIVELIST_MAX_ENTRIES 20 VIRTUAL_DISK1=/var/tmp/disk1 VIRTUAL_DISK2=/var/tmp/disk2 @@ -65,14 +66,14 @@ log_must zfs clone $TESTPOOL2/$TESTFS@snap $TESTPOOL2/$TESTCLONE log_must mkfile 10m /$TESTPOOL2/$TESTCLONE/A log_must mkfile 1m /$TESTPOOL2/$TESTCLONE/B log_must zpool sync $TESTPOOL2 -set_tunable32 zfs_livelist_condense_sync_pause 1 +set_tunable32 $LIVELIST_CONDENSE_SYNC_PAUSE 1 # Add a new dev and remove the old one log_must zpool add $TESTPOOL2 $VIRTUAL_DISK2 log_must zpool remove $TESTPOOL2 $VIRTUAL_DISK1 wait_for_removal $TESTPOOL2 -set_tunable32 zfs_livelist_condense_new_alloc 0 +set_tunable32 $LIVELIST_CONDENSE_NEW_ALLOC 0 # Trigger a condense log_must mkfile 10m /$TESTPOOL2/$TESTCLONE/A log_must zpool sync $TESTPOOL2 @@ -82,10 +83,10 @@ log_must zpool sync $TESTPOOL2 log_must mkfile 1m /$TESTPOOL2/$TESTCLONE/B # Resume condense thr -set_tunable32 zfs_livelist_condense_sync_pause 0 +set_tunable32 $LIVELIST_CONDENSE_SYNC_PAUSE 0 log_must zpool sync $TESTPOOL2 # Check that we've added new ALLOC blkptrs during the condense -[[ "0" < "$(get_tunable zfs_livelist_condense_new_alloc)" ]] || \ +[[ "0" < "$(get_tunable $LIVELIST_CONDENSE_NEW_ALLOC)" ]] || \ log_fail "removal/condense test failed" log_must zfs destroy $TESTPOOL2/$TESTCLONE diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/socket.c b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/socket.c index 2fe9de77c..a8c814e7b 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/socket.c +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/socket.c @@ -22,6 +22,7 @@ #include #include #include +#include /* ARGSUSED */ int diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh index 55dd8b66f..5efaff8cd 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh @@ -84,7 +84,11 @@ do continue; fi - filetime="$(stat -c '%Z' $file)" + if is_freebsd; then + filetime="$(stat -f "%c" $file)" + else + filetime="$(stat -c '%Z' $file)" + fi if [[ "$filetime" != "$ctime" ]]; then log_fail "Unexpected ctime for file $file ($filetime != $ctime)" else diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_types.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_types.ksh index 9c81084d1..8e521b9f5 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_types.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_types.ksh @@ -70,8 +70,13 @@ DATASET="$TESTPOOL/$TESTFS/fs" TESTSNAP1="$DATASET@snap1" TESTSNAP2="$DATASET@snap2" FILEDIFF="$TESTDIR/zfs-diff.txt" -MAJOR=$(stat -c %t /dev/null) -MINOR=$(stat -c %T /dev/null) +if is_freebsd; then + MAJOR=$(stat -f %Hr /dev/null) + MINOR=$(stat -f %Lr /dev/null) +else + MAJOR=$(stat -c %t /dev/null) + MINOR=$(stat -c %T /dev/null) +fi # 1. Prepare a dataset log_must zfs create $DATASET @@ -106,7 +111,11 @@ verify_object_class "$MNTPOINT/cdev" "C" # 2. | (Named pipe) log_must zfs snapshot "$TESTSNAP1" -log_must mknod "$MNTPOINT/fifo" p +if is_freebsd; then + log_must mkfifo "$MNTPOINT/fifo" +else + log_must mknod "$MNTPOINT/fifo" p +fi log_must zfs snapshot "$TESTSNAP2" verify_object_class "$MNTPOINT/fifo" "|" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh index 92d51944f..eeae5390f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_001_pos.ksh @@ -58,14 +58,19 @@ done typeset zfs_props=("type" used available creation volsize referenced \ compressratio mounted origin recordsize quota reservation mountpoint \ - sharenfs checksum compression atime devices exec readonly setuid zoned \ - snapdir acltype aclinherit canmount primarycache secondarycache \ - usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \ - version) - + sharenfs checksum compression atime devices exec readonly setuid \ + snapdir aclinherit canmount primarycache secondarycache version \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots) +if is_freebsd; then + typeset zfs_props_os=(jailed aclmode) +else + typeset zfs_props_os=(zoned acltype) +fi typeset userquota_props=(userquota@root groupquota@root userused@root \ groupused@root) -typeset all_props=("${zfs_props[@]}" "${userquota_props[@]}") +typeset all_props=("${zfs_props[@]}" \ + "${zfs_props_os[@]}" \ + "${userquota_props[@]}") typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP) diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh index f49f58e8c..c3746514e 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_002_pos.ksh @@ -49,13 +49,19 @@ typeset options=(" " p r H) typeset zfs_props=("type" used available creation volsize referenced \ compressratio mounted origin recordsize quota reservation mountpoint \ - sharenfs checksum compression atime devices exec readonly setuid zoned \ - snapdir acltype aclinherit canmount primarycache secondarycache \ - usedbychildren usedbydataset usedbyrefreservation usedbysnapshots version) - + sharenfs checksum compression atime devices exec readonly setuid \ + snapdir aclinherit canmount primarycache secondarycache version \ + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots) +if is_freebsd; then + typeset zfs_props_os=(jailed aclmode) +else + typeset zfs_props_os=(zoned acltype) +fi typeset userquota_props=(userquota@root groupquota@root userused@root \ groupused@root) -typeset props=("${zfs_props[@]}" "${userquota_props[@]}") +typeset props=("${zfs_props[@]}" \ + "${zfs_props_os[@]}" \ + "${userquota_props[@]}") typeset dataset=($TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTVOL@$TESTSNAP) diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh index 2de640f87..510c54506 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_005_neg.ksh @@ -47,13 +47,19 @@ verify_runnable "both" typeset val_opts=(p r H) typeset v_props=(type used available creation volsize referenced compressratio \ mounted origin recordsize quota reservation mountpoint sharenfs checksum \ - compression atime devices exec readonly setuid zoned snapdir acltype \ + compression atime devices exec readonly setuid snapdir version \ aclinherit canmount primarycache secondarycache \ - usedbychildren usedbydataset usedbyrefreservation usedbysnapshots version) - + usedbychildren usedbydataset usedbyrefreservation usedbysnapshots) +if is_freebsd; then + typeset v_props_os=(jailed aclmode) +else + typeset v_props_os=(zoned acltype) +fi typeset userquota_props=(userquota@root groupquota@root userused@root \ groupused@root) -typeset val_props=("${v_props[@]}" "${userquota_props[@]}") +typeset val_props=("${v_props[@]}" \ + "${v_props_os[@]}" \ + "${userquota_props[@]}") set -f # Force shell does not parse '?' and '*' as the wildcard typeset inval_opts=(P R h ? *) typeset inval_props=(Type 0 ? * -on --on readonl time USED RATIO MOUNTED) diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh index 29bd10d48..296fe9996 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_008_pos.ksh @@ -52,14 +52,19 @@ set -A options " " "-r" "-H" "-p" "-rHp" "-o name" \ set -A props type used available creation volsize referenced compressratio \ mounted origin recordsize quota reservation mountpoint sharenfs \ - checksum compression atime devices exec readonly setuid zoned snapdir \ - acltype aclinherit canmount primarycache secondarycache \ + checksum compression atime devices exec readonly setuid snapdir \ + aclinherit canmount primarycache secondarycache \ usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \ userquota@root groupquota@root userused@root groupused@root +if is_freebsd; then + set -A props ${props[*]} jailed aclmode +else + set -A props ${props[*]} zoned acltype +fi zfs upgrade -v > /dev/null 2>&1 if [[ $? -eq 0 ]]; then - set -A all_props ${all_props[*]} version + set -A props ${props[*]} version fi set -A dataset $TESTPOOL/$TESTCTR $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh index d4ebbb155..7fd6918b4 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_009_pos.ksh @@ -55,9 +55,14 @@ log_onexit depth_fs_cleanup set -A all_props type used available creation volsize referenced \ compressratio mounted origin recordsize quota reservation mountpoint \ sharenfs checksum compression atime devices exec readonly setuid \ - zoned snapdir acltype aclinherit canmount primarycache secondarycache \ + snapdir aclinherit canmount primarycache secondarycache \ usedbychildren usedbydataset usedbyrefreservation usedbysnapshots \ userquota@root groupquota@root userused@root groupused@root +if is_freebsd; then + set -A all_props ${all_props[*]} jailed aclmode +else + set -A all_props ${all_props[*]} zoned acltype +fi zfs upgrade -v > /dev/null 2>&1 if [[ $? -eq 0 ]]; then diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_005_pos.ksh index fc97520f5..c0cb693f6 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_005_pos.ksh @@ -44,13 +44,15 @@ # 2. Apply 'zfs set mountpoint=path '. # 3. Change directory to that given mountpoint. # 3. Invoke 'zfs mount '. -# 4. Verify that mount succeeds on Linux and fails for other platforms. +# 4. Verify that mount succeeds on Linux and FreeBSD and fails for other +# platforms. # verify_runnable "both" function cleanup { + [[ "$PWD" = "$TESTDIR" ]] && cd - log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS log_must force_unmount $TESTPOOL/$TESTFS return 0 @@ -74,7 +76,7 @@ cd $TESTDIR || \ zfs $mountcmd $TESTPOOL/$TESTFS ret=$? -if is_linux; then +if is_linux || is_freebsd; then (( ret == 0 )) || \ log_fail "'zfs $mountcmd $TESTPOOL/$TESTFS' " \ "unexpected return code of $ret." @@ -85,7 +87,7 @@ else fi log_note "Make sure the filesystem $TESTPOOL/$TESTFS is unmounted" -if is_linux; then +if is_linux || is_freebsd; then mounted $TESTPOOL/$TESTFS || \ log_fail Filesystem $TESTPOOL/$TESTFS is unmounted else diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh index 52ae1879d..ee5d30451 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_007_pos.ksh @@ -123,7 +123,8 @@ for property in ${properties[@]}; do # Set filesystem property temporarily reverse_opt=$(get_reverse_option $fs $property) - log_must zfs mount -o remount,$reverse_opt $fs + log_must zfs unmount $fs + log_must zfs mount -o $reverse_opt $fs cur_val=$(get_prop $property $fs) (($? != 0)) && log_fail "get_prop $property $fs" @@ -135,7 +136,7 @@ for property in ${properties[@]}; do "be enabled in LZ" fi elif [[ $orig_val == $cur_val ]]; then - log_fail "zfs mount -o remount,$reverse_opt " \ + log_fail "zfs mount -o $reverse_opt " \ "doesn't change property." fi @@ -146,7 +147,7 @@ for property in ${properties[@]}; do cur_val=$(get_prop $property $fs) (($? != 0)) && log_fail "get_prop $property $fs" if [[ $orig_val != $cur_val ]]; then - log_fail "zfs mount -o remount,$reverse_opt " \ + log_fail "zfs mount -o $reverse_opt " \ "change the property that is stored on disks" fi done diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_010_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_010_neg.ksh index 0b5d61f62..53ebf1f26 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_010_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_010_neg.ksh @@ -65,7 +65,7 @@ mpt=$(get_prop mountpoint $fs) log_must zfs umount $fs curpath=`dirname $0` cd $mpt -if is_linux; then +if is_linux || is_freebsd; then log_must zfs mount $fs else log_mustnot zfs mount $fs diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_012_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_012_neg.ksh index 19fb3b259..3e6799aa0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_012_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_012_neg.ksh @@ -18,7 +18,12 @@ # # DESCRIPTION: -# Verify that zfs mount should fail with a non-empty directory +# Linux: +# Verify that zfs mount fails with a non-empty directory +# FreeSD: +# Verify that zfs mount succeeds with a non-empty directory +# + # # STRATEGY: # 1. Unmount the dataset @@ -34,7 +39,13 @@ verify_runnable "both" -log_assert "zfs mount fails with non-empty directory" +if is_linux; then + behaves="fails" +else + behaves="succeeds" +fi + +log_assert "zfs mount $behaves with non-empty directory" fs=$TESTPOOL/$TESTFS @@ -44,7 +55,12 @@ log_must zfs set mountpoint=$TESTDIR $fs log_must zfs mount $fs log_must zfs umount $fs log_must touch $TESTDIR/testfile.$$ -log_mustnot zfs mount $fs +if is_linux; then + log_mustnot zfs mount $fs +else + log_must zfs mount $fs + log_must zfs umount $fs +fi log_must rm -rf $TESTDIR -log_pass "zfs mount fails non-empty directory as expected." +log_pass "zfs mount $behaves with non-empty directory as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail.ksh index d7fcd20af..93a47d7d6 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_all_fail.ksh @@ -30,7 +30,8 @@ # 1. Create zfs filesystems # 2. Unmount a leaf filesystem # 3. Create a file in the above filesystem's mountpoint -# 4. Verify that 'zfs mount -a' fails to mount the above +# 4. Verify that 'zfs mount -a' fails to mount the above if on Linux +# or succeeds if on FreeBSD # 5. Verify that all other filesystems were mounted # @@ -82,15 +83,22 @@ done # Create a stray file in one filesystem's mountpoint touch $path/0/strayfile -# Verify that zfs mount -a fails +# Verify that zfs mount -a fails on Linux or succeeds on FreeBSD export __ZFS_POOL_RESTRICT="$TESTPOOL" -log_mustnot zfs $mountall +if is_linux; then + log_mustnot zfs $mountall + log_mustnot mounted "$TESTPOOL/0" + typeset behaved="failed" +else + log_must zfs $mountall + log_must mounted "$TESTPOOL/0" + typeset behaved="succeeded" +fi unset __ZFS_POOL_RESTRICT -# All filesystems except for "0" should be mounted -log_mustnot mounted "$TESTPOOL/0" +# All other filesystems should be mounted for ((i=1; i<$fscount; i++)); do log_must mounted "$TESTPOOL/$i" done -log_pass "'zfs $mountall' failed as expected." +log_pass "'zfs $mountall' $behaved as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_remount.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_remount.ksh index 66a433865..9712c793a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_remount.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_remount.ksh @@ -53,6 +53,14 @@ function cleanup return 0 } +if is_freebsd; then + typeset RO="-t zfs -ur" + typeset RW="-t zfs -uw" +else + typeset RO="-o remount,ro" + typeset RW="-o remount,rw" +fi + # # Verify the $filesystem is mounted readonly # This is preferred over "log_mustnot touch $fs" because we actually want to @@ -76,8 +84,13 @@ function checkmount # dataset option { typeset dataset="$1" typeset option="$2" + typeset options="" - options="$(awk -v ds="$dataset" '$1 == ds { print $4 }' /proc/mounts)" + if is_freebsd; then + options=$(mount -p | awk -v ds="$dataset" '$1 == ds { print $4 }') + else + options=$(awk -v ds="$dataset" '$1 == ds { print $4 }' /proc/mounts) + fi if [[ "$options" == '' ]]; then log_fail "Dataset $dataset is not mounted" elif [[ ! -z "${options##*$option*}" ]]; then @@ -105,21 +118,23 @@ log_must mkdir -p $MNTPSNAP # 2. Verify we can (re)mount the dataset readonly/read-write log_must touch $MNTPFS/file.dat checkmount $TESTFS 'rw' -log_must mount -o remount,ro $TESTFS $MNTPFS +log_must mount $RO $TESTFS $MNTPFS readonlyfs $MNTPFS checkmount $TESTFS 'ro' -log_must mount -o remount,rw $TESTFS $MNTPFS +log_must mount $RW $TESTFS $MNTPFS log_must touch $MNTPFS/file.dat checkmount $TESTFS 'rw' -# 3. Verify we can (re)mount the snapshot readonly -log_must mount -t zfs $TESTSNAP $MNTPSNAP -readonlyfs $MNTPSNAP -checkmount $TESTSNAP 'ro' -log_must mount -o remount,ro $TESTSNAP $MNTPSNAP -readonlyfs $MNTPSNAP -checkmount $TESTSNAP 'ro' -log_must umount $MNTPSNAP +if is_linux; then + # 3. Verify we can (re)mount the snapshot readonly + log_must mount -t zfs $TESTSNAP $MNTPSNAP + readonlyfs $MNTPSNAP + checkmount $TESTSNAP 'ro' + log_must mount $RO $TESTSNAP $MNTPSNAP + readonlyfs $MNTPSNAP + checkmount $TESTSNAP 'ro' + log_must umount $MNTPSNAP +fi # 4. Verify we can't remount a snapshot read-write # The "mount -o rw" command will succeed but the snapshot is mounted readonly. @@ -127,7 +142,7 @@ log_must umount $MNTPSNAP log_must mount -t zfs -o rw $TESTSNAP $MNTPSNAP readonlyfs $MNTPSNAP checkmount $TESTSNAP 'ro' -log_mustnot mount -o remount,rw $TESTSNAP $MNTPSNAP +log_mustnot mount $RW $TESTSNAP $MNTPSNAP readonlyfs $MNTPSNAP checkmount $TESTSNAP 'ro' log_must umount $MNTPSNAP @@ -138,7 +153,7 @@ log_must eval "echo 'password' | zfs create -o sync=disabled \ -o encryption=on -o keyformat=passphrase $TESTFS/crypt" CRYPT_MNTPFS="$(get_prop mountpoint $TESTFS/crypt)" log_must touch $CRYPT_MNTPFS/file.dat -log_must mount -o remount,ro $TESTFS/crypt $CRYPT_MNTPFS +log_must mount $RO $TESTFS/crypt $CRYPT_MNTPFS log_must umount -f $CRYPT_MNTPFS zpool sync $TESTPOOL @@ -149,7 +164,7 @@ log_must zpool import -o readonly=on $TESTPOOL # 7. Verify we can't remount its filesystem read-write readonlyfs $MNTPFS checkmount $TESTFS 'ro' -log_mustnot mount -o remount,rw $MNTPFS +log_mustnot mount $RW $MNTPFS readonlyfs $MNTPFS checkmount $TESTFS 'ro' diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_multi_mount.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_multi_mount.ksh index e015d0aff..bd86eaa16 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_multi_mount.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_multi_mount.ksh @@ -59,7 +59,12 @@ log_must mkfile 128k $FILENAME log_must exec 9<> $FILENAME # open file # 3. Lazy umount -log_must umount -l $MNTPFS +if is_freebsd; then + # FreeBSD does not support lazy unmount + log_must umount $MNTPFS +else + log_must umount -l $MNTPFS +fi if [ -f $FILENAME ]; then log_fail "Lazy unmount failed" fi diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_incremental.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_incremental.ksh index c52a12e78..964c80657 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_incremental.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_incremental.ksh @@ -77,7 +77,7 @@ log_must eval "zfs send -w $snap1 | zfs receive $TESTPOOL/$TESTFS2" log_must eval "echo $passphrase2 | zfs change-key $TESTPOOL/$TESTFS1" log_must eval "zfs send -w -i $snap1 $snap2 > $ibackup" -typeset trunc_size=$(stat -c %s $ibackup) +typeset trunc_size=$(stat_size $ibackup) trunc_size=$(expr $trunc_size - 64) log_must cp $ibackup $ibackup_trunc log_must truncate -s $trunc_size $ibackup_trunc diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib index f69ec300c..fa494f9cb 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib @@ -76,8 +76,7 @@ function setup_snap_env # mount it. Otherwise, only check if this ufs|ext file system # was mounted. # - log_must eval "echo "y" | \ - newfs -v $ZVOL_DEVDIR/$VOL > /dev/null 2>&1" + log_must new_fs $ZVOL_DEVDIR/$VOL [[ ! -d $TESTDIR1 ]] && log_must mkdir $TESTDIR1 diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_007_pos.ksh index 5fdb125bc..da0aebe6b 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_007_pos.ksh @@ -89,7 +89,7 @@ test_pool () } test_pool $TESTPOOL -log_must truncate --size=1G $vdev +log_must truncate -s 1G $vdev log_must zpool create -o version=1 tmp_pool $vdev test_pool tmp_pool log_must zpool destroy tmp_pool diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_sparse.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_sparse.ksh index 735430506..e37c3f28a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_sparse.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_sparse.ksh @@ -57,8 +57,8 @@ function write_compare_files # # compare sparse files recvfile="$(get_prop mountpoint $recvfs)/data.bin" log_must cmp $sendfile $recvfile $offset $offset - sendsz=$(stat -c '%s' $sendfile) - recvsz=$(stat -c '%s' $recvfile) + sendsz=$(stat_size $sendfile) + recvsz=$(stat_size $recvfile) if [[ $sendsz -ne $recvsz ]]; then log_fail "$sendfile ($sendsz) and $recvfile ($recvsz) differ." fi diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh index 27003b21b..f30d00522 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/checksum_001_pos.ksh @@ -46,7 +46,10 @@ verify_runnable "both" set -A dataset "$TESTPOOL" "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTVOL" -set -A values "on" "off" "fletcher2" "fletcher4" "sha256" "sha512" "skein" "edonr" "noparity" +set -A values "on" "off" "fletcher2" "fletcher4" "sha256" "sha512" "skein" "noparity" +if is_linux; then + values+=("edonr") +fi log_assert "Setting a valid checksum on a file system, volume," \ "it should be successful." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos.ksh index 9bbb480ae..4d86100c0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/mountpoint_003_pos.ksh @@ -76,6 +76,14 @@ if is_linux; then if [[ $(linux_version) -lt $(linux_version "4.4") ]]; then args+=("mand" "nomand") fi +elif is_freebsd; then + # 'xattr' and 'devices' are not supported on FreeBSD + # Perhaps more options need to be added. + set -A args \ + "noexec" "exec" \ + "ro" "rw" \ + "nosuid" "suid" \ + "atime" "noatime" else set -A args \ "devices" "/devices/" "nodevices" "/nodevices/" \ @@ -96,11 +104,11 @@ log_must zfs set mountpoint=legacy $testfs typeset i=0 while ((i < ${#args[@]})); do - if is_linux; then + if is_linux || is_freebsd; then log_must mount -t zfs -o ${args[$i]} $testfs $tmpmnt msg=$(mount | grep "$tmpmnt ") - + echo $msg | grep "${args[((i))]}" > /dev/null 2>&1 if (($? != 0)) ; then echo $msg | grep "${args[((i-1))]}" > /dev/null 2>&1 diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/onoffs_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/onoffs_001_pos.ksh index 498567fdd..7ba6d7fb6 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/onoffs_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/onoffs_001_pos.ksh @@ -51,7 +51,12 @@ function cleanup log_onexit cleanup -set -A props "atime" "readonly" "setuid" "zoned" +set -A props "atime" "readonly" "setuid" +if is_freebsd; then + props+=("jailed") +else + props+=("zoned") +fi set -A values "on" "off" if is_global_zone ; then diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh index 9af8811e4..22fb0a77c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh @@ -113,7 +113,7 @@ function verify_readonly # $1 dataset, $2 on|off fi ;; volume) - $expect eval "echo 'y' | newfs \ + $expect eval "new_fs \ ${ZVOL_DEVDIR}/$dataset > /dev/null 2>&1" ;; *) diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_keylocation.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_keylocation.ksh index 313fa4e4d..00e7ff1a9 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_keylocation.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_keylocation.ksh @@ -64,7 +64,14 @@ log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 log_mustnot zfs set keylocation=none $TESTPOOL/$TESTFS1 -log_mustnot zfs set keylocation=/$TESTPOOL/pkey $TESTPOOL/$TESTFS1 +if is_linux; then + log_mustnot zfs set keylocation=/$TESTPOOL/pkey $TESTPOOL/$TESTFS1 +else + # file:///$TESTPOOL/pkey and /$TESTPOOL/pkey are equivalent on FreeBSD + # thanks to libfetch. Eventually we want to make the other platforms + # work this way as well, either by porting libfetch or by other means. + log_must zfs set keylocation=/$TESTPOOL/pkey $TESTPOOL/$TESTFS1 +fi log_must zfs set keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 log_must verify_keylocation $TESTPOOL/$TESTFS1 "file:///$TESTPOOL/pkey" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_sysfs/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_sysfs/cleanup.ksh index 79cd6e9f9..7d6a7e13d 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_sysfs/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_sysfs/cleanup.ksh @@ -27,4 +27,8 @@ . $STF_SUITE/include/libtest.shlib +if ! is_linux ; then + log_unsupported "sysfs is linux-only" +fi + default_cleanup diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_sysfs/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_sysfs/setup.ksh index 969238599..261bce438 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_sysfs/setup.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_sysfs/setup.ksh @@ -27,6 +27,10 @@ . $STF_SUITE/include/libtest.shlib +if ! is_linux ; then + log_unsupported "sysfs is linux-only" +fi + DISK=${DISKS%% *} default_container_volume_setup $DISK diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh index afec9d896..209497d9c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh @@ -133,7 +133,7 @@ done # Testing legacy mounted filesystem log_must zfs set mountpoint=legacy $fs1 -if is_linux; then +if is_linux || is_freebsd; then log_must mount -t zfs $fs1 /tmp/$dir else log_must mount -F zfs $fs1 /tmp/$dir diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh index 4cdc71123..9440e807f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_002_pos.ksh @@ -90,6 +90,10 @@ if is_linux; then echo "$corepath/core.zpool" >/proc/sys/kernel/core_pattern echo 0 >/proc/sys/kernel/core_uses_pid export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0" +elif is_freebsd; then + ulimit -c unlimited + log_must sysctl kern.corefile=$corepath/core.zpool + export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0" else coreadm -p ${corepath}/core.%f fi diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh index 0f04f0c04..5b9adf609 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool/zpool_003_pos.ksh @@ -65,6 +65,10 @@ if is_linux; then echo "core" >/proc/sys/kernel/core_pattern echo 0 >/proc/sys/kernel/core_uses_pid export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0" +elif is_freebsd; then + ulimit -c unlimited + log_must sysctl kern.corefile=$corepath/core.zpool + export ASAN_OPTIONS="abort_on_error=1:disable_coredump=0" fi ZFS_ABORT=1; export ZFS_ABORT diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/add_prop_ashift.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/add_prop_ashift.ksh index 29debe106..184c7e3de 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_add/add_prop_ashift.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_add/add_prop_ashift.ksh @@ -77,7 +77,7 @@ do for cmdval in ${ashifts[@]} do log_must zpool create -o ashift=$ashift $TESTPOOL $disk1 - log_must zpool add $TESTPOOL -o ashift=$cmdval $disk2 + log_must zpool add -o ashift=$cmdval $TESTPOOL $disk2 verify_ashift $disk2 $cmdval if [[ $? -ne 0 ]] then diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.cfg index e4429b2a8..b9e687c2b 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.cfg +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.cfg @@ -63,7 +63,7 @@ set_disks export SIZE="$(((MINVDEVSIZE / (1024 * 1024)) * 2))m" -if is_linux; then +if is_linux || is_freebsd; then set_device_dir set_slice_prefix export SLICE0=1 diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.kshlib b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.kshlib index 94615ee3a..9e3bf1795 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add.kshlib @@ -40,7 +40,7 @@ function find_vfstab_dev typeset vfstabdevs="" typeset line - if is_linux; then + if is_freebsd || is_linux; then vfstab="/etc/fstab" tmpfile="$TEST_BASE_DIR/fstab.tmp" else @@ -69,7 +69,12 @@ function find_mnttab_dev typeset mnttabdevs="" typeset line - if is_linux; then + if is_freebsd; then + # FreeBSD doesn't have a mnttab file. + mount -p | awk -v dir="^${DEV_DSKDIR}" \ + '$1 ~ dir { print $1 }' | xargs + return 0 + elif is_linux; then typeset mnttab="/etc/mtab" typeset tmpfile="$TEST_BASE_DIR/mtab.tmp" else @@ -97,7 +102,9 @@ function save_dump_dev typeset dumpdev - if is_linux; then + if is_freebsd; then + dumpdev=$(dumpon -l) + elif is_linux; then dumpdev="" else typeset fnd="Dump device" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_005_pos.ksh index 1516cb20a..8bffb94a7 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_add/zpool_add_005_pos.ksh @@ -56,7 +56,11 @@ function cleanup destroy_pool "$TESTPOOL1" if [[ -n $saved_dump_dev ]]; then - log_must eval "dumpadm -u -d $saved_dump_dev > /dev/null" + if is_freebsd; then + log_must eval "dumpon $saved_dump_dev > /dev/null" + else + log_must eval "dumpadm -u -d $saved_dump_dev > /dev/null" + fi fi partition_cleanup @@ -87,8 +91,12 @@ else fi if ! is_linux; then - log_must echo "y" | newfs ${DEV_DSKDIR}/$dump_dev > /dev/null 2>&1 - log_must dumpadm -u -d ${DEV_DSKDIR}/$dump_dev > /dev/null + log_must eval "new_fs ${DEV_DSKDIR}/$dump_dev > /dev/null 2>&1" + if is_freebsd; then + log_must eval "dumpon ${DEV_DSKDIR}/$dump_dev > /dev/null" + else + log_must eval "dumpadm -u -d ${DEV_DSKDIR}/$dump_dev > /dev/null" + fi log_mustnot zpool add -f "$TESTPOOL" $dump_dev fi diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib index 31244f4ec..51735f9c4 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create.shlib @@ -74,9 +74,7 @@ function create_blockfile log_must mkdir -p $dir fi - echo "y" | newfs ${DEV_RDSKDIR}/$disk >/dev/null 2>&1 - (( $? != 0 )) && - log_fail "Create file system fail." + log_must eval "new_fs ${DEV_RDSKDIR}/$disk >/dev/null 2>&1" log_must mount ${DEV_DSKDIR}/$disk $dir log_must truncate -s $size $file @@ -125,7 +123,7 @@ function find_vfstab_dev typeset vfstabdevs="" typeset line - if is_linux; then + if is_freebsd || is_linux; then vfstab="/etc/fstab" tmpfile="$TEST_BASE_DIR/fstab.tmp" else @@ -152,7 +150,9 @@ function save_dump_dev { typeset dumpdev - if is_linux; then + if is_freebsd; then + dumpdev=$(dumpon -l) + elif is_linux; then dumpdev="" else typeset fnd="Dump device" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh index b98e5ac92..ffbdd237d 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_002_pos.ksh @@ -76,8 +76,8 @@ else disk=$DISK0 fi create_pool "$TESTPOOL" "${disk}${SLICE_PREFIX}${SLICE0}" -log_must echo "y" | newfs \ - ${DEV_RDSKDIR}/${disk}${SLICE_PREFIX}${SLICE1} >/dev/null 2>&1 +log_must eval "new_fs \ + ${DEV_RDSKDIR}/${disk}${SLICE_PREFIX}${SLICE1} >/dev/null 2>&1" create_blockfile $FILESIZE $TESTDIR0/$FILEDISK0 ${disk}${SLICE_PREFIX}${SLICE4} create_blockfile $FILESIZE1 $TESTDIR1/$FILEDISK1 ${disk}${SLICE_PREFIX}${SLICE5} log_must truncate -s $SIZE $TEST_BASE_DIR/$FILEDISK0 diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg.ksh index 8ade2561f..4f2394f0c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_011_neg.ksh @@ -55,7 +55,11 @@ function cleanup done if [[ -n $saved_dump_dev ]]; then - log_must dumpadm -u -d $saved_dump_dev + if is_freebsd; then + log_must dumpon $saved_dump_dev + else + log_must dumpadm -u -d $saved_dump_dev + fi fi partition_disk $SIZE $disk 7 @@ -128,7 +132,11 @@ if ! is_linux; then log_must zpool create -f $TESTPOOL3 $disk log_must zpool destroy -f $TESTPOOL3 - log_must dumpadm -d ${DEV_DSKDIR}/$specified_dump_dev + if is_freebsd; then + log_must dumpon ${DEV_DSKDIR}/$specified_dump_dev + else + log_must dumpadm -d ${DEV_DSKDIR}/$specified_dump_dev + fi log_mustnot zpool create -f $TESTPOOL1 "$specified_dump_dev" # Also check to see that in-use checking prevents us from creating diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh index fc383be9b..64ffed5ec 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/zpool_create_014_neg.ksh @@ -82,7 +82,7 @@ typeset TMP_FILE=$mntp/tmpfile.$$ create_pool $TESTPOOL $pool_dev log_must zfs create -V 100m $vol_name block_device_wait -log_must echo "y" | newfs ${ZVOL_DEVDIR}/$vol_name > /dev/null 2>&1 +log_must eval "new_fs ${ZVOL_DEVDIR}/$vol_name > /dev/null 2>&1" log_must mount ${ZVOL_DEVDIR}/$vol_name $mntp log_must mkfile 50m $TMP_FILE diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg index 9dea1e2cd..566a56c1a 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_get/zpool_get.cfg @@ -82,8 +82,7 @@ typeset -a properties=( "feature@log_spacemap" ) -# Additional properties added for Linux. -if is_linux; then +if is_linux || is_freebsd; then properties+=( "ashift" "feature@large_dnode" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/setup.ksh index 9f0ccfb6c..6d7b0e156 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_import/setup.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_import/setup.ksh @@ -47,7 +47,7 @@ done typeset -i i=0 while (( i <= $GROUP_NUM )); do - if ! is_linux; then + if ! is_linux && ! is_freebsd; then if (( i == 2 )); then (( i = i + 1 )) continue diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg index 79423abe2..7a6bae34f 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import.cfg @@ -62,6 +62,13 @@ case "${#disk_array[*]}" in else log_fail "$ZFS_DISK1 not supported for partitioning." fi + elif is_freebsd; then + SLICE_PREFIX="p" + PRIMARY_SLICE=1 + DISK_COUNT=1 + ZFS_DISK1=${disk_array[0]} + ZFS_DISK2=${disk_array[0]} + ZFSSIDE_DISK1=${ZFS_DISK1}p1 else export DEV_DSKDIR="/dev" PRIMARY_SLICE=2 @@ -93,6 +100,12 @@ case "${#disk_array[*]}" in log_fail "$ZFS_DISK1 not supported for partitioning." fi ZFS_DISK2=${disk_array[1]} + elif is_freebsd; then + SLICE_PREFIX="p" + PRIMARY_SLICE=1 + DISK_COUNT=2 + ZFS_DISK1=${disk_array[0]} + ZFSSIDE_DISK1=${ZFS_DISK1}p1 else export DEV_DSKDIR="/dev" PRIMARY_SLICE=2 diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg b/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg index 85148d6e8..b2a10aa28 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_labelclear/labelclear.cfg @@ -16,6 +16,13 @@ . $STF_SUITE/include/libtest.shlib typeset disks=(${DISKS[*]}) -typeset disk1=${disks[0]} -typeset disk2=${disks[1]} -typeset disk3=${disks[2]} + +if is_freebsd; then + typeset disk1=/dev/${disks[0]} + typeset disk2=/dev/${disks[1]} + typeset disk3=/dev/${disks[2]} +else + typeset disk1=${disks[0]} + typeset disk2=${disks[1]} + typeset disk3=${disks[2]} +fi diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_remove/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_remove/setup.ksh index f3e36066e..c63e17945 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_remove/setup.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_remove/setup.ksh @@ -34,7 +34,7 @@ verify_runnable "global" -if ! $(is_physical_device $DISKS) ; then +if ! is_physical_device $DISKS ; then log_unsupported "This directory cannot be run on raw files." fi diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_reopen/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_reopen/cleanup.ksh index a9fcef790..25fced1ec 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_reopen/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_reopen/cleanup.ksh @@ -20,6 +20,10 @@ verify_runnable "global" +if ! is_linux; then + log_unsupported "scsi debug module unsupported" +fi + cleanup_devices $DISKS # Unplug the disk and remove scsi_debug module diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_vdevs.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_vdevs.ksh index b7ebe55cb..9866cf7a5 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_vdevs.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_split/zpool_split_vdevs.ksh @@ -125,7 +125,7 @@ do add_config="$(awk '{$1= "";print $0}' <<< $config)" log_must zpool create $TESTPOOL $(pool_config $create_config) for vdev in $add_config; do - log_must zpool add $TESTPOOL -f $(pool_config $vdev) + log_must zpool add -f $TESTPOOL $(pool_config $vdev) done log_must zpool split -R $altroot $TESTPOOL $TESTPOOL2 log_must poolexists $TESTPOOL2 @@ -140,7 +140,7 @@ do add_config="$(awk '{$1= "";print $0}' <<< $config)" log_must zpool create $TESTPOOL $(pool_config $create_config) for vdev in $add_config; do - log_must zpool add $TESTPOOL -f $(pool_config $vdev) + log_must zpool add -f $TESTPOOL $(pool_config $vdev) done log_mustnot zpool split -R $altroot $TESTPOOL $TESTPOOL2 log_mustnot poolexists $TESTPOOL2 diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/misc.cfg b/tests/zfs-tests/tests/functional/cli_user/misc/misc.cfg index 06d211ce1..af867ded5 100644 --- a/tests/zfs-tests/tests/functional/cli_user/misc/misc.cfg +++ b/tests/zfs-tests/tests/functional/cli_user/misc/misc.cfg @@ -54,6 +54,32 @@ if is_linux; then off /tmp/zfstest 100M off \ 512 10m off \ hidden" +elif is_freebsd; then + PROP_NAMES="\ + acltype atime \ + checksum compression devices \ + exec mountpoint quota readonly \ + recordsize reservation setuid \ + snapdir" + + # these are a set of values we apply, for use when testing the + # zfs get/set subcommands - ordered as per the list above so we + # can iterate over both sets in an array + PROP_VALS="\ + posixacl on \ + fletcher2 on on \ + on legacy none on \ + 128K none on \ + visible" + + # these are an alternate set of property values + PROP_ALTVALS="\ + noacl off \ + fletcher4 lzjb off \ + off /tmp/zfstest 100M off \ + 512 10m off \ + hidden" + else # these are the set of setable ZFS properties PROP_NAMES="\ diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_share_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_share_001_neg.ksh index 3f120c243..14c35b3da 100755 --- a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_share_001_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_share_001_neg.ksh @@ -45,7 +45,7 @@ verify_runnable "global" -if is_linux; then +if is_linux || is_freebsd; then log_unsupported "Requires additional dependencies" fi diff --git a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_unshare_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_unshare_001_neg.ksh index 72ed1f5d3..7ae86fc4e 100755 --- a/tests/zfs-tests/tests/functional/cli_user/misc/zfs_unshare_001_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_user/misc/zfs_unshare_001_neg.ksh @@ -45,7 +45,7 @@ verify_runnable "global" -if is_linux; then +if is_linux || is_freebsd; then log_unsupported "Requires additional dependencies" fi diff --git a/tests/zfs-tests/tests/functional/ctime/ctime.c b/tests/zfs-tests/tests/functional/ctime/ctime.c index 1cd183234..d01fa0d4e 100644 --- a/tests/zfs-tests/tests/functional/ctime/ctime.c +++ b/tests/zfs-tests/tests/functional/ctime/ctime.c @@ -31,7 +31,9 @@ #include #include +#ifndef __FreeBSD__ #include +#endif #include #include #include @@ -251,6 +253,7 @@ do_chown(const char *pfile) return (ret); } +#ifndef __FreeBSD__ static int do_xattr(const char *pfile) { @@ -268,6 +271,7 @@ do_xattr(const char *pfile) } return (ret); } +#endif static void cleanup(void) @@ -289,7 +293,9 @@ static timetest_t timetest_table[] = { { ST_CTIME, "st_ctime", do_chown }, { ST_CTIME, "st_ctime", do_link }, { ST_CTIME, "st_ctime", do_utime }, +#ifndef __FreeBSD__ { ST_CTIME, "st_ctime", do_xattr }, +#endif }; #define NCOMMAND (sizeof (timetest_table) / sizeof (timetest_table[0])) diff --git a/tests/zfs-tests/tests/functional/delegate/cleanup.ksh b/tests/zfs-tests/tests/functional/delegate/cleanup.ksh index 31a57590f..2d129fbc1 100755 --- a/tests/zfs-tests/tests/functional/delegate/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/delegate/cleanup.ksh @@ -43,6 +43,10 @@ if ! is_linux; then fi fi +if is_freebsd; then + log_must sysctl vfs.usermount=0 +fi + if is_linux; then log_must set_tunable64 zfs_admin_snapshot 0 fi diff --git a/tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib b/tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib index d088eaf37..6643f938d 100644 --- a/tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib +++ b/tests/zfs-tests/tests/functional/delegate/delegate_common.kshlib @@ -483,6 +483,7 @@ function verify_userprop typeset stamp=${perm}.${user}.$(date +'%F-%T-%N') user_run $user zfs set "$user:ts=$stamp" $dtst + zpool sync ${dtst%%/*} if [[ $stamp != $(get_prop "$user:ts" $dtst) ]]; then return 1 fi @@ -684,7 +685,7 @@ function verify_fs_destroy # Verify that given the correct delegation, a regular user can: # Take a snapshot of an unmounted dataset -# Take a snapshot of an mounted dataset +# Take a snapshot of a mounted dataset # Create a snapshot by making a directory in the .zfs/snapshot directory function verify_fs_snapshot { @@ -716,12 +717,15 @@ function verify_fs_snapshot fi log_must zfs destroy $snap - typeset snapdir=${mntpt}/.zfs/snapshot/snap.$stamp - user_run $user mkdir $snapdir - if ! datasetexists $snap ; then - return 1 + # Creating snaps via mkdir is not supported on FreeBSD + if ! is_freebsd; then + typeset snapdir=${mntpt}/.zfs/snapshot/snap.$stamp + user_run $user mkdir $snapdir + if ! datasetexists $snap ; then + return 1 + fi + log_must zfs destroy $snap fi - log_must zfs destroy $snap return 0 } diff --git a/tests/zfs-tests/tests/functional/delegate/setup.ksh b/tests/zfs-tests/tests/functional/delegate/setup.ksh index 149cf7869..d28e16375 100755 --- a/tests/zfs-tests/tests/functional/delegate/setup.ksh +++ b/tests/zfs-tests/tests/functional/delegate/setup.ksh @@ -44,6 +44,11 @@ if ! is_linux; then fi fi +if is_freebsd; then + # To pass user mount tests + log_must sysctl vfs.usermount=1 +fi + cleanup_user_group # Create staff group and add two user to it diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_001_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_001_pos.ksh index 3db1af509..1e0ed80d3 100755 --- a/tests/zfs-tests/tests/functional/delegate/zfs_allow_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/delegate/zfs_allow_001_pos.ksh @@ -83,7 +83,7 @@ if ! cat /etc/group | awk -F: '{print $1}' | \ grep -w 'everyone' > /dev/null 2>&1 then group_added="TRUE" - log_must groupadd everyone + log_must add_group everyone fi for dtst in $DATASETS ; do @@ -92,7 +92,7 @@ for dtst in $DATASETS ; do done log_must restore_root_datasets if [[ $group_added == "TRUE" ]]; then - log_must groupdel everyone + log_must del_group everyone fi log_pass "everyone is always interpreted as keyword passed." diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_010_pos.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_010_pos.ksh index 7b70e1322..ed9b852c3 100755 --- a/tests/zfs-tests/tests/functional/delegate/zfs_allow_010_pos.ksh +++ b/tests/zfs-tests/tests/functional/delegate/zfs_allow_010_pos.ksh @@ -87,6 +87,47 @@ set -A perms create true false \ promote true true \ xattr true false \ receive true false + +elif is_freebsd; then +# Results in Results in +# Permission Filesystem Volume +# +# Removed for FreeBSD +# - zoned - zones are not supported +# - sharenfs - sharing requires superuser privileges +# - share - sharing requires superuser privileges +# - xattr - Not supported on FreeBSD +# +set -A perms create true false \ + snapshot true true \ + mount true false \ + send true true \ + allow true true \ + quota true false \ + reservation true true \ + dnodesize true false \ + recordsize true false \ + mountpoint true false \ + checksum true true \ + compression true true \ + canmount true false \ + atime true false \ + devices true false \ + exec true false \ + volsize false true \ + setuid true false \ + readonly true true \ + snapdir true false \ + userprop true true \ + aclmode true false \ + aclinherit true false \ + rollback true true \ + clone true true \ + rename true true \ + promote true true \ + receive true false \ + destroy true true + else set -A perms create true false \ diff --git a/tests/zfs-tests/tests/functional/delegate/zfs_allow_012_neg.ksh b/tests/zfs-tests/tests/functional/delegate/zfs_allow_012_neg.ksh index 4da559bfc..e46de9760 100755 --- a/tests/zfs-tests/tests/functional/delegate/zfs_allow_012_neg.ksh +++ b/tests/zfs-tests/tests/functional/delegate/zfs_allow_012_neg.ksh @@ -61,6 +61,12 @@ set -A perms create snapshot mount send allow quota reservation \ devices exec volsize setuid readonly snapdir userprop \ rollback clone rename promote dnodesize \ zoned xattr receive destroy +elif is_freebsd; then +set -A perms create snapshot mount send allow quota reservation \ + recordsize mountpoint checksum compression canmount atime \ + devices exec volsize setuid readonly snapdir userprop \ + aclmode aclinherit rollback clone rename promote dnodesize \ + zoned receive destroy else set -A perms create snapshot mount send allow quota reservation \ recordsize mountpoint checksum compression canmount atime \ diff --git a/tests/zfs-tests/tests/functional/devices/devices_common.kshlib b/tests/zfs-tests/tests/functional/devices/devices_common.kshlib index 2c7df8d05..2148bae0a 100644 --- a/tests/zfs-tests/tests/functional/devices/devices_common.kshlib +++ b/tests/zfs-tests/tests/functional/devices/devices_common.kshlib @@ -42,83 +42,190 @@ function create_dev_file typeset filetype=$1 typeset filename=$2 + case $(uname) in + FreeBSD) + create_dev_file_freebsd "$filetype" "$filename" + ;; + Linux) + create_dev_file_linux "$filetype" "$filename" + ;; + *) + create_dev_file_illumos "$filetype" "$filename" + ;; + esac + + return 0 +} + +function create_dev_file_freebsd +{ + typeset filetype=$1 + typeset filename=$2 + case $filetype in - b) - if is_linux; then - major=$(awk '/[hsv]d/ { print $1; exit }' \ - /proc/partitions) - minor=$(awk '/[hsv]d/ { print $2; exit }' \ - /proc/partitions) - log_must mknod $filename b $major $minor - return 0 - fi - - devtype=$(df -n / | awk '{print $3}') - case $devtype in - zfs) - rootpool=$(df / | \ - awk '{print $2}') - rootpool=${rootpool#\(} - rootpool=${rootpool%%/*} - - devstr=$(get_disklist $rootpool) - devstr=$(echo "$devstr" | \ - awk '{print $1}') - [[ -z $devstr ]] && \ - log_fail "Can not get block device file." - devstr=$DEV_DSKDIR/${devstr} - ;; - ufs) - # - # Get the existing block device file in current system. - # And bring out the first one. - # - devstr=$(df-lhF ufs | \ - grep "^${DEV_DSKDIR}" | \ - awk '{print $1}') - devstr=$(echo "$devstr" | \ - awk '{print $1}') - [[ -z $devstr ]] && \ - log_fail "Can not get block device file." - ;; - *) - log_unsupported "Unsupported fstype " \ - "for / ($devtype)," \ - "only ufs|zfs is supported." - ;; - esac - - # - # Get the device file information. i.e: - # $DEV_DSKDIR/c0t0d0s0: block special (28/768) - # - devstr=$(file $devstr) - - # - # Bring out major and minor number. - # - major=${devstr##*\(} - major=${major%%/*} - minor=${devstr##*/} - minor=${minor%\)} - - log_must mknod $filename b $major $minor + b) + devtype=$(df -T / | grep -v "Type" | awk '{print $2}') + case $devtype in + zfs) + rootpool=$(df / | grep -v "Filesystem" | \ + awk '{print $2}') + rootpool=${rootpool#\(} + rootpool=${rootpool%%/*} + + devstr=$(get_disklist $rootpool) + devstr=$(echo "$devstr" | \ + awk '{print $1}') + [[ -z $devstr ]] && \ + log_fail "Can not get block device file." + devstr=/dev/${devstr} ;; - c) - # - # Create device file '/dev/null' - # - if is_linux; then - major=$(stat -c %t /dev/null) - minor=$(stat -c %T /dev/null) - log_must mknod $filename c $major $minor - else - log_must mknod $filename c $(getmajor mm) 2 - fi + ufs) + # + # Get the existing block device file in current system. + # And bring out the first one. + # + devstr=$(df -t ufs | \ + grep "^/dev/" | \ + head -n 1 | \ + awk '{print $1}') + devstr=$(echo "$devstr" | \ + awk '{print $1}') + [[ -z $devstr ]] && \ + log_fail "Can not get block device file." ;; *) - log_fail "'$filetype' is wrong." + log_unsupported "Unsupported fstype " \ + "for / ($devtype)," \ + "only ufs|zfs is supported." ;; + esac + + # + # Get the device file information. i.e: + # /dev/c0t0d0s0: block special (28/768) + # + devstr=$(file $devstr) + + # + # Bring out major and minor number. + # + major=${devstr##*\(} + major=${major%%/*} + minor=${devstr##*/} + minor=${minor%\)} + + log_must mknod $filename b $major $minor + ;; + c) + # + # Create device file '/dev/null' + # + log_must mknod $filename c 13 2 + ;; + *) + log_fail "'$filetype' is wrong." + ;; + esac + + return 0 +} + +function create_dev_file_illumos +{ + typeset filetype=$1 + typeset filename=$2 + + case $filetype in + b) + devtype=$(df -n / | awk '{print $3}') + case $devtype in + zfs) + rootpool=$(df / | \ + awk '{print $2}') + rootpool=${rootpool#\(} + rootpool=${rootpool%%/*} + + devstr=$(get_disklist $rootpool) + devstr=$(echo "$devstr" | \ + awk '{print $1}') + [[ -z $devstr ]] && \ + log_fail "Can not get block device file." + devstr=$DEV_DSKDIR/${devstr} + ;; + ufs) + # + # Get the existing block device file in current system. + # And bring out the first one. + # + devstr=$(df-lhF ufs | \ + grep "^${DEV_DSKDIR}" | \ + awk '{print $1}') + devstr=$(echo "$devstr" | \ + awk '{print $1}') + [[ -z $devstr ]] && \ + log_fail "Can not get block device file." + ;; + *) + log_unsupported "Unsupported fstype " \ + "for / ($devtype)," \ + "only ufs|zfs is supported." + ;; + esac + + # + # Get the device file information. i.e: + # $DEV_DSKDIR/c0t0d0s0: block special (28/768) + # + devstr=$(file $devstr) + + # + # Bring out major and minor number. + # + major=${devstr##*\(} + major=${major%%/*} + minor=${devstr##*/} + minor=${minor%\)} + + log_must mknod $filename b $major $minor + ;; + c) + # + # Create device file '/dev/null' + # + log_must mknod $filename c $(getmajor mm) 2 + ;; + *) + log_fail "'$filetype' is wrong." + ;; + esac + + return 0 +} + +create_dev_file_linux +{ + typeset filetype=$1 + typeset filename=$2 + + case $filetype in + b) + major=$(awk '/[hsv]d/ { print $1; exit }' \ + /proc/partitions) + minor=$(awk '/[hsv]d/ { print $2; exit }' \ + /proc/partitions) + log_must mknod $filename b $major $minor + ;; + c) + # + # Create device file '/dev/null' + # + major=$(stat -c %t /dev/null) + minor=$(stat -c %T /dev/null) + log_must mknod $filename c $major $minor + ;; + *) + log_fail "'$filetype' is wrong." + ;; esac return 0 diff --git a/tests/zfs-tests/tests/functional/fault/auto_spare_002_pos.ksh b/tests/zfs-tests/tests/functional/fault/auto_spare_002_pos.ksh index 63aaead08..f6d720a01 100755 --- a/tests/zfs-tests/tests/functional/fault/auto_spare_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/fault/auto_spare_002_pos.ksh @@ -50,8 +50,11 @@ log_assert "Testing automated auto-spare FMA test" log_onexit cleanup -# Clear events from previous runs -zed_events_drain +# Events not supported on FreeBSD +if ! is_freebsd; then + # Clear events from previous runs + zed_events_drain +fi TESTFILE="/$TESTPOOL/$TESTFS/testfile" diff --git a/tests/zfs-tests/tests/functional/fault/auto_spare_multiple.ksh b/tests/zfs-tests/tests/functional/fault/auto_spare_multiple.ksh index 25c23aecc..bec413527 100755 --- a/tests/zfs-tests/tests/functional/fault/auto_spare_multiple.ksh +++ b/tests/zfs-tests/tests/functional/fault/auto_spare_multiple.ksh @@ -53,8 +53,11 @@ function cleanup log_assert "ZED should be able to handle multiple faulted devices" log_onexit cleanup -# Clear events from previous runs -zed_events_drain +# Events not supported on FreeBSD +if ! is_freebsd; then + # Clear events from previous runs + zed_events_drain +fi FAULT_DEV1="$TEST_BASE_DIR/fault-dev1" FAULT_DEV2="$TEST_BASE_DIR/fault-dev2" diff --git a/tests/zfs-tests/tests/functional/fault/decompress_fault.ksh b/tests/zfs-tests/tests/functional/fault/decompress_fault.ksh index ea831efdf..2b3998049 100755 --- a/tests/zfs-tests/tests/functional/fault/decompress_fault.ksh +++ b/tests/zfs-tests/tests/functional/fault/decompress_fault.ksh @@ -31,9 +31,15 @@ log_assert "Testing that injected decompression errors are handled correctly" +if is_freebsd; then + COMPRESSION=compressed_arc_enabled +else + COMPRESSION=zfs_compressed_arc_enabled +fi + function cleanup { - log_must set_tunable64 zfs_compressed_arc_enabled 1 + log_must set_tunable64 $COMPRESSION 1 log_must zinject -c all default_cleanup_noexit } @@ -41,15 +47,18 @@ function cleanup log_onexit cleanup default_mirror_setup_noexit $DISK1 $DISK2 -log_must set_tunable64 zfs_compressed_arc_enabled 0 +log_must set_tunable64 $COMPRESSION 0 log_must zfs create -o compression=on $TESTPOOL/fs mntpt=$(get_prop mountpoint $TESTPOOL/fs) -write_compressible $mntpt 32m 1 0 "testfile" +write_compressible $mntpt 32m 1 1024k "testfile" log_must sync log_must zfs umount $TESTPOOL/fs log_must zfs mount $TESTPOOL/fs log_must zinject -a -t data -e decompress -f 20 $mntpt/testfile.0 log_mustnot eval "cat $mntpt/testfile.0 > /dev/null" -log_must eval "zpool events $TESTPOOL | grep -q 'data'" +if ! is_freebsd; then + # Events are not supported on FreeBSD + log_must eval "zpool events $TESTPOOL | grep -q 'data'" +fi log_pass "Injected decompression errors are handled correctly" diff --git a/tests/zfs-tests/tests/functional/fault/decrypt_fault.ksh b/tests/zfs-tests/tests/functional/fault/decrypt_fault.ksh index ca698f778..d81c4b2bd 100755 --- a/tests/zfs-tests/tests/functional/fault/decrypt_fault.ksh +++ b/tests/zfs-tests/tests/functional/fault/decrypt_fault.ksh @@ -50,6 +50,9 @@ log_must zfs umount $TESTPOOL/fs log_must zfs mount $TESTPOOL/fs log_mustnot eval "cat $mntpt/file1 > /dev/null" -log_must eval "zpool events $TESTPOOL | grep -q 'authentication'" +# Events are not supported on FreeBSD +if ! is_freebsd; then + log_must eval "zpool events $TESTPOOL | grep -q 'authentication'" +fi log_pass "Injected decryption errors are handled correctly" diff --git a/tests/zfs-tests/tests/functional/history/history_002_pos.ksh b/tests/zfs-tests/tests/functional/history/history_002_pos.ksh index 553328745..7055413e8 100755 --- a/tests/zfs-tests/tests/functional/history/history_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/history/history_002_pos.ksh @@ -88,6 +88,31 @@ props=( compression gzip compression gzip-$((RANDOM%9 + 1)) copies $((RANDOM%3 + 1)) ) +elif is_freebsd; then +# property value property value +# +props=( + quota 64M recordsize 512 + reservation 32M reservation none + mountpoint /history.$$ mountpoint legacy + mountpoint none sharenfs on + sharenfs off + compression on compression off + compression lzjb aclmode discard + aclmode groupmask aclmode passthrough + atime on atime off + devices on devices off + exec on exec off + setuid on setuid off + readonly on readonly off + zoned on zoned off + snapdir hidden snapdir visible + aclinherit discard aclinherit noallow + aclinherit secure aclinherit passthrough + canmount off canmount on + compression gzip compression gzip-$((RANDOM%9 + 1)) + copies $((RANDOM%3 + 1)) +) else # property value property value # diff --git a/tests/zfs-tests/tests/functional/history/history_007_pos.ksh b/tests/zfs-tests/tests/functional/history/history_007_pos.ksh index d1c92c5e7..0504e1765 100755 --- a/tests/zfs-tests/tests/functional/history/history_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/history/history_007_pos.ksh @@ -73,7 +73,7 @@ for arch in "i386" "sparc"; do cat $orig_cmds_f | grep -v "^$" > $orig_cmds_f1 log_must cp $tst_dir/${arch}.migratedpool.DAT.Z $import_dir - log_must uncompress $import_dir/${arch}.migratedpool.DAT.Z + log_must uncompress -f $import_dir/${arch}.migratedpool.DAT.Z # destroy the pool with same name, so that import operation succeeds. poolexists $migratedpoolname && \ diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_001_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_001_pos.ksh index aecdc5a3b..e2668fe14 100755 --- a/tests/zfs-tests/tests/functional/inuse/inuse_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/inuse/inuse_001_pos.ksh @@ -43,8 +43,8 @@ verify_runnable "global" -if is_linux; then - log_unsupported "Test case isn't applicable to Linux" +if is_linux || is_freebsd; then + log_unsupported "Test case isn't applicable to Linux/FreeBSD" fi function cleanup diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_003_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_003_pos.ksh index bdd79d9c4..3a218f40f 100755 --- a/tests/zfs-tests/tests/functional/inuse/inuse_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/inuse/inuse_003_pos.ksh @@ -50,8 +50,8 @@ verify_runnable "global" -if is_linux; then - log_unsupported "Test case isn't applicable to Linux" +if is_linux || is_freebsd; then + log_unsupported "Test case isn't applicable to Linux/FreeBSD" fi function cleanup @@ -109,7 +109,7 @@ for num in 0 1 2; do done log_note "Make a ufs filesystem on source $rawdisk1" -echo "y" | newfs -v $rawdisk1 > /dev/null 2>&1 +new_fs $rawdisk1 > /dev/null 2>&1 (($? != 0)) && log_untested "Unable to create ufs filesystem on $rawdisk1" log_must mkdir -p $UFSMP diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_004_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_004_pos.ksh index b126f66a0..a9725e06d 100755 --- a/tests/zfs-tests/tests/functional/inuse/inuse_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/inuse/inuse_004_pos.ksh @@ -72,6 +72,9 @@ function mini_format if is_linux; then parted $disk -s -- mklabel gpt typeset -i retval=$? + elif is_freebsd; then + gpart create -s gpt $disk + typeset -i retval=$? else typeset format_file=$TEST_BASE_DIR/format_in.$$.1 echo "partition" > $format_file diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_005_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_005_pos.ksh index 6b0abf429..71e742f30 100755 --- a/tests/zfs-tests/tests/functional/inuse/inuse_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/inuse/inuse_005_pos.ksh @@ -63,10 +63,10 @@ function verify_assertion #slices typeset targets=$1 for t in $targets; do - echo "y" | newfs -v $t > /dev/null 2>&1 - (( $? !=0 )) || \ + if new_fs $t; then log_fail "newfs over active pool " \ - "unexpected return code of 0" + "unexpected return code of 0" + fi done return 0 diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_006_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_006_pos.ksh index 0ce45a661..ae97620f5 100755 --- a/tests/zfs-tests/tests/functional/inuse/inuse_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/inuse/inuse_006_pos.ksh @@ -44,8 +44,8 @@ verify_runnable "global" -if is_linux; then - log_unsupported "Test case isn't applicable to Linux" +if is_linux || is_freebsd; then + log_unsupported "Test case isn't applicable to Linux/FreeBSD" fi function cleanup diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_007_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_007_pos.ksh index 22ac064ef..e2d7c4a97 100755 --- a/tests/zfs-tests/tests/functional/inuse/inuse_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/inuse/inuse_007_pos.ksh @@ -45,8 +45,8 @@ verify_runnable "global" -if is_linux; then - log_unsupported "Test case isn't applicable to Linux" +if is_linux || is_freebsd; then + log_unsupported "Test case isn't applicable to Linux/FreeBSD" fi function cleanup diff --git a/tests/zfs-tests/tests/functional/inuse/inuse_008_pos.ksh b/tests/zfs-tests/tests/functional/inuse/inuse_008_pos.ksh index 1f5510ae5..d549896ca 100755 --- a/tests/zfs-tests/tests/functional/inuse/inuse_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/inuse/inuse_008_pos.ksh @@ -66,10 +66,10 @@ function verify_assertion #slices typeset targets=$1 for t in $targets; do - echo "y" | newfs -v $t > /dev/null 2>&1 - (( $? !=0 )) && \ + if ! new_fs $t; then log_fail "newfs over exported pool " \ "fails unexpectedly." + fi done return 0 diff --git a/tests/zfs-tests/tests/functional/migration/setup.ksh b/tests/zfs-tests/tests/functional/migration/setup.ksh index cae66aa5b..58edc0a92 100755 --- a/tests/zfs-tests/tests/functional/migration/setup.ksh +++ b/tests/zfs-tests/tests/functional/migration/setup.ksh @@ -57,9 +57,9 @@ log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS rm -rf $NONZFS_TESTDIR || log_unresolved Could not remove $NONZFS_TESTDIR mkdir -p $NONZFS_TESTDIR || log_unresolved Could not create $NONZFS_TESTDIR -echo "y" | newfs -v ${DEV_DSKDIR}/$NONZFS_DISK +new_fs ${DEV_DSKDIR}/$NONZFS_DISK (( $? != 0 )) && - log_untested "Unable to setup a UFS file system" + log_untested "Unable to setup a $NEWFS_DEFAULT_FS file system" log_must mount ${DEV_DSKDIR}/$NONZFS_DISK $NONZFS_TESTDIR diff --git a/tests/zfs-tests/tests/functional/mount/umountall_001.ksh b/tests/zfs-tests/tests/functional/mount/umountall_001.ksh index b8c89c623..814c831e4 100755 --- a/tests/zfs-tests/tests/functional/mount/umountall_001.ksh +++ b/tests/zfs-tests/tests/functional/mount/umountall_001.ksh @@ -45,6 +45,8 @@ zfs_list="/ /lib /sbin /tmp /usr /var /var/adm /var/run" # Append our ZFS filesystems to the list, not worrying about duplicates. if is_linux; then typeset mounts=$(mount | awk '{if ($5 == "zfs") print $3}') +elif is_freebsd; then + typeset mounts=$(mount -p | awk '{if ($3 == "zfs") print $2}') else typeset mounts=$(mount -p | awk '{if ($4 == "zfs") print $3}') fi @@ -60,6 +62,9 @@ if is_linux; then if [[ -z $mounts ]]; then mounts=$(awk '/zfs/ { print $2 }' /proc/mounts) fi +elif is_freebsd; then + # Umountall and umount not supported on FreeBSD + mounts=$(mount -t zfs | sort -r | awk '{print $3}') else mounts=$(umountall -n -F zfs 2>&1 | awk '{print $2}') fi diff --git a/tests/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib b/tests/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib index 24b3fab38..6b925501b 100644 --- a/tests/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib +++ b/tests/zfs-tests/tests/functional/mv_files/mv_files_common.kshlib @@ -152,8 +152,7 @@ function generate_files # function mv_files { - - find $1 -type f -print | xargs -i \ + find $1 -type f -print | xargs -I "{}" \ mv {} $2 > /dev/null 2>&1 } diff --git a/tests/zfs-tests/tests/functional/no_space/enospc_003_pos.ksh b/tests/zfs-tests/tests/functional/no_space/enospc_003_pos.ksh index 40aa50024..a5643a0cb 100755 --- a/tests/zfs-tests/tests/functional/no_space/enospc_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/no_space/enospc_003_pos.ksh @@ -51,7 +51,7 @@ log_onexit cleanup log_assert "ENOSPC is returned on pools with large physical block size" -log_must zpool create $TESTPOOL1 -o ashift=13 $DISK_LARGE +log_must zpool create -o ashift=13 $TESTPOOL1 $DISK_LARGE log_must zfs set mountpoint=$TESTDIR $TESTPOOL1 log_must zfs set compression=off $TESTPOOL1 log_must zfs set recordsize=512 $TESTPOOL1 diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh index 4d06cfe4a..039b661e2 100755 --- a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh +++ b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh @@ -51,6 +51,10 @@ if is_linux; then o_atime=$(stat -c %X $TESTDIR/clone/file) o_ctime=$(stat -c %Z $TESTDIR/clone/file) o_mtime=$(stat -c %Y $TESTDIR/clone/file) +elif is_freebsd; then + o_atime=$(stat -f "%a" $TESTDIR/clone/file) + o_ctime=$(stat -f "%c" $TESTDIR/clone/file) + o_mtime=$(stat -f "%m" $TESTDIR/clone/file) else o_atime=$(ls -E% all $TESTDIR/clone/file | awk '/atime/ {print $4}') o_ctime=$(ls -E% all $TESTDIR/clone/file | awk '/ctime/ {print $4}') @@ -66,6 +70,10 @@ if is_linux; then atime=$(stat -c %X $TESTDIR/clone/file) ctime=$(stat -c %Z $TESTDIR/clone/file) mtime=$(stat -c %Y $TESTDIR/clone/file) +elif is_freebsd; then + atime=$(stat -f "%a" $TESTDIR/clone/file) + ctime=$(stat -f "%c" $TESTDIR/clone/file) + mtime=$(stat -f "%m" $TESTDIR/clone/file) else atime=$(ls -E% all $TESTDIR/clone/file | awk '/atime/ {print $4}') ctime=$(ls -E% all $TESTDIR/clone/file | awk '/ctime/ {print $4}') diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh index 126a00ea1..a118b9822 100755 --- a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh +++ b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh @@ -51,6 +51,7 @@ zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone $origin@a $clone log_must zfs set compress=on $clone log_must zfs set checksum=sha256 $clone +block_device_wait dd if=$vol of=$volclone bs=8192 count=4096 conv=notrunc >/dev/null 2>&1 || \ log_fail "dd into $clone failed." log_must verify_nopwrite $origin $origin@a $clone diff --git a/tests/zfs-tests/tests/functional/privilege/cleanup.ksh b/tests/zfs-tests/tests/functional/privilege/cleanup.ksh index 45a6a0f76..99985c670 100755 --- a/tests/zfs-tests/tests/functional/privilege/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/privilege/cleanup.ksh @@ -31,7 +31,7 @@ . $STF_SUITE/include/libtest.shlib -if is_linux; then +if is_linux || is_freebsd; then log_unsupported "Privilege tests require pfexec command" fi diff --git a/tests/zfs-tests/tests/functional/privilege/privilege_001_pos.ksh b/tests/zfs-tests/tests/functional/privilege/privilege_001_pos.ksh index ae869380d..af4f70567 100755 --- a/tests/zfs-tests/tests/functional/privilege/privilege_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/privilege/privilege_001_pos.ksh @@ -57,7 +57,7 @@ # We can only run this in the global zone verify_runnable "global" -if is_linux; then +if is_linux || is_freebsd; then log_unsupported "Requires pfexec command" fi diff --git a/tests/zfs-tests/tests/functional/privilege/privilege_002_pos.ksh b/tests/zfs-tests/tests/functional/privilege/privilege_002_pos.ksh index 22cfaf55d..ab00e3295 100755 --- a/tests/zfs-tests/tests/functional/privilege/privilege_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/privilege/privilege_002_pos.ksh @@ -60,7 +60,7 @@ verify_runnable "both" -if is_linux; then +if is_linux || is_freebsd; then log_unsupported "Requires pfexec command" fi diff --git a/tests/zfs-tests/tests/functional/privilege/setup.ksh b/tests/zfs-tests/tests/functional/privilege/setup.ksh index 94576d835..5ee593a7c 100755 --- a/tests/zfs-tests/tests/functional/privilege/setup.ksh +++ b/tests/zfs-tests/tests/functional/privilege/setup.ksh @@ -31,7 +31,7 @@ . $STF_SUITE/include/libtest.shlib -if is_linux; then +if is_linux || is_freebsd; then log_unsupported "Requires pfexec command" fi diff --git a/tests/zfs-tests/tests/functional/procfs/procfs_list_concurrent_readers.ksh b/tests/zfs-tests/tests/functional/procfs/procfs_list_concurrent_readers.ksh index 473de5c84..6ca7fd7d6 100755 --- a/tests/zfs-tests/tests/functional/procfs/procfs_list_concurrent_readers.ksh +++ b/tests/zfs-tests/tests/functional/procfs/procfs_list_concurrent_readers.ksh @@ -75,7 +75,7 @@ msgs2=$(mktemp) || log_fail # Truncate the result of the read that completed second in case it picked up an # extra message that was logged after the first read completed. # -log_must truncate -s $(stat -c "%s" $msgs1) $msgs2 +log_must truncate -s $(stat_size $msgs1) $msgs2 log_must diff $msgs1 $msgs2 diff --git a/tests/zfs-tests/tests/functional/procfs/setup.ksh b/tests/zfs-tests/tests/functional/procfs/setup.ksh index b3812dbdc..fd022ee61 100755 --- a/tests/zfs-tests/tests/functional/procfs/setup.ksh +++ b/tests/zfs-tests/tests/functional/procfs/setup.ksh @@ -26,9 +26,5 @@ . $STF_SUITE/include/libtest.shlib -if ! is_linux ; then - log_unsupported "procfs is only used on Linux" -fi - default_mirror_setup $DISKS log_pass diff --git a/tests/zfs-tests/tests/functional/quota/quota.kshlib b/tests/zfs-tests/tests/functional/quota/quota.kshlib index 082a77c03..0ffe6394b 100644 --- a/tests/zfs-tests/tests/functional/quota/quota.kshlib +++ b/tests/zfs-tests/tests/functional/quota/quota.kshlib @@ -33,6 +33,8 @@ # BLOCK_SIZE, QUOTA_VALUE and TOLERANCE set in quota.cfg if is_linux; then readonly EDQUOT=122 +elif is_freebsd; then + readonly EDQUOT=69 else readonly EDQUOT=49 fi diff --git a/tests/zfs-tests/tests/functional/redacted_send/redacted_holes.ksh b/tests/zfs-tests/tests/functional/redacted_send/redacted_holes.ksh index 47063848f..783851494 100755 --- a/tests/zfs-tests/tests/functional/redacted_send/redacted_holes.ksh +++ b/tests/zfs-tests/tests/functional/redacted_send/redacted_holes.ksh @@ -109,8 +109,8 @@ for i in {1..31} {97..256}; do "File f$i did not match in the send and recv datasets." done for i in {32..96}; do - file_size=$(stat -c %s $send_mnt/manyrm/f$i) - redacted_size=$(stat -c %s $recv_mnt/f$i) + file_size=$(stat_size $send_mnt/manyrm/f$i) + redacted_size=$(stat_size $recv_mnt/f$i) [[ $file_size -eq $redacted_size ]] || log_fail \ "File f$i has size $file_size and redacted size $redacted_size" done diff --git a/tests/zfs-tests/tests/functional/removal/removal.kshlib b/tests/zfs-tests/tests/functional/removal/removal.kshlib index 360b06d53..31e31ace6 100644 --- a/tests/zfs-tests/tests/functional/removal/removal.kshlib +++ b/tests/zfs-tests/tests/functional/removal/removal.kshlib @@ -97,7 +97,7 @@ function random_write # file write_size { typeset file=$1 typeset block_size=$2 - typeset file_size=$(stat -c%s $file 2>/dev/null) + typeset file_size=$(stat_size $file 2>/dev/null) typeset nblocks=$((file_size / block_size)) [[ -w $file ]] || return 1 diff --git a/tests/zfs-tests/tests/functional/removal/removal_remap_deadlists.ksh b/tests/zfs-tests/tests/functional/removal/removal_remap_deadlists.ksh index 6db3587c5..934802286 100755 --- a/tests/zfs-tests/tests/functional/removal/removal_remap_deadlists.ksh +++ b/tests/zfs-tests/tests/functional/removal/removal_remap_deadlists.ksh @@ -34,7 +34,7 @@ log_must zfs snapshot $TESTPOOL/$TESTFS@snap-pre2 log_must dd if=/dev/zero of=$TESTDIR/file bs=1024k count=100 \ conv=notrunc seek=200 -if is_linux; then +if is_linux || is_freebsd; then log_must attempt_during_removal $TESTPOOL $REMOVEDISK zdb -cd $TESTPOOL else log_must attempt_during_removal $TESTPOOL $REMOVEDISK diff --git a/tests/zfs-tests/tests/functional/rootpool/rootpool_007_pos.ksh b/tests/zfs-tests/tests/functional/rootpool/rootpool_007_pos.ksh index e355a0f1f..e4d4268cc 100755 --- a/tests/zfs-tests/tests/functional/rootpool/rootpool_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/rootpool/rootpool_007_pos.ksh @@ -45,9 +45,13 @@ verify_runnable "global" function cleanup { - log_must zfs set compression=$orig_compress $rootfs + [[ -n "$orig_compress" ]] && \ + log_must zfs set compression=$orig_compress $rootfs } +typeset assert_msg="the zfs rootfs's compression property can be set to \ + gzip and gzip[1-9]" + log_onexit cleanup log_assert $assert_msg @@ -55,9 +59,6 @@ typeset rootpool=$(get_rootpool) typeset rootfs=$(get_pool_prop bootfs $rootpool) typeset orig_compress=$(get_prop compression $rootfs) -typeset assert_msg="the zfs rootfs's compression property can be set to \ - gzip and gzip[1-9]" - set -A gtype "gzip" "gzip-1" "gzip-2" "gzip-3" "gzip-4" "gzip-5" \ "gzip-6" "gzip-7" "gzip-8" "gzip-9" diff --git a/tests/zfs-tests/tests/functional/rootpool/setup.ksh b/tests/zfs-tests/tests/functional/rootpool/setup.ksh index 5c3e56b91..8d8097108 100755 --- a/tests/zfs-tests/tests/functional/rootpool/setup.ksh +++ b/tests/zfs-tests/tests/functional/rootpool/setup.ksh @@ -37,6 +37,6 @@ verify_runnable "global" # This functionality is supported under Linux, but these test cases # are disabled by default since they manipulate the systems root pool. # -if is_linux; then +if is_linux || is_freebsd; then log_unsupported "Supported but disabled by default" fi diff --git a/tests/zfs-tests/tests/functional/rsend/rsend.kshlib b/tests/zfs-tests/tests/functional/rsend/rsend.kshlib index 0c7d1f633..8ffb133af 100644 --- a/tests/zfs-tests/tests/functional/rsend/rsend.kshlib +++ b/tests/zfs-tests/tests/functional/rsend/rsend.kshlib @@ -571,7 +571,8 @@ function mess_file { file=$1 - filesize=$(stat -c '%s' $file) + filesize=$(stat_size $file) + offset=$(($RANDOM * $RANDOM % $filesize)) if (($RANDOM % 7 <= 1)); then # @@ -795,10 +796,20 @@ function rand_set_prop } # Generate a recursive checksum of a filesystem which includes the file -# contents and any associated xattrs. +# contents and any associated extended attributes. function recursive_cksum { - find $1 -type f -exec sh -c 'sha256sum {}; getfattr \ - --absolute-names --only-values -d {} | sha256sum' \; | \ - sort -k 2 | awk '{ print $1 }' | sha256sum + case "$(uname)" in + FreeBSD) + find $1 -type f -exec sh -c 'sha256 -q {}; lsextattr -q \ + system {} | sha256 -q; lsextattr -q user {} | sha256 -q' \ + \; | sort | sha256 -q + ;; + *) + find $1 -type f -exec sh -c 'sha256sum {}; getfattr \ + --absolute-names --only-values -d {} | sha256sum' \; | \ + sort -k 2 | awk '{ print $1 }' | sha256sum | \ + awk '{ print $1 }' + ;; + esac } diff --git a/tests/zfs-tests/tests/functional/rsend/rsend_012_pos.ksh b/tests/zfs-tests/tests/functional/rsend/rsend_012_pos.ksh index d9a79b6bb..24b1ed7e0 100755 --- a/tests/zfs-tests/tests/functional/rsend/rsend_012_pos.ksh +++ b/tests/zfs-tests/tests/functional/rsend/rsend_012_pos.ksh @@ -129,7 +129,9 @@ for fs in "$POOL" "$POOL/pclone" "$POOL/$FS" "$POOL/$FS/fs1" \ rand_set_prop $fs dnodesize "legacy" "auto" "1k" "2k" "4k" "8k" "16k" rand_set_prop $fs setuid "on" "off" rand_set_prop $fs snapdir "hidden" "visible" - rand_set_prop $fs xattr "on" "off" + if ! is_freebsd; then + rand_set_prop $fs xattr "on" "off" + fi rand_set_prop $fs user:prop "aaa" "bbb" "23421" "()-+?" done diff --git a/tests/zfs-tests/tests/functional/rsend/send-cD.ksh b/tests/zfs-tests/tests/functional/rsend/send-cD.ksh index d0754a4f1..97db0a7c2 100755 --- a/tests/zfs-tests/tests/functional/rsend/send-cD.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send-cD.ksh @@ -60,8 +60,8 @@ log_must zfs snapshot $sendfs@snap1 # The stream sizes should match, since the second stream contains no new blocks log_must eval "zfs send -D -c $sendfs@snap1 >$stream1" -typeset size0=$(stat -c %s $stream0) -typeset size1=$(stat -c %s $stream1) +typeset size0=$(stat_size $stream0) +typeset size1=$(stat_size $stream1) within_percent $size0 $size1 90 || log_fail "$size0 and $size1" # Finally, make sure the receive works correctly. @@ -71,7 +71,7 @@ log_must eval "zfs recv -d $recvfs <$inc" cmp_ds_cont $sendfs $recvfs # The size of the incremental should be the same as the initial send. -typeset size2=$(stat -c %s $inc) +typeset size2=$(stat_size $inc) within_percent $size0 $size2 90 || log_fail "$size0 and $size1" log_pass "The -c and -D flags do not interfere with each other" diff --git a/tests/zfs-tests/tests/functional/rsend/send-c_embedded_blocks.ksh b/tests/zfs-tests/tests/functional/rsend/send-c_embedded_blocks.ksh index 1983a3ea1..70f79b317 100755 --- a/tests/zfs-tests/tests/functional/rsend/send-c_embedded_blocks.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send-c_embedded_blocks.ksh @@ -53,7 +53,7 @@ for recsize in "${recsize_prop_vals[@]}"; do # For lz4, this method works for blocks up to 16k, but not larger [[ $recsize -eq $((32 * 1024)) ]] && break - if is_linux; then + if is_linux || is_freebsd; then log_must truncate -s $recsize $dir/$recsize log_must dd if=/dev/urandom of=$dir/$recsize \ seek=$((recsize - 8)) bs=1 count=8 conv=notrunc diff --git a/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh b/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh index 268f1d827..840b5f085 100755 --- a/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh @@ -40,7 +40,12 @@ function get_estimated_size { typeset cmd=$1 typeset ds=${cmd##* } - typeset tmpfile=$(mktemp -p $BACKDIR) + if is_freebsd; then + mkdir -p $BACKDIR + typeset tmpfile=$(TMPDIR=$BACKDIR mktemp) + else + typeset tmpfile=$(mktemp -p $BACKDIR) + fi eval "$cmd >$tmpfile" [[ $? -eq 0 ]] || log_fail "get_estimated_size: $cmd" diff --git a/tests/zfs-tests/tests/functional/rsend/send-cpL_varied_recsize.ksh b/tests/zfs-tests/tests/functional/rsend/send-cpL_varied_recsize.ksh index 84c0a5e3c..e1ac00c79 100755 --- a/tests/zfs-tests/tests/functional/rsend/send-cpL_varied_recsize.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send-cpL_varied_recsize.ksh @@ -72,8 +72,12 @@ function check_recsize [[ -f $file ]] || log_fail "file '$file' doesn't exist" typeset read_recsize=$(get_prop recsize $recv_ds) - typeset read_file_bs=$(stat $file | sed -n \ - 's/.*IO Block: \([0-9]*\).*/\1/p') + if is_freebsd; then + typeset read_file_bs=$(stat -f "%k" $file) + else + typeset read_file_bs=$(stat $file | sed -n \ + 's/.*IO Block: \([0-9]*\).*/\1/p') + fi [[ $read_recsize = $expected_recsize ]] || log_fail \ "read_recsize: $read_recsize expected_recsize: $expected_recsize" diff --git a/tests/zfs-tests/tests/functional/rsend/send-wDR_encrypted_zvol.ksh b/tests/zfs-tests/tests/functional/rsend/send-wDR_encrypted_zvol.ksh index 0a7ae7482..b2797cce7 100755 --- a/tests/zfs-tests/tests/functional/rsend/send-wDR_encrypted_zvol.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send-wDR_encrypted_zvol.ksh @@ -64,7 +64,12 @@ log_must zfs create -o dedup=on -o encryption=on -o keyformat=passphrase \ -o keylocation=file://$keyfile -V 128M $TESTPOOL/$TESTVOL block_device_wait -log_must eval "echo 'y' | newfs -t ext4 -v $zdev" +if is_linux; then + # ext4 only supported on Linux + log_must new_fs -t ext4 $zdev +else + log_must new_fs $zdev +fi log_must mkdir -p $mntpnt log_must mkdir -p $recvmnt log_must mount $zdev $mntpnt diff --git a/tests/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files.ksh b/tests/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files.ksh index d701bcecb..c710b3d91 100755 --- a/tests/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files.ksh @@ -52,8 +52,16 @@ log_onexit cleanup function recursive_cksum { - find $1 -type f -exec sha256sum {} \; | \ - sort -k 2 | awk '{ print $1 }' | sha256sum + case "$(uname)" in + FreeBSD) + find $1 -type f -exec sha256 -q {} \; | \ + sort | sha256digest + ;; + *) + find $1 -type f -exec sha256sum {} \; | \ + sort -k 2 | awk '{ print $1 }' | sha256digest + ;; + esac } log_assert "Verify 'zfs send -w' works with many different file layouts" diff --git a/tests/zfs-tests/tests/functional/slog/slog_013_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_013_pos.ksh index d6917065d..89b3aeb40 100755 --- a/tests/zfs-tests/tests/functional/slog/slog_013_pos.ksh +++ b/tests/zfs-tests/tests/functional/slog/slog_013_pos.ksh @@ -50,6 +50,8 @@ function cleanup_testenv if [[ -n $lofidev ]]; then if is_linux; then losetup -d $lofidev + elif is_freebsd; then + mdconfig -du ${lofidev#md} else lofiadm -d $lofidev fi @@ -78,6 +80,8 @@ if is_linux; then lofidev=$(losetup -f) log_must losetup $lofidev ${LDEV2%% *} lofidev=${lofidev##*/} +elif is_freebsd; then + lofidev=$(mdconfig -a ${LDEV2%% *}) else lofidev=${LDEV2%% *} log_must lofiadm -a $lofidev diff --git a/tests/zfs-tests/tests/functional/slog/slog_014_pos.ksh b/tests/zfs-tests/tests/functional/slog/slog_014_pos.ksh index e8ea29f1f..f8530a623 100755 --- a/tests/zfs-tests/tests/functional/slog/slog_014_pos.ksh +++ b/tests/zfs-tests/tests/functional/slog/slog_014_pos.ksh @@ -64,7 +64,7 @@ for type in "mirror" "raidz" "raidz2"; do # Corrupt a pool device to make the pool DEGRADED # The oseek value below is to skip past the vdev label. # - if is_linux; then + if is_linux || is_freebsd; then log_must dd if=/dev/urandom of=$VDIR/a bs=1024k \ seek=4 conv=notrunc count=50 else diff --git a/tests/zfs-tests/tests/functional/slog/slog_015_neg.ksh b/tests/zfs-tests/tests/functional/slog/slog_015_neg.ksh index a53aeabff..ebca409a1 100755 --- a/tests/zfs-tests/tests/functional/slog/slog_015_neg.ksh +++ b/tests/zfs-tests/tests/functional/slog/slog_015_neg.ksh @@ -40,17 +40,22 @@ function cleanup # wait - set_tunable64 zfs_commit_timeout_pct $ORIG_TIMEOUT + set_tunable64 $COMMIT_TIMEOUT_PCT $ORIG_TIMEOUT poolexists $TESTPOOL && zpool destroy -f $TESTPOOL } -ORIG_TIMEOUT=$(get_tunable zfs_commit_timeout_pct | tail -1 | awk '{print $NF}') +if is_freebsd; then + typeset COMMIT_TIMEOUT_PCT=commit_timeout_pct +else + typeset COMMIT_TIMEOUT_PCT=zfs_commit_timeout_pct +fi +typeset ORIG_TIMEOUT=$(get_tunable $COMMIT_TIMEOUT_PCT) log_onexit cleanup log_must setup for PCT in 0 1 2 4 8 16 32 64 128 256 512 1024; do - log_must set_tunable64 zfs_commit_timeout_pct $PCT + log_must set_tunable64 $COMMIT_TIMEOUT_PCT $PCT log_must zpool create $TESTPOOL $VDEV log $SDEV diff --git a/tests/zfs-tests/tests/functional/slog/slog_replay_fs_001.ksh b/tests/zfs-tests/tests/functional/slog/slog_replay_fs_001.ksh index 8954caa1c..c737eac52 100755 --- a/tests/zfs-tests/tests/functional/slog/slog_replay_fs_001.ksh +++ b/tests/zfs-tests/tests/functional/slog/slog_replay_fs_001.ksh @@ -122,7 +122,11 @@ log_must rm -rf /$TESTPOOL/$TESTFS/dict # TX_SETATTR log_must touch /$TESTPOOL/$TESTFS/setattr log_must chmod 567 /$TESTPOOL/$TESTFS/setattr -log_must chgrp root /$TESTPOOL/$TESTFS/setattr +if is_freebsd; then + log_must chgrp wheel /$TESTPOOL/$TESTFS/setattr +else + log_must chgrp root /$TESTPOOL/$TESTFS/setattr +fi log_must touch -cm -t 201311271200 /$TESTPOOL/$TESTFS/setattr # TX_TRUNCATE (to zero) @@ -146,14 +150,24 @@ log_must dd if=/dev/zero of=/$TESTPOOL/$TESTFS/holes.3 bs=128k count=2 \ # TX_MKXATTR log_must mkdir /$TESTPOOL/$TESTFS/xattr.dir -log_must attr -qs fileattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.dir -log_must attr -qs tmpattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.dir -log_must attr -qr tmpattr /$TESTPOOL/$TESTFS/xattr.dir - log_must touch /$TESTPOOL/$TESTFS/xattr.file -log_must attr -qs fileattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.file -log_must attr -qs tmpattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.file -log_must attr -qr tmpattr /$TESTPOOL/$TESTFS/xattr.file +if is_freebsd; then + log_must setextattr -q user fileattr HelloWorld /$TESTPOOL/$TESTFS/xattr.dir + log_must setextattr -q user tmpattr HelloWorld /$TESTPOOL/$TESTFS/xattr.dir + log_must rmextattr -q user fileattr /$TESTPOOL/$TESTFS/xattr.dir + + log_must setextattr -q user fileattr HelloWorld /$TESTPOOL/$TESTFS/xattr.file + log_must setextattr -q user tmpattr HelloWorld /$TESTPOOL/$TESTFS/xattr.file + log_must rmextattr -q user tmpattr /$TESTPOOL/$TESTFS/xattr.file +elif is_linux; then + log_must attr -qs fileattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.dir + log_must attr -qs tmpattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.dir + log_must attr -qr tmpattr /$TESTPOOL/$TESTFS/xattr.dir + + log_must attr -qs fileattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.file + log_must attr -qs tmpattr -V HelloWorld /$TESTPOOL/$TESTFS/xattr.file + log_must attr -qr tmpattr /$TESTPOOL/$TESTFS/xattr.file +fi # TX_WRITE, TX_LINK, TX_REMOVE # Make sure TX_REMOVE won't affect TX_WRITE if file is not destroyed @@ -197,8 +211,13 @@ log_note "Verify current block usage:" log_must zdb -bcv $TESTPOOL log_note "Verify copy of xattrs:" -log_must attr -l /$TESTPOOL/$TESTFS/xattr.dir -log_must attr -l /$TESTPOOL/$TESTFS/xattr.file +if is_freebsd; then + log_must lsextattr -s /$TESTPOOL/$TESTFS/xattr.dir + log_must lsextattr -s /$TESTPOOL/$TESTFS/xattr.file +elif is_linux; then + log_must attr -l /$TESTPOOL/$TESTFS/xattr.dir + log_must attr -l /$TESTPOOL/$TESTFS/xattr.file +fi log_note "Verify working set diff:" log_must diff -r /$TESTPOOL/$TESTFS $TESTDIR/copy diff --git a/tests/zfs-tests/tests/functional/slog/slog_replay_volume.ksh b/tests/zfs-tests/tests/functional/slog/slog_replay_volume.ksh index f513d04fe..d39c6ded5 100755 --- a/tests/zfs-tests/tests/functional/slog/slog_replay_volume.ksh +++ b/tests/zfs-tests/tests/functional/slog/slog_replay_volume.ksh @@ -61,10 +61,11 @@ verify_runnable "global" VOLUME=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL MNTPNT=$TESTDIR/$TESTVOL +FSTYPE=none function cleanup_volume { - if ismounted $MNTPNT ext4; then + if ismounted $MNTPNT $FSTYPE; then log_must umount $MNTPNT rmdir $MNTPNT fi @@ -88,10 +89,19 @@ log_must zfs set compression=on $TESTPOOL/$TESTVOL log_must zfs set sync=always $TESTPOOL/$TESTVOL log_must mkdir -p $TESTDIR block_device_wait -echo "y" | newfs -t ext4 -v $VOLUME -log_must mkdir -p $MNTPNT -log_must mount -o discard $VOLUME $MNTPNT -log_must rmdir $MNTPNT/lost+found +if is_linux; then + # ext4 only on Linux + log_must new_fs -t ext4 -v $VOLUME + log_must mkdir -p $MNTPNT + log_must mount -o discard $VOLUME $MNTPNT + FSTYPE=ext4 + log_must rmdir $MNTPNT/lost+found +else + log_must new_fs $VOLUME + log_must mkdir -p $MNTPNT + log_must mount $VOLUME $MNTPNT + FSTYPE=$NEWFS_DEFAULT_FS +fi log_must zpool sync # @@ -116,13 +126,15 @@ log_must dd if=/dev/urandom of=$MNTPNT/throughput-128k bs=128k count=1 log_must dd if=/dev/urandom of=$MNTPNT/holes bs=128k count=8 log_must dd if=/dev/zero of=$MNTPNT/holes bs=128k count=2 seek=2 conv=notrunc -# TX_TRUNCATE -if fallocate --punch-hole 2>&1 | grep -q "unrecognized option"; then - log_note "fallocate(1) does not support --punch-hole" -else - log_must dd if=/dev/urandom of=$MNTPNT/discard bs=128k count=16 - log_must fallocate --punch-hole -l 128K -o 512K $MNTPNT/discard - log_must fallocate --punch-hole -l 512K -o 1M $MNTPNT/discard +if is_linux; then + # TX_TRUNCATE + if fallocate --punch-hole 2>&1 | grep -q "unrecognized option"; then + log_note "fallocate(1) does not support --punch-hole" + else + log_must dd if=/dev/urandom of=$MNTPNT/discard bs=128k count=16 + log_must fallocate --punch-hole -l 128K -o 512K $MNTPNT/discard + log_must fallocate --punch-hole -l 512K -o 1M $MNTPNT/discard + fi fi # diff --git a/tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh index 526897193..63bd98147 100755 --- a/tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh @@ -61,7 +61,17 @@ set -A args "$SNAPFS" "$SNAPDIR" "$TESTPOOL/$TESTCLONE" "$TESTDIR.0" \ function setup_all { + if is_freebsd; then + # Pool creation on zvols is forbidden by default. + # Save and the current setting. + typeset _saved=$(get_tunable vol.recursive) + log_must set_tunable64 vol.recursive 1 + fi create_pool $TESTPOOL1 ${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL + if is_freebsd; then + # Restore the previous setting. + log_must set_tunable64 vol.recursive $_saved + fi log_must zfs create $TESTPOOL1/$TESTFS log_must zfs set mountpoint=$TESTDIR2 $TESTPOOL1/$TESTFS diff --git a/tests/zfs-tests/tests/functional/trim/setup.ksh b/tests/zfs-tests/tests/functional/trim/setup.ksh index cdcf038ad..3eb644690 100755 --- a/tests/zfs-tests/tests/functional/trim/setup.ksh +++ b/tests/zfs-tests/tests/functional/trim/setup.ksh @@ -23,15 +23,20 @@ verify_runnable "global" -DISK1=${DISKS%% *} +if is_freebsd; then + diskinfo -v $DISKS | grep -qE 'No.*# TRIM/UNMAP support' && + log_unsupported "DISKS do not support discard (TRIM/UNMAP)" +else + DISK1=${DISKS%% *} -typeset -i max_discard=0 -if [[ -b $DEV_RDSKDIR/$DISK1 ]]; then - max_discard=$(lsblk -Dbn $DEV_RDSKDIR/$DISK1 | awk '{ print $4; exit }') -fi + typeset -i max_discard=0 + if [[ -b $DEV_RDSKDIR/$DISK1 ]]; then + max_discard=$(lsblk -Dbn $DEV_RDSKDIR/$DISK1 | awk '{ print $4; exit }') + fi -if test $max_discard -eq 0; then - log_unsupported "DISKS do not support discard (TRIM/UNMAP)" + if test $max_discard -eq 0; then + log_unsupported "DISKS do not support discard (TRIM/UNMAP)" + fi fi log_pass diff --git a/tests/zfs-tests/tests/functional/truncate/truncate_timestamps.ksh b/tests/zfs-tests/tests/functional/truncate/truncate_timestamps.ksh index c365c7415..27b28e82e 100755 --- a/tests/zfs-tests/tests/functional/truncate/truncate_timestamps.ksh +++ b/tests/zfs-tests/tests/functional/truncate/truncate_timestamps.ksh @@ -38,13 +38,23 @@ function verify_truncate #