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 <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Matt Macy <mmacy@FreeBSD.org>
Signed-off-by: Ryan Moeller <ryan@ixsystems.com>
Closes #9692
This commit is contained in:
Matthew Macy 2019-12-18 12:29:43 -08:00 committed by Brian Behlendorf
parent 118fc3ef07
commit 7839c4b5e1
145 changed files with 1723 additions and 573 deletions

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
#
# CDDL HEADER START
#
@ -47,10 +47,19 @@ TAGS=""
ITERATIONS=1
ZFS_DBGMSG="$STF_SUITE/callbacks/zfs_dbgmsg.ksh"
ZFS_DMESG="$STF_SUITE/callbacks/zfs_dmesg.ksh"
ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh"
TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"}
LOSETUP=${LOSETUP:-/sbin/losetup}
DMSETUP=${DMSETUP:-/sbin/dmsetup}
UNAME=$(uname -s)
# Override some defaults if on FreeBSD
if [ "$UNAME" = "FreeBSD" ] ; then
TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DMESG"}
LOSETUP=/sbin/mdconfig
DMSETUP=/sbin/gpart
else
ZFS_MMP="$STF_SUITE/callbacks/zfs_mmp.ksh"
TESTFAIL_CALLBACKS=${TESTFAIL_CALLBACKS:-"$ZFS_DBGMSG:$ZFS_DMESG:$ZFS_MMP"}
LOSETUP=${LOSETUP:-/sbin/losetup}
DMSETUP=${DMSETUP:-/sbin/dmsetup}
fi
#
# Log an informational message when additional verbosity is enabled.
@ -70,6 +79,33 @@ fail() {
exit 1
}
cleanup_freebsd_loopback() {
for TEST_LOOPBACK in ${LOOPBACKS}; do
if [ -c "/dev/${TEST_LOOPBACK}" ]; then
sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}" ||
echo "Failed to destroy: ${TEST_LOOPBACK}"
fi
done
}
cleanup_linux_loopback() {
for TEST_LOOPBACK in ${LOOPBACKS}; do
LOOP_DEV=$(basename "$TEST_LOOPBACK")
DM_DEV=$(sudo "${DMSETUP}" ls 2>/dev/null | \
grep "${LOOP_DEV}" | cut -f1)
if [ -n "$DM_DEV" ]; then
sudo "${DMSETUP}" remove "${DM_DEV}" ||
echo "Failed to remove: ${DM_DEV}"
fi
if [ -n "${TEST_LOOPBACK}" ]; then
sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" ||
echo "Failed to remove: ${TEST_LOOPBACK}"
fi
done
}
#
# Attempt to remove loopback devices and files which where created earlier
# by this script to run the test framework. The '-k' option may be passed
@ -80,22 +116,13 @@ cleanup() {
return 0
fi
if [ "$LOOPBACK" = "yes" ]; then
for TEST_LOOPBACK in ${LOOPBACKS}; do
LOOP_DEV=$(basename "$TEST_LOOPBACK")
DM_DEV=$(sudo "${DMSETUP}" ls 2>/dev/null | \
grep "${LOOP_DEV}" | cut -f1)
if [ -n "$DM_DEV" ]; then
sudo "${DMSETUP}" remove "${DM_DEV}" ||
echo "Failed to remove: ${DM_DEV}"
fi
if [ -n "${TEST_LOOPBACK}" ]; then
sudo "${LOSETUP}" -d "${TEST_LOOPBACK}" ||
echo "Failed to remove: ${TEST_LOOPBACK}"
fi
done
if [ "$UNAME" = "FreeBSD" ] ; then
cleanup_freebsd_loopback
else
cleanup_linux_loopback
fi
fi
for TEST_FILE in ${FILES}; do
@ -118,7 +145,11 @@ cleanup_all() {
local TEST_POOLS
TEST_POOLS=$(sudo "$ZPOOL" list -H -o name | grep testpool)
local TEST_LOOPBACKS
TEST_LOOPBACKS=$(sudo "${LOSETUP}" -a|grep file-vdev|cut -f1 -d:)
if [ "$UNAME" = "FreeBSD" ] ; then
TEST_LOOPBACKS=$(sudo "${LOSETUP}" -l)
else
TEST_LOOPBACKS=$(sudo "${LOSETUP}" -a|grep file-vdev|cut -f1 -d:)
fi
local TEST_FILES
TEST_FILES=$(ls /var/tmp/file-vdev* 2>/dev/null)
@ -129,13 +160,19 @@ cleanup_all() {
sudo "$ZPOOL" destroy "${TEST_POOL}"
done
msg "Removing dm(s): $(sudo "${DMSETUP}" ls |
grep loop | tr '\n' ' ')"
sudo "${DMSETUP}" remove_all
if [ "$UNAME" != "FreeBSD" ] ; then
msg "Removing dm(s): $(sudo "${DMSETUP}" ls |
grep loop | tr '\n' ' ')"
sudo "${DMSETUP}" remove_all
fi
msg "Removing loopback(s): $(echo "${TEST_LOOPBACKS}" | tr '\n' ' ')"
for TEST_LOOPBACK in $TEST_LOOPBACKS; do
sudo "${LOSETUP}" -d "${TEST_LOOPBACK}"
if [ "$UNAME" = "FreeBSD" ] ; then
sudo "${LOSETUP}" -d -u "${TEST_LOOPBACK}"
else
sudo "${LOSETUP}" -d "${TEST_LOOPBACK}"
fi
done
msg "Removing files(s): $(echo "${TEST_FILES}" | tr '\n' ' ')"
@ -202,6 +239,9 @@ create_links() {
constrain_path() {
. "$STF_SUITE/include/commands.cfg"
SYSTEM_DIRS="/bin /sbin /usr/bin /usr/sbin"
SYSTEM_DIRS+=" /usr/local/bin /usr/local/sbin"
if [ "$INTREE" = "yes" ]; then
# Constrained path set to ./zfs/bin/
STF_PATH="$BIN_DIR"
@ -224,30 +264,40 @@ constrain_path() {
else
# Constrained path set to /var/tmp/constrained_path.*
SYSTEMDIR=${SYSTEMDIR:-/var/tmp/constrained_path.XXXX}
STF_PATH=$(/bin/mktemp -d "$SYSTEMDIR")
STF_PATH=$(mktemp -d "$SYSTEMDIR")
STF_PATH_REMOVE="yes"
STF_MISSING_BIN=""
chmod 755 "$STF_PATH" || fail "Couldn't chmod $STF_PATH"
# Special case links for standard zfs utilities
create_links "/bin /usr/bin /sbin /usr/sbin" "$ZFS_FILES"
create_links "$SYSTEM_DIRS" "$ZFS_FILES"
# Special case links for zfs test suite utilities
create_links "$STF_SUITE/bin" "$ZFSTEST_FILES"
fi
# Standard system utilities
create_links "/bin /usr/bin /sbin /usr/sbin" "$SYSTEM_FILES"
SYSTEM_FILES="$SYSTEM_FILES_COMMON"
if [ "$UNAME" = "FreeBSD" ] ; then
SYSTEM_FILES+=" $SYSTEM_FILES_FREEBSD"
else
SYSTEM_FILES+=" $SYSTEM_FILES_LINUX"
fi
create_links "$SYSTEM_DIRS" "$SYSTEM_FILES"
# Exceptions
ln -fs "$STF_PATH/awk" "$STF_PATH/nawk"
ln -fs /sbin/fsck.ext4 "$STF_PATH/fsck"
ln -fs /sbin/mkfs.ext4 "$STF_PATH/newfs"
ln -fs "$STF_PATH/gzip" "$STF_PATH/compress"
ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress"
ln -fs "$STF_PATH/exportfs" "$STF_PATH/share"
ln -fs "$STF_PATH/exportfs" "$STF_PATH/unshare"
if [ "$UNAME" = "Linux" ] ; then
ln -fs /sbin/fsck.ext4 "$STF_PATH/fsck"
ln -fs /sbin/mkfs.ext4 "$STF_PATH/newfs"
ln -fs "$STF_PATH/gzip" "$STF_PATH/compress"
ln -fs "$STF_PATH/gunzip" "$STF_PATH/uncompress"
ln -fs "$STF_PATH/exportfs" "$STF_PATH/share"
ln -fs "$STF_PATH/exportfs" "$STF_PATH/unshare"
elif [ "$UNAME" = "FreeBSD" ] ; then
ln -fs /usr/local/bin/ksh93 "$STF_PATH/ksh"
fi
if [ -L "$STF_PATH/arc_summary3" ]; then
ln -fs "$STF_PATH/arc_summary3" "$STF_PATH/arc_summary"
@ -466,6 +516,9 @@ constrain_path
#
# Check if ksh exists
#
if [ "$UNAME" = "FreeBSD" ]; then
sudo ln -fs /usr/local/bin/ksh93 /bin/ksh
fi
[ -e "$STF_PATH/ksh" ] || fail "This test suite requires ksh."
[ -e "$STF_SUITE/include/default.cfg" ] || fail \
"Missing $STF_SUITE/include/default.cfg file."
@ -509,7 +562,11 @@ fi
#
# See libzfs/libzfs_config.c for more information.
#
__ZFS_POOL_EXCLUDE="$(echo "$KEEP" | sed ':a;N;s/\n/ /g;ba')"
if [ "$UNAME" = "FreeBSD" ] ; then
__ZFS_POOL_EXCLUDE="$(echo "$KEEP" | tr -s '\n' ' ')"
else
__ZFS_POOL_EXCLUDE="$(echo "$KEEP" | sed ':a;N;s/\n/ /g;ba')"
fi
. "$STF_SUITE/include/default.cfg"
@ -549,15 +606,28 @@ if [ -z "${DISKS}" ]; then
test -x "$LOSETUP" || fail "$LOSETUP utility must be installed"
for TEST_FILE in ${FILES}; do
TEST_LOOPBACK=$(sudo "${LOSETUP}" -f)
sudo "${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" ||
fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
LOOPBACKS="${LOOPBACKS}${TEST_LOOPBACK} "
BASELOOPBACKS=$(basename "$TEST_LOOPBACK")
if [[ "$DISKS" ]]; then
DISKS="$DISKS $BASELOOPBACKS"
if [ "$UNAME" = "FreeBSD" ] ; then
MDDEVICE=$(sudo "${LOSETUP}" -a -t vnode -f "${TEST_FILE}")
if [ -z "$MDDEVICE" ] ; then
fail "Failed: ${TEST_FILE} -> loopback"
fi
LOOPBACKS="${LOOPBACKS}${MDDEVICE} "
if [[ "$DISKS" ]]; then
DISKS="$DISKS $MDDEVICE"
else
DISKS="$MDDEVICE"
fi
else
DISKS="$BASELOOPBACKS"
TEST_LOOPBACK=$(sudo "${LOSETUP}" -f)
sudo "${LOSETUP}" "${TEST_LOOPBACK}" "${TEST_FILE}" ||
fail "Failed: ${TEST_FILE} -> ${TEST_LOOPBACK}"
LOOPBACKS="${LOOPBACKS}${TEST_LOOPBACK} "
BASELOOPBACKS=$(basename "$TEST_LOOPBACK")
if [[ "$DISKS" ]]; then
DISKS="$DISKS $BASELOOPBACKS"
else
DISKS="$BASELOOPBACKS"
fi
fi
done
fi
@ -604,8 +674,14 @@ export __ZFS_POOL_EXCLUDE
export TESTFAIL_CALLBACKS
export PATH=$STF_PATH
RESULTS_FILE=$(mktemp -u -t zts-results.XXXX -p "$FILEDIR")
REPORT_FILE=$(mktemp -u -t zts-report.XXXX -p "$FILEDIR")
if [ "$UNAME" = "FreeBSD" ] ; then
mkdir -p "$FILEDIR" || true
RESULTS_FILE=$(mktemp -u "${FILEDIR}/zts-results.XXXX")
REPORT_FILE=$(mktemp -u "${FILEDIR}/zts-report.XXXX")
else
RESULTS_FILE=$(mktemp -u -t zts-results.XXXX -p "$FILEDIR")
REPORT_FILE=$(mktemp -u -t zts-report.XXXX -p "$FILEDIR")
fi
#
# Run all the tests as specified.

View File

@ -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

View File

@ -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

View File

@ -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"),

View File

@ -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);
}

View File

@ -30,7 +30,9 @@
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#ifdef __linux__
#include <sys/xattr.h>
#endif
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/param.h>
@ -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);

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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 #<disk> <slice>
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 #<disk> <slice>
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 #<group_name> <user_name> <basedir>
{
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 #<logname>
{
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 #<group_name>
{
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 #<group_name>
{
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 #<group_name> <user_name> <basedir>
{
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 #<user_name>
{
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 #<group_name>
{
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 #<group_name>
{
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 #<group_name> <user_name> <basedir>
{
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 #<user_name>
{
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 #<group_name>
{
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 #<group_name>
{
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 #<group_name> <user_name> <basedir>
{
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 #<logname> <basedir>
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 #<group_name>
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 #<group_name>
#
function del_group #<group_name>
{
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 #<args>
{
case $(uname) in
FreeBSD)
newfs "$@"
;;
*)
echo y | newfs -v "$@"
;;
esac
}
function stat_size #<path>
{
typeset path=$1
case $(uname) in
FreeBSD)
stat -f %z "$path"
;;
*)
stat -c %s "$path"
;;
esac
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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=$@

View File

@ -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

View File

@ -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."

View File

@ -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}}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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]}')

View File

@ -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

View File

@ -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."

View File

@ -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
;;
*)

View File

@ -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

View File

@ -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

View File

@ -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."

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -22,6 +22,7 @@
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* ARGSUSED */
int

View File

@ -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

View File

@ -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" "|"

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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 \

View File

@ -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

View File

@ -44,13 +44,15 @@
# 2. Apply 'zfs set mountpoint=path <filesystem>'.
# 3. Change directory to that given mountpoint.
# 3. Invoke 'zfs mount <filesystem>'.
# 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

View File

@ -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

View File

@ -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

View File

@ -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."

View File

@ -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."

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -57,8 +57,8 @@ function write_compare_files # <sendfs> <recvfs> <offset>
# 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

View File

@ -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."

View File

@ -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

View File

@ -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

View File

@ -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"
;;
*)

View File

@ -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"

View File

@ -27,4 +27,8 @@
. $STF_SUITE/include/libtest.shlib
if ! is_linux ; then
log_unsupported "sysfs is linux-only"
fi
default_cleanup

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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="\

View File

@ -45,7 +45,7 @@
verify_runnable "global"
if is_linux; then
if is_linux || is_freebsd; then
log_unsupported "Requires additional dependencies"
fi

View File

@ -45,7 +45,7 @@
verify_runnable "global"
if is_linux; then
if is_linux || is_freebsd; then
log_unsupported "Requires additional dependencies"
fi

View File

@ -31,7 +31,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#ifndef __FreeBSD__
#include <sys/xattr.h>
#endif
#include <utime.h>
#include <stdio.h>
#include <stdlib.h>
@ -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]))

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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."

View File

@ -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 \

View File

@ -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 \

View File

@ -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
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%%/*}
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
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

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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
#

View File

@ -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 && \

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

Some files were not shown because too many files have changed in this diff Show More