Skip to content

Commit

Permalink
ZTS: Another round of changes for FreeBSD
Browse files Browse the repository at this point in the history
Highlights:
* is_linux -> is_illumos swaps
* make block_device_wait more clever when paths are given
* slightly optimize default_cleanup_noexit
* remove platform differences in user_run
* temporarily expect non-libfetch behavior for keylocation=/foo/bar
* fix sharenfs exceptions
* don't test multihost property
* fix misc broken platform checks
* clear zinjected faults in removal_resume_export callback

Reviewed-by: Brian Behlendorf <[email protected]>
Reviewed-by: John Kennedy <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes openzfs#10092
  • Loading branch information
Ryan Moeller authored Mar 6, 2020
1 parent f5f6fb0 commit 2b95e91
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 59 deletions.
25 changes: 22 additions & 3 deletions tests/zfs-tests/include/blkdev.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,33 @@ function block_device_wait
{
if is_linux; then
udevadm trigger $*
typeset local start=$SECONDS
typeset start=$SECONDS
udevadm settle
typeset local elapsed=$((SECONDS - start))
typeset elapsed=$((SECONDS - start))
[[ $elapsed > 60 ]] && \
log_note udevadm settle time too long: $elapsed
elif is_freebsd; then
sleep 3
if [[ ${#@} -eq 0 ]]; then
sleep 3
return
fi
fi
# Poll for the given paths to appear, but give up eventually.
typeset -i i
for (( i = 0; i < 5; ++i )); do
typeset missing=false
typeset dev
for dev in "${@}"; do
if ! [[ -f $dev ]]; then
missing=true
break
fi
done
if ! $missing; then
break
fi
sleep ${#@}
done
}

#
Expand Down
10 changes: 2 additions & 8 deletions tests/zfs-tests/include/libtest.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@ function default_cleanup_noexit
then
destroy_pool $pool
fi
ALL_POOLS=$(get_all_pools)
done
ALL_POOLS=$(get_all_pools)
done

zfs mount -a
Expand Down Expand Up @@ -3315,13 +3315,7 @@ function user_run
shift

log_note "user:$user $@"
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
eval su - \$user -c \"$@\" > $TEST_BASE_DIR/out 2>$TEST_BASE_DIR/err
}

#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ 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
if is_linux; then
if true; then
log_mustnot zfs set keylocation=/$TESTPOOL/pkey $TESTPOOL/$TESTFS1
else
### SOON: ###
# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ while (( $i < ${#args[*]} )); do
typeset arg=${args[i]}
if is_freebsd; then
# FreeBSD does not strictly validate share opts (yet).
if [[ $arg == "-o sharenfs="* ]]; then
if [[ $arg == "sharenfs="* ]]; then
((i = i + 1))
continue
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ for option in "" "-Df"; do
if ((nfs_share_bit == 1)); then
log_note "Set sharenfs=on $pool"
log_must zfs set sharenfs=on $pool
log_must is_shared $pool
! is_freebsd && log_must is_shared $pool
f_share="true"
nfs_flag="sharenfs=on"
fi
Expand Down Expand Up @@ -181,19 +181,21 @@ for option in "" "-Df"; do
for fs in $mount_fs; do
log_must ismounted $pool/$fs
[[ -n $f_share ]] && \
! is_freebsd && \
log_must is_shared $pool/$fs
done

for fs in $nomount_fs; do
log_mustnot ismounted $pool/$fs
log_mustnot is_shared $pool/$fs
! is_freebsd && \
log_mustnot is_shared $pool/$fs
done
((guid_bit = guid_bit + 1))
done
# reset nfsshare=off
if [[ -n $f_share ]]; then
log_must zfs set sharenfs=off $pool
log_mustnot is_shared $pool
! is_freebsd && log_mustnot is_shared $pool
fi
((nfs_share_bit = nfs_share_bit + 1))
done
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function cleanup
destroy_pool $TESTPOOL
destroy_pool $TESTPOOL2
rm -f $DEVICE1 $DEVICE2
log_must mmp_clear_hostid
! is_freebsd && log_must mmp_clear_hostid
}

function setup_mirror
Expand All @@ -48,9 +48,8 @@ function setup_mirror
log_assert "'zpool split' can set new property values on the new pool"
log_onexit cleanup

if [ -e $HOSTID_FILE ]; then
log_unsupported "System has existing $HOSTID_FILE file"
fi
DEVICE1="$TEST_BASE_DIR/device-1"
DEVICE2="$TEST_BASE_DIR/device-2"

typeset good_props=('comment=text' 'ashift=12' 'multihost=on'
'listsnapshots=on' 'autoexpand=on' 'autoreplace=on'
Expand All @@ -59,12 +58,15 @@ typeset bad_props=("bootfs=$TESTPOOL2/bootfs" 'version=28' 'ashift=4'
'allocated=1234' 'capacity=5678' 'multihost=none'
'feature@async_destroy=disabled' 'feature@xxx_fake_xxx=enabled'
'propname=propval' 'readonly=on')

DEVICE1="$TEST_BASE_DIR/device-1"
DEVICE2="$TEST_BASE_DIR/device-2"

# Needed to set multihost=on
log_must mmp_set_hostid $HOSTID1
if ! is_freebsd; then
good_props+=('multihost=on')
bad_props+=('multihost=none')
if [ -e $HOSTID_FILE ]; then
log_unsupported "System has existing $HOSTID_FILE file"
fi
# Needed to set multihost=on
log_must mmp_set_hostid $HOSTID1
fi

# Verify we can set a combination of valid property values on the new pool
for prop in "${good_props[@]}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ log_must ulimit -f 1024
log_mustnot sh -c 'dd if=/dev/zero of=$TESTDIR/ulimit_write_file bs=1M count=2'
log_must rm $TESTDIR/ulimit_write_file
# FreeBSD allows the sparse file because space has not been allocated.
if !is_freebsd; then
if ! is_freebsd; then
log_mustnot sh -c 'truncate -s2M $TESTDIR/ulimit_trunc_file'
log_must rm $TESTDIR/ulimit_trunc_file
fi
Expand Down
30 changes: 13 additions & 17 deletions tests/zfs-tests/tests/functional/redacted_send/redacted.kshlib
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ function setup_embedded
typeset recsize
typeset mntpnt=$(get_prop mountpoint $sendfs)
for recsize in 512 1024 2048 4096 8192 16384; do
if is_linux; then
if is_illumos; then
log_must mkholes -d $((recsize - 8)):8 $mntpnt/$recsize
else
log_must dd if=/dev/urandom of=$mntpnt/$recsize bs=8 \
count=1 seek=$(((recsize / 8) - 1))
else
log_must mkholes -d $((recsize - 8)):8 $mntpnt/$recsize
fi
done
}
Expand All @@ -79,22 +79,22 @@ function setup_holes
typeset mntpnt=$(get_prop mountpoint $sendfs)
typeset M=$((1024 * 1024))

if is_linux; then
if is_illumos; then
log_must mkholes -d 0:$((8 * M)) $mntpnt/f1
log_must mkholes -d 0:$M -d $((7 * M)):$M $mntpnt/f2
log_must mkholes -d $M:$((6 * M)) -h $((7 * M)):$M $mntpnt/f3
log_must mkholes -h 0:$((8 * M)) $mntpnt/f4
else
log_must dd if=/dev/urandom of=$mntpnt/f1 bs=8M count=1

log_must dd if=/dev/urandom of=$mntpnt/f2 bs=1M count=1
log_must dd if=/dev/urandom of=$mntpnt/f2 bs=1M count=1 seek=7 \
conv=notrunc

log_must dd if=/dev/urandom of=$mntpnt/f3 bs=1M count=6 seek=1
log_must truncate $mntpnt/f3 --size=$((8 * M))
log_must truncate -s $((8 * M)) $mntpnt/f3

log_must truncate $mntpnt/f4 --size=$((8 * M))
else
log_must mkholes -d 0:$((8 * M)) $mntpnt/f1
log_must mkholes -d 0:$M -d $((7 * M)):$M $mntpnt/f2
log_must mkholes -d $M:$((6 * M)) -h $((7 * M)):$M $mntpnt/f3
log_must mkholes -h 0:$((8 * M)) $mntpnt/f4
log_must truncate -s $((8 * M)) $mntpnt/f4
fi

log_must zfs create $sendfs/manyrm
Expand Down Expand Up @@ -237,15 +237,11 @@ function redacted_cleanup
typeset ds_list=$@
typeset ds

# Verify the receiving pool can still be exported and imported.
log_must zpool export $POOL2
log_must zpool import $POOL2

for ds in $ds_list; do
datasetexists $ds && log_must zfs destroy -R $ds
zfs destroy -R $ds
done

log_must set_tunable32 ALLOW_REDACTED_DATASET_MOUNT 0
set_tunable32 ALLOW_REDACTED_DATASET_MOUNT 0
rm -f $(get_prop mountpoint $POOL)/tmp/*
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ typeset M=$((1024 * 1024))
log_onexit redacted_cleanup $sendfs $recvfs

# Write holes at the start and end of a non-sparse file.
if is_linux; then
if is_illumos; then
log_must mkholes -h 0:$M -h $((7 * M)):$M $clone_mnt/f1
else
log_must dd if=/dev/zero of=$clone_mnt/f1 bs=1M count=1 conv=notrunc
log_must dd if=/dev/zero of=$clone_mnt/f1 bs=1M count=1 conv=notrunc seek=7
else
log_must mkholes -h 0:$M -h $((7 * M)):$M $clone_mnt/f1
fi
log_must zfs snapshot $clone@snap1
log_must zfs redact $sendfs@snap book1 $clone@snap1
Expand All @@ -72,11 +72,11 @@ log_must zfs rollback -R $clone@snap
log_must zfs destroy -R $recvfs

# Write data into the middle of a hole.
if is_linux; then
if is_illumos; then
log_must mkholes -d $((3 * M)):$((2 * M)) $clone_mnt/f2
else
log_must dd if=/dev/urandom of=$clone_mnt/f2 bs=1M count=2 seek=3 \
conv=notrunc
else
log_must mkholes -d $((3 * M)):$((2 * M)) $clone_mnt/f2
fi
log_must zfs snapshot $clone@snap1
log_must zfs redact $sendfs@snap book3 $clone@snap1
Expand Down
25 changes: 17 additions & 8 deletions tests/zfs-tests/tests/functional/removal/removal_resume_export.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,28 @@

function cleanup
{
log_must zinject -c all
zinject -c all
default_cleanup_noexit
}

function callback
{
#
# Inject an error so export fails after having just suspended
# the removal thread. [spa_inject_ref gets incremented]
#
log_must zinject -d $REMOVEDISK -D 10:1 $TESTPOOL

#
# Because of the above error export should fail.
#
log_mustnot zpool export $TESTPOOL

#
# Let the removal finish.
#
log_must zinject -c all

return 0
}

Expand Down Expand Up @@ -78,13 +93,7 @@ log_must dd if=/dev/urandom of=$TESTDIR/$TESTFILE0 bs=64M count=32
log_must zpool add -f $TESTPOOL $NOTREMOVEDISK

#
# Inject an error so export fails after having just suspended
# the removal thread. [spa_inject_ref gets incremented]
#
log_must zinject -d $REMOVEDISK -D 10:1 $TESTPOOL

#
# Because of the above error export should fail.
# Attempt the export with errors injected.
#
log_must attempt_during_removal $TESTPOOL $REMOVEDISK callback

Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/tests/functional/rsend/send_hole_birth.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ log_must truncate -s 1G /$sendfs/file1
log_must dd if=/dev/urandom of=/$sendfs/file1 bs=4k count=11264 seek=1152
log_must zfs snapshot $sendfs@snap1

log_must truncate -s 4194304 /$sendfs/file1
log_must truncate -s 4M /$sendfs/file1
log_must dd if=/dev/urandom of=/$sendfs/file1 bs=4k count=152 seek=384 \
conv=notrunc
log_must dd if=/dev/urandom of=/$sendfs/file1 bs=4k count=10 seek=1408 \
Expand Down

0 comments on commit 2b95e91

Please sign in to comment.