Skip to content

Commit

Permalink
Fix some ZFS Test Suite issues
Browse files Browse the repository at this point in the history
* Add 'zfs bookmark' coverage (zfs_bookmark_cliargs)

 * Add OpenZFS 8166 coverage (zpool_scrub_offline_device)

 * Fix "busy" zfs_mount_remount failures

 * Fix bootfs_003_pos, bootfs_004_neg, zdb_005_pos local cleanup

 * Update usage of $KEEP variable, add get_all_pools() function

 * Enable history_008_pos and rsend_019_pos (non-32bit builders)

 * Enable zfs_copies_005_neg, update local cleanup

 * Fix zfs_send_007_pos (large_dnode + OpenZFS 8199)

 * Fix rollback_003_pos (use dataset name, not mountpoint, to unmount)

 * Update default_raidz_setup() to work properly with more than 3 disks

 * Use $TEST_BASE_DIR instead of hardcoded (/var)/tmp for file VDEVs

 * Update usage of /dev/random to /dev/urandom

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Issue #6086 
Closes #5658 
Closes #6143 
Closes #6421 
Closes #6627 
Closes #6632
  • Loading branch information
loli10K authored and behlendorf committed Sep 25, 2017
1 parent b33d668 commit 3fd3e56
Show file tree
Hide file tree
Showing 44 changed files with 479 additions and 143 deletions.
2 changes: 1 addition & 1 deletion cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -6729,7 +6729,7 @@ unshare_unmount(int op, int argc, char **argv)

case OP_MOUNT:
if (zfs_unmount(node->un_zhp,
node->un_mountp, flags) != 0)
node->un_zhp->zfs_name, flags) != 0)
ret = 1;
break;
}
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ AC_CONFIG_FILES([
tests/zfs-tests/tests/functional/clean_mirror/Makefile
tests/zfs-tests/tests/functional/cli_root/Makefile
tests/zfs-tests/tests/functional/cli_root/zdb/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_bookmark/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_change-key/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_clone/Makefile
tests/zfs-tests/tests/functional/cli_root/zfs_copies/Makefile
Expand Down
6 changes: 5 additions & 1 deletion lib/libzfs/libzfs_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ is_shared(libzfs_handle_t *hdl, const char *mountpoint, zfs_share_proto_t proto)
if (hdl->libzfs_sharetab == NULL)
return (SHARED_NOT_SHARED);

/* Reopen ZFS_SHARETAB to prevent reading stale data from open file */
if (freopen(ZFS_SHARETAB, "r", hdl->libzfs_sharetab) == NULL)
return (SHARED_NOT_SHARED);

(void) fseek(hdl->libzfs_sharetab, 0, SEEK_SET);

while (fgets(buf, sizeof (buf), hdl->libzfs_sharetab) != NULL) {
Expand Down Expand Up @@ -660,7 +664,7 @@ zfs_unmount(zfs_handle_t *zhp, const char *mountpoint, int flags)
* then get freed later. We strdup it to play it safe.
*/
if (mountpoint == NULL)
mntpt = zfs_strdup(hdl, entry.mnt_mountp);
mntpt = zfs_strdup(hdl, entry.mnt_special);
else
mntpt = zfs_strdup(hdl, mountpoint);

Expand Down
18 changes: 16 additions & 2 deletions scripts/zfs-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,28 @@ fi

#
# By default preserve any existing pools
# NOTE: Since 'zpool list' outputs a newline-delimited list convert $KEEP from
# space-delimited to newline-delimited.
#
if [ -z "${KEEP}" ]; then
KEEP=$(sudo "$ZPOOL" list -H -o name)
KEEP="$(sudo "$ZPOOL" list -H -o name)"
if [ -z "${KEEP}" ]; then
KEEP="rpool"
fi
else
KEEP="$(echo -e "${KEEP//[[:blank:]]/\n}")"
fi

__ZFS_POOL_EXCLUDE="$(echo $KEEP | sed ':a;N;s/\n/ /g;ba')"
#
# NOTE: The following environment variables are undocumented
# and should be used for testing purposes only:
#
# __ZFS_POOL_EXCLUDE - don't iterate over the pools it lists
# __ZFS_POOL_RESTRICT - iterate only over the pools it lists
#
# See libzfs/libzfs_config.c for more information.
#
__ZFS_POOL_EXCLUDE="$(echo "$KEEP" | sed ':a;N;s/\n/ /g;ba')"

. "$STF_SUITE/include/default.cfg"

Expand Down Expand Up @@ -524,6 +537,7 @@ export STF_TOOLS
export STF_SUITE
export STF_PATH
export DISKS
export FILEDIR
export KEEP
export __ZFS_POOL_EXCLUDE
export TESTFAIL_CALLBACKS
Expand Down
7 changes: 4 additions & 3 deletions tests/runfiles/linux.run
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ post =
[tests/functional/cli_root/zfs]
tests = ['zfs_001_neg', 'zfs_002_pos', 'zfs_003_neg']

[tests/functional/cli_root/zfs_bookmark]
tests = ['zfs_bookmark_cliargs']

[tests/functional/cli_root/zfs_change-key]
tests = ['zfs_change-key', 'zfs_change-key_child', 'zfs_change-key_format',
'zfs_change-key_inherit', 'zfs_change-key_load', 'zfs_change-key_location',
Expand Down Expand Up @@ -293,12 +296,10 @@ tests = ['zpool_replace_001_neg', 'replace-o_ashift', 'replace_prop_ashift']
[tests/functional/cli_root/zpool_scrub]
tests = ['zpool_scrub_001_neg', 'zpool_scrub_002_pos', 'zpool_scrub_003_pos',
'zpool_scrub_004_pos', 'zpool_scrub_005_pos',
'zpool_scrub_encrypted_unloaded']
'zpool_scrub_encrypted_unloaded', 'zpool_scrub_offline_device']

[tests/functional/cli_root/zpool_set]
tests = ['zpool_set_001_pos', 'zpool_set_002_neg', 'zpool_set_003_neg']
pre =
post =

[tests/functional/cli_root/zpool_status]
tests = ['zpool_status_001_pos', 'zpool_status_002_pos','zpool_status_003_pos',
Expand Down
4 changes: 3 additions & 1 deletion tests/zfs-tests/include/default.cfg.in
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ export NO_POOLS="no pools available"
# pattern to ignore from 'zfs list'.
export NO_DATASETS="no datasets available"

export TEST_BASE_DIR="/var/tmp"
# Default directory used for test files
# NOTE: remove trailing "/", some functions rely on this to do pattern matching
export TEST_BASE_DIR="$(dirname ${FILEDIR:-/var/tmp}/.)"

# Default to compression ON
export COMPRESSION_PROP=on
Expand Down
26 changes: 16 additions & 10 deletions tests/zfs-tests/include/libtest.shlib
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ function default_raidz_setup
fi

[[ -d /$TESTPOOL ]] && rm -rf /$TESTPOOL
log_must zpool create -f $TESTPOOL raidz $1 $2 $3
log_must zpool create -f $TESTPOOL raidz $disklist
log_must zfs create $TESTPOOL/$TESTFS
log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS

Expand All @@ -503,19 +503,27 @@ function default_cleanup
log_pass
}

#
# Utility function used to list all available pool names.
#
# NOTE: $KEEP is a variable containing pool names, separated by a newline
# character, that must be excluded from the returned list.
#
function get_all_pools
{
zpool list -H -o name | grep -Fvx "$KEEP" | grep -v "$NO_POOLS"
}

function default_cleanup_noexit
{
typeset exclude=""
typeset pool=""
#
# Destroying the pool will also destroy any
# filesystems it contains.
#
if is_global_zone; then
zfs unmount -a > /dev/null 2>&1
exclude=`eval echo \"'(${KEEP})'\"`
ALL_POOLS=$(zpool list -H -o name \
| grep -v "$NO_POOLS" | egrep -v "$exclude")
ALL_POOLS=$(get_all_pools)
# Here, we loop through the pools we're allowed to
# destroy, only destroying them if it's safe to do
# so.
Expand All @@ -527,9 +535,7 @@ function default_cleanup_noexit
then
destroy_pool $pool
fi
ALL_POOLS=$(zpool list -H -o name \
| grep -v "$NO_POOLS" \
| egrep -v "$exclude")
ALL_POOLS=$(get_all_pools)
done
done

Expand Down Expand Up @@ -1617,7 +1623,7 @@ function zfs_zones_setup #zone_name zone_root zone_ip
# If current system support slog, add slog device for pool
#
if verify_slog_support ; then
typeset sdevs="/var/tmp/sdev1 /var/tmp/sdev2"
typeset sdevs="$TEST_BASE_DIR/sdev1 $TEST_BASE_DIR/sdev2"
log_must mkfile $MINVDEVSIZE $sdevs
log_must zpool add $pool_name log mirror $sdevs
fi
Expand Down Expand Up @@ -2615,7 +2621,7 @@ function random_get
#
function verify_slog_support
{
typeset dir=/tmp/disk.$$
typeset dir=$TEST_BASE_DIR/disk.$$
typeset pool=foo.$$
typeset vdev=$dir/a
typeset sdev=$dir/b
Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/tests/functional/bootfs/bootfs_003_pos.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function cleanup {
if poolexists $POOL ; then
log_must zpool destroy $POOL
fi
rm /bootfs_003.$$.dat
rm $TESTDIR/bootfs_003.$$.dat
}


Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/tests/functional/bootfs/bootfs_004_neg.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function cleanup {
if poolexists $POOL; then
log_must zpool destroy $POOL
fi
rm /bootfs_004.$$.dat
rm $TESTDIR/bootfs_004.$$.dat
}


Expand Down
3 changes: 2 additions & 1 deletion tests/zfs-tests/tests/functional/cache/cache.kshlib
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ function display_status
((ret |= $?))

typeset mntpnt=$(get_prop mountpoint $pool)
dd if=/dev/random of=$mntpnt/testfile.$$ &
dd if=/dev/urandom of=$mntpnt/testfile.$$ &
typeset pid=$!

zpool iostat -v 1 3 > /dev/null
((ret |= $?))

kill -9 $pid
wait

return $ret
}
Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/tests/functional/cli_root/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ dist_pkgdata_SCRIPTS = \
SUBDIRS = \
zdb \
zfs \
zfs_bookmark \
zfs_change-key \
zfs_clone \
zfs_copies \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ log_onexit cleanup
function cleanup
{
datasetexists $TESTPOOL && destroy_pool $TESTPOOL
rm -f $TEMPFILE
}

verify_runnable "global"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zfs_bookmark
dist_pkgdata_SCRIPTS = \
setup.ksh \
cleanup.ksh \
zfs_bookmark_cliargs.ksh
29 changes: 29 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/zfs_bookmark/cleanup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

default_cleanup
31 changes: 31 additions & 0 deletions tests/zfs-tests/tests/functional/cli_root/zfs_bookmark/setup.ksh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

DISK=${DISKS%% *}

default_volume_setup $DISK
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

#
# DESCRIPTION:
# 'zfs bookmark' should work with both full and short arguments.
#
# STRATEGY:
# 1. Create initial snapshot
# 2. Verify we can create a bookmark specifying snapshot and bookmark full paths
# 3. Verify we can create a bookmark specifying the snapshot name
# 4. Verify we can create a bookmark specifying the bookmark name
#

verify_runnable "both"

function cleanup
{
if snapexists "$DATASET@$TESTSNAP"; then
log_must zfs destroy "$DATASET@$TESTSNAP"
fi
if bkmarkexists "$DATASET#$TESTBM"; then
log_must zfs destroy "$DATASET#$TESTBM"
fi
}

log_assert "'zfs bookmark' works as expected when passed valid arguments."
log_onexit cleanup

DATASET="$TESTPOOL/$TESTFS"
TESTSNAP='snapshot'
TESTBM='bookmark'

# Create initial snapshot
log_must zfs snapshot "$DATASET@$TESTSNAP"

# Verify we can create a bookmark specifying snapshot and bookmark full paths
log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET#$TESTBM"
log_must eval "bkmarkexists $DATASET#$TESTBM"
log_must zfs destroy "$DATASET#$TESTBM"

# Verify we can create a bookmark specifying the snapshot name
log_must zfs bookmark "@$TESTSNAP" "$DATASET#$TESTBM"
log_must eval "bkmarkexists $DATASET#$TESTBM"
log_must zfs destroy "$DATASET#$TESTBM"

# Verify we can create a bookmark specifying the bookmark name
log_must zfs bookmark "$DATASET@$TESTSNAP" "#$TESTBM"
log_must eval "bkmarkexists $DATASET#$TESTBM"
log_must zfs destroy "$DATASET#$TESTBM"

log_pass "'zfs bookmark' works as expected when passed valid arguments."
Loading

0 comments on commit 3fd3e56

Please sign in to comment.