diff --git a/tests/zfs-tests/tests/functional/bootfs/bootfs_002_neg.ksh b/tests/zfs-tests/tests/functional/bootfs/bootfs_002_neg.ksh index 6a72bfcdc40c..a5bc7753e96e 100755 --- a/tests/zfs-tests/tests/functional/bootfs/bootfs_002_neg.ksh +++ b/tests/zfs-tests/tests/functional/bootfs/bootfs_002_neg.ksh @@ -1,86 +1,81 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Copyright 2015 Nexenta Systems, Inc. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # # # Copyright (c) 2012, 2015 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # # Invalid datasets are rejected as boot property values # # STRATEGY: # # 1. Create a zvol # 2. Verify that we can't set the bootfs to that dataset # verify_runnable "global" function cleanup { - if datasetexists $TESTPOOL/vol - then - log_must zfs destroy $TESTPOOL/vol - fi - if poolexists $TESTPOOL - then - log_must zpool destroy $TESTPOOL - fi + datasetexists $TESTPOOL/vol && destroy_dataset $TESTPOOL/vol + poolexists $TESTPOOL && log_must zpool destroy $TESTPOOL + if [[ -f $VDEV ]]; then log_must rm -f $VDEV fi } zpool set 2>&1 | grep bootfs > /dev/null if [ $? -ne 0 ] then log_unsupported "bootfs pool property not supported on this release." fi log_assert "Invalid datasets are rejected as boot property values" log_onexit cleanup typeset VDEV=$TESTDIR/bootfs_002_neg_a.$$.dat log_must mkfile 400m $VDEV create_pool "$TESTPOOL" "$VDEV" log_must zfs create -V 10m $TESTPOOL/vol block_device_wait log_mustnot zpool set bootfs=$TESTPOOL/vol $TESTPOOL log_pass "Invalid datasets are rejected as boot property values" diff --git a/tests/zfs-tests/tests/functional/casenorm/casenorm.kshlib b/tests/zfs-tests/tests/functional/casenorm/casenorm.kshlib index cb61798d7be7..f0fe1bbaa886 100644 --- a/tests/zfs-tests/tests/functional/casenorm/casenorm.kshlib +++ b/tests/zfs-tests/tests/functional/casenorm/casenorm.kshlib @@ -1,131 +1,131 @@ # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2015 Nexenta Systems, Inc. All rights reserved. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/casenorm/casenorm.cfg function create_testfs { typeset opts=$1 rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR mkdir -p $TESTDIR || log_unresolved Could not create $TESTDIR log_must zfs create $opts $TESTPOOL/$TESTFS log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS } function destroy_testfs { if datasetexists $TESTPOOL/$TESTFS ; then - log_must zfs destroy -f $TESTPOOL/$TESTFS + destroy_dataset $TESTPOOL/$TESTFS -f rm -rf $TESTDIR || log_unresolved Could not remove $TESTDIR fi } function create_file { typeset name=$TESTDIR/$1 echo $name > $name } function delete_file { typeset name=$TESTDIR/$1 rm $name >/dev/null 2>&1 if [[ $? -ne 0 ]] ; then return 1 fi if [[ -f $name ]] ; then return 2 fi } function lookup_file { typeset name=$1 if is_illumos; then zlook -l $TESTDIR $name >/dev/null 2>&1 else test -f "${TESTDIR}/${name}" >/dev/null 2>&1 fi } function lookup_file_ci { typeset name=$1 if is_illumos; then zlook -il $TESTDIR $name >/dev/null 2>&1 else test -f "${TESTDIR}/${name}" >/dev/null 2>&1 fi } function lookup_any { for name in $NAMES_ALL ; do lookup_file $name if [[ $? -eq 0 ]] ; then return 0 fi done return 1 } function switch_norm { typeset norm=$(get_norm $1) if [[ $norm == "C" ]] ; then print "D" else print "C" fi } function get_norm { if [[ "${NAMES_C#*$1}" != "${NAMES_C}" ]] ; then print "C" elif [[ "${NAMES_D#*$1}" != "${NAMES_D}" ]] ; then print "D" else return 1 fi } function get_case { if [[ ${NAMES_UPPER#*$1} != ${NAMES_UPPER} ]] ; then print "UPPER" elif [[ ${NAMES_LOWER#*$1} != ${NAMES_LOWER} ]] ; then print "LOWER" elif [[ ${NAMES_ORIG#*$1} != ${NAMES_ORIG} ]] ; then print "ORIG" else return 1 fi } diff --git a/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.ksh b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.ksh index d486c25f4487..eba01b17c80e 100755 --- a/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.ksh +++ b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.exists.ksh @@ -1,45 +1,45 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2017 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/channel_program/channel_common.kshlib # # DESCRIPTION: # zfs.exists should accurately report whether a dataset exists, and # report an error if a dataset is in another pool. verify_runnable "global" # create $TESTSNAP and $TESTCLONE create_snapshot create_clone function cleanup { datasetexists $TESTPOOL/$TESTFS@$TESTSNAP && \ - log_must zfs destroy -R $TESTPOOL/$TESTFS@$TESTSNAP + destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP -R } log_must_program $TESTPOOL $ZCP_ROOT/lua_core/tst.exists.zcp \ $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS@$TESTSNAP \ $TESTPOOL/$TESTCLONE log_mustnot_checkerror_program "not in the target pool" \ $TESTPOOL - <<-EOF return zfs.exists('rpool') EOF log_pass "zfs.exists() gives correct results" diff --git a/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.return_large.ksh b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.return_large.ksh index ba9c40739471..bbaeb54f59a5 100755 --- a/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.return_large.ksh +++ b/tests/zfs-tests/tests/functional/channel_program/lua_core/tst.return_large.ksh @@ -1,54 +1,54 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2016, 2017 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/channel_program/channel_common.kshlib # # DESCRIPTION: Returning very large (up to the memory limit) lists should # function correctly. # verify_runnable "global" fs=$TESTPOOL/$TESTFS/testchild function cleanup { - datasetexists $fs && log_must zfs destroy -R $fs + datasetexists $fs && destroy_dataset $fs -R } log_onexit cleanup log_must zfs create $fs # # Actually checking in the ~500kb expected result of this program would be # awful, so we just make sure it was as long as we expected. # output_lines=$(log_must zfs program $TESTPOOL \ $ZCP_ROOT/lua_core/tst.return_large.zcp | wc -l) [[ $output_lines -lt 5000 ]] && log_fail "Expected return of full list but only got $output_lines lines" # # Make sure we fail if the return is over the memory limit # log_mustnot_program -m 10000 $TESTPOOL \ $ZCP_ROOT/lua_core/tst.return_large.zcp log_pass "Large return values work properly" diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_string_props.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_string_props.ksh index b7d784489ac8..31ae4a5717f5 100755 --- a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_string_props.ksh +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.get_string_props.ksh @@ -1,45 +1,45 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/channel_program/channel_common.kshlib # # DESCRIPTION: # Getting string props should work correctly. # verify_runnable "global" fs=$TESTPOOL/testchild snap=$fs@$TESTSNAP clone=$TESTPOOL/$TESTCLONE function cleanup { - datasetexists $clone && log_must zfs destroy $clone - datasetexists $fs && log_must zfs destroy -R $fs + datasetexists $clone && destroy_dataset $clone + datasetexists $fs && destroy_dataset $fs -R } log_onexit cleanup log_must zfs create $fs create_snapshot $fs $TESTSNAP create_clone $snap $clone log_must_program $TESTPOOL $ZCP_ROOT/synctask_core/tst.get_string_props.zcp $fs $snap $clone log_pass "Getting string props should work correctly." diff --git a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.terminate_by_signal.ksh b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.terminate_by_signal.ksh index 0a5fb804ac39..2c9014a08483 100755 --- a/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.terminate_by_signal.ksh +++ b/tests/zfs-tests/tests/functional/channel_program/synctask_core/tst.terminate_by_signal.ksh @@ -1,98 +1,98 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2017 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/channel_program/channel_common.kshlib # # DESCRIPTION: Execute a long-running zfs channel program and attempt to # cancel it by sending a signal. # verify_runnable "global" rootfs=$TESTPOOL/$TESTFS snapname=snap limit=50000000 function cleanup { - datasetexists $rootfs && log_must zfs destroy -R $rootfs + datasetexists $rootfs && destroy_dataset $rootfs -R } log_onexit cleanup # # Create a working set of 100 file systems # for i in {1..100}; do log_must zfs create "$rootfs/child$i" done # # Attempt to create 100 snapshots with zfs.sync.snapshot() along with some # time consuming efforts. We use loops of zfs.check.* (dry run operations) # to consume instructions before the next zfs.sync.snapshot() occurs. # # Without a signal interruption this ZCP would take several minutes and # generate over 30 million Lua instructions. # function chan_prog { zfs program -t $limit $TESTPOOL - $rootfs $snapname <<-EOF arg = ... fs = arg["argv"][1] snap = arg["argv"][2] for child in zfs.list.children(fs) do local snapname = child .. "@" .. snap zfs.check.snapshot(snapname) zfs.sync.snapshot(snapname) for i=1,20000,1 do zfs.check.snapshot(snapname) zfs.check.destroy(snapname) zfs.check.destroy(fs) end end return "should not have reached here" EOF } log_note "Executing a long-running zfs program in the background" chan_prog & CHILD=$! # # After waiting, send a kill signal to the channel program process. # This should stop the ZCP near a million instructions but still have # created some of the snapshots. Note that since the above zfs program # command might get wrapped, we also issue a kill to the group. # sleep 10 log_pos pkill -P $CHILD log_pos kill $CHILD # # Make sure the channel program did not fully complete by enforcing # that not all of the snapshots were created. # snap_count=$(zfs list -t snapshot | grep $TESTPOOL | wc -l) log_note "$snap_count snapshots created by ZCP" if [ "$snap_count" -eq 0 ]; then log_fail "Channel program failed to run." elif [ "$snap_count" -gt 90 ]; then log_fail "Too many snapshots after a cancel ($snap_count)." else log_pass "Canceling a long-running channel program works." fi diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh index b475960c9dea..1290d888a947 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs/zfs_002_pos.ksh @@ -1,123 +1,121 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # With ZFS_ABORT set, all zfs commands should be able to abort and generate a # core file. # # STRATEGY: # 1. Create an array of zfs command # 2. Execute each command in the array # 3. Verify the command aborts and generate a core file # verify_runnable "both" function cleanup { unset ZFS_ABORT if is_freebsd && [[ -n $savedcorefile ]]; then sysctl kern.corefile=$savedcorefile fi if [[ -d $corepath ]]; then rm -rf $corepath fi for ds in $fs1 $fs $ctr; do - if datasetexists $ds; then - log_must zfs destroy -rRf $ds - fi + datasetexists $ds && destroy_dataset $ds -rRf done } log_assert "With ZFS_ABORT set, all zfs commands can abort and generate a " \ "core file." log_onexit cleanup # Preparation work for testing savedcorefile="" corepath=$TESTDIR/core corefile=$corepath/core.zfs if [[ -d $corepath ]]; then rm -rf $corepath fi log_must mkdir $corepath ctr=$TESTPOOL/$TESTCTR log_must zfs create $ctr fs=$ctr/$TESTFS fs1=$ctr/$TESTFS1 snap=$fs@$TESTSNAP clone=$ctr/$TESTCLONE streamf=$corepath/s.$$ typeset cmds=("create $fs" "list $fs" "snapshot $snap" "set snapdir=hidden $fs" \ "get snapdir $fs" "rollback $snap" "inherit snapdir $fs" \ "rename $fs $fs-new" "rename $fs-new $fs" "unmount $fs" \ "mount $fs" "share $fs" "unshare $fs" "send $snap \>$streamf" \ "receive $fs1 \<$streamf" "clone $snap $clone" "promote $clone" \ "promote $fs" "destroy -rRf $fs") typeset badparams=("" "create" "destroy" "snapshot" "rollback" "clone" \ "promote" "rename" "list -*" "set" "get -*" "inherit" "mount -A" \ "unmount" "share" "unshare" "send" "receive") if is_linux; then ulimit -c unlimited 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 log_must export ZFS_ABORT=yes for subcmd in "${cmds[@]}" "${badparams[@]}"; do zfs $subcmd >/dev/null 2>&1 && log_fail "$subcmd passed incorrectly." if [[ ! -e $corefile ]]; then log_fail "zfs $subcmd cannot generate core file with " \ "ZFS_ABORT set." fi log_must rm -f $corefile done log_pass "With ZFS_ABORT set, zfs command can abort and generate core file " \ "as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh index 10e93337abf8..3a1cddb5c64a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_bookmark/zfs_bookmark_cliargs.ksh @@ -1,238 +1,237 @@ #!/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 . All rights reserved. # Copyright 2019, 2020 by Christian Schwarz. 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 short snapshot name # 4. Verify we can create a bookmark specifying the short bookmark name # 5. Verify at least a full dataset path is required and both snapshot and # bookmark name must be valid # # 6. Verify we can copy a bookmark by specifying the source bookmark and new # bookmark full paths. # 7. Verify we can copy a bookmark specifying the short source name # 8. Verify we can copy a bookmark specifying the short new name # 9. Verify two short paths are not allowed, and test empty paths # 10. Verify we cannot copy a bookmark if the new bookmark already exists # 11. Verify that copying a bookmark only works if new and source name # have the same dataset # 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 - if bkmarkexists "$DATASET#$TESTBMCOPY"; then - log_must zfs destroy "$DATASET#$TESTBMCOPY" - fi + snapexists "$DATASET@$TESTSNAP" && \ + destroy_dataset "$DATASET@$TESTSNAP" + + bkmarkexists "$DATASET#$TESTBM" && \ + destroy_dataset "$DATASET#$TESTBM" + + bkmarkexists "$DATASET#$TESTBMCOPY" && \ + destroy_dataset "$DATASET#$TESTBMCOPY" } log_assert "'zfs bookmark' should work only when passed valid arguments." log_onexit cleanup DATASET="$TESTPOOL/$TESTFS" DATASET_TWO="$TESTPOOL/${TESTFS}_two" TESTSNAP='snapshot' TESTSNAP2='snapshot2' TESTBM='bookmark' TESTBMCOPY='bookmark_copy' # Create initial snapshot log_must zfs snapshot "$DATASET@$TESTSNAP" # # Bookmark creation tests # # 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" # Verify at least a full dataset path is required and both snapshot and # bookmark name must be valid log_mustnot zfs bookmark "@$TESTSNAP" "#$TESTBM" log_mustnot zfs bookmark "$TESTSNAP" "#$TESTBM" log_mustnot zfs bookmark "@$TESTSNAP" "$TESTBM" log_mustnot zfs bookmark "$TESTSNAP" "$TESTBM" log_mustnot zfs bookmark "$TESTSNAP" "$DATASET#$TESTBM" log_mustnot zfs bookmark "$DATASET" "$TESTBM" log_mustnot zfs bookmark "$DATASET@" "$TESTBM" log_mustnot zfs bookmark "$DATASET" "#$TESTBM" log_mustnot zfs bookmark "$DATASET@" "#$TESTBM" log_mustnot zfs bookmark "$DATASET@$TESTSNAP" "$TESTBM" log_mustnot zfs bookmark "@" "#$TESTBM" log_mustnot zfs bookmark "@" "#" log_mustnot zfs bookmark "@$TESTSNAP" "#" log_mustnot zfs bookmark "@$TESTSNAP" "$DATASET#" log_mustnot zfs bookmark "@$TESTSNAP" "$DATASET" log_mustnot zfs bookmark "$TESTSNAP" "$DATASET#" log_mustnot zfs bookmark "$TESTSNAP" "$DATASET" log_mustnot eval "bkmarkexists $DATASET#$TESTBM" # Verify that we can create a bookmarks on another origin filesystem log_must zfs clone "$DATASET@$TESTSNAP" "$DATASET_TWO" log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET_TWO#$TESTBM" log_must eval "destroy_dataset $DATASET_TWO" # Verify that we can cannot create bookmarks on a non-origin filesystem log_must zfs create "$DATASET_TWO" log_mustnot_expect "source is not an ancestor of the new bookmark's dataset" zfs bookmark "$DATASET@$TESTSNAP" "$DATASET_TWO#$TESTBM" log_must zfs destroy "$DATASET_TWO" # Verify that we can create bookmarks of snapshots on the pool dataset log_must zfs snapshot "$TESTPOOL@$TESTSNAP" log_must zfs bookmark "$TESTPOOL@$TESTSNAP" "$TESTPOOL#$TESTBM" log_must zfs destroy "$TESTPOOL#$TESTBM" log_must zfs destroy "$TESTPOOL@$TESTSNAP" # # Bookmark copying tests # # create the source bookmark log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET#$TESTBM" # Verify we can copy a bookmark by specifying the source bookmark # and new bookmark full paths. log_must eval "bkmarkexists $DATASET#$TESTBM" log_must zfs bookmark "$DATASET#$TESTBM" "$DATASET#$TESTBMCOPY" log_must eval "bkmarkexists $DATASET#$TESTBMCOPY" ## validate destroy once (should be truly independent bookmarks) log_must zfs destroy "$DATASET#$TESTBM" log_mustnot eval "bkmarkexists $DATASET#$TESTBM" log_must eval "bkmarkexists $DATASET#$TESTBMCOPY" log_must zfs destroy "$DATASET#$TESTBMCOPY" log_mustnot eval "bkmarkexists $DATASET#$TESTBMCOPY" log_mustnot eval "bkmarkexists $DATASET#$TESTBM" ## recreate the source bookmark log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET#$TESTBM" # Verify we can copy a bookmark specifying the short source name log_must zfs bookmark "#$TESTBM" "$DATASET#$TESTBMCOPY" log_must eval "bkmarkexists $DATASET#$TESTBMCOPY" log_must zfs destroy "$DATASET#$TESTBMCOPY" # Verify we can copy a bookmark specifying the short bookmark name log_must zfs bookmark "$DATASET#$TESTBM" "#$TESTBMCOPY" log_must eval "bkmarkexists $DATASET#$TESTBMCOPY" log_must zfs destroy "$DATASET#$TESTBMCOPY" # Verify two short paths are not allowed, and test empty paths log_mustnot zfs bookmark "#$TESTBM" "#$TESTBMCOPY" log_mustnot zfs bookmark "#$TESTBM" "#" log_mustnot zfs bookmark "#" "#$TESTBMCOPY" log_mustnot zfs bookmark "#" "#" log_mustnot zfs bookmark "#" "" log_mustnot zfs bookmark "" "#" log_mustnot zfs bookmark "" "" # Verify that we can copy bookmarks on another origin filesystem log_must zfs clone "$DATASET@$TESTSNAP" "$DATASET_TWO" log_must zfs bookmark "$DATASET#$TESTBM" "$DATASET_TWO#$TESTBMCOPY" log_must zfs destroy "$DATASET_TWO" # Verify that we can cannot create bookmarks on another non-origin filesystem log_must zfs create "$DATASET_TWO" log_mustnot_expect "source is not an ancestor of the new bookmark's dataset" zfs bookmark "$DATASET#$TESTBM" "$DATASET_TWO#$TESTBMCOPY" log_must zfs destroy "$DATASET_TWO" # Verify that we can copy bookmarks on the pool dataset log_must zfs snapshot "$TESTPOOL@$TESTSNAP" log_must zfs bookmark "$TESTPOOL@$TESTSNAP" "$TESTPOOL#$TESTBM" log_must zfs bookmark "$TESTPOOL#$TESTBM" "$TESTPOOL#$TESTBMCOPY" log_must zfs destroy "$TESTPOOL#$TESTBM" log_must zfs destroy "$TESTPOOL#$TESTBMCOPY" log_must zfs destroy "$TESTPOOL@$TESTSNAP" # Verify that copied 'normal' bookmarks are independent of the source bookmark log_must zfs bookmark "$DATASET#$TESTBM" "$DATASET#$TESTBMCOPY" log_must zfs destroy "$DATASET#$TESTBM" log_must eval "zfs send $DATASET@$TESTSNAP > $TEST_BASE_DIR/zfstest_datastream.$$" log_must eval "destroy_dataset $TESTPOOL/$TESTFS/recv" log_must eval "zfs recv -o mountpoint=none $TESTPOOL/$TESTFS/recv < $TEST_BASE_DIR/zfstest_datastream.$$" log_must zfs snapshot "$DATASET@$TESTSNAP2" log_must eval "zfs send -i \#$TESTBMCOPY $DATASET@$TESTSNAP2 > $TEST_BASE_DIR/zfstest_datastream.$$" log_must eval "zfs recv $TESTPOOL/$TESTFS/recv < $TEST_BASE_DIR/zfstest_datastream.$$" # cleanup log_must eval "destroy_dataset $DATASET@$TESTSNAP2" log_must zfs destroy "$DATASET#$TESTBMCOPY" log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET#$TESTBM" # Verify that copied redaction bookmarks are independent of the source bookmark ## create redaction bookmark log_must zfs destroy "$DATASET#$TESTBM" log_must zfs destroy "$DATASET@$TESTSNAP" log_must eval "echo secret > $TESTDIR/secret" log_must zfs snapshot "$DATASET@$TESTSNAP" log_must eval "echo redacted > $TESTDIR/secret" log_must zfs snapshot "$DATASET@$TESTSNAP2" # TESTSNAP2 is the redaction snapshot log_must zfs list -t all -o name,createtxg,guid,mountpoint,written log_must zfs redact "$DATASET@$TESTSNAP" "$TESTBM" "$DATASET@$TESTSNAP2" # ensure our primitive for testing whether a bookmark is a redaction bookmark works log_must eval "zfs get all $DATASET#$TESTBM | grep redact_snaps" ## copy the redaction bookmark log_must zfs bookmark "$DATASET#$TESTBM" "#$TESTBMCOPY" log_mustnot eval "zfs get all $DATASET#$TESTBMCOPY | grep redact_snaps" log_must eval "zfs send --redact "$TESTBMCOPY" -i $DATASET@$TESTSNAP $DATASET@$TESTSNAP2 2>&1 | head -n 100 | grep 'not a redaction bookmark'" # try the above again after destroying the source bookmark, preventive measure for future work log_must zfs destroy "$DATASET#$TESTBM" log_mustnot eval "zfs get all $DATASET#$TESTBMCOPY | grep redact_snaps" log_must eval "zfs send --redact "$TESTBMCOPY" -i $DATASET@$TESTSNAP $DATASET@$TESTSNAP2 2>&1 | head -n 100 | grep 'not a redaction bookmark'" ## cleanup log_must eval "destroy_dataset $DATASET@$TESTSNAP2" log_must zfs destroy "$DATASET#$TESTBMCOPY" log_must eval "destroy_dataset $DATASET@$TESTSNAP" log_must zfs snapshot "$DATASET@$TESTSNAP" log_must zfs bookmark "$DATASET@$TESTSNAP" "$DATASET#$TESTBM" log_pass "'zfs bookmark' works as expected" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key.ksh index 781caae5b5c0..821abdeb32f7 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key.ksh @@ -1,62 +1,62 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs change-key' should change the key material. # # STRATEGY: # 1. Create an encrypted dataset # 2. Attempt to change the key # 3. Unmount the dataset and unload its key # 4. Attempt to load the old key # 5. Verify the key is not loaded # 6. Attempt to load the new key # 7. Verify the key is loaded # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup log_assert "'zfs change-key' should change the key material" log_must eval "echo $PASSPHRASE1 | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1" log_must eval "echo $PASSPHRASE2 | zfs change-key $TESTPOOL/$TESTFS1" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_mustnot eval "echo $PASSPHRASE1 | zfs load-key $TESTPOOL/$TESTFS1" log_must key_unavailable $TESTPOOL/$TESTFS1 log_must eval "echo $PASSPHRASE2 | zfs load-key $TESTPOOL/$TESTFS1" log_must key_available $TESTPOOL/$TESTFS1 log_pass "'zfs change-key' changes the key material" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_child.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_child.ksh index a886ab8a7793..592f1eccca93 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_child.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_child.ksh @@ -1,91 +1,91 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs change-key' should promote an encrypted child to an encryption root. # # STRATEGY: # 1. Create an encrypted dataset # 2. Create an encrypted child dataset # 3. Create an unencrypted child dataset # 4. Attempt to change the key without any flags # 5. Attempt to change the key specifying keylocation # 6. Attempt to change the key specifying keyformat # 7. Verify the new encryption root can unload and load its key # 8. Recreate the child dataset # 9. Attempt to change the key specifying both the keylocation and keyformat # 10. Verify the new encryption root can unload and load its key # 11. Verify the unencrytped child is still accessible normally # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r } log_onexit cleanup log_assert "'zfs change-key' should promote an encrypted child to an" \ "encryption root" log_must eval "echo $PASSPHRASE1 | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1" log_must zfs create $TESTPOOL/$TESTFS1/child log_must zfs create -o encryption=off $TESTPOOL/$TESTFS1/child2 log_mustnot eval "echo $PASSPHRASE2 | zfs change-key" \ "$TESTPOOL/$TESTFS1/child" log_mustnot eval "echo $PASSPHRASE2 | zfs change-key -o keylocation=prompt" \ "$TESTPOOL/$TESTFS1/child" log_must eval "echo $PASSPHRASE2 | zfs change-key -o keyformat=passphrase" \ "$TESTPOOL/$TESTFS1/child" log_must zfs unmount $TESTPOOL/$TESTFS1/child log_must zfs unload-key $TESTPOOL/$TESTFS1/child log_must key_unavailable $TESTPOOL/$TESTFS1/child log_must eval "echo $PASSPHRASE2 | zfs load-key $TESTPOOL/$TESTFS1/child" log_must key_available $TESTPOOL/$TESTFS1/child log_must zfs destroy $TESTPOOL/$TESTFS1/child log_must zfs create $TESTPOOL/$TESTFS1/child log_must eval "echo $PASSPHRASE2 | zfs change-key -o keyformat=passphrase" \ "-o keylocation=prompt $TESTPOOL/$TESTFS1/child" log_must zfs unmount $TESTPOOL/$TESTFS1/child log_must zfs unload-key $TESTPOOL/$TESTFS1/child log_must key_unavailable $TESTPOOL/$TESTFS1/child log_must eval "echo $PASSPHRASE2 | zfs load-key $TESTPOOL/$TESTFS1/child" log_must key_available $TESTPOOL/$TESTFS1/child log_must zfs unmount $TESTPOOL/$TESTFS1/child2 log_must zfs mount $TESTPOOL/$TESTFS1/child2 log_pass "'zfs change-key' promotes an encrypted child to an encryption root" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_clones.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_clones.ksh index 497fb99c8102..70a9df618e1f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_clones.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_clones.ksh @@ -1,80 +1,80 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs change-key' should correctly update encryption roots with clones. # # STRATEGY: # 1. Create an encrypted dataset # 2. Create an encryption root child of the first dataset # 3. Clone the child encryption root twice # 4. Add inheriting children to the encryption root and each of the clones # 5. Verify the encryption roots # 6. Have the child encryption root inherit from its parent # 7. Verify the encryption root for all datasets is now the parent dataset # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -Rf $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -Rf } log_onexit cleanup log_assert "'zfs change-key' should correctly update encryption " \ "roots with clones" log_must eval "echo $PASSPHRASE1 | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1" log_must eval "echo $PASSPHRASE2 | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1/child" log_must zfs snapshot $TESTPOOL/$TESTFS1/child@1 log_must zfs clone $TESTPOOL/$TESTFS1/child@1 $TESTPOOL/$TESTFS1/clone1 log_must zfs clone $TESTPOOL/$TESTFS1/child@1 $TESTPOOL/$TESTFS1/clone2 log_must zfs create $TESTPOOL/$TESTFS1/child/A log_must zfs create $TESTPOOL/$TESTFS1/clone1/B log_must zfs create $TESTPOOL/$TESTFS1/clone2/C log_must verify_encryption_root $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/$TESTFS1/child $TESTPOOL/$TESTFS1/child log_must verify_encryption_root $TESTPOOL/$TESTFS1/clone1 $TESTPOOL/$TESTFS1/child log_must verify_encryption_root $TESTPOOL/$TESTFS1/clone2 $TESTPOOL/$TESTFS1/child log_must verify_encryption_root $TESTPOOL/$TESTFS1/child/A $TESTPOOL/$TESTFS1/child log_must verify_encryption_root $TESTPOOL/$TESTFS1/clone1/B $TESTPOOL/$TESTFS1/child log_must verify_encryption_root $TESTPOOL/$TESTFS1/clone2/C $TESTPOOL/$TESTFS1/child log_must zfs change-key -i $TESTPOOL/$TESTFS1/child log_must verify_encryption_root $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/$TESTFS1/child $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/$TESTFS1/clone1 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/$TESTFS1/clone2 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/$TESTFS1/child/A $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/$TESTFS1/clone1/B $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/$TESTFS1/clone2/C $TESTPOOL/$TESTFS1 log_pass "'zfs change-key' correctly updates encryption roots with clones" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_format.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_format.ksh index 6344b8d05a20..22212d72d1d6 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_format.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_format.ksh @@ -1,72 +1,72 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # Copyright (c) 2019 DilOS # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs change-key -o' should change the key format. # # STRATEGY: # 1. Create an encryption dataset with a passphrase key format # 2. Unmount the dataset # 3. Verify the key format is passphrase # 4. Change the key format to hex # 5. Verify the key format is hex # 6. Attempt to reload the dataset's key # 7. Change the key format to raw # 8. Verify the key format is raw # 9. Attempt to reload the dataset's key # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup log_assert "'zfs change-key -o' should change the key format" log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must verify_keyformat $TESTPOOL/$TESTFS1 "passphrase" log_must eval "echo $HEXKEY | zfs change-key -o keyformat=hex" \ "$TESTPOOL/$TESTFS1" log_must verify_keyformat $TESTPOOL/$TESTFS1 "hex" log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must eval "echo $HEXKEY | zfs load-key $TESTPOOL/$TESTFS1" log_must eval "printf '%s' $RAWKEY | zfs change-key -o keyformat=raw" \ "$TESTPOOL/$TESTFS1" log_must verify_keyformat $TESTPOOL/$TESTFS1 "raw" log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must eval "printf '%s' $RAWKEY | zfs load-key $TESTPOOL/$TESTFS1" log_pass "'zfs change-key -o' changes the key format" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_inherit.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_inherit.ksh index 94820c37ecc0..e9b010e912fc 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_inherit.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_inherit.ksh @@ -1,78 +1,78 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs change-key -i' should cause a dataset to inherit its parent key # # STRATEGY: # 1. Create a parent encrypted dataset # 2. Create a child dataset as an encryption root # 3. Attempt to inherit the parent key # 4. Verify the key is inherited # 5. Unmount the parent and unload its key # 6. Verify the key is unavailable for parent and child # 7. Load the parent key # 8. Verify the key is available for parent and child # 9. Attempt to mount the datasets # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r } log_onexit cleanup log_assert "'zfs change-key -i' should cause a dataset to inherit its" \ "parent key" log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1" log_must eval "echo $PASSPHRASE1 | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt" \ "$TESTPOOL/$TESTFS1/child" log_must verify_encryption_root $TESTPOOL/$TESTFS1/child \ "$TESTPOOL/$TESTFS1/child" log_must zfs change-key -i $TESTPOOL/$TESTFS1/child log_must verify_encryption_root $TESTPOOL/$TESTFS1/child "$TESTPOOL/$TESTFS1" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must key_unavailable $TESTPOOL/$TESTFS1 log_must key_unavailable $TESTPOOL/$TESTFS1/child log_must eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS1" log_must key_available $TESTPOOL/$TESTFS1 log_must key_available $TESTPOOL/$TESTFS1/child log_must zfs mount $TESTPOOL/$TESTFS1 log_must zfs mount $TESTPOOL/$TESTFS1/child log_pass "'zfs change-key -i' causes a dataset to inherit its parent key" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_load.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_load.ksh index 4ed4aadfe0fa..a5a9976196e9 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_load.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_load.ksh @@ -1,58 +1,58 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs change-key -l' should load a dataset's key to change it. # # STRATEGY: # 1. Create an encrypted dataset # 2. Unload dataset and unload its key # 3. Attempt to change the key # 4. Verify the dataset key is loaded # 3. Attempt to change the key # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup log_assert "'zfs change-key -l' should load a dataset's key to change it" log_must eval "echo $PASSPHRASE > /$TESTPOOL/pkey" log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must zfs change-key -l $TESTPOOL/$TESTFS1 log_must key_available $TESTPOOL/$TESTFS1 log_must zfs change-key -l $TESTPOOL/$TESTFS1 log_pass "'zfs change-key -l' loads a dataset's key to change it" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_location.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_location.ksh index 5cbe34b269ba..607e2208cef4 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_location.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_location.ksh @@ -1,65 +1,65 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs change-key -o' should change the keylocation. # # STRATEGY: # 1. Create an encryption dataset with a file key location # 2. Change the key location to 'prompt' # 3. Verify the key location # 4. Unmount the dataset and unload its key # 5. Attempt to load the dataset's key # 6. Attempt to change the key location to 'none' # 7. Attempt to change the key location to an invalid value # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup log_assert "'zfs change-key -o' should change the keylocation" log_must eval "echo $PASSPHRASE > /$TESTPOOL/pkey" log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 log_must verify_keylocation $TESTPOOL/$TESTFS1 "file:///$TESTPOOL/pkey" log_must eval "echo $PASSPHRASE1 | zfs change-key -o keylocation=prompt" \ "$TESTPOOL/$TESTFS1" log_must verify_keylocation $TESTPOOL/$TESTFS1 "prompt" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must eval "echo $PASSPHRASE1 | zfs load-key $TESTPOOL/$TESTFS1" log_mustnot zfs change-key -o keylocation=none $TESTPOOL/$TESTFS1 log_mustnot zfs change-key -o keylocation=foobar $TESTPOOL/$TESTFS1 log_pass "'zfs change-key -o' changes the keylocation" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_pbkdf2iters.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_pbkdf2iters.ksh index b1672248be12..224fabf22620 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_pbkdf2iters.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_change-key/zfs_change-key_pbkdf2iters.ksh @@ -1,75 +1,75 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs change-key -o' should change the pbkdf2 iterations. # # STRATEGY: # 1. Create an encryption dataset with 200k PBKDF2 iterations # 2. Unmount the dataset # 3. Change the PBKDF2 iterations to 150k # 4. Verify the PBKDF2 iterations # 5. Unload the dataset's key # 6. Attempt to load the dataset's key # verify_runnable "both" function verify_pbkdf2iters { typeset ds=$1 typeset iterations=$2 typeset iters=$(get_prop pbkdf2iters $ds) if [[ "$iters" != "$iterations" ]]; then log_fail "Expected $iterations iterations, got $iters" fi return 0 } function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup log_assert "'zfs change-key -o' should change the pbkdf2 iterations" log_must eval "echo $PASSPHRASE > /$TESTPOOL/pkey" log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey -o pbkdf2iters=200000 \ $TESTPOOL/$TESTFS1 log_must zfs unmount $TESTPOOL/$TESTFS1 log_must verify_pbkdf2iters $TESTPOOL/$TESTFS1 "200000" log_must zfs change-key -o pbkdf2iters=150000 $TESTPOOL/$TESTFS1 log_must verify_pbkdf2iters $TESTPOOL/$TESTFS1 "150000" log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must zfs load-key $TESTPOOL/$TESTFS1 log_pass "'zfs change-key -o' changes the pbkdf2 iterations" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh index b83ccdf48c79..e6ffa26c0208 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_001_neg.ksh @@ -1,126 +1,126 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs clone' should fail with inapplicable scenarios, including: # * Null arguments # * non-existent snapshots. # * invalid characters in ZFS namesapec # * Leading slash in the target clone name # * The argument contains an empty component. # * The pool specified in the target doesn't exist. # * The parent dataset of the target doesn't exist. # * The argument refer to a pool, not dataset. # * The target clone already exists. # * Null target clone argument. # * Too many arguments. # * Invalid record sizes. # # STRATEGY: # 1. Create an array of parameters # 2. For each parameter in the array, execute the sub-command # 3. Verify an error is returned. # verify_runnable "both" typeset target1=$TESTPOOL/$TESTFS1 typeset target2=$TESTPOOL/$TESTCTR1/$TESTFS1 typeset targets="$target1 $target2 $NONEXISTPOOLNAME/$TESTFS" set -A args "" \ "$TESTPOOL/$TESTFS@blah $target1" "$TESTPOOL/$TESTVOL@blah $target1" \ "$TESTPOOL/$TESTFS@blah* $target1" "$TESTPOOL/$TESTVOL@blah* $target1" \ "$SNAPFS $target1*" "$SNAPFS1 $target1*" \ "$SNAPFS /$target1" "$SNAPFS1 /$target1" \ "$SNAPFS $TESTPOOL//$TESTFS1" "$SNAPFS1 $TESTPOOL//$TESTFS1" \ "$SNAPFS $NONEXISTPOOLNAME/$TESTFS" "$SNAPFS1 $NONEXISTPOOLNAME/$TESTFS" \ "$SNAPFS" "$SNAPFS1" \ "$SNAPFS $target1 $target2" "$SNAPFS1 $target1 $target2" \ "-o recordsize=2M $SNAPFS1 $target1" \ "-o recordsize=128B $SNAPFS1 $target1" typeset -i argsnum=${#args[*]} typeset -i j=0 while (( j < argsnum )); do args[((argsnum+j))]="-p ${args[j]}" ((j = j + 1)) done set -A moreargs "$SNAPFS $target2" "$SNAPFS1 $target2" \ "$SNAPFS $TESTPOOL" "$SNAPFS1 $TESTPOOL" \ "$SNAPFS $TESTPOOL/$TESTCTR" "$SNAPFS $TESTPOOL/$TESTFS" \ "$SNAPFS1 $TESTPOOL/$TESTCTR" "$SNAPFS1 $TESTPOOL/$TESTFS" set -A args ${args[*]} ${moreargs[*]} function setup_all { log_note "Create snapshots and mount them..." for snap in $SNAPFS $SNAPFS1 ; do if ! snapexists $snap ; then log_must zfs snapshot $snap fi done return 0 } function cleanup_all { for fs in $targets; do - datasetexists $fs && log_must zfs destroy -f $fs + datasetexists $fs && destroy_dataset $fs -f done for snap in $SNAPFS $SNAPFS1 ; do - snapexists $snap && log_must zfs destroy -Rf $snap + snapexists $snap && destroy_dataset $snap -Rf done return 0 } log_assert "Badly-formed 'zfs clone' with inapplicable scenarios" \ "should return an error." log_onexit cleanup_all setup_all typeset -i i=0 while (( i < ${#args[*]} )); do log_mustnot zfs clone ${args[i]} ((i = i + 1)) done log_pass "Badly formed 'zfs clone' with inapplicable scenarios" \ "fail as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_002_pos.ksh index 8e69a7adcc3d..96eb3ea48d64 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_002_pos.ksh @@ -1,89 +1,85 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs clone -p' should work as expected # # STRATEGY: # 1. prepare snapshots # 2. make sure without -p option, 'zfs clone' will fail # 3. with -p option, the clone can be created # 4. run 'zfs clone -p' again, the exit code should be zero # verify_runnable "both" function setup_all { log_note "Create snapshots and mount them..." for snap in $SNAPFS $SNAPFS1 ; do if ! snapexists $snap ; then log_must zfs snapshot $snap fi done return 0 } function cleanup_all { - if datasetexists $TESTPOOL/notexist ; then - log_must zfs destroy -rRf $TESTPOOL/notexist - fi + datasetexists $TESTPOOL/notexist && destroy_dataset $TESTPOOL/notexist -rRf for snap in $SNAPFS $SNAPFS1 ; do - if snapexists $snap ; then - log_must zfs destroy -Rf $snap - fi + snapexists $snap && destroy_dataset $snap -Rf done return 0 } log_assert "clone -p should work as expected." log_onexit cleanup_all setup_all log_must verify_opt_p_ops "clone" "fs" $SNAPFS \ $TESTPOOL/notexist/new/clonefs$$ if is_global_zone ; then log_must verify_opt_p_ops "clone" "vol" $SNAPFS1 \ $TESTPOOL/notexist/new/clonevol$$ fi log_pass "clone -p should work as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_003_pos.ksh index 522275759880..6484de9c91a8 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_003_pos.ksh @@ -1,76 +1,74 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib # # DESCRIPTION: # 'zfs clone -o property=value filesystem' can successfully create a ZFS # clone filesystem with correct property set. # # STRATEGY: # 1. Create a ZFS clone filesystem in the storage pool with -o option # 2. Verify the filesystem created successfully # 3. Verify the property is correctly set # verify_runnable "both" function cleanup { - if snapexists $SNAPFS ; then - log_must zfs destroy -Rf $SNAPFS - fi + snapexists $SNAPFS && destroy_dataset $SNAPFS -Rf } log_onexit cleanup log_assert "'zfs clone -o property=value filesystem' can successfully create" \ "a ZFS clone filesystem with correct property set." log_must zfs snapshot $SNAPFS typeset -i i=0 while (( $i < ${#RW_FS_PROP[*]} )); do log_must zfs clone -o ${RW_FS_PROP[$i]} $SNAPFS $TESTPOOL/$TESTCLONE datasetexists $TESTPOOL/$TESTCLONE || \ log_fail "zfs clone $TESTPOOL/$TESTCLONE fail." propertycheck $TESTPOOL/$TESTCLONE ${RW_FS_PROP[i]} || \ log_fail "${RW_FS_PROP[i]} is failed to set." log_must zfs destroy -f $TESTPOOL/$TESTCLONE (( i = i + 1 )) done log_pass "'zfs clone -o property=value filesystem' can successfully create" \ "a ZFS clone filesystem with correct property set." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_004_pos.ksh index 8d86f5501863..1c4c579f26bd 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_004_pos.ksh @@ -1,87 +1,85 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib # # DESCRIPTION: # 'zfs clone -o property=value filesystem' can successfully create a ZFS # clone filesystem with multiple properties set. # # STRATEGY: # 1. Create a ZFS clone filesystem in the storage pool with multiple -o options # 2. Verify the filesystem created successfully # 3. Verify the properties are correctly set # verify_runnable "both" function cleanup { - if snapexists $SNAPFS ; then - log_must zfs destroy -Rf $SNAPFS - fi + snapexists $SNAPFS && destroy_dataset $SNAPFS -Rf } log_onexit cleanup log_assert "'zfs clone -o property=value filesystem' can successfully create" \ "a ZFS clone filesystem with multiple properties set." typeset -i i=0 typeset opts="" log_must zfs snapshot $SNAPFS while (( $i < ${#RW_FS_PROP[*]} )); do if [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then opts="$opts -o ${RW_FS_PROP[$i]}" fi (( i = i + 1 )) done log_must zfs clone $opts $SNAPFS $TESTPOOL/$TESTCLONE datasetexists $TESTPOOL/$TESTCLONE || \ log_fail "zfs create $TESTPOOL/$TESTCLONE fail." i=0 while (( $i < ${#RW_FS_PROP[*]} )); do if [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then propertycheck $TESTPOOL/$TESTCLONE ${RW_FS_PROP[i]} || \ log_fail "${RW_FS_PROP[i]} is failed to set." fi (( i = i + 1 )) done log_pass "'zfs clone -o property=value filesystem' can successfully create" \ "a ZFS clone filesystem with multiple properties set." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_005_pos.ksh index afa8b46a6f7c..6f17b176734a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_005_pos.ksh @@ -1,78 +1,76 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib # # DESCRIPTION: # 'zfs clone -o property=value -V size volume' can successfully create a ZFS # clone volume with correct property set. # # STRATEGY: # 1. Create a ZFS clone volume in the storage pool with -o option # 2. Verify the volume created successfully # 3. Verify the property is correctly set # verify_runnable "global" function cleanup { - if snapexists $SNAPFS1 ; then - log_must zfs destroy -Rf $SNAPFS1 - fi + snapexists $SNAPFS1 && destroy_dataset $SNAPFS1 -Rf } log_onexit cleanup log_assert "'zfs clone -o property=value -V size volume' can successfully" \ "create a ZFS clone volume with correct property set." log_must zfs snapshot $SNAPFS1 typeset -i i=0 while (( $i < ${#RW_VOL_CLONE_PROP[*]} )); do log_must zfs clone -o ${RW_VOL_CLONE_PROP[$i]} $SNAPFS1 \ $TESTPOOL/$TESTCLONE block_device_wait datasetexists $TESTPOOL/$TESTCLONE || \ log_fail "zfs clone $TESTPOOL/$TESTCLONE fail." propertycheck $TESTPOOL/$TESTCLONE ${RW_VOL_CLONE_PROP[i]} || \ log_fail "${RW_VOL_CLONE_PROP[i]} is failed to set." log_must zfs destroy -f $TESTPOOL/$TESTCLONE (( i = i + 1 )) done log_pass "'zfs clone -o property=value volume' can successfully" \ "create a ZFS clone volume with correct property set." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_006_pos.ksh index 2127eb117bf5..f2f7a5bcd077 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_006_pos.ksh @@ -1,86 +1,84 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib # # DESCRIPTION: # 'zfs clone -o property=value volume' can successfully create a ZFS # clone volume with multiple properties set. # # STRATEGY: # 1. Create a ZFS clone volume in the storage pool with -o option # 2. Verify the volume created successfully # 3. Verify the properties are correctly set # verify_runnable "global" function cleanup { - if snapexists $SNAPFS1 ; then - log_must_busy zfs destroy -Rf $SNAPFS1 - fi + snapexists $SNAPFS1 && destroy_dataset $SNAPFS1 -Rf } log_onexit cleanup log_assert "'zfs clone -o property=value volume' can successfully" \ "create a ZFS clone volume with multiple correct properties set." typeset -i i=0 typeset opts="" log_must zfs snapshot $SNAPFS1 while (( $i < ${#RW_VOL_CLONE_PROP[*]} )); do if [[ ${RW_VOL_CLONE_PROP[$i]} != *"checksum"* ]]; then opts="$opts -o ${RW_VOL_CLONE_PROP[$i]}" fi (( i = i + 1 )) done log_must zfs clone $opts $SNAPFS1 $TESTPOOL/$TESTCLONE i=0 while (( $i < ${#RW_VOL_CLONE_PROP[*]} )); do if [[ ${RW_VOL_CLONE_PROP[$i]} != *"checksum"* ]]; then propertycheck $TESTPOOL/$TESTCLONE ${RW_VOL_CLONE_PROP[i]} || \ log_fail "${RW_VOL_CLONE_PROP[i]} is failed to set." fi (( i = i + 1 )) done log_pass "'zfs clone -o property=value volume' can successfully" \ "create a ZFS clone volume with multiple correct properties set." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_007_pos.ksh index 6fba72b58067..4bfb3d5f78ab 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_007_pos.ksh @@ -1,85 +1,83 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs clone -o version=' could upgrade version, but downgrade is denied. # # STRATEGY: # 1. Create clone with "-o version=" specified # 2. Verify it succeed while upgrade, but fails while the version downgraded. # ZFS_VERSION=$(zfs upgrade | head -1 | awk '{print $NF}' \ | sed -e 's/\.//g') verify_runnable "both" function cleanup { - if snapexists $SNAPFS ; then - log_must zfs destroy -Rf $SNAPFS - fi + snapexists $SNAPFS && destroy_dataset $SNAPFS -Rf } log_onexit cleanup log_assert "'zfs clone -o version=' could upgrade version," \ "but downgrade is denied." log_must zfs snapshot $SNAPFS typeset -i ver if (( ZFS_TEST_VERSION == 0 )) ; then (( ZFS_TEST_VERSION = ZFS_VERSION )) fi (( ver = ZFS_TEST_VERSION )) while (( ver <= ZFS_VERSION )); do log_must zfs clone -o version=$ver $SNAPFS $TESTPOOL/$TESTCLONE cleanup (( ver = ver + 1 )) done (( ver = 0 )) while (( ver < ZFS_TEST_VERSION )); do log_mustnot zfs clone -o version=$ver \ $SNAPFS $TESTPOOL/$TESTCLONE log_mustnot datasetexists $TESTPOOL/$TESTCLONE cleanup (( ver = ver + 1 )) done log_pass "'zfs clone -o version=' could upgrade version," \ "but downgrade is denied." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_008_neg.ksh index 8e306fd445ea..2f2b0ca18d64 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_008_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_008_neg.ksh @@ -1,80 +1,78 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib # # DESCRIPTION: # 'zfs clone -o ' fails with bad arguments, including: # *Same property set multiple times via '-o property=value' # *Volume's property set on filesystem # # STRATEGY: # 1. Create an array of arguments # 2. Execute 'zfs clone -o ' with each argument # 3. Verify an error is returned. # verify_runnable "both" function cleanup { - if snapexists $SNAPFS ; then - log_must zfs destroy -Rf $SNAPFS - fi + snapexists $SNAPFS && destroy_dataset $SNAPFS -Rf } log_onexit cleanup log_assert "Verify 'zfs clone -o ' fails with bad argument." log_must zfs snapshot $SNAPFS typeset -i i=0 while (( $i < ${#RW_FS_PROP[*]} )); do log_mustnot zfs clone -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \ $SNAPFS $TESTPOOL/$TESTCLONE log_mustnot zfs clone -p -o ${RW_FS_PROP[i]} -o ${RW_FS_PROP[i]} \ $SNAPFS $TESTPOOL/$TESTCLONE ((i = i + 1)) done i=0 while (( $i < ${#VOL_ONLY_PROP[*]} )); do log_mustnot zfs clone -o ${VOL_ONLY_PROP[i]} \ $SNAPFS $TESTPOOL/$TESTCLONE log_mustnot zfs clone -p -o ${VOL_ONLY_PROP[i]} \ $SNAPFS $TESTPOOL/$TESTCLONE ((i = i + 1)) done log_pass "'zfs clone -o ' fails with bad argument." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_009_neg.ksh index 030c6af7ae68..6cdf5717fa92 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_009_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_009_neg.ksh @@ -1,80 +1,78 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib # # DESCRIPTION: # 'zfs clone -o ' fails with badly formed arguments,including: # *Same property set multiple times via '-o property=value' # *Filesystems's property set on volume # # STRATEGY: # 1. Create an array of badly formed arguments # 2. For each argument, execute 'zfs clone -o ' # 3. Verify an error is returned. # verify_runnable "global" function cleanup { - if snapexists $SNAPFS1 ; then - log_must zfs destroy -Rf $SNAPFS1 - fi + snapexists $SNAPFS1 && destroy_dataset $SNAPFS1 -Rf } log_onexit cleanup log_assert "Verify 'zfs clone -o ' fails with bad argument." log_must zfs snapshot $SNAPFS1 typeset -i i=0 while (( $i < ${#RW_VOL_PROP[*]} )); do log_mustnot zfs clone -o ${RW_VOL_PROP[i]} -o ${RW_VOL_PROP[i]} \ $SNAPFS1 $TESTPOOL/$TESTCLONE log_mustnot zfs clone -p -o ${RW_VOL_PROP[i]} -o ${RW_VOL_PROP[i]} \ $SNAPFS1 $TESTPOOL/$TESTCLONE ((i = i + 1)) done i=0 while (( $i < ${#FS_ONLY_PROP[*]} )); do log_mustnot zfs clone -o ${FS_ONLY_PROP[i]} \ $SNAPFS1 $TESTPOOL/$TESTCLONE log_mustnot zfs clone -p -o ${FS_ONLY_PROP[i]} \ $SNAPFS1 $TESTPOOL/$TESTCLONE ((i = i + 1)) done log_pass "Verify 'zfs clone -o ' fails with bad argument." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_010_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_010_pos.ksh index dcf80095db28..13f5418d4bf5 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_010_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_010_pos.ksh @@ -1,229 +1,229 @@ #!/bin/ksh # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify 'zfs list -t all -o name,origin,clones' prints the correct # clone information # # STRATEGY: # 1. Create datasets # 2. Create recursive snapshots and their clones # 3. Verify zfs clones property displays right information for different # cases # verify_runnable "both" function local_cleanup { typeset -i i=1 for ds in $datasets; do datasetexists $ds/$TESTCLONE.$i && \ - log_must zfs destroy -rf $ds/$TESTCLONE.$i - datasetexists $ds && log_must zfs destroy -Rf $ds + destroy_dataset $ds/$TESTCLONE.$i -rf + datasetexists $ds && destroy_dataset $ds -Rf ((i=i+1)) done } # Set up filesystem with clones function setup_ds { typeset -i i=1 # create nested datasets log_must zfs create -p $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3 # verify dataset creation for ds in $datasets; do datasetexists $ds || log_fail "Create $ds dataset fail." done # create recursive nested snapshot log_must zfs snapshot -r $TESTPOOL/$TESTFS1@snap for ds in $datasets; do datasetexists $ds@snap || \ log_fail "Create $ds@snap snapshot fail." done for ds in $datasets; do for fs in $datasets; do log_must zfs clone $ds@snap $fs/$TESTCLONE.$i done ((i=i+1)) done } # Verify clone list function verify_clones { typeset -i no_clones=$1 typeset unexpected=$2 typeset clone_snap=$3 typeset -i i=1 for ds in $datasets; do if [[ -n $clone_snap ]]; then clone_snap=/$TESTCLONE.$i fi snapshot=$(echo "$names" | grep $ds$clone_snap@snap) actual_clone=$(zfs list -t all -o clones $snapshot | tail -1) save=$IFS IFS=',' typeset -a clones=() for token in $actual_clone; do clones=( "${clones[@]}" "$token" ) done IFS=$save [[ ${#clones[*]} -ne $no_clones ]] && \ log_fail "$snapshot has unexpected number of clones" \ " ${#clones[*]}" expected_clone="" unexpected_clone="" if [[ $unexpected -eq 1 ]]; then for fs in $datasets; do if [[ $fs == $ds ]]; then if [[ -z $clone_snap ]]; then unexpected_clone=$fs/$TESTCLONE.$i (for match in ${clones[@]};do [[ $match != $unexpected_clone ]] && \ exit 0; done) || log_fail \ "Unexpected clones of the snapshot" else expected_clone=$fs unexpected_clone=$fs/$TESTCLONE.$i (for match in ${clones[@]};do [[ $match == $expected_clone ]] && \ [[ $match != $unexpected_clone ]] \ && exit 0; done) || log_fail \ "Unexpected clones of the snapshot" fi else expected_clone=$fs/$TESTCLONE.$i (for match in ${clones[@]};do [[ $match == $expected_clone ]] && \ exit 0; done) || log_fail \ "Unexpected clones of the snapshot" fi done else for fs in $datasets; do expected_clone=$fs/$TESTCLONE.$i (for match in ${clones[@]};do [[ $match == $expected_clone ]] && exit 0; \ done) || log_fail "Unexpected clones" \ " of the snapshot" done fi ((i=i+1)) done } log_onexit local_cleanup datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS2 $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3" typeset -a d_clones typeset -a deferred_snaps typeset -i i log_must setup_ds log_note "Verify zfs clone property for multiple clones" names=$(zfs list -rt all -o name $TESTPOOL) log_must verify_clones 3 0 log_note "verify clone property for clone deletion" i=1 for ds in $datasets; do log_must zfs destroy $ds/$TESTCLONE.$i ((i=i+1)) done names=$(zfs list -rt all -o name $TESTPOOL) log_must verify_clones 2 1 log_must local_cleanup log_must setup_ds log_note "verify zfs deferred destroy on clones property" names=$(zfs list -rt all -o name $TESTPOOL) for ds in $datasets; do log_must zfs destroy -d $ds@snap deferred_snaps=( "${deferred_snaps[@]}" "$ds@snap" ) done log_must verify_clones 3 0 log_note "verify zfs deferred destroy by destroying clones on clones property" d_clones=() i=1 for ds in $datasets; do for fs in $datasets; do log_must zfs destroy $fs/$TESTCLONE.$i d_clones=( "${d_clones[@]}" "$fs/$TESTCLONE.$i" ) done ((i=i+1)) done names=$(zfs list -rtall -o name $TESTPOOL) for snap in ${deferred_snaps[@]}; do status=$(echo "$names" | grep $snap) [[ -z $status ]] || \ log_fail "$snap exist after deferred destroy" done for dclone in ${d_clones[@]}; do log_note "D CLONE = $dclone" status=$(echo "$names" | grep $dclone) [[ -z $status ]] || \ log_fail "$dclone exist after deferred destroy" done log_must local_cleanup log_must setup_ds log_note "verify clone property for zfs promote" i=1 for ds in $datasets; do log_must zfs promote $ds/$TESTCLONE.$i ((i=i+1)) done names=$(zfs list -rt all -o name,clones $TESTPOOL) log_must verify_clones 3 1 $TESTCLONE for ds in $datasets; do log_must zfs promote $ds done log_must local_cleanup log_note "verify clone list truncated correctly" fs=$TESTPOOL/$TESTFS1 xs=""; for i in {1..200}; do xs+="x"; done if is_linux; then ZFS_MAXPROPLEN=4096 else ZFS_MAXPROPLEN=1024 fi log_must zfs create $fs log_must zfs snapshot $fs@snap for (( i = 1; i <= (ZFS_MAXPROPLEN / 200 + 1); i++ )); do log_must zfs clone ${fs}@snap ${fs}/${TESTCLONE}${xs}.${i} done clone_list=$(zfs list -o clones $fs@snap) char_count=$(echo "$clone_list" | tail -1 | wc | awk '{print $3}') [[ $char_count -eq $ZFS_MAXPROPLEN ]] || \ log_fail "Clone list not truncated correctly. Unexpected character count" \ "$char_count" log_pass "'zfs list -o name,origin,clones prints the correct clone information." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_encrypted.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_encrypted.ksh index 86f335bde2a0..1f07b9eb03bc 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_encrypted.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_clone/zfs_clone_encrypted.ksh @@ -1,83 +1,83 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs clone' should create encrypted clones of encrypted datasets # # STRATEGY: # 1. Create an encrypted dataset # 2. Create a snapshot of the dataset # 3. Attempt to clone the snapshot as an unencrypted dataset # 4. Attempt to clone the snapshot with a new key # 5. Attempt to clone the snapshot as a child of an unencrypted dataset # 6. Attempt to clone the snapshot as a child of an encrypted dataset # 7. Verify the encryption root of the datasets # 8. Unmount all datasets and unload their keys # 9. Attempt to load the encryption root's key # 10. Verify each dataset's key is loaded # 11. Attempt to mount each dataset # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -f datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r } log_onexit cleanup log_assert "'zfs clone' should create encrypted clones of encrypted datasets" log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1" log_must zfs snapshot $TESTPOOL/$TESTFS1@now log_mustnot zfs clone -o encryption=off $TESTPOOL/$TESTFS1@now \ $TESTPOOL/$TESTFS2 log_mustnot eval "echo $PASSPHRASE1 | zfs clone -o keyformat=passphrase" \ "$TESTPOOL/$TESTFS1@now $TESTPOOL/$TESTFS2" log_must zfs clone $TESTPOOL/$TESTFS1@now $TESTPOOL/$TESTFS2 log_must zfs clone $TESTPOOL/$TESTFS1@now $TESTPOOL/$TESTFS1/child log_must verify_encryption_root $TESTPOOL/$TESTFS2 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/$TESTFS1/child $TESTPOOL/$TESTFS1 log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unmount $TESTPOOL/$TESTFS2 log_must zfs unload-key -a log_must eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS1" log_must key_available $TESTPOOL/$TESTFS1 log_must key_available $TESTPOOL/$TESTFS1/child log_must key_available $TESTPOOL/$TESTFS2 log_must zfs mount $TESTPOOL/$TESTFS1 log_must zfs mount $TESTPOOL/$TESTFS1/child log_must zfs mount $TESTPOOL/$TESTFS2 log_pass "'zfs clone' creates encrypted clones of encrypted datasets" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_001_pos.ksh index 2ed881a36706..672692b59e42 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_001_pos.ksh @@ -1,116 +1,114 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib # # DESCRIPTION: # Verify "copies" property can be correctly set as 1,2 and 3 and different # filesystem can have different value of "copies" property within the same pool. # # STRATEGY: # 1. Create different filesystems with copies set as 1,2,3; # 2. Verify that the "copies" property has been set correctly # verify_runnable "both" function cleanup { typeset ds for ds in $fs1 $fs2 $vol1 $vol2; do - if datasetexists $ds; then - log_must zfs destroy $ds - fi + datasetexists $ds && destroy_dataset $ds done } log_assert "Verify 'copies' property with correct arguments works or not." log_onexit cleanup fs=$TESTPOOL/$TESTFS fs1=$TESTPOOL/$TESTFS1 fs2=$TESTPOOL/$TESTFS2 vol=$TESTPOOL/$TESTVOL vol1=$TESTPOOL/$TESTVOL1 vol2=$TESTPOOL/$TESTVOL2 # # Check the default value for copies property # for ds in $fs $vol; do cmp_prop $ds 1 done for val in 1 2 3; do log_must zfs create -o copies=$val $fs1 if is_global_zone; then log_must zfs create -V $VOLSIZE -o copies=$val $vol1 block_device_wait else log_must zfs create -o copies=$val $vol1 fi for ds in $fs1 $vol1; do cmp_prop $ds $val done for val2 in 3 2 1; do log_must zfs create -o copies=$val2 $fs2 if is_global_zone; then log_must zfs create -V $VOLSIZE -o copies=$val2 $vol2 block_device_wait else log_must zfs create -o copies=$val2 $vol2 fi for ds in $fs2 $vol2; do cmp_prop $ds $val2 - log_must zfs destroy $ds + destroy_dataset $ds block_device_wait done done for ds in $fs1 $vol1; do - log_must zfs destroy $ds + destroy_dataset $ds block_device_wait done done for val in 3 2 1; do for ds in $fs $vol; do log_must zfs set copies=$val $ds cmp_prop $ds $val done done log_pass "'copies' property with correct arguments works as expected. " diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh index 6e293ca63829..b644fcae3cf8 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_002_pos.ksh @@ -1,119 +1,118 @@ #!/bin/ksh # # 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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib # # DESCRIPTION: # Verify that the space used by multiple copies is charged correctly # # STRATEGY: # 1. Create filesystems with copies set as 2,3 respectively; # 2. Copy specified size data into each filesystem; # 3. Verify that the space is charged as expected with zfs list, ls -s, df(1m), # du(1) commands; # verify_runnable "both" function cleanup { typeset val for val in 1 2 3; do - if datasetexists $TESTPOOL/fs_$val; then - log_must zfs destroy $TESTPOOL/fs_$val - fi + datasetexists $TESTPOOL/fs_$val && \ + destroy_dataset $TESTPOOL/fs_$val done } log_assert "Verify that the space used by multiple copies is charged correctly." log_onexit cleanup for val in 1 2 3; do log_must zfs create -o copies=$val $TESTPOOL/fs_$val log_must mkfile $FILESIZE /$TESTPOOL/fs_$val/$FILE done # # Sync up the filesystem # sync # # Verify 'zfs list' can correctly list the space charged # log_note "Verify 'zfs list' can correctly list the space charged." fsize=${FILESIZE%[m|M]} for val in 1 2 3; do used=$(get_prop used $TESTPOOL/fs_$val) check_used $used $val done log_note "Verify 'ls -s' can correctly list the space charged." if is_linux || is_freebsd; then blksize=1024 else blksize=512 fi for val in 1 2 3; do blks=`ls -ls /$TESTPOOL/fs_$val/$FILE | awk '{print $1}'` (( used = blks * $blksize )) # bytes check_used $used $val done log_note "Verify df(1) can correctly display the space charged." for val in 1 2 3; do 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 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 log_pass "The space used by multiple copies is charged correctly as expected. " diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_003_pos.ksh index 98420cb7f2ab..94e72bce4e67 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_003_pos.ksh @@ -1,68 +1,66 @@ #!/bin/ksh # # 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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib # # DESCRIPTION: # Verify that the volume space used by multiple copies is charged correctly # # STRATEGY: # 1. Create volume; # 2. Create ZFS filesystem based on the volume; # 3. Set the copies property of volume to 1,2 or 3; # 4. Copy specified size data into each filesystem; # 5. Verify that the volume space is charged as expected. # verify_runnable "global" function cleanup { if poolexists $TESTPOOL1; then destroy_pool $TESTPOOL1 fi - if datasetexists $vol; then - log_must zfs destroy $vol - fi + datasetexists $vol && destroy_dataset $vol } log_assert "Verify that ZFS volume space used by multiple copies is charged correctly." log_onexit cleanup vol=$TESTPOOL/$TESTVOL1 for val in 1 2 3; do do_vol_test zfs $val done log_pass "The volume space used by multiple copies is charged correctly as expected. " diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_006_pos.ksh index 4a3ef76de763..6dc9306b33ef 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_copies/zfs_copies_006_pos.ksh @@ -1,77 +1,75 @@ #!/bin/ksh # # 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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_copies/zfs_copies.kshlib # # DESCRIPTION: # Verify that the volume space used by multiple copies is charged correctly # # STRATEGY: # 1. Create volume # 2. Create UFS filesystem based on the volume # 3. Set the copies property of volume to 1,2 or 3 # 4. Copy specified size data into each filesystem # 5. Verify that the volume space is charged as expected # verify_runnable "global" function cleanup { if ismounted $mntp $NEWFS_DEFAULT_FS ; then log_must umount $mntp fi - if datasetexists $vol; then - log_must zfs destroy $vol - fi + datasetexists $vol && destroy_dataset $vol if [[ -d $mntp ]]; then rm -rf $mntp fi } log_assert "Verify that ZFS volume space used by multiple copies is charged correctly." log_onexit cleanup mntp=$FS_MNTPOINT vol=$TESTPOOL/$TESTVOL1 if [[ ! -d $mntp ]]; then mkdir -p $mntp fi for copies in 1 2 3; do do_vol_test $NEWFS_DEFAULT_FS $copies $mntp done log_pass "The volume space used by multiple copies is charged correctly as expected. " diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos.ksh index d0807ac8d176..f74b2c9816f3 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_001_pos.ksh @@ -1,77 +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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs create ' can create a ZFS filesystem in the namespace. # # STRATEGY: # 1. Create a ZFS filesystem in the storage pool # 2. Verify the filesystem created successfully # verify_runnable "both" function cleanup { typeset -i i=0 while (( $i < ${#datasets[*]} )); do datasetexists ${datasets[$i]} && \ - log_must zfs destroy -f ${datasets[$i]} + destroy_dataset ${datasets[$i]} -f ((i = i + 1)) done zfs destroy -f "$TESTPOOL/with a space" } log_onexit cleanup set -A datasets "$TESTPOOL/$TESTFS1" "$TESTPOOL/$LONGFSNAME" "$TESTPOOL/..." \ "$TESTPOOL/_1234_" log_assert "'zfs create ' can create a ZFS filesystem in the namespace." typeset -i i=0 while (( $i < ${#datasets[*]} )); do log_must zfs create ${datasets[$i]} datasetexists ${datasets[$i]} || \ log_fail "zfs create ${datasets[$i]} fail." ((i = i + 1)) done log_must zfs create "$TESTPOOL/with a space" log_must zfs unmount "$TESTPOOL/with a space" log_must zfs mount "$TESTPOOL/with a space" log_pass "'zfs create ' works as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_003_pos.ksh index 2906e32dab8c..120de10281db 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_003_pos.ksh @@ -1,69 +1,68 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg # # DESCRIPTION: # 'zfs create [-b ] -V ' can create a volume # with specified blocksize, which is power of 2 between 512 - 128k. # # STRATEGY: # 1. Create a volume with blocksize in the storage pool # 2. Verify the volume created successfully # verify_runnable "global" function cleanup { - datasetexists $vol && \ - log_must zfs destroy -f $vol + datasetexists $vol && destroy_dataset $vol -f } log_assert "Verify creating volume with specified blocksize works." log_onexit cleanup set -A options "" "-b 1k" "-b 1K" "-b 1024" "-b 1024b" vol=$TESTPOOL/$TESTVOL typeset -i i=0 while (( i < ${#options[*]} )); do log_must zfs create ${options[i]} -V $VOLSIZE $vol datasetexists $vol || \ log_fail "zfs create ${options[i]} -V $VOLSIZE $vol fail." log_must_busy zfs destroy -f $vol ((i = i + 1)) done log_pass "'zfs create [-b ] -V ' works as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_004_pos.ksh index 200b4a091567..9e69366c8793 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_004_pos.ksh @@ -1,73 +1,72 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib # # DESCRIPTION: # 'zfs create -o property=value filesystem' can successfully create a ZFS # filesystem with correct property set. # # STRATEGY: # 1. Create a ZFS filesystem in the storage pool with -o option # 2. Verify the filesystem created successfully # 3. Verify the property is correctly set # verify_runnable "both" function cleanup { - datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + datasetexists $TESTPOOL/$TESTFS1 && destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup log_assert "'zfs create -o property=value filesystem' can successfully create \ a ZFS filesystem with correct property set." typeset -i i=0 while (( $i < ${#RW_FS_PROP[*]} )); do log_must zfs create -o ${RW_FS_PROP[$i]} $TESTPOOL/$TESTFS1 datasetexists $TESTPOOL/$TESTFS1 || \ log_fail "zfs create $TESTPOOL/$TESTFS1 fail." propertycheck $TESTPOOL/$TESTFS1 ${RW_FS_PROP[i]} || \ log_fail "${RW_FS_PROP[i]} is failed to set." - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + log_must_busy zfs destroy -f $TESTPOOL/$TESTFS1 (( i = i + 1 )) done log_pass "'zfs create -o property=value filesystem' can successfully create \ a ZFS filesystem with correct property set." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_005_pos.ksh index e953c65ded95..98cf70938e87 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_005_pos.ksh @@ -1,85 +1,85 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib # # DESCRIPTION: # 'zfs create -o property=value filesystem' can successfully create a ZFS # filesystem with multiple properties set. # # STRATEGY: # 1. Create a ZFS filesystem in the storage pool with multiple -o options # 2. Verify the filesystem created successfully # 3. Verify the properties are correctly set # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup log_assert "'zfs create -o property=value filesystem' can successfully create \ a ZFS filesystem with multiple properties set." typeset -i i=0 typeset opts="" while (( $i < ${#RW_FS_PROP[*]} )); do if [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then opts="$opts -o ${RW_FS_PROP[$i]}" fi (( i = i + 1 )) done log_must zfs create $opts $TESTPOOL/$TESTFS1 datasetexists $TESTPOOL/$TESTFS1 || \ log_fail "zfs create $TESTPOOL/$TESTFS1 fail." i=0 while (( $i < ${#RW_FS_PROP[*]} )); do if [[ ${RW_FS_PROP[$i]} != *"checksum"* ]]; then propertycheck $TESTPOOL/$TESTFS1 ${RW_FS_PROP[i]} || \ log_fail "${RW_FS_PROP[i]} is failed to set." fi (( i = i + 1 )) done log_pass "'zfs create -o property=value filesystem' can successfully create \ a ZFS filesystem with multiple properties set." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_006_pos.ksh index 2a664a424619..551ae78cd239 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_006_pos.ksh @@ -1,84 +1,84 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib # # DESCRIPTION: # 'zfs create -o property=value -V size volume' can successfully create a ZFS # volume with correct property set. # # STRATEGY: # 1. Create a ZFS volume in the storage pool with -o option # 2. Verify the volume created successfully # 3. Verify the property is correctly set # verify_runnable "global" function cleanup { datasetexists $TESTPOOL/$TESTVOL1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTVOL1 + destroy_dataset $TESTPOOL/$TESTVOL1 -f } log_onexit cleanup log_assert "'zfs create -o property=value -V size volume' can successfully \ create a ZFS volume with correct property set." typeset -i i=0 while (( $i < ${#RW_VOL_PROP[*]} )); do log_must zfs create -o ${RW_VOL_PROP[$i]} -V $VOLSIZE \ $TESTPOOL/$TESTVOL1 datasetexists $TESTPOOL/$TESTVOL1 || \ log_fail "zfs create -V size $TESTPOOL/$TESTVOL1 fail." propertycheck $TESTPOOL/$TESTVOL1 ${RW_VOL_PROP[i]} || \ log_fail "${RW_VOL_PROP[i]} is failed to set." log_must_busy zfs destroy -f $TESTPOOL/$TESTVOL1 log_must zfs create -s -o ${RW_VOL_PROP[$i]} -V $VOLSIZE \ $TESTPOOL/$TESTVOL1 datasetexists $TESTPOOL/$TESTVOL1 || \ log_fail "zfs create -s -V $TESTPOOL/$TESTVOL1 fail." propertycheck $TESTPOOL/$TESTVOL1 ${RW_VOL_PROP[i]} || \ log_fail "${RW_VOL_PROP[i]} is failed to set." log_must_busy zfs destroy -f $TESTPOOL/$TESTVOL1 (( i = i + 1 )) done log_pass "'zfs create -o property=value -V size volume' can successfully \ create a ZFS volume with correct property set." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_008_neg.ksh index 43c3ab0de338..a905e50dfaa2 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_008_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_008_neg.ksh @@ -1,113 +1,112 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create.cfg # # DESCRIPTION: # 'zfs create' should return an error with badly formed parameters. # # STRATEGY: # 1. Create an array of parameters # 2. For each parameter in the array, execute 'zfs create' # 3. Verify an error is returned. # verify_runnable "both" function cleanup { - if datasetexists $TESTPOOL/$TESTFS1 ; then - log_must zfs destroy -f $TESTPOOL/$TESTFS1 - fi + datasetexists $TESTPOOL/$TESTFS1 && \ + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup set -A args "ab" "-?" "-cV" "-Vc" "-c -V" "c" "V" "--c" "-e" "-s" \ "-blah" "-cV 12k" "-s -cV 1P" "-sc" "-Vs 5g" "-o" "--o" "-O" "--O" \ "-o QuOta=none" "-o quota=non" "-o quota=abcd" "-o quota=0" "-o quota=" \ "-o ResErVaTi0n=none" "-o reserV=none" "-o reservation=abcd" "-o reserv=" \ "-o recorDSize=64k" "-o recordsize=2048K" "-o recordsize=2M" \ "-o recordsize=256" "-o recsize=" "-o recsize=zero" "-o recordsize=0" \ "-o mountPoint=/tmp/tmpfile$$" "-o mountpoint=non0" "-o mountpoint=" \ "-o mountpoint=LEGACY" "-o mounpoint=none" \ "-o sharenfs=ON" "-o ShareNFS=off" "-o sharenfs=sss" \ "-o checkSUM=on" "-o checksum=SHA256" "-o chsum=off" "-o checksum=aaa" \ "-o checkSUM=on -V $VOLSIZE" "-o checksum=SHA256 -V $VOLSIZE" \ "-o chsum=off -V $VOLSIZE" "-o checksum=aaa -V $VOLSIZE" \ "-o compression=of" "-o ComPression=lzjb" "-o compress=ON" "-o compress=a" \ "-o compression=of -V $VOLSIZE" "-o ComPression=lzjb -V $VOLSIZE" \ "-o compress=ON -V $VOLSIZE" "-o compress=a -V $VOLSIZE" \ "-o atime=ON" "-o ATime=off" "-o atime=bbb" \ "-o deviCes=on" "-o devices=OFF" "-o devices=aaa" \ "-o exec=ON" "-o EXec=off" "-o exec=aaa" \ "-o readonly=ON" "-o reADOnly=off" "-o rdonly=OFF" "-o rdonly=aaa" \ "-o readonly=ON -V $VOLSIZE" "-o reADOnly=off -V $VOLSIZE" \ "-o rdonly=OFF -V $VOLSIZE" "-o rdonly=aaa -V $VOLSIZE" \ "-o snapdIR=hidden" "-o snapdir=VISible" "-o snapdir=aaa" \ "-o aclmode=DIScard" "-o aclmODE=groupmask" "-o aclmode=aaa" \ "-o aclinherit=deny" "-o aclinHerit=secure" "-o aclinherit=aaa" \ "-o type=volume" "-o type=snapshot" "-o type=filesystem" \ "-o type=volume -V $VOLSIZE" "-o type=snapshot -V $VOLSIZE" \ "-o type=filesystem -V $VOLSIZE" \ "-o creation=aaa" "-o creation=aaa -V $VOLSIZE" \ "-o used=10K" "-o used=10K -V $VOLSIZE" \ "-o available=10K" "-o available=10K -V $VOLSIZE" \ "-o referenced=10K" "-o referenced=10K -V $VOLSIZE" \ "-o compressratio=1.00x" "-o compressratio=1.00x -V $VOLSIZE" \ "-o version=0" "-o version=1.234" "-o version=10K" "-o version=-1" \ "-o version=aaa" "-o version=999" if is_freebsd; then args+=("-o jailed=ON" "-o JaiLed=off" "-o jailed=aaa") else args+=("-o zoned=ON" "-o ZoNed=off" "-o zoned=aaa") fi log_assert "'zfs create' should return an error with badly-formed parameters." typeset -i i=0 while [[ $i -lt ${#args[*]} ]]; do typeset arg=${args[i]} if is_freebsd; then # FreeBSD does not strictly validate share options (yet). if [[ "$arg" == "-o sharenfs="* ]]; then ((i = i + 1)) continue fi fi log_mustnot zfs create $arg $TESTPOOL/$TESTFS1 log_mustnot zfs create -p $arg $TESTPOOL/$TESTFS1 ((i = i + 1)) done log_pass "'zfs create' with badly formed parameters failed as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_011_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_011_pos.ksh index 982a4ea16b5e..c5012d4f34a8 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_011_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_011_pos.ksh @@ -1,70 +1,69 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs create -p' should work as expected # # STRATEGY: # 1. To create $newdataset with -p option, first make sure the upper level # of $newdataset does not exist # 2. Make sure without -p option, 'zfs create' will fail # 3. Create $newdataset with -p option, verify it is created # 4. Run 'zfs create -p $newdataset' again, the exit code should be zero # even $newdataset exists # verify_runnable "both" function cleanup { - if datasetexists $TESTPOOL/$TESTFS1 ; then - log_must zfs destroy -rf $TESTPOOL/$TESTFS1 - fi + datasetexists $TESTPOOL/$TESTFS1 && \ + destroy_dataset $TESTPOOL/$TESTFS1 -rf } log_onexit cleanup typeset newdataset1="$TESTPOOL/$TESTFS1/$TESTFS/$TESTFS1" typeset newdataset2="$TESTPOOL/$TESTFS1/$TESTFS/$TESTVOL1" log_assert "'zfs create -p' works as expected." log_must verify_opt_p_ops "create" "fs" $newdataset1 # verify volume creation if is_global_zone; then log_must verify_opt_p_ops "create" "vol" $newdataset2 fi log_pass "'zfs create -p' works as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_012_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_012_pos.ksh index d8aa06407755..a0b8d52f0c43 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_012_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_012_pos.ksh @@ -1,71 +1,70 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib # # DESCRIPTION: # 'zfs create -p -o version=1' should only cause the leaf filesystem to be version=1 # # STRATEGY: # 1. Create $newdataset with -p option, verify it is created # 2. Verify only the leaf filesystem to be version=1, others use the current version # ZFS_VERSION=$(zfs upgrade | head -1 | awk '{print $NF}' \ | sed -e 's/\.//g') verify_runnable "both" function cleanup { - if datasetexists $TESTPOOL/$TESTFS1 ; then - log_must zfs destroy -rf $TESTPOOL/$TESTFS1 - fi + datasetexists $TESTPOOL/$TESTFS1 && \ + destroy_dataset $TESTPOOL/$TESTFS1 -rf } log_onexit cleanup typeset newdataset1="$TESTPOOL/$TESTFS1/$TESTFS/$TESTFS1" log_assert "'zfs create -p -o version=1' only cause the leaf filesystem to be version=1." log_must zfs create -p -o version=1 $newdataset1 log_must datasetexists $newdataset1 log_must check_fs_version $TESTPOOL/$TESTFS1/$TESTFS/$TESTFS1 1 for fs in $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS ; do log_must check_fs_version $fs $ZFS_VERSION done log_pass "'zfs create -p -o version=1' only cause the leaf filesystem to be version=1." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_014_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_014_pos.ksh index d1a8153d60e5..2482a68dc089 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_014_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_014_pos.ksh @@ -1,59 +1,58 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # check 'zfs create ' works at the name length boundary # # STRATEGY: # 1. Verify creating filesystem with name length 255 would succeed # 2. Verify creating filesystem with name length 256 would fail # 3. Verify the pool can be re-imported verify_runnable "both" # namelen 255 and 256 TESTFS1=$(for i in $(seq $((254 - ${#TESTPOOL}))); do echo z ; done | tr -d '\n') TESTFS2=$(for i in $(seq $((255 - ${#TESTPOOL}))); do echo z ; done | tr -d '\n') function cleanup { - datasetexists $TESTPOOL/$TESTFS1 && - log_must zfs destroy $TESTPOOL/$TESTFS1 + datasetexists $TESTPOOL/$TESTFS1 && destroy_dataset $TESTPOOL/$TESTFS1 } log_onexit cleanup log_assert "'zfs create ' can create a ZFS filesystem with name length 255." log_must zfs create $TESTPOOL/$TESTFS1 log_mustnot zfs create $TESTPOOL/$TESTFS2 log_must zpool export $TESTPOOL log_must zpool import $TESTPOOL log_pass "'zfs create ' works as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_crypt_combos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_crypt_combos.ksh index 141b2557d622..758b800c2fe8 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_crypt_combos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_crypt_combos.ksh @@ -1,99 +1,99 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017, Datto, Inc. All rights reserved. # Copyright (c) 2019, DilOS # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib # # DESCRIPTION: # 'zfs create' should create an encrypted dataset with a valid encryption # algorithm, key format, key location, and key. # # STRATEGY: # 1. Create a filesystem for each combination of encryption type and key format # 2. Verify that each filesystem has the correct properties set # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup set -A ENCRYPTION_ALGS \ "encryption=on" \ "encryption=aes-128-ccm" \ "encryption=aes-192-ccm" \ "encryption=aes-256-ccm" \ "encryption=aes-128-gcm" \ "encryption=aes-192-gcm" \ "encryption=aes-256-gcm" set -A ENCRYPTION_PROPS \ "encryption=aes-256-gcm" \ "encryption=aes-128-ccm" \ "encryption=aes-192-ccm" \ "encryption=aes-256-ccm" \ "encryption=aes-128-gcm" \ "encryption=aes-192-gcm" \ "encryption=aes-256-gcm" set -A KEYFORMATS "keyformat=raw" \ "keyformat=hex" \ "keyformat=passphrase" set -A USER_KEYS "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" \ "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" \ "abcdefgh" log_assert "'zfs create' should create encrypted datasets using all" \ "combinations of supported properties" typeset -i i=0 while (( i < ${#ENCRYPTION_ALGS[*]} )); do typeset -i j=0 while (( j < ${#KEYFORMATS[*]} )); do log_must eval "printf '%s' ${USER_KEYS[j]} | zfs create" \ "-o ${ENCRYPTION_ALGS[i]} -o ${KEYFORMATS[j]}" \ "$TESTPOOL/$TESTFS1" datasetexists $TESTPOOL/$TESTFS1 || \ log_fail "Failed to create dataset using" \ "${ENCRYPTION_ALGS[i]} and ${KEYFORMATS[j]}" propertycheck $TESTPOOL/$TESTFS1 ${ENCRYPTION_PROPS[i]} || \ log_fail "failed to set ${ENCRYPTION_ALGS[i]}" propertycheck $TESTPOOL/$TESTFS1 ${KEYFORMATS[j]} || \ log_fail "failed to set ${KEYFORMATS[j]}" - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + log_must_busy zfs destroy -f $TESTPOOL/$TESTFS1 (( j = j + 1 )) done (( i = i + 1 )) done log_pass "'zfs create' creates encrypted datasets using all combinations of" \ "supported properties" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_dryrun.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_dryrun.ksh index 64b8296f46bf..703ae8043d48 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_dryrun.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_dryrun.ksh @@ -1,169 +1,168 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2019 Joyent, Inc. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib # # DESCRIPTION: # zfs create -n should perform basic sanity checking but should never create a # dataset. If -v and/or -P are used, it should verbose about what would be # created if sanity checks pass. # # STRATEGY: # 1. Attempt to create a file system and a volume using various combinations of # -n with -v and -P. # verify_runnable "both" # # Verifies that valid commands with -n and without -[vP]: # - succeed # - do not create a dataset # - do not generate output # function dry_create_no_output { typeset -a cmd=(zfs create -n "$@") log_note "$0: ${cmd[@]}" log_must "${cmd[@]}" datasetexists "$TESTPOOL/$TESTFS1" && log_fail "$TESTPOOL/$TESTFS1 unexpectedly created by '${cmd[@]}'" typeset out=$("${cmd[@]}" 2>&1) [[ -z "$out" ]] || log_fail "unexpected output '$out' from '${cmd[@]}'" } # # Verifies that commands with invalid properties or invalid property values # - fail # - do not create a dataset # - generate a message on stderr # function dry_create_error { typeset -a cmd=(zfs create -n "$@") log_note "$0: ${cmd[@]}" log_mustnot "${cmd[@]}" datasetexists "$TESTPOOL/$TESTFS1" && log_fail "$TESTPOOL/$TESTFS1 unexpectedly created by '${cmd[@]}'" typeset out=$("${cmd[@]}" 2>&1 >/dev/null) [[ -z "$out" ]] && log_fail "expected an error message but got none from '${cmd[@]}'" } # # Verifies that dry-run commands with parseable output # - succeed # - do not create datasets # - generate parseable output on stdout # - output matches expectations # function dry_create_parseable { typeset -n exp=$1 shift typeset -a cmd=(zfs create -Pn "$@") typeset ds=${cmd[${#cmd[@]} - 1]} typeset out typeset -a toks typeset -a props typeset found_create=false log_note "$0: ${cmd[@]}" out=$("${cmd[@]}") (( $? == 0 )) || log_fail "unexpected failure getting stdout from '${cmd[@]}'" datasetexists "$TESTPOOL/$TESTFS1" && log_fail "$TESTPOOL/$TESTFS1 unexpectedly created by '${cmd[@]}'" echo "$out" | while IFS=$'\t' read -A toks; do log_note "verifying ${toks[@]}" case ${toks[0]} in create) log_must test "${#toks[@]}" -eq 2 log_must test "${toks[1]}" == "$ds" found_create="yes, I found create" ;; property) log_must test "${#toks[@]}" -eq 3 typeset prop=${toks[1]} typeset val=${toks[2]} if [[ -z "${exp[$prop]}" ]]; then log_fail "unexpectedly got property '$prop'" fi # We may not know the exact value a property will take # on. This is the case for at least refreservation. if [[ ${exp[$prop]} != "*" ]]; then log_must test "${exp[$prop]}" == "$val" fi unset exp[$prop] ;; *) log_fail "Unexpected line ${toks[@]}" ;; esac done log_must test "$found_create" == "yes, I found create" log_must test "extra props: ${!exp[@]}" == "extra props: " } function cleanup { - if datasetexists "$TESTPOOL/$TESTFS1"; then - log_must zfs destroy -r "$TESTPOOL/$TESTFS1" - fi + datasetexists "$TESTPOOL/$TESTFS1" && \ + destroy_dataset "$TESTPOOL/$TESTFS1" -r } log_onexit cleanup log_assert "zfs create -n creates nothing but can describe what would be" \ "created" # Typical creations should succeed dry_create_no_output "$TESTPOOL/$TESTFS1" dry_create_no_output -V 10m "$TESTPOOL/$TESTFS1" # It shouldn't do a space check right now dry_create_no_output -V 100t "$TESTPOOL/$TESTFS1" # It shouldn't create parent datasets either dry_create_no_output -p "$TESTPOOL/$TESTFS1/$TESTFS2" dry_create_no_output -pV 10m "$TESTPOOL/$TESTFS1/$TESTFS2" # Various invalid properties should be recognized and result in an error dry_create_error -o nosuchprop=42 "$TESTPOOL/$TESTFS1" dry_create_error -b 1234 -V 10m "$TESTPOOL/$TESTFS1" # Parseable output should be parseable. typeset -A expect expect=([compression]=on) dry_create_parseable expect -o compression=on "$TESTPOOL/$TESTFS1" # Sparse volumes should not get a gratuitous refreservation expect=([volblocksize]=4096 [volsize]=$((1024 * 1024 * 10))) dry_create_parseable expect -b 4k -V 10m -s "$TESTPOOL/$TESTFS1" # Non-sparse volumes should have refreservation expect=( [volblocksize]=4096 [volsize]=$((1024 * 1024 * 10)) [refreservation]="*" ) dry_create_parseable expect -b 4k -V 10m "$TESTPOOL/$TESTFS1" log_pass "zfs create -n creates nothing but can describe what would be" \ "created" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_encrypted.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_encrypted.ksh index 7e5072f0d5fd..e32545c689fe 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_encrypted.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_encrypted.ksh @@ -1,136 +1,136 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017, Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_create/properties.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # ZFS should create datasets only if they have a valid combination of # encryption properties set. # # penc = parent encrypted # enc = encryption # loc = keylocation provided # fmt = keyformat provided # # penc enc fmt loc valid notes # ------------------------------------------- # no unspec 0 0 yes inherit no encryption (not tested here) # no unspec 0 1 no no crypt specified # no unspec 1 0 no no crypt specified # no unspec 1 1 no no crypt specified # no off 0 0 yes explicit no encryption # no off 0 1 no keylocation given, but crypt off # no off 1 0 no keyformat given, but crypt off # no off 1 1 no keyformat given, but crypt off # no on 0 0 no no keyformat specified for new key # no on 0 1 no no keyformat specified for new key # no on 1 0 yes new encryption root # no on 1 1 yes new encryption root # yes unspec 0 0 yes inherit encryption # yes unspec 0 1 no no keyformat specified # yes unspec 1 0 yes new encryption root, crypt inherited # yes unspec 1 1 yes new encryption root, crypt inherited # yes off 0 0 yes unencrypted child of encrypted parent # yes off 0 1 no keylocation given, but crypt off # yes off 1 0 no keyformat given, but crypt off # yes off 1 1 no keyformat given, but crypt off # yes on 0 0 yes inherited encryption, local crypt # yes on 0 1 no no keyformat specified for new key # yes on 1 0 yes new encryption root # yes on 1 1 yes new encryption root # # STRATEGY: # 1. Attempt to create a dataset using all combinations of encryption # properties # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r } log_onexit cleanup log_assert "ZFS should create datasets only if they have a valid" \ "combination of encryption properties set." # Unencrypted parent log_must zfs create $TESTPOOL/$TESTFS1 log_mustnot zfs create -o keyformat=passphrase $TESTPOOL/$TESTFS1/c1 log_mustnot zfs create -o keylocation=prompt $TESTPOOL/$TESTFS1/c1 log_mustnot zfs create -o keyformat=passphrase -o keylocation=prompt \ $TESTPOOL/$TESTFS1/c1 log_must zfs create -o encryption=off $TESTPOOL/$TESTFS1/c1 log_mustnot zfs create -o encryption=off -o keylocation=prompt \ $TESTPOOL/$TESTFS1/c2 log_mustnot zfs create -o encryption=off -o keyformat=passphrase \ $TESTPOOL/$TESTFS1/c2 log_mustnot zfs create -o encryption=off -o keyformat=passphrase \ -o keylocation=prompt $TESTPOOL/$TESTFS1/c2 log_mustnot zfs create -o encryption=on $TESTPOOL/$TESTFS1/c2 log_mustnot zfs create -o encryption=on -o keylocation=prompt \ $TESTPOOL/$TESTFS1/c2 log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1/c3" log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1/c4" # Encrypted parent log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS2" log_must zfs create $TESTPOOL/$TESTFS2/c1 log_mustnot zfs create -o keylocation=prompt $TESTPOOL/$TESTFS2/c2 log_must eval "echo $PASSPHRASE | zfs create -o keyformat=passphrase" \ "$TESTPOOL/$TESTFS2/c3" log_must eval "echo $PASSPHRASE | zfs create -o keyformat=passphrase" \ "-o keylocation=prompt $TESTPOOL/$TESTFS2/c4" log_must zfs create -o encryption=off $TESTPOOL/$TESTFS2/c5 log_must test "$(get_prop 'encryption' $TESTPOOL/$TESTFS2/c5)" == "off" log_mustnot zfs create -o encryption=off -o keylocation=prompt \ $TESTPOOL/$TESTFS2/c5 log_mustnot zfs create -o encryption=off -o keyformat=passphrase \ $TESTPOOL/$TESTFS2/c5 log_mustnot zfs create -o encryption=off -o keyformat=passphrase \ -o keylocation=prompt $TESTPOOL/$TESTFS2/c5 log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "$TESTPOOL/$TESTFS2/c6" log_mustnot zfs create -o encryption=on -o keylocation=prompt \ $TESTPOOL/$TESTFS2/c7 log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS2/c7" log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS2/c8" log_pass "ZFS creates datasets only if they have a valid combination of" \ "encryption properties set." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_verbose.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_verbose.ksh index a07ccc7e9ace..acab500062ca 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_verbose.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_create/zfs_create_verbose.ksh @@ -1,165 +1,164 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2019 Joyent, Inc. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_create/zfs_create_common.kshlib # # DESCRIPTION: # zfs create -P without -n should be verbose about dataset creation. # # STRATEGY: # 1. Attempt to create a file system and a volume using various properties # and -P # 2. Exercise the combination of -p and -P. # verify_runnable "both" # # Verifies that non dry-run commands with parseable output # - succeed # - create datasets # - generate parseable output on stdout # - output matches expectations # function dry_create_parseable { typeset -n exp=$1 shift typeset -a cmd=(zfs create -P "$@") typeset ds=${cmd[${#cmd[@]} - 1]} typeset out typeset -a toks typeset -a props typeset found_create=false typeset create_ancestors= typeset opt # Parse the arguments to see if -p was used. while getopts :PV:b:ospv opt; do case $opt in p) create_ancestors=needed ;; *) continue ;; esac done log_note "$0: ${cmd[@]}" out=$("${cmd[@]}") (( $? == 0 )) || log_fail "unexpected failure getting stdout from '${cmd[@]}'" datasetexists "$TESTPOOL/$TESTFS1" || log_fail "$TESTPOOL/$TESTFS1 unexpectedly created by '${cmd[@]}'" echo "$out" | while IFS=$'\t' read -A toks; do log_note "verifying ${toks[@]}" case ${toks[0]} in create_ancestors) case "$create_ancestors" in needed) log_must test "${toks[1]}" == "$ds" create_ancestors="found ${toks[1]}" ;; found*) log_fail "multiple ancestor creation" \ "$create_ancestors and ${toks[1]}" ;; "") log_fail "unexpected create_ancestors" ;; *) log_fail "impossible error: fix the test" ;; esac ;; create) log_must test "${#toks[@]}" -eq 2 log_must test "${toks[1]}" == "$ds" found_create="yes, I found create" ;; property) log_must test "${#toks[@]}" -eq 3 typeset prop=${toks[1]} typeset val=${toks[2]} if [[ -z "${exp[$prop]}" ]]; then log_fail "unexpectedly got property '$prop'" fi # We may not know the exact value a property will take # on. This is the case for at least refreservation. if [[ ${exp[$prop]} != "*" ]]; then log_must test "${exp[$prop]}" == "$val" fi unset exp[$prop] ;; *) log_fail "Unexpected line ${toks[@]}" ;; esac done log_must test "$found_create" == "yes, I found create" log_must test "extra props: ${!exp[@]}" == "extra props: " case "$create_ancestors" in "") log_must_busy zfs destroy "$ds" ;; "found $ds") log_must_busy zfs destroy -r "$(echo "$ds" | cut -d/ -f1-2)" ;; needed) log_fail "Expected but did not find create_ancestors" ;; *) log_fail "Unexpected value for create_ancestors:" \ "$create_ancestors" ;; esac } function cleanup { - if datasetexists "$TESTPOOL/$TESTFS1"; then - log_must_busy zfs destroy -r "$TESTPOOL/$TESTFS1" - fi + datasetexists "$TESTPOOL/$TESTFS1" && \ + destroy_dataset "$TESTPOOL/$TESTFS1" -r } log_onexit cleanup log_assert "zfs create -v creates datasets verbosely" # Parseable output should be parseable. typeset -A expect expect=([compression]=on) dry_create_parseable expect -o compression=on "$TESTPOOL/$TESTFS1" # Ancestor creation with -p should emit relevant line expect=([compression]=on) dry_create_parseable expect -p -o compression=on "$TESTPOOL/$TESTFS1" expect=([compression]=on) dry_create_parseable expect -p -o compression=on "$TESTPOOL/$TESTFS1/$TESTVOL" # Sparse volumes should not get a gratuitous refreservation expect=([volblocksize]=4096 [volsize]=$((1024 * 1024 * 10))) dry_create_parseable expect -b 4k -V 10m -s "$TESTPOOL/$TESTFS1" # Non-sparse volumes should have refreservation expect=( [volblocksize]=4096 [volsize]=$((1024 * 1024 * 10)) [refreservation]="*" ) dry_create_parseable expect -b 4k -V 10m "$TESTPOOL/$TESTFS1" log_pass "zfs create -v creates datasets verbosely" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh index 26857d48d48b..11157e93c78d 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_001_pos.ksh @@ -1,235 +1,233 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib # # DESCRIPTION: # 'zfs destroy -r|-rf|-R|-Rf ' should recursively destroy # all children and clones based on options. # # STRATEGY: # 1. Create test environment according to options. There are three test # models can be created. Only ctr, fs & vol; with snap; with clone. # 2. According to option, make the dataset busy or not. # 3. Run 'zfs destroy [-rRf] ' # 4. According to dataset and option, check if get the expected results. # verify_runnable "both" # # According to parameters, 1st, create suitable testing environment. 2nd, # run 'zfs destroy $opt '. 3rd, check the system status. # # $1 option of 'zfs destroy' # $2 dataset will be destroyed. # function test_n_check { typeset opt=$1 typeset dtst=$2 if ! is_global_zone ; then if [[ $dtst == $VOL || $dtst == $VOLSNAP ]]; then log_note "UNSUPPORTED: Volume are unavailable in LZ." return fi fi # '-f' has no effect on non-filesystems if [[ $opt == -f ]]; then if [[ $dtst != $FS ]]; then log_note "UNSUPPORTED: '-f ' is only available for " \ "leaf FS." return fi fi # Clean the test environment and make it clear. - if datasetexists $CTR; then - log_must zfs destroy -Rf $CTR - fi + datasetexists $CTR && destroy_dataset $CTR -Rf # According to option create test compatible environment. case $opt in -r|-rf) setup_testenv snap ;; -R|-Rf) setup_testenv clone ;; -f) setup_testenv ;; *) log_fail "Incorrect option: '$opt'." ;; esac # # According to different dataset type, create busy condition when try to # destroy this dataset. # typeset mpt_dir case $dtst in $CTR|$FS) if [[ $opt == *f* ]]; then mpt_dir=$(get_prop mountpoint $FS) pidlist="$pidlist $(mkbusy \ $mpt_dir/$TESTFILE0)" log_note "mkbusy $mpt_dir/$TESTFILE0 " \ "(pidlist: $pidlist)" [[ -z $pidlist ]] && \ log_fail "Failure from mkbusy" log_mustnot zfs destroy -rR $dtst fi ;; $VOL) if [[ $opt == *f* ]]; then pidlist="$pidlist $(mkbusy \ $TESTDIR1/$TESTFILE0)" log_note "mkbusy $TESTDIR1/$TESTFILE0 " \ "(pidlist: $pidlist)" [[ -z $pidlist ]] && \ log_fail "Failure from mkbusy" log_mustnot zfs destroy -rR $dtst fi ;; $VOLSNAP) if [[ $opt == *f* ]]; then pidlist="$pidlist $(mkbusy \ $TESTDIR1/$TESTFILE0)" log_note "mkbusy $TESTDIR1/$TESTFILE0 " \ "(pidlist: $pidlist)" [[ -z $pidlist ]] && \ log_fail "Failure from mkbusy" log_must_busy zfs destroy -rR $dtst log_must zfs snapshot $dtst fi ;; $FSSNAP) if [[ $opt == *f* ]]; then mpt_dir=$(snapshot_mountpoint $dtst) pidlist="$pidlist $(mkbusy $mpt_dir)" log_note "mkbusy $mpt_dir (pidlist: $pidlist)" [[ -z $pidlist ]] && \ log_fail "Failure from mkbusy" if is_linux ; then log_mustnot zfs destroy -rR $dtst else log_must zfs destroy -rR $dtst log_must zfs snapshot $dtst fi fi ;; *) log_fail "Unsupported dataset: '$dtst'." esac # Kill any lingering instances of mkbusy, and clear the list. if is_linux ; then [[ -z $pidlist ]] || log_must kill -TERM $pidlist pidlist="" log_mustnot pgrep -fl mkbusy fi # Firstly, umount ufs filesystem which was created by zfs volume. if is_global_zone; then log_must umount -f $TESTDIR1 fi # Invoke 'zfs destroy [-rRf] ' log_must_busy zfs destroy $opt $dtst block_device_wait # Kill any lingering instances of mkbusy, and clear the list. if ! is_linux ; then [[ -z $pidlist ]] || log_must kill -TERM $pidlist pidlist="" log_mustnot pgrep -fl mkbusy fi case $dtst in $CTR) check_dataset datasetnonexists \ $CTR $FS $VOL $FSSNAP $VOLSNAP if [[ $opt == *R* ]]; then check_dataset datasetnonexists \ $FSCLONE $VOLCLONE fi ;; $FS) check_dataset datasetexists $CTR $VOL check_dataset datasetnonexists $FS if [[ $opt != -f ]]; then check_dataset datasetexists $VOLSNAP check_dataset datasetnonexists $FSSNAP fi if [[ $opt == *R* ]]; then check_dataset datasetexists $VOLCLONE check_dataset datasetnonexists $FSCLONE fi ;; $VOL) check_dataset datasetexists $CTR $FS $FSSNAP check_dataset datasetnonexists $VOL $VOLSNAP if [[ $opt == *R* ]]; then check_dataset datasetexists $FSCLONE check_dataset datasetnonexists $VOLCLONE fi ;; $FSSNAP) check_dataset datasetexists $CTR $FS $VOL $VOLSNAP check_dataset datasetnonexists $FSSNAP if [[ $opt == *R* ]]; then check_dataset datasetexists $VOLCLONE check_dataset datasetnonexists $FSCLONE fi ;; $VOLSNAP) check_dataset datasetexists $CTR $FS $VOL $FSSNAP check_dataset datasetnonexists $VOLSNAP if [[ $opt == *R* ]]; then check_dataset datasetexists $FSCLONE check_dataset datasetnonexists $VOLCLONE fi ;; esac log_note "'zfs destroy $opt $dtst' passed." } log_assert "'zfs destroy -r|-R|-f|-rf|-Rf ' should " \ "recursively destroy all children." log_onexit cleanup_testenv typeset dtst="" typeset opt="" typeset pidlist="" for dtst in $CTR $FS $VOL $FSSNAP $VOLSNAP; do for opt in "-r" "-R" "-f" "-rf" "-Rf"; do log_note "Starting test: zfs destroy $opt $dtst" test_n_check $opt $dtst done done log_pass "'zfs destroy -r|-R|-f|-rf|-Rf ' passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh index 04e9713124b1..8b7e59b412b4 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh @@ -1,156 +1,155 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg # # DESCRIPTION: # Verify 'zfs destroy [-rR]' succeeds as root. # # STRATEGY: # 1. Create two datasets in the storage pool # 2. Create fs,vol,ctr,snapshot and clones of snapshot in the two datasets # 3. Create clone in the second dataset for the snapshot in the first dataset # 4. Verify 'zfs destroy -r' fails to destroy dataset with clone outside it # 5. Verify 'zfs destroy -R' succeeds to destroy dataset with clone outside it # 6. Verify 'zfs destroy -r' succeeds to destroy dataset without clone outside it. # verify_runnable "both" function cleanup { for obj in $ctr2 $ctr1 $ctr; do - datasetexists $obj && \ - log_must zfs destroy -Rf $obj + datasetexists $obj && destroy_dataset $obj -Rf done for mntp in $TESTDIR1 $TESTDIR2; do [[ -d $mntp ]] && \ log_must rm -rf $mntp done } log_assert "Verify that 'zfs destroy [-rR]' succeeds as root. " log_onexit cleanup # # Preparations for testing # for dir in $TESTDIR1 $TESTDIR2; do [[ ! -d $dir ]] && \ log_must mkdir -p $dir done ctr=$TESTPOOL/$TESTCTR ctr1=$TESTPOOL/$TESTCTR1 ctr2=$ctr/$TESTCTR2 ctr3=$ctr1/$TESTCTR2 child_fs=$ctr/$TESTFS1 child_fs1=$ctr1/$TESTFS2 child_fs_mntp=$TESTDIR1 child_fs1_mntp=$TESTDIR2 child_vol=$ctr/$TESTVOL child_vol1=$ctr1/$TESTVOL child_fs_snap=$child_fs@snap child_fs1_snap=$child_fs1@snap child_fs_snap_clone=$ctr/$TESTCLONE child_fs_snap_clone1=$ctr1/${TESTCLONE}_across_ctr child_fs_snap_clone2=$ctr2/$TESTCLONE2 child_fs1_snap_clone=$ctr1/$TESTCLONE1 child_fs1_snap_clone1=$ctr/${TESTCLONE1}_across_ctr # # Create two datasets in the storage pool # log_must zfs create $ctr log_must zfs create $ctr1 # # Create children datasets fs,vol,snapshot in the datasets, and # clones across two datasets # log_must zfs create $ctr2 for fs in $child_fs $child_fs1; do log_must zfs create $fs done log_must zfs set mountpoint=$child_fs_mntp $child_fs log_must zfs set mountpoint=$child_fs1_mntp $child_fs1 for snap in $child_fs_snap $child_fs1_snap; do log_must zfs snapshot $snap done if is_global_zone ; then for vol in $child_vol $child_vol1; do log_must zfs create -V $VOLSIZE $vol done fi for clone in $child_fs_snap_clone $child_fs_snap_clone1; do log_must zfs clone $child_fs_snap $clone done for clone in $child_fs1_snap_clone $child_fs1_snap_clone1; do log_must zfs clone $child_fs1_snap $clone done log_note "Verify that 'zfs destroy -r' fails to destroy dataset " \ "with dependent clone outside it." for obj in $child_fs $child_fs1 $ctr $ctr1; do log_mustnot zfs destroy -r $obj datasetexists $obj || \ log_fail "'zfs destroy -r' fails to keep dependent " \ "clone outside the hierarchy." done log_note "Verify that 'zfs destroy -R' succeeds to destroy dataset " \ "with dependent clone outside it." -log_must zfs destroy -R $ctr1 +log_must_busy zfs destroy -R $ctr1 datasetexists $ctr1 && \ log_fail "'zfs destroy -R' fails to destroy dataset with clone outside it." log_note "Verify that 'zfs destroy -r' succeeds to destroy dataset " \ "without dependent clone outside it." -log_must zfs destroy -r $ctr +log_must_busy zfs destroy -r $ctr datasetexists $ctr && \ log_fail "'zfs destroy -r' fails to destroy dataset with clone outside it." log_pass "'zfs destroy [-rR] succeeds as root." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh index 3db1331ff57e..9a2ff6bea36d 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh @@ -1,126 +1,122 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg # # DESCRIPTION: # Verify 'zfs destroy -f' succeeds as root. # # STRATEGY: # 1. Create filesystem in the storage pool # 2. Set mountpoint for the filesystem and make it busy # 3. Verify that 'zfs destroy' fails to destroy the filesystem # 4. Verify 'zfs destroy -f' succeeds to destroy the filesystem. # verify_runnable "both" function cleanup { cd $olddir - datasetexists $clone && \ - log_must zfs destroy -f $clone - - snapexists $snap && \ - log_must zfs destroy -f $snap + datasetexists $clone && destroy_dataset $clone -f + snapexists $snap && destroy_dataset $snap -f for fs in $fs1 $fs2; do - datasetexists $fs && \ - log_must zfs destroy -f $fs + datasetexists $fs && destroy_dataset $fs -f done for dir in $TESTDIR1 $TESTDIR2; do [[ -d $dir ]] && \ log_must rm -rf $dir done } log_assert "Verify that 'zfs destroy -f' succeeds as root. " log_onexit cleanup # # Preparations for testing # olddir=$PWD for dir in $TESTDIR1 $TESTDIR2; do [[ ! -d $dir ]] && \ log_must mkdir -p $dir done fs1=$TESTPOOL/$TESTFS1 mntp1=$TESTDIR1 fs2=$TESTPOOL/$TESTFS2 snap=$TESTPOOL/$TESTFS2@snap clone=$TESTPOOL/$TESTCLONE mntp2=$TESTDIR2 # # Create filesystem and clone in the storage pool, mount them and # make the mountpoint busy # for fs in $fs1 $fs2; do log_must zfs create $fs done log_must zfs snapshot $snap log_must zfs clone $snap $clone log_must zfs set mountpoint=$mntp1 $fs1 log_must zfs set mountpoint=$mntp2 $clone for arg in "$fs1 $mntp1" "$clone $mntp2"; do fs=`echo $arg | awk '{print $1}'` mntp=`echo $arg | awk '{print $2}'` log_note "Verify that 'zfs destroy' fails to" \ "destroy filesystem when it is busy." cd $mntp log_mustnot zfs destroy $fs if is_linux; then log_mustnot zfs destroy -f $fs datasetnonexists $fs && \ log_fail "'zfs destroy -f' destroyed busy filesystem." else log_must zfs destroy -f $fs datasetexists $fs && \ log_fail "'zfs destroy -f' fail to destroy busy filesystem." fi cd $olddir done log_pass "'zfs destroy -f' succeeds as root." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh index 70ad45af0488..57eb736fd88b 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_007_neg.ksh @@ -1,76 +1,76 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg # # DESCRIPTION: # 'zpool destroy' failed if this filesystem is namespace-parent # of origin. # # STRATEGY: # 1. Create pool, fs and snapshot. # 2. Create a namespace-parent of origin clone. # 3. Promote this clone # 4. Verify the original fs can not be destroyed. # verify_runnable "both" function cleanup { if datasetexists $clonesnap; then log_must zfs promote $fs fi - datasetexists $clone && log_must zfs destroy $clone - datasetexists $fssnap && log_must zfs destroy $fssnap + datasetexists $clone && destroy_dataset $clone + datasetexists $fssnap && destroy_dataset $fssnap } log_assert "Destroy dataset which is namespace-parent of origin should failed." log_onexit cleanup # Define variable $fssnap & and namespace-parent of origin clone. fs=$TESTPOOL/$TESTFS fssnap=$fs@snap clone=$fs/clone clonesnap=$fs/clone@snap # Define key word for expected failure. KEY_WORDS="filesystem has children" log_must zfs snapshot $fssnap log_must zfs clone $fssnap $clone log_must zfs promote $clone log_mustnot_expect "$KEY_WORDS" zfs destroy $fs log_mustnot_expect "$KEY_WORDS" zfs destroy $clone log_pass "Destroy dataset which is namespace-parent of origin passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_014_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_014_pos.ksh index 58c4cfb5646d..e150cddfa1a5 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_014_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_014_pos.ksh @@ -1,79 +1,79 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg # # DESCRIPTION: # 'zfs destroy -R ' can destroy all the child # snapshots and preserves all the nested datasets. # # STRATEGY: # 1. Create nested datasets in the storage pool. # 2. Create recursive snapshots for all the nested datasets. # 3. Verify when snapshots are destroyed recursively, all # the nested datasets still exist. # verify_runnable "both" log_assert "Verify 'zfs destroy -R ' does not destroy" \ "nested datasets." log_onexit cleanup datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS2 $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3" function cleanup { for ds in $datasets; do - datasetexists $ds && zfs destroy -rf $ds + datasetexists $ds && destroy_dataset $ds -rf done } # create nested datasets log_must zfs create -p $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3 # verify dataset creation for ds in $datasets; do datasetexists $ds || log_fail "Create $ds dataset fail." done # create recursive nested snapshot log_must zfs snapshot -r $TESTPOOL/$TESTFS1@snap for ds in $datasets; do datasetexists $ds@snap || log_fail "Create $ds@snap snapshot fail." done # destroy nested snapshot recursively log_must zfs destroy -R $TESTPOOL/$TESTFS1@snap # verify snapshot destroy for ds in $datasets; do datasetexists $ds@snap && log_fail "$ds@snap exists. Destroy failed!" done # verify nested datasets still exist for ds in $datasets; do datasetexists $ds || log_fail "Recursive snapshot destroy deleted $ds" done log_pass "'zfs destroy -R ' works as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_015_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_015_pos.ksh index fb29e4acda14..f1868f522c84 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_015_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_015_pos.ksh @@ -1,161 +1,161 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # # DESCRIPTION # zfs destroy can destroy a list of multiple # snapshots from the same datasets # # STRATEGY # 1. Create multiple snapshots for the same dataset # 2. Run zfs destroy for these snapshots for a mix of valid and # invalid snapshot names # 3. Run zfs destroy for snapshots from different datasets and # pools . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg function cleanup { - datasetexists $TESTPOOL/$TESTFS1 && zfs destroy -R $TESTPOOL/$TESTFS1 - datasetexists $TESTPOOL/$TESTFS2 && zfs destroy -R $TESTPOOL/$TESTFS2 + datasetexists $TESTPOOL/$TESTFS1 && destroy_dataset $TESTPOOL/$TESTFS1 -R + datasetexists $TESTPOOL/$TESTFS2 && destroy_dataset $TESTPOOL/$TESTFS2 -R poolexists $TESTPOOL2 && zpool destroy $TESTPOOL2 rm -rf $VIRTUAL_DISK } log_assert "zfs destroy for multiple snapshot is handled correctly" log_onexit cleanup zfs create $TESTPOOL/$TESTFS1 typeset -i i=1 snaplist="" log_note "zfs destroy on valid snapshot names" for i in 1 2 3 4 5; do log_must zfs snapshot $TESTPOOL/$TESTFS1@snap$i snaplist=$snaplist,snap$i done snaplist=${snaplist#,} log_must zfs destroy $TESTPOOL/$TESTFS1@$snaplist for i in 1 2 3 4 5; do log_mustnot snapexists $TESTPOOL/$TESFS1@snap$i done log_note "zfs destroy with all bogus snapshot names" log_mustnot zfs destroy $TESTPOOL/$TESTFS1@snap12,snap21,sna@pple1@,s""nappy2 log_note "zfs destroy with some bogus snapshot names" for i in 1 2 3; do log_must zfs snapshot $TESTPOOL/$TESTFS1@snap$i done log_must zfs destroy $TESTPOOL/$TESTFS1@snap1,snap2,snapple1,snappy2,snap3 for i in 1 2 3; do log_mustnot snapexists $TESTPOOL/$TESTFS1@snap$i done log_note "zfs destroy with some snapshot names having special characters" for i in 1 2 3; do log_must zfs snapshot $TESTPOOL/$TESTFS1@snap$i done log_must zfs destroy $TESTPOOL/$TESTFS1@snap1,@,snap2,,,,snap3, for i in 1 2 3; do log_mustnot snapexists $TESTPOOL/$TESTFS1@snap$i done log_note "zfs destroy for too many snapshots" snaplist="" for i in {1..100}; do log_must zfs snapshot $TESTPOOL/$TESTFS1@snap$i snaplist=$snaplist,snap$i done snaplist=${snaplist#,} log_must zfs destroy $TESTPOOL/$TESTFS1@$snaplist for i in {1..100}; do log_mustnot snapexists $TESTPOOL/$TESTFS1@snap$i done log_note "zfs destroy multiple snapshots with hold" snaplist="" for i in 1 2 3 4 5; do log_must zfs snapshot $TESTPOOL/$TESTFS1@snap$i log_must zfs hold keep $TESTPOOL/$TESTFS1@snap$i snaplist=$snaplist,snap$i done snaplist=${snaplist#,} log_mustnot zfs destroy $TESTPOOL/$TESTFS1@$snaplist for i in 1 2 3 4 5; do log_must zfs release keep $TESTPOOL/$TESTFS1@snap$i done log_must zfs destroy $TESTPOOL/$TESTFS1@$snaplist log_note "zfs destroy for multiple snapshots having clones" for i in 1 2 3 4 5; do log_must zfs snapshot $TESTPOOL/$TESTFS1@snap$i done snaplist="" for i in 1 2 3 4 5; do log_must zfs clone $TESTPOOL/$TESTFS1@snap$i $TESTPOOL/$TESTFS1/clone$i snaplist=$snaplist,snap$i done snaplist=${snaplist#,} log_mustnot zfs destroy $TESTPOOL/$TESTFS1@$snaplist for i in 1 2 3 4 5; do log_must snapexists $TESTPOOL/$TESTFS1@snap$i log_must zfs destroy $TESTPOOL/$TESTFS1/clone$i done log_note "zfs destroy for snapshots for different datasets" log_must zfs create $TESTPOOL/$TESTFS2 log_must zfs snapshot $TESTPOOL/$TESTFS2@fs2snap log_must zfs create $TESTPOOL/$TESTFS1/$TESTFS2 log_must zfs snapshot $TESTPOOL/$TESTFS1/$TESTFS2@fs12snap long_arg=$TESTPOOL/$TESTFS1@snap1,$TESTPOOL/$TESTFS2@fs2snap, long_arg=$long_arg$TESTPOOL/$TESTFS1/$TESTFS2@fs12snap log_must zfs destroy $long_arg log_mustnot snapexists $TESTPOOL/$TESTFS1@snap1 log_must snapexists $TESTPOOL/$TESTFS2@fs2snap log_must snapexists $TESTPOOL/$TESTFS1/$TESTFS2@fs12snap log_must zfs destroy $TESTPOOL/$TESTFS1@fs2snap,fs12snap,snap2 log_must snapexists $TESTPOOL/$TESTFS2@fs2snap log_must snapexists $TESTPOOL/$TESTFS1/$TESTFS2@fs12snap log_mustnot snapexists $TESTPOOL/$TESTFS1@snap2 log_must zfs destroy $TESTPOOL/$TESTFS2@fs2snap,fs12snap,snap3 log_mustnot snapexists $TESTPOOL/$TESTFS2@fs2snap log_must snapexists $TESTPOOL/$TESTFS1/$TESTFS2@fs12snap log_must snapexists $TESTPOOL/$TESTFS1@snap3 log_note "zfs destroy for snapshots from different pools" VIRTUAL_DISK=$TEST_BASE_DIR/disk log_must mkfile $MINVDEVSIZE $VIRTUAL_DISK log_must zpool create $TESTPOOL2 $VIRTUAL_DISK log_must poolexists $TESTPOOL2 log_must zfs create $TESTPOOL2/$TESTFS1 log_must zfs snapshot $TESTPOOL2/$TESTFS1@snap long_arg=$TESTPOOL2/$TESTFS1@snap,$TESTPOOL/$TESTFS1@snap3, long_arg=$long_arg$TESTPOOL/$TESTFS1@snap5 log_must zfs destroy $long_arg log_mustnot snapexists $TESTPOOL2/$TESTFS1@snap log_must snapexists $TESTPOOL/$TESTFS1@snap3 log_must snapexists $TESTPOOL/$TESTFS1@snap5 log_must zfs snapshot $TESTPOOL2/$TESTFS1@snap log_must zfs destroy $TESTPOOL2/$TESTFS1@snap5,snap3,snap log_mustnot snapexists $TESTPOOL2/$TESTFS1@snap log_must snapexists $TESTPOOL/$TESTFS1@snap3 log_must snapexists $TESTPOOL/$TESTFS1@snap5 log_pass "zfs destroy for multiple snapshots passes" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_016_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_016_pos.ksh index 1e129ddd3bc9..93c8c63fd23f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_016_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_016_pos.ksh @@ -1,186 +1,186 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # # DESCRIPTION # Verify zfs destroy test for range of snapshots by giving a list # of valid and invalid arguments. # STRATEGY # 1. Create a list of valid and invalid arguments for range snapshot # destroy. # 2. Set up a filesystem and a volume with multiple snapshots # 3. Run zfs destroy for all the arguments and verify existence of snapshots # 4. Verify the destroy for snapshots with clones and hold . $STF_SUITE/include/libtest.shlib function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -R $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -R datasetexists $TESTPOOL/$TESTVOL && \ - log_must zfs destroy -Rf $TESTPOOL/$TESTVOL + destroy_dataset $TESTPOOL/$TESTVOL -Rf } function setup_snapshots { for i in $snaps; do datasetexists $TESTPOOL/$TESTFS1@snap$i && \ - log_must zfs destroy $TESTPOOL/$TESTFS1@snap$i + destroy_dataset $TESTPOOL/$TESTFS1@snap$i datasetexists $TESTPOOL/$TESTVOL@snap$i && \ - log_must zfs destroy $TESTPOOL/$TESTVOL@snap$i + destroy_dataset $TESTPOOL/$TESTVOL@snap$i log_must zfs snapshot $TESTPOOL/$TESTFS1@snap$i log_must zfs snapshot $TESTPOOL/$TESTVOL@snap$i done } function verify_snapshots { typeset snap_exists=${1:-0} if [[ $snap_exists == 1 ]]; then for i in $range; do snapexists $TESTPOOL/$TESTFS1@snap$i || \ log_fail "zfs destroy should not have destroyed" \ "$TESTPOOL/$TESTFS1@snap$i" snapexists $TESTPOOL/$TESTVOL@snap$i || \ log_fail "zfs destroy should not have destroyed" \ "$TESTPOOL/$TESTVOL@snap$i" done else for i in $range; do snapexists $TESTPOOL/$TESTFS1@snap$i && \ log_fail "zfs destroy should have destroyed" \ "$TESTPOOL/$TESTFS1@snap$i" snapexists $TESTPOOL/$TESTVOL@snap$i && \ log_fail "zfs destroy should have destroyed" \ "$TESTPOOL/$TESTVOL@snap$i" done fi } invalid_args="@snap0%snap5 @snap1%snap6 @snap0%snap6 @snap5%snap1 \ @snap1%$TESTPOOL/$TESTFS1@snap5 @snap1%%snap5 @snap1%@snap5 \ @@snap1%snap5 snap1%snap5 snap1%snap3%snap5" valid_args="@snap1%snap5 @%" log_assert "zfs destroy deletes ranges of snapshots" log_onexit cleanup log_must zfs create $TESTPOOL/$TESTFS1 log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL snaps="1 2 3 4 5" log_note "Verify the valid arguments" range="1 2 3 4 5" for args in $valid_args; do setup_snapshots log_must zfs destroy $TESTPOOL/$TESTFS1$args log_must zfs destroy $TESTPOOL/$TESTVOL$args verify_snapshots done log_note "Verify invalid arguments" setup_snapshots for args in $invalid_args; do log_mustnot zfs destroy $TESTPOOL/$TESTFS1$args log_mustnot zfs destroy $TESTPOOL/$TESTVOL$args log_must verify_snapshots 1 done log_note "Destroy the beginning range" log_must zfs destroy $TESTPOOL/$TESTFS1@%snap3 log_must zfs destroy $TESTPOOL/$TESTVOL@%snap3 range="1 2 3" verify_snapshots range="4 5" verify_snapshots 1 setup_snapshots log_note "Destroy the mid range" log_must zfs destroy $TESTPOOL/$TESTFS1@snap2%snap4 log_must zfs destroy $TESTPOOL/$TESTVOL@snap2%snap4 range="2 3 4" verify_snapshots log_must zfs destroy $TESTPOOL/$TESTFS1@snap1%snap5 log_must zfs destroy $TESTPOOL/$TESTVOL@snap1%snap5 range="1 5" verify_snapshots setup_snapshots log_note "Destroy the end range" log_must zfs destroy $TESTPOOL/$TESTFS1@snap3% log_must zfs destroy $TESTPOOL/$TESTVOL@snap3% range="1 2" verify_snapshots 1 range="3 4 5" verify_snapshots setup_snapshots log_note "Destroy a simple list" log_must zfs destroy $TESTPOOL/$TESTFS1@snap2,snap4 log_must zfs destroy $TESTPOOL/$TESTVOL@snap2,snap4 range="2 4" verify_snapshots range="1 3 5" verify_snapshots 1 setup_snapshots log_note "Destroy a list and range together" log_must zfs destroy $TESTPOOL/$TESTFS1@snap1%snap3,snap5 log_must zfs destroy $TESTPOOL/$TESTVOL@snap1%snap3,snap5 range="1 2 3 5" verify_snapshots range=4 verify_snapshots 1 snaps="1 2 3 5 6 7 8 9 10" setup_snapshots log_note "Destroy a list of ranges" log_must zfs destroy $TESTPOOL/$TESTFS1@snap1%snap3,snap5 log_must zfs destroy $TESTPOOL/$TESTVOL@snap1%snap3,snap5 range="1 2 3 5" verify_snapshots range=4 verify_snapshots 1 snaps="1 2 3 4 5" setup_snapshots log_note "Snapshot destroy with hold" range="1 2 3 4 5" for i in 1 2 3 4 5; do log_must zfs hold keep $TESTPOOL/$TESTFS1@snap$i log_must zfs hold keep $TESTPOOL/$TESTVOL@snap$i done log_mustnot zfs destroy $TESTPOOL/$TESTFS1@snap1%snap5 log_mustnot zfs destroy $TESTPOOL/$TESTVOL@snap1%snap5 verify_snapshots 1 for i in 1 2 3 4 5; do log_must zfs release keep $TESTPOOL/$TESTFS1@snap$i log_must zfs release keep $TESTPOOL/$TESTVOL@snap$i done log_must zfs destroy $TESTPOOL/$TESTFS1@snap1%snap5 log_must zfs destroy $TESTPOOL/$TESTVOL@snap1%snap5 verify_snapshots log_note "Range destroy for snapshots having clones" setup_snapshots for i in 1 2 3 4 5; do log_must zfs clone $TESTPOOL/$TESTFS1@snap$i $TESTPOOL/$TESTFS1/clone$i done log_must zfs destroy -R $TESTPOOL/$TESTFS1@snap1%snap5 log_must zfs destroy $TESTPOOL/$TESTVOL@snap1%snap5 verify_snapshots log_pass "'zfs destroy' successfully destroys ranges of snapshots" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_clone_livelist.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_clone_livelist.ksh index 2da58ec96cac..e7663ef7973c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_clone_livelist.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_clone_livelist.ksh @@ -1,164 +1,164 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2018, 2020 by Delphix. All rights reserved. # # DESCRIPTION # Verify zfs destroy test for clones with the livelist feature # enabled. # STRATEGY # 1. One clone with an empty livelist # - create the clone, check that livelist exists # - delete the clone, check that livelist is eventually # destroyed # 2. One clone with populated livelist # - create the clone, check that livelist exists # - write multiple files to the clone # - delete the clone, check that livelist is eventually # destroyed # 3. Multiple clones with empty livelists # - same as 1. but with multiple clones # 4. Multiple clones with populated livelists # - same as 2. but with multiple clones # 5. Clone of clone with populated livelists with promote . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib function cleanup { - datasetexists $TESTPOOL/$TESTFS1 && zfs destroy -R $TESTPOOL/$TESTFS1 + datasetexists $TESTPOOL/$TESTFS1 && destroy_dataset $TESTPOOL/$TESTFS1 -R # reset the livelist sublist size to its original value set_tunable64 LIVELIST_MAX_ENTRIES $ORIGINAL_MAX } function clone_write_file { log_must mkfile 1m /$TESTPOOL/$1/$2 log_must zpool sync $TESTPOOL } function test_one_empty { clone_dataset $TESTFS1 snap $TESTCLONE log_must zfs destroy $TESTPOOL/$TESTCLONE check_livelist_gone } function test_one { clone_dataset $TESTFS1 snap $TESTCLONE clone_write_file $TESTCLONE $TESTFILE0 clone_write_file $TESTCLONE $TESTFILE1 clone_write_file $TESTCLONE $TESTFILE2 log_must rm /$TESTPOOL/$TESTCLONE/$TESTFILE0 log_must rm /$TESTPOOL/$TESTCLONE/$TESTFILE2 check_livelist_exists $TESTCLONE log_must zfs destroy $TESTPOOL/$TESTCLONE check_livelist_gone } function test_multiple_empty { clone_dataset $TESTFS1 snap $TESTCLONE clone_dataset $TESTFS1 snap $TESTCLONE1 clone_dataset $TESTFS1 snap $TESTCLONE2 log_must zfs destroy $TESTPOOL/$TESTCLONE log_must zfs destroy $TESTPOOL/$TESTCLONE1 log_must zfs destroy $TESTPOOL/$TESTCLONE2 check_livelist_gone } function test_multiple { clone_dataset $TESTFS1 snap $TESTCLONE clone_dataset $TESTFS1 snap $TESTCLONE1 clone_dataset $TESTFS1 snap $TESTCLONE2 clone_write_file $TESTCLONE $TESTFILE0 clone_write_file $TESTCLONE1 $TESTFILE0 clone_write_file $TESTCLONE1 $TESTFILE1 clone_write_file $TESTCLONE1 $TESTFILE2 clone_write_file $TESTCLONE2 $TESTFILE0 log_must rm /$TESTPOOL/$TESTCLONE2/$TESTFILE0 clone_write_file $TESTCLONE2 $TESTFILE1 log_must rm /$TESTPOOL/$TESTCLONE2/$TESTFILE1 check_livelist_exists $TESTCLONE check_livelist_exists $TESTCLONE1 check_livelist_exists $TESTCLONE2 log_must zfs destroy $TESTPOOL/$TESTCLONE log_must zfs destroy $TESTPOOL/$TESTCLONE1 log_must zfs destroy $TESTPOOL/$TESTCLONE2 check_livelist_gone } function test_promote { clone_dataset $TESTFS1 snap $TESTCLONE log_must zfs promote $TESTPOOL/$TESTCLONE check_livelist_gone log_must zfs destroy -R $TESTPOOL/$TESTCLONE } function test_clone_clone_promote { log_must zfs create $TESTPOOL/fs log_must dd if=/dev/zero of=/$TESTPOOL/fs/file bs=128k count=100 log_must zfs snapshot $TESTPOOL/fs@snap log_must zfs clone $TESTPOOL/fs@snap $TESTPOOL/clone log_must dd if=/dev/zero of=/$TESTPOOL/clone/clonefile bs=128k count=10 log_must zfs snapshot $TESTPOOL/clone@csnap log_must zfs clone $TESTPOOL/clone@csnap $TESTPOOL/cloneclone check_livelist_exists clone check_livelist_exists cloneclone # Promote should remove both clones' livelists log_must zfs promote $TESTPOOL/cloneclone check_livelist_gone # This destroy should not use a livelist log_must zfs destroy $TESTPOOL/clone log_must zdb -bcc $TESTPOOL } ORIGINAL_MAX=$(get_tunable LIVELIST_MAX_ENTRIES) log_onexit cleanup log_must zfs create $TESTPOOL/$TESTFS1 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 LIVELIST_MAX_ENTRIES 20 test_one_empty test_one test_multiple_empty test_multiple test_promote test_clone_clone_promote log_pass "Clone with the livelist feature enabled could be destroyed," \ "also could be promoted and destroyed as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib index 096c18f069ff..1a20b7a33131 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_common.kshlib @@ -1,174 +1,172 @@ # # 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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2018 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg # # Create or recover a set of test environment which include ctr, vol, fs, # snap & clone. It looks like the following. # # pool # |ctr # | |fs # | | |fssnap # | |vol # | |volsnap # |fsclone # |volclone # # $1 indicate which dependent dataset need be created. Such as 'snap', 'clone'. # function setup_testenv #[dtst] { typeset dtst=$1 if ! datasetexists $CTR; then log_must zfs create $CTR fi if ! datasetexists $FS; then log_must zfs create $FS fi # Volume test is only available on global zone if ! datasetexists $VOL && is_global_zone; then log_must zfs create -V $VOLSIZE $VOL block_device_wait log_must new_fs $ZVOL_DEVDIR/$VOL if [[ ! -d $TESTDIR1 ]]; then log_must mkdir $TESTDIR1 fi log_must mount $ZVOL_DEVDIR/$VOL $TESTDIR1 fi if [[ $dtst == snap || $dtst == clone ]]; then if ! datasetexists $FSSNAP; then log_must zfs snapshot $FSSNAP fi if ! datasetexists $VOLSNAP && is_global_zone; then log_must zfs snapshot $VOLSNAP fi fi if [[ $dtst == clone ]]; then if ! datasetexists $FSCLONE; then log_must zfs clone $FSSNAP $FSCLONE fi if ! datasetexists $VOLCLONE && is_global_zone; then log_must zfs clone $VOLSNAP $VOLCLONE block_device_wait fi fi } # Clean up the testing environment # function cleanup_testenv { if is_global_zone && ismounted "$TESTDIR1" "$NEWFS_DEFAULT_FS" ; then log_must umount -f $TESTDIR1 fi if [[ -d $TESTDIR1 ]]; then log_must rm -rf $TESTDIR1 fi pkill mkbusy - if datasetexists $CTR; then - log_must zfs destroy -Rf $CTR - fi + datasetexists $CTR && destroy_dataset $CTR -Rf } # # Delete volume and related datasets from list, if the test cases was # running in local zone. Then check them are existed or non-exists. # # $1 function name # $2-n datasets name # function check_dataset { typeset funname=$1 typeset newlist="" typeset dtst shift for dtst in "$@"; do # Volume and related stuff are unavailable in local zone if ! is_global_zone; then if [[ $dtst == $VOL || $dtst == $VOLSNAP || \ $dtst == $VOLCLONE ]] then continue fi fi newlist="$newlist $dtst" done if (( ${#newlist} != 0 )); then # Run each item in $newlist individually so on failure, the # problematic dataset is listed in the logs. for i in $newlist; do log_must $funname $i done fi } # Use zdb to see if a livelist exists for a given clone # $1 clone name function check_livelist_exists { zdb -vvvvv $TESTPOOL/$1 | grep "Livelist" || \ log_fail "zdb could not find Livelist" } # Check that a livelist has been removed, waiting for deferred destroy entries # to be cleared from zdb. function check_livelist_gone { log_must zpool wait -t free $TESTPOOL zpool sync zdb -vvvvv $TESTPOOL | grep "Livelist" && \ log_fail "zdb found Livelist after the clone is deleted." } # Create a clone in the testpool based on $TESTFS@snap. Verify that the clone # was created and that it includes a livelist # $1 fs name # $2 snap name # $3 clone name function clone_dataset { log_must zfs clone $TESTPOOL/$1@$2 $TESTPOOL/$3 datasetexists $TESTPOOL/$3 || \ log_fail "zfs clone $TESTPOOL/$3 fail." check_livelist_exists $3 } diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_cliargs.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_cliargs.ksh index c4b42afee472..7063bbe9ce6a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_cliargs.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_cliargs.ksh @@ -1,80 +1,78 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2017, loli10K . All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs diff' should only work with supported options. # # STRATEGY: # 1. Create two snapshots # 2. Verify every supported option is accepted # 3. Verify supported options raise an error with unsupported arguments # 4. Verify other unsupported options raise an error # verify_runnable "both" function cleanup { for snap in $TESTSNAP1 $TESTSNAP2; do - if snapexists "$snap"; then - log_must zfs destroy "$snap" - fi + snapexists "$snap" && destroy_dataset "$snap" done } log_assert "'zfs diff' should only work with supported options." log_onexit cleanup typeset goodopts=("" "-F" "-H" "-t" "-FH" "-Ft" "-Ht" "-FHt") typeset badopts=("-f" "-h" "-h" "-T" "-Fx" "-Ho" "-tT" "-") DATASET="$TESTPOOL/$TESTFS" TESTSNAP1="$DATASET@snap1" TESTSNAP2="$DATASET@snap2" # 1. Create two snapshots log_must zfs snapshot "$TESTSNAP1" log_must zfs snapshot "$TESTSNAP2" # 2. Verify every supported option is accepted for opt in ${goodopts[@]} do log_must zfs diff $opt "$TESTSNAP1" log_must zfs diff $opt "$TESTSNAP1" "$DATASET" log_must zfs diff $opt "$TESTSNAP1" "$TESTSNAP2" done # 3. Verify supported options raise an error with unsupported arguments for opt in ${goodopts[@]} do log_mustnot zfs diff $opt log_mustnot zfs diff $opt "$DATASET" log_mustnot zfs diff $opt "$DATASET@noexists" log_mustnot zfs diff $opt "$DATASET" "$TESTSNAP1" log_mustnot zfs diff $opt "$TESTSNAP2" "$TESTSNAP1" done # 4. Verify other unsupported options raise an error for opt in ${badopts[@]} do log_mustnot zfs diff $opt "$TESTSNAP1" "$DATASET" log_mustnot zfs diff $opt "$TESTSNAP1" "$TESTSNAP2" done log_pass "'zfs diff' only works with supported options." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh index 62c4e768c0a1..0d08cf629572 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_diff/zfs_diff_timestamp.ksh @@ -1,100 +1,98 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2017, loli10K . All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs diff -t' should display inode change time correctly. # # STRATEGY: # 1. Create a snapshot # 2. Create some files with a random delay and snapshot the filesystem again # 3. Verify 'zfs diff -t' correctly display timestamps # verify_runnable "both" function cleanup { for snap in $TESTSNAP1 $TESTSNAP2; do - if snapexists "$snap"; then - log_must zfs destroy "$snap" - fi + snapexists "$snap" && destroy_dataset "$snap" done find "$MNTPOINT" -type f -delete rm -f "$FILEDIFF" } # # Creates $count files in $fspath. Waits a random delay between each file. # function create_random # { fspath="$1" typeset -i count="$2" typeset -i i=0 while (( i < count )); do log_must touch "$fspath/file$i" sleep $(random_int_between 1 3) (( i = i + 1 )) done } log_assert "'zfs diff -t' should display inode change time correctly." log_onexit cleanup DATASET="$TESTPOOL/$TESTFS" TESTSNAP1="$DATASET@snap1" TESTSNAP2="$DATASET@snap2" MNTPOINT="$(get_prop mountpoint $DATASET)" FILEDIFF="$TESTDIR/zfs-diff.txt" FILENUM=5 # 1. Create a snapshot log_must zfs snapshot "$TESTSNAP1" # 2. Create some files with a random delay and snapshot the filesystem again create_random "$MNTPOINT" $FILENUM log_must zfs snapshot "$TESTSNAP2" # 3. Verify 'zfs diff -t' correctly display timestamps typeset -i count=0 log_must eval "zfs diff -t $TESTSNAP1 $TESTSNAP2 > $FILEDIFF" awk '{print substr($1,1,index($1,".")-1)" "$NF}' < "$FILEDIFF" | while read line do read ctime file <<< "$line" # If path from 'zfs diff' is not a file (could be xattr object) skip it if [[ ! -f "$file" ]]; then continue; fi filetime=$(stat_ctime $file) if [[ "$filetime" != "$ctime" ]]; then log_fail "Unexpected ctime for file $file ($filetime != $ctime)" else log_note "Correct ctime read on $file: $ctime" fi (( i = i + 1 )) done if [[ $i != $FILENUM ]]; then log_fail "Wrong number of files verified ($i != $FILENUM)" fi log_pass "'zfs diff -t' displays inode change time correctly." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh index 4bd61137c7be..3bc4c6240ed3 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_004_pos.ksh @@ -1,227 +1,224 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify 'zfs get all' can get all properties for all datasets in the system # # STRATEGY: # 1. Create datasets for testing # 2. Issue 'zfs get all' command # 3. Verify the command gets all available properties of all datasets # verify_runnable "both" function cleanup { [[ -e $propfile ]] && rm -f $propfile - datasetexists $clone && \ - log_must zfs destroy $clone + datasetexists $clone && destroy_dataset $clone for snap in $fssnap $volsnap ; do - snapexists $snap && \ - log_must zfs destroy $snap + snapexists $snap && destroy_dataset $snap done if [[ -n $globalzone ]] ; then for pool in $TESTPOOL1 $TESTPOOL2 $TESTPOOL3; do poolexists $pool && \ log_must zpool destroy -f $pool done for file in `ls $TESTDIR1/poolfile*`; do rm -f $file done else for fs in $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2 $TESTPOOL/$TESTFS3; do - datasetexists $fs && \ - log_must zfs destroy -rf $fs + datasetexists $fs && destroy_dataset $fs -rf done fi } log_assert "Verify the functions of 'zfs get all' work." log_onexit cleanup typeset globalzone="" if is_global_zone ; then globalzone="true" fi set -A opts "" "-r" "-H" "-p" "-rHp" "-o name" \ "-s local,default,temporary,inherited,none" \ "-o name -s local,default,temporary,inherited,none" \ "-rHp -o name -s local,default,temporary,inherited,none" set -A usrprops "a:b=c" "d_1:1_e=0f" "123:456=789" fs=$TESTPOOL/$TESTFS fssnap=$fs@$TESTSNAP clone=$TESTPOOL/$TESTCLONE volsnap=$TESTPOOL/$TESTVOL@$TESTSNAP #set user defined properties for $TESTPOOL for usrprop in ${usrprops[@]}; do log_must zfs set $usrprop $TESTPOOL done # create snapshot and clone in $TESTPOOL log_must zfs snapshot $fssnap log_must zfs clone $fssnap $clone log_must zfs snapshot $volsnap # collect datasets which can be set user defined properties usrpropds="$clone $fs" # collect all datasets which we are creating allds="$fs $clone $fssnap $volsnap" #create pool and datasets to guarantee testing under multiple pools and datasets. file=$TESTDIR1/poolfile typeset FILESIZE=$MINVDEVSIZE (( DFILESIZE = $FILESIZE * 2 )) typeset -i VOLSIZE=10485760 availspace=$(get_prop available $TESTPOOL) typeset -i i=0 # make sure 'availspace' is larger then twice of FILESIZE to create a new pool. # If any, we only totally create 3 pools for multiple datasets testing to limit # testing time while (( availspace > DFILESIZE )) && (( i < 3 )) ; do (( i += 1 )) if [[ -n $globalzone ]] ; then log_must mkfile $FILESIZE ${file}$i eval pool=\$TESTPOOL$i log_must zpool create $pool ${file}$i else eval pool=$TESTPOOL/\$TESTFS$i log_must zfs create $pool fi #set user defined properties for testing for usrprop in ${usrprops[@]}; do log_must zfs set $usrprop $pool done #create datasets in pool log_must zfs create $pool/$TESTFS log_must zfs snapshot $pool/$TESTFS@$TESTSNAP log_must zfs clone $pool/$TESTFS@$TESTSNAP $pool/$TESTCLONE if [[ -n $globalzone ]] ; then log_must zfs create -V $VOLSIZE $pool/$TESTVOL else log_must zfs create $pool/$TESTVOL fi ds=`zfs list -H -r -o name -t filesystem,volume $pool` usrpropds="$usrpropds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL" allds="$allds $pool/$TESTFS $pool/$TESTCLONE $pool/$TESTVOL \ $pool/$TESTFS@$TESTSNAP" availspace=$(get_prop available $TESTPOOL) done #the expected number of property for each type of dataset in this testing typeset -i fspropnum=27 typeset -i snappropnum=8 typeset -i volpropnum=15 propfile=$TEST_BASE_DIR/allpropfile.$$ typeset -i i=0 typeset -i propnum=0 typeset -i failflag=0 while (( i < ${#opts[*]} )); do [[ -e $propfile ]] && rm -f $propfile log_must eval "zfs get ${opts[i]} all >$propfile" for ds in $allds; do grep $ds $propfile >/dev/null 2>&1 (( $? != 0 )) && \ log_fail "There is no property for" \ "dataset $ds in 'get all' output." propnum=`cat $propfile | awk '{print $1}' | \ grep "${ds}$" | wc -l` ds_type=`zfs get -H -o value type $ds` case $ds_type in filesystem ) (( propnum < fspropnum )) && \ (( failflag += 1 )) ;; snapshot ) (( propnum < snappropnum )) && \ (( failflag += 1 )) ;; volume ) (( propnum < volpropnum )) && \ (( failflag += 1 )) ;; esac (( failflag != 0 )) && \ log_fail " 'zfs get all' fails to get out " \ "all properties for dataset $ds." (( propnum = 0 )) (( failflag = 0 )) done (( i += 1 )) done log_note "'zfs get' can get particular property for all datasets with that property." function do_particular_prop_test # { typeset props="$1" typeset ds="$2" for prop in ${commprops[*]}; do ds=`zfs get -H -o name $prop` [[ "$ds" != "$allds" ]] && \ log_fail "The result datasets are $ds, but all suitable" \ "datasets are $allds for the property $prop" done } # Here, we do a testing for user defined properties and the most common properties # for all datasets. commprop="type creation used referenced compressratio" usrprop="a:b d_1:1_e 123:456" do_particular_prop_test "$commprop" "$allds" do_particular_prop_test "$usrprop" "$usrpropds" log_pass "'zfs get all' works as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib index 48b3268f7813..d5388e6ef2ae 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_get/zfs_get_list_d.kshlib @@ -1,84 +1,82 @@ # # 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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib DEPTH_FS=$TESTPOOL/depth_fs MAX_DEPTH=3 DS_COUNT=3 set -A depth_options "d 0" "d 1" "d 2" "d 4" "d 32" set -A depth_array 0 1 2 4 32 # # Setup multiple depths datasets, including fs, volumes, snapshots and bookmarks. # function depth_fs_setup { typeset -i i j k typeset fslist log_must zfs create $DEPTH_FS (( i=1 )) while (( i<=MAX_DEPTH )); do if (( i==1 )); then fslist=$DEPTH_FS else (( k=i-1 )) fslist=$(zfs list -rH -t filesystem -o name $DEPTH_FS|grep depth"$k"$) if (( $? != 0 )); then log_fail "No depth$k filesystem" fi fi for fs in $fslist; do (( j=1 )) while (( j<=DS_COUNT )); do log_must zfs create $fs/fs_"$j"_depth"$i" if is_global_zone ; then log_must zfs create -V 8M $fs/vol_"$j"_depth"$i" fi log_must zfs snapshot $fs@snap_"$j"_depth"$i" log_must zfs bookmark $fs@snap_"$j"_depth"$i" '#bookmark'_"$j"_depth"$i" (( j=j+1 )) done done (( i=i+1 )) done } # # Cleanup multiple depths filesystem. # function depth_fs_cleanup { - log_must zfs destroy -rR $DEPTH_FS + datasetexists $DEPTH_FS && destroy_dataset $DEPTH_FS -rR } - - diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh index 61f22ea091d1..8e37e8dbcae0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_002_neg.ksh @@ -1,107 +1,106 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2011, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs inherit' should return an error with bad parameters in one command. # # STRATEGY: # 1. Set an array of bad options and invalid properties to 'zfs inherit' # 2. Execute 'zfs inherit' with bad options and passing invalid properties # 3. Verify an error is returned. # verify_runnable "both" function cleanup { - if snapexists $TESTPOOL/$TESTFS@$TESTSNAP; then - log_must zfs destroy $TESTPOOL/$TESTFS@$TESTSNAP - fi + snapexists $TESTPOOL/$TESTFS@$TESTSNAP && \ + destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP } log_assert "'zfs inherit' should return an error with bad parameters in" \ "one command." log_onexit cleanup set -A badopts "r" "R" "-R" "-rR" "-a" "-" "-?" "-1" "-2" "-v" "-n" set -A props "recordsize" "mountpoint" "sharenfs" "checksum" "compression" \ "atime" "devices" "exec" "setuid" "readonly" "snapdir" "aclmode" \ "aclinherit" "xattr" "copies" if is_freebsd; then props+=("jailed") else props+=("zoned") fi set -A illprops "recordsiz" "mountpont" "sharen" "compres" "atme" "blah" log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP typeset -i i=0 for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL \ $TESTPOOL/$TESTFS@$TESTSNAP; do # zfs inherit should fail with bad options for opt in ${badopts[@]}; do for prop in ${props[@]}; do log_mustnot eval "zfs inherit $opt $prop $ds \ >/dev/null 2>&1" done done # zfs inherit should fail with invalid properties for prop in "${illprops[@]}"; do log_mustnot eval "zfs inherit $prop $ds >/dev/null 2>&1" log_mustnot eval "zfs inherit -r $prop $ds >/dev/null 2>&1" done # zfs inherit should fail with too many arguments (( i = 0 )) while (( i < ${#props[*]} -1 )); do log_mustnot eval "zfs inherit ${props[(( i ))]} \ ${props[(( i + 1 ))]} $ds >/dev/null 2>&1" log_mustnot eval "zfs inherit -r ${props[(( i ))]} \ ${props[(( i + 1 ))]} $ds >/dev/null 2>&1" (( i = i + 2 )) done done # zfs inherit should fail with missing datasets for prop in ${props[@]}; do log_mustnot eval "zfs inherit $prop >/dev/null 2>&1" log_mustnot eval "zfs inherit -r $prop >/dev/null 2>&1" done log_pass "'zfs inherit' failed as expected when passing illegal arguments." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh index 3317b09e2b5b..3f7e4ff972ed 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_inherit/zfs_inherit_003_pos.ksh @@ -1,90 +1,88 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # 'zfs inherit' should return an error with bad parameters in one command. # # STRATEGY: # 1. Set an array of bad options and invalid properties to 'zfs inherit' # 2. Execute 'zfs inherit' with bad options and passing invalid properties # 3. Verify an error is returned. # verify_runnable "both" function cleanup { for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do - if snapexists $ds@$TESTSNAP; then - log_must zfs destroy $ds@$TESTSNAP - fi + snapexists $ds@$TESTSNAP && destroy_dataset $ds@$TESTSNAP done cleanup_user_prop $TESTPOOL } log_assert "'zfs inherit' should inherit user property." log_onexit cleanup for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do typeset prop_name=$(valid_user_property 10) typeset value=$(user_property_value 16) log_must eval "zfs set $prop_name='$value' $ds" log_must zfs snapshot $ds@$TESTSNAP typeset snapvalue=$(get_prop $prop_name $ds@$TESTSNAP) if [[ "$snapvalue" != "$value" ]] ; then log_fail "The '$ds@$TESTSNAP '$prop_name' value '$snapvalue' " \ "not equal to the expected value '$value'." fi snapvalue=$(user_property_value 16) log_must eval "zfs set $prop_name='$snapvalue' $ds@$TESTSNAP" log_must zfs inherit $prop_name $ds@$TESTSNAP snapvalue=$(get_prop $prop_name $ds@$TESTSNAP) if [[ "$snapvalue" != "$value" ]] ; then log_fail "The '$ds@$TESTSNAP '$prop_name' value '$snapvalue' " \ "not equal to the expected value '$value'." fi done log_pass "'zfs inherit' inherit user property." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key.ksh index 847a6aabd3c8..8af9f80cfbd7 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key.ksh @@ -1,85 +1,85 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs load-key' should only load a key for an unloaded encrypted dataset. # # STRATEGY: # 1. Attempt to load the default dataset's key # 2. Unmount the dataset # 3. Attempt to load the default dataset's key # 4. Create an encrypted dataset # 5. Unmount the dataset and unload its key # 6. Attempt to load the dataset's key # 7. Verify the dataset's key is loaded # 8. Attempt to load the dataset's key again # 9. Create an encrypted pool # 10. Unmount the pool and unload its key # 11. Attempt to load the pool's key # 12. Verify the pool's key is loaded # 13. Attempt to load the pool's key again # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 poolexists $TESTPOOL1 && log_must destroy_pool $TESTPOOL1 } log_onexit cleanup log_assert "'zfs load-key' should only load the key for an" \ "unloaded encrypted dataset" log_mustnot eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS" log_must zfs unmount $TESTPOOL/$TESTFS log_mustnot eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS" log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS1" log_must key_available $TESTPOOL/$TESTFS1 log_mustnot eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS1" typeset DISK2="$(echo $DISKS | awk '{ print $2 }')" log_must eval "echo $PASSPHRASE | zpool create -O encryption=on" \ "-O keyformat=passphrase -O keylocation=prompt $TESTPOOL1 $DISK2" log_must zfs unmount $TESTPOOL1 log_must zfs unload-key $TESTPOOL1 log_must eval "echo $PASSPHRASE | zfs load-key $TESTPOOL1" log_must key_available $TESTPOOL1 log_mustnot eval "echo $PASSPHRASE | zfs load-key $TESTPOOL1" log_pass "'zfs load-key' only loads the key for an unloaded encrypted dataset" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_all.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_all.ksh index 5e331fd1200d..5e330eb0deb9 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_all.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_all.ksh @@ -1,77 +1,76 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs load-key -a' should load keys for all datasets. # # STRATEGY: # 1. Create an encrypted filesystem, encrypted zvol, and an encrypted pool # 2. Unmount all datasets and unload their keys # 3. Attempt to load all dataset keys # 4. Verify each dataset has its key loaded # 5. Attempt to mount the pool and filesystem # verify_runnable "both" function cleanup { - datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy $TESTPOOL/$TESTFS1 - datasetexists $TESTPOOL/zvol && log_must zfs destroy $TESTPOOL/zvol + datasetexists $TESTPOOL/$TESTFS1 && destroy_dataset $TESTPOOL/$TESTFS1 + datasetexists $TESTPOOL/zvol && destroy_dataset $TESTPOOL/zvol poolexists $TESTPOOL1 && log_must destroy_pool $TESTPOOL1 } log_onexit cleanup log_assert "'zfs load-key -a' should load keys for all datasets" log_must eval "echo $PASSPHRASE1 > /$TESTPOOL/pkey" log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 log_must zfs create -V 64M -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/zvol typeset DISK2="$(echo $DISKS | awk '{ print $2}')" log_must zpool create -O encryption=on -O keyformat=passphrase \ -O keylocation=file:///$TESTPOOL/pkey $TESTPOOL1 $DISK2 log_must zfs unmount $TESTPOOL/$TESTFS1 -log_must zfs unload-key $TESTPOOL/$TESTFS1 +log_must_busy zfs unload-key $TESTPOOL/$TESTFS1 -log_must zfs unload-key $TESTPOOL/zvol +log_must_busy zfs unload-key $TESTPOOL/zvol log_must zfs unmount $TESTPOOL1 -log_must zfs unload-key $TESTPOOL1 +log_must_busy zfs unload-key $TESTPOOL1 log_must zfs load-key -a log_must key_available $TESTPOOL1 log_must key_available $TESTPOOL/zvol log_must key_available $TESTPOOL/$TESTFS1 log_must zfs mount $TESTPOOL1 log_must zfs mount $TESTPOOL/$TESTFS1 log_pass "'zfs load-key -a' loads keys for all datasets" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_file.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_file.ksh index 7cbda43ff241..73c461fd6b39 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_file.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_file.ksh @@ -1,58 +1,58 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs load-key' should load a dataset's key from a file. # # STRATEGY: # 1. Create an encrypted dataset with a key file # 2. Unmount the dataset and unload the key # 3. Attempt to load the dataset's key # 4. Verify the key is loaded # 5. Attempt to mount the dataset # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 } log_onexit cleanup log_assert "'zfs load-key' should load a key from a file" log_must eval "echo $PASSPHRASE > /$TESTPOOL/pkey" log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must zfs load-key $TESTPOOL/$TESTFS1 log_must key_available $TESTPOOL/$TESTFS1 log_must zfs mount $TESTPOOL/$TESTFS1 log_pass "'zfs load-key' loads a key from a file" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_location.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_location.ksh index d0b1cdb20ec7..8538143cb62e 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_location.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_location.ksh @@ -1,73 +1,73 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs load-key -L' should override keylocation with provided value. # # STRATEGY: # 1. Create a key file # 2. Copy the key file to another location # 3. Create an encrypted dataset using the keyfile # 4. Unmount the dataset and unload its key # 5. Attempt to load the dataset specifying a keylocation of file # 6. Verify the key is loaded # 7. Verify the keylocation is the original key file # 8. Unload the dataset's key # 9. Attempt to load the dataset specifying a keylocation of prompt # 10. Verify the key is loaded # 11. Verify the keylocation is the original key file # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 } log_onexit cleanup log_assert "'zfs load-key -L' should override keylocation with provided value" typeset key_location="/$TESTPOOL/pkey1" log_must eval "echo $PASSPHRASE > $key_location" log_must cp $key_location /$TESTPOOL/pkey2 log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file://$key_location $TESTPOOL/$TESTFS1 log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must zfs load-key -L file:///$TESTPOOL/pkey2 $TESTPOOL/$TESTFS1 log_must key_available $TESTPOOL/$TESTFS1 log_must verify_keylocation $TESTPOOL/$TESTFS1 "file://$key_location" log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must eval "echo $PASSPHRASE | zfs load-key -L prompt $TESTPOOL/$TESTFS1" log_must key_available $TESTPOOL/$TESTFS1 log_must verify_keylocation $TESTPOOL/$TESTFS1 "file://$key_location" log_pass "'zfs load-key -L' overrides keylocation with provided value" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_noop.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_noop.ksh index bfce786448d9..2ee17834696f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_noop.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_noop.ksh @@ -1,54 +1,54 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs load-key -n' should load the key for an already loaded dataset. # # STRATEGY: # 1. Create an encrypted dataset # 2. Attempt to load the dataset's key # 3. Verify the key is loaded # 4. Attempt to load the dataset's key with an invalid key # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 } log_onexit cleanup log_assert "'zfs load-key -n' should load the key for a loaded dataset" log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1" log_must eval "echo $PASSPHRASE | zfs load-key -n $TESTPOOL/$TESTFS1" log_must key_available $TESTPOOL/$TESTFS1 log_mustnot eval "echo $PASSPHRASE1 | zfs load-key -n $TESTPOOL/$TESTFS1" log_pass "'zfs load-key -n' loads the key for a loaded dataset" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_recursive.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_recursive.ksh index 7385b69cf5fe..54c390f2737f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_recursive.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_load-key/zfs_load-key_recursive.ksh @@ -1,66 +1,66 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs load-key -r' should recursively load keys. # # STRATEGY: # 1. Create an encrypted dataset # 2. Create a child dataset as an encryption root # 3. Unmount all datasets and unload their keys # 4. Attempt to load all dataset keys # 5. Verify each dataset has its key loaded # 6. Attempt to mount each dataset # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r } log_onexit cleanup log_assert "'zfs load-key -r' should recursively load keys" log_must eval "echo $PASSPHRASE1 > /$TESTPOOL/pkey" log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 log_must zfs create -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1/child log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1/child log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must zfs load-key -r $TESTPOOL log_must key_available $TESTPOOL/$TESTFS1 log_must key_available $TESTPOOL/$TESTFS1/child log_must zfs mount $TESTPOOL/$TESTFS1 log_must zfs mount $TESTPOOL/$TESTFS1/child log_pass "'zfs load-key -r' recursively loads keys" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh index 4b3bf40bc3be..6a251330f62d 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_008_pos.ksh @@ -1,97 +1,95 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib # # DESCRIPTION: # 'zfs mount -O' allow the file system to be mounted over an existing # mount point, making the underlying file system inaccessible. # # STRATEGY: # 1. Create two filesystem fs & fs1, and create two test files for them. # 2. Unmount fs1 and set mountpoint property is identical to fs. # 3. Verify 'zfs mount -O' will make the underlying filesystem fs # inaccessible. # function cleanup { ! ismounted $fs && log_must zfs mount $fs - if datasetexists $fs1; then - log_must zfs destroy $fs1 - fi + datasetexists $fs1 && destroy_dataset $fs1 if [[ -f $testfile ]]; then log_must rm -f $testfile fi } log_assert "Verify 'zfs mount -O' will override existing mount point." log_onexit cleanup fs=$TESTPOOL/$TESTFS; fs1=$TESTPOOL/$TESTFS1 cleanup # Get the original mountpoint of $fs and $fs1 mntpnt=$(get_prop mountpoint $fs) log_must zfs create $fs1 mntpnt1=$(get_prop mountpoint $fs1) testfile=$mntpnt/$TESTFILE0; testfile1=$mntpnt1/$TESTFILE1 log_must mkfile 1M $testfile $testfile1 log_must zfs unmount $fs1 log_must zfs set mountpoint=$mntpnt $fs1 log_must zfs mount $fs1 log_must zfs unmount $fs1 log_must zfs mount -O $fs1 # Create new file in override mountpoint log_must mkfile 1M $mntpnt/$TESTFILE2 # Verify the underlying file system inaccessible log_mustnot ls $testfile log_must ls $mntpnt/$TESTFILE1 $mntpnt/$TESTFILE2 # Verify $TESTFILE2 was created in $fs1, rather than $fs log_must zfs unmount $fs1 log_must zfs set mountpoint=$mntpnt1 $fs1 log_must zfs mount $fs1 log_must ls $testfile1 $mntpnt1/$TESTFILE2 # Verify $TESTFILE2 was not created in $fs, and $fs is accessible again. log_mustnot ls $mntpnt/$TESTFILE2 log_must ls $testfile log_pass "Verify 'zfs mount -O' override mount point passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_011_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_011_neg.ksh index a116b4647c09..95e2bc39727a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_011_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_011_neg.ksh @@ -1,81 +1,80 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that zfs mount should fail with bad parameters # # STRATEGY: # 1. Make an array of bad parameters # 2. Use zfs mount to mount the filesystem # 3. Verify that zfs mount returns error # verify_runnable "both" function cleanup { - if snapexists $TESTPOOL/$TESTFS@$TESTSNAP; then - log_must_busy zfs destroy $TESTPOOL/$TESTFS@$TESTSNAP - fi + snapexists $TESTPOOL/$TESTFS@$TESTSNAP && \ + destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP if is_global_zone && datasetexists $TESTPOOL/$TESTVOL; then - log_must_busy zfs destroy $TESTPOOL/$TESTVOL + destroy_dataset $TESTPOOL/$TESTVOL fi } log_assert "zfs mount fails with bad parameters" log_onexit cleanup fs=$TESTPOOL/$TESTFS set -A badargs "A" "-A" "-" "-x" "-?" "=" "-o *" "-a" for arg in "${badargs[@]}"; do log_mustnot eval "zfs mount $arg $fs >/dev/null 2>&1" done #verify that zfs mount fails with invalid dataset for opt in "-o abc" "-O"; do log_mustnot eval "zfs mount $opt /$fs >/dev/null 2>&1" done #verify that zfs mount fails with volume and snapshot log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP log_mustnot eval "zfs mount $TESTPOOL/$TESTFS@$TESTSNAP >/dev/null 2>&1" if is_global_zone; then log_must zfs create -V 10m $TESTPOOL/$TESTVOL log_mustnot eval "zfs mount $TESTPOOL/$TESTVOL >/dev/null 2>&1" fi log_pass "zfs mount fails with bad parameters as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_encrypted.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_encrypted.ksh index 9749a9b3aa8a..a95e7507b4d0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_encrypted.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_encrypted.ksh @@ -1,69 +1,69 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017, Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs mount -l' should accept a valid key as it mounts the filesystem. # # STRATEGY: # 1. Create an encrypted dataset # 2. Unmount and unload the dataset's key # 3. Verify the key is unloaded # 4. Attempt to mount all datasets in the pool # 5. Verify that no error code is produced # 6. Verify that the encrypted dataset is not mounted # 7. Attempt to load the key while mounting the dataset # 8. Verify the key is loaded # 9. Verify the dataset is mounted # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup log_assert "'zfs mount -l' should properly load a valid wrapping key" log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must key_unavailable $TESTPOOL/$TESTFS1 log_must zfs mount -a unmounted $TESTPOOL/$TESTFS1 || \ log_fail "Filesystem $TESTPOOL/$TESTFS1 is mounted" log_must eval "echo $PASSPHRASE | zfs mount -l $TESTPOOL/$TESTFS1" log_must key_available $TESTPOOL/$TESTFS1 mounted $TESTPOOL/$TESTFS1 || \ log_fail "Filesystem $TESTPOOL/$TESTFS1 is unmounted" log_pass "'zfs mount -l' properly loads a valid wrapping key" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_remount.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_remount.ksh index 9712c793a919..ac6103ebc7bf 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_remount.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_mount/zfs_mount_remount.ksh @@ -1,171 +1,171 @@ #!/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 . All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib # # DESCRIPTION: # Verify remount functionality, especially on readonly objects. # # STRATEGY: # 1. Prepare a filesystem and a snapshot # 2. Verify we can (re)mount the dataset readonly/read-write # 3. Verify we can mount the snapshot and it's mounted readonly # 4. Verify we can't remount it read-write # 5. Verify we can remount a dataset readonly and unmount it with # encryption=on and sync=disabled (issue #7753) # 6. Re-import the pool readonly # 7. Verify we can't remount its filesystem read-write # verify_runnable "both" function cleanup { log_must_busy zpool export $TESTPOOL log_must zpool import $TESTPOOL - snapexists $TESTSNAP && log_must zfs destroy $TESTSNAP + snapexists $TESTSNAP && destroy_dataset $TESTSNAP [[ -d $MNTPSNAP ]] && log_must rmdir $MNTPSNAP 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 # verify the error returned is EROFS # function readonlyfs # filesystem { typeset filesystem="$1" file_write -o create -f $filesystem/file.dat ret=$? if [[ $ret != 30 ]]; then log_fail "Writing to $filesystem did not return EROFS ($ret)." fi } # # Verify $dataset is mounted with $option # function checkmount # dataset option { typeset dataset="$1" typeset option="$2" typeset options="" 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 log_fail "Dataset $dataset is not mounted with expected "\ "option $option ($options)" else log_note "Dataset $dataset is mounted with option $option" fi } log_assert "Verify remount functionality on both filesystem and snapshots" log_onexit cleanup # 1. Prepare a filesystem and a snapshot TESTFS=$TESTPOOL/$TESTFS TESTSNAP="$TESTFS@snap" datasetexists $TESTFS || log_must zfs create $TESTFS snapexists $TESTSNAP || log_must zfs snapshot $TESTSNAP log_must zfs set readonly=off $TESTFS MNTPFS="$(get_prop mountpoint $TESTFS)" MNTPSNAP="$TESTDIR/zfs_snap_mount" 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 $RO $TESTFS $MNTPFS readonlyfs $MNTPFS checkmount $TESTFS 'ro' log_must mount $RW $TESTFS $MNTPFS log_must touch $MNTPFS/file.dat checkmount $TESTFS 'rw' 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. # The "mount -o remount,rw" command must fail with an explicit error. log_must mount -t zfs -o rw $TESTSNAP $MNTPSNAP readonlyfs $MNTPSNAP checkmount $TESTSNAP 'ro' log_mustnot mount $RW $TESTSNAP $MNTPSNAP readonlyfs $MNTPSNAP checkmount $TESTSNAP 'ro' log_must umount $MNTPSNAP # 5. Verify we can remount a dataset readonly and unmount it with # encryption=on and sync=disabled (issue #7753) 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 $RO $TESTFS/crypt $CRYPT_MNTPFS log_must umount -f $CRYPT_MNTPFS zpool sync $TESTPOOL # 6. Re-import the pool readonly log_must zpool export $TESTPOOL 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 $RW $MNTPFS readonlyfs $MNTPFS checkmount $TESTFS 'ro' log_pass "Both filesystem and snapshots can be remounted correctly." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_001_pos.ksh index 0bf7c5b6a176..dc3ffd65ed38 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_001_pos.ksh @@ -1,127 +1,126 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs promote' can promote a clone filesystem to no longer be dependent # on its "origin" snapshot. # # STRATEGY: # 1. Create a snapshot and a clone of the snapshot # 2. Promote the clone filesystem # 3. Verify the promoted filesystem become independent # verify_runnable "both" function cleanup { if snapexists $csnap; then log_must zfs promote $fs fi - snapexists $snap && \ - log_must zfs destroy -rR $snap + snapexists $snap && destroy_dataset $snap -rR typeset data for data in $file0 $file1; do [[ -e $data ]] && rm -f $data done } function testing_verify { typeset ds=$1 typeset ds_file=$2 typeset snap_file=$3 typeset c_ds=$4 typeset c_file=$5 typeset csnap_file=$6 typeset origin_prop="" snapexists $ds@$TESTSNAP && \ log_fail "zfs promote cannot promote $ds@$TESTSNAP." ! snapexists $c_ds@$TESTSNAP && \ log_fail "The $c_ds@$TESTSNAP after zfs promote doesn't exist." origin_prop=$(get_prop origin $ds) [[ "$origin_prop" != "$c_ds@$TESTSNAP" ]] && \ log_fail "The dependency of $ds is not correct." origin_prop=$(get_prop origin $c_ds) [[ "$origin_prop" != "-" ]] && \ log_fail "The dependency of $c_ds is not correct." if [[ -e $snap_file ]] || [[ ! -e $csnap_file ]]; then log_fail "Data file $snap_file cannot be correctly promoted." fi if [[ ! -e $ds_file ]] || [[ ! -e $c_file ]]; then log_fail "There exists data file losing after zfs promote." fi log_mustnot zfs destroy -r $c_ds } log_assert "'zfs promote' can promote a clone filesystem." log_onexit cleanup fs=$TESTPOOL/$TESTFS file0=$TESTDIR/$TESTFILE0 file1=$TESTDIR/$TESTFILE1 snap=$fs@$TESTSNAP snapfile=$TESTDIR/.zfs/snapshot/$TESTSNAP/$TESTFILE0 clone=$TESTPOOL/$TESTCLONE cfile=/$clone/$CLONEFILE csnap=$clone@$TESTSNAP csnapfile=/$clone/.zfs/snapshot/$TESTSNAP/$TESTFILE0 # setup for promte testing log_must mkfile $FILESIZE $file0 log_must zfs snapshot $snap log_must mkfile $FILESIZE $file1 log_must rm -f $file0 log_must zfs clone $snap $clone log_must mkfile $FILESIZE $cfile log_must zfs promote $clone # verify the 'promote' operation testing_verify $fs $file1 $snapfile $clone $cfile $csnapfile log_note "Verify 'zfs promote' can change back the dependency relationship." log_must zfs promote $fs #verify the result testing_verify $clone $cfile $csnapfile $fs $file1 $snapfile log_pass "'zfs promote' reverses the clone parent-child dependency relationship"\ "as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_003_pos.ksh index e0d0e8457a26..7dedaf91bed6 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_003_pos.ksh @@ -1,134 +1,133 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs promote' can deal with multi-point snapshots. # # STRATEGY: # 1. Create multiple snapshots and a clone to a middle point snapshot # 2. Promote the clone filesystem # 3. Verify the origin filesystem and promoted filesystem include # correct datasets separated by the clone point. # verify_runnable "both" function cleanup { if snapexists ${csnap[2]}; then log_must zfs promote $fs fi typeset ds typeset data for ds in ${snap[*]}; do - snapexists $ds && \ - log_must zfs destroy -rR $ds + snapexists $ds && destroy_dataset $ds -rR done for data in ${file[*]}; do [[ -e $data ]] && rm -f $data done } log_assert "'zfs promote' can deal with multi-point snapshots." log_onexit cleanup fs=$TESTPOOL/$TESTFS clone=$TESTPOOL/$TESTCLONE # Define some arrays here to use loop to reduce code amount # Array which stores the origin snapshots created in the origin filesystem set -A snap "${fs}@$TESTSNAP" "${fs}@$TESTSNAP1" "${fs}@$TESTSNAP2" "${fs}@$TESTSNAP3" # Array which stores the snapshots existing in the clone after promote operation set -A csnap "${clone}@$TESTSNAP" "${clone}@$TESTSNAP1" "${clone}@$TESTSNAP2" \ "${clone}@$TESTSNAP3" # The data will inject into the origin filesystem set -A file "$TESTDIR/$TESTFILE0" "$TESTDIR/$TESTFILE1" "$TESTDIR/$TESTFILE2" \ "$TESTDIR/$TESTFILE3" snapdir=$TESTDIR/.zfs/snapshot # The data which will exist in the snapshot after creation of snapshot set -A snapfile "$snapdir/$TESTSNAP/$TESTFILE0" "$snapdir/$TESTSNAP1/$TESTFILE1" \ "$snapdir/$TESTSNAP2/$TESTFILE2" "$snapdir/$TESTSNAP3/$TESTFILE3" csnapdir=/$clone/.zfs/snapshot # The data which will exist in the snapshot of clone filesystem after promote set -A csnapfile "${csnapdir}/$TESTSNAP/$TESTFILE0" "${csnapdir}/$TESTSNAP1/$TESTFILE1" \ "${csnapdir}/$TESTSNAP2/$TESTFILE2" # setup for promote testing typeset -i i=0 while (( i < 4 )); do log_must mkfile $FILESIZE ${file[i]} (( i>0 )) && log_must rm -f ${file[((i-1))]} log_must zfs snapshot ${snap[i]} (( i = i + 1 )) done log_must zfs clone ${snap[2]} $clone log_must mkfile $FILESIZE /$clone/$CLONEFILE log_must rm -f /$clone/$TESTFILE2 log_must zfs snapshot ${csnap[3]} log_must zfs promote $clone # verify the 'promote' operation for ds in ${snap[3]} ${csnap[*]}; do ! snapexists $ds && \ log_fail "The snapshot $ds disappear after zfs promote." done for data in ${csnapfile[*]} $TESTDIR/$TESTFILE3 /$clone/$CLONEFILE; do [[ ! -e $data ]] && \ log_fail "The data file $data loses after zfs promote." done for ds in ${snap[0]} ${snap[1]} ${snap[2]}; do snapexists $ds && \ log_fail "zfs promote cannot promote the snapshot $ds." done for data in ${snapfile[0]} ${snapfile[1]} ${snapfile[2]}; do [[ -e $data ]] && \ log_fail "zfs promote cannot promote the data $data." done origin_prop=$(get_prop origin $fs) [[ "$origin_prop" != "${csnap[2]}" ]] && \ log_fail "The dependency is not correct for $fs after zfs promote." origin_prop=$(get_prop origin $clone) [[ "$origin_prop" != "-" ]] && \ log_fail "The dependency is not correct for $clone after zfs promote." log_pass "'zfs promote' deal with multi-point snapshots as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos.ksh index 23b5991084f8..b8a5ab9c1707 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_004_pos.ksh @@ -1,140 +1,139 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs promote' can deal with multi-level clones. # # STRATEGY: # 1. Create multiple snapshots and multi-level clones # 2. Promote a clone filesystem # 3. Verify the dataset dependency relationships are correct after promotion. # verify_runnable "both" function cleanup { if snapexists ${c1snap[1]}; then log_must zfs promote $clone fi typeset ds typeset data for ds in ${snap[*]}; do - snapexists $ds && \ - log_must zfs destroy -rR $ds + snapexists $ds && destroy_dataset $ds -rR done for data in ${file[*]}; do [[ -e $data ]] && rm -f $data done } log_assert "'zfs promote' can deal with multi-level clone." log_onexit cleanup fs=$TESTPOOL/$TESTFS clone=$TESTPOOL/$TESTCLONE clone1=$TESTPOOL/$TESTCLONE1 # Define some arrays here to use loop to reduce code amount # Array which stores the origin snapshots created in the origin filesystem set -A snap "${fs}@$TESTSNAP" "${fs}@$TESTSNAP1" "${fs}@$TESTSNAP2" "${fs}@$TESTSNAP3" # Array which stores the snapshots existing in the first clone set -A csnap "${clone}@$TESTSNAP3" "${clone}@$TESTSNAP4" "${clone}@$TESTSNAP5" # Array which stores the snapshots existing in the second clone after promote operation set -A c1snap "${clone1}@$TESTSNAP3" "${clone1}@$TESTSNAP4" "${clone1}@$TESTSNAP5" # The data will inject into the origin filesystem set -A file "$TESTDIR/$TESTFILE0" "$TESTDIR/$TESTFILE1" "$TESTDIR/$TESTFILE2" \ "$TESTDIR/$TESTFILE3" cdir=/$TESTPOOL/$TESTCLONE # The data will inject into the first clone set -A cfile "${cdir}/$CLONEFILE" "${cdir}/$CLONEFILE1" "${cdir}/$CLONEFILE2" c1snapdir=/$TESTPOOL/$TESTCLONE1/.zfs/snapshot # The data which will exist in the snapshot of the second clone filesystem after promote set -A c1snapfile "${c1snapdir}/$TESTSNAP3/$CLONEFILE" \ "${c1snapdir}/$TESTSNAP4/$CLONEFILE1" \ "${c1snapdir}/$TESTSNAP5/$CLONEFILE2" # setup for promote testing typeset -i i=0 while (( i < 4 )); do log_must mkfile $FILESIZE ${file[i]} (( i>0 )) && log_must rm -f ${file[((i-1))]} log_must zfs snapshot ${snap[i]} (( i = i + 1 )) done log_must zfs clone ${snap[2]} $clone log_must rm -f /$clone/$TESTFILE2 i=0 while (( i < 3 )); do log_must mkfile $FILESIZE ${cfile[i]} (( i>0 )) && log_must rm -f ${cfile[(( i-1 ))]} log_must zfs snapshot ${csnap[i]} (( i = i + 1 )) done log_must zfs clone ${csnap[1]} $clone1 log_must mkfile $FILESIZE /$clone1/$CLONEFILE2 log_must rm -f /$clone1/$CLONEFILE1 log_must zfs snapshot ${c1snap[2]} log_must zfs promote $clone1 # verify the 'promote' operation for ds in ${snap[*]} ${csnap[2]} ${c1snap[*]}; do ! snapexists $ds && \ log_fail "The snapshot $ds disappear after zfs promote." done for data in ${c1snapfile[*]}; do [[ ! -e $data ]] && \ log_fail "The data file $data loses after zfs promote." done origin_prop=$(get_prop origin $fs) [[ "$origin_prop" != "-" ]] && \ log_fail "The dependency is not correct for $fs after zfs promote." origin_prop=$(get_prop origin $clone) [[ "$origin_prop" != "${c1snap[1]}" ]] && \ log_fail "The dependency is not correct for $clone after zfs promote." origin_prop=$(get_prop origin $clone1) [[ "$origin_prop" != "${snap[2]}" ]] && \ log_fail "The dependency is not correct for $clone1 after zfs promote." log_pass "'zfs promote' deal with multi-level clones as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_005_pos.ksh index c669a44eb096..289ddc6713bc 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_005_pos.ksh @@ -1,73 +1,73 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # The original fs was unmounted, 'zfs promote' still should succeed. # # STRATEGY: # 1. Create pool, fs and snapshot. # 2. Create clone of fs. # 3. Unmount fs, then verify 'zfs promote' clone still succeed. # verify_runnable "both" function cleanup { if datasetexists $fssnap ; then - datasetexists $clone && log_must zfs destroy $clone - log_must zfs destroy $fssnap + datasetexists $clone && destroy_dataset $clone + destroy_dataset $fssnap fi if datasetexists $clone ; then log_must zfs promote $fs log_must zfs destroy $clone log_must zfs destroy $fssnap fi } log_assert "The original fs was unmounted, 'zfs promote' still should succeed." log_onexit cleanup fs=$TESTPOOL/$TESTFS clone=$TESTPOOL/$TESTCLONE fssnap=$fs@fssnap log_must zfs snapshot $fssnap log_must zfs clone $fssnap $clone log_must zfs unmount $fs log_must zfs promote $clone log_must zfs unmount $clone log_must zfs promote $fs log_pass "Unmount original fs, 'zfs promote' passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_006_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_006_neg.ksh index 286c14ac12d9..7f08f28a9379 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_006_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_006_neg.ksh @@ -1,90 +1,86 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs promote' will fail with invalid arguments: # (1) NULL arguments # (2) non-existent clone # (3) non-clone datasets: # pool, fs, snapshot,volume # (4) too many arguments. # (5) invalid options # (6) temporary %recv datasets # # STRATEGY: # 1. Create an array of invalid arguments # 2. For each invalid argument in the array, 'zfs promote' should fail # 3. Verify the return code from zfs promote # verify_runnable "both" snap=$TESTPOOL/$TESTFS@$TESTSNAP clone=$TESTPOOL/$TESTCLONE recvfs=$TESTPOOL/recvfs set -A args "" \ "$TESTPOOL/blah" \ "$TESTPOOL" "$TESTPOOL/$TESTFS" "$snap" \ "$TESTPOOL/$TESTVOL" "$TESTPOOL $TESTPOOL/$TESTFS" \ "$clone $TESTPOOL/$TESTFS" "- $clone" "-? $clone" \ "$recvfs/%recv" function cleanup { - if datasetexists $clone; then - log_must zfs destroy $clone - fi + datasetexists $clone && destroy_dataset $clone - if datasetexists $recvfs; then - log_must zfs destroy -r $recvfs - fi + datasetexists $recvfs && destroy_dataset $recvfs -r if snapexists $snap; then destroy_snapshot $snap fi } log_assert "'zfs promote' will fail with invalid arguments. " log_onexit cleanup create_recv_clone $recvfs typeset -i i=0 while (( i < ${#args[*]} )); do log_mustnot zfs promote ${args[i]} (( i = i + 1 )) done log_pass "'zfs promote' fails with invalid argument as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_007_neg.ksh index 3f8ee1941dde..95db7d9e6b4e 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_007_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_007_neg.ksh @@ -1,78 +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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_promote/zfs_promote.cfg . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs promote' can deal with conflicts in the namespaces. # # STRATEGY: # 1. Create a snapshot and a clone of the snapshot # 2. Create the same name snapshot for the clone # 3. Promote the clone filesystem # 4. Verify the promote operation fail due to the name conflicts. # verify_runnable "both" function cleanup { - snapexists $snap && \ - log_must zfs destroy -rR $snap + snapexists $snap && destroy_dataset $snap -rR typeset data for data in $TESTDIR/$TESTFILE0 $TESTDIR/$TESTFILE1; do [[ -e $data ]] && rm -f $data done } log_assert "'zfs promote' can deal with name conflicts." log_onexit cleanup snap=$TESTPOOL/$TESTFS@$TESTSNAP clone=$TESTPOOL/$TESTCLONE clonesnap=$TESTPOOL/$TESTCLONE@$TESTSNAP # setup for promte testing log_must mkfile $FILESIZE $TESTDIR/$TESTFILE0 log_must zfs snapshot $snap log_must mkfile $FILESIZE $TESTDIR/$TESTFILE1 log_must rm -f $TESTDIR/$TESTFILE0 log_must zfs clone $snap $clone log_must mkfile $FILESIZE /$clone/$CLONEFILE log_must zfs snapshot $clonesnap log_mustnot zfs promote $clone log_pass "'zfs promote' deals with name conflicts as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_encryptionroot.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_encryptionroot.ksh index 2c7584d3541d..fd6ed7e58e3a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_encryptionroot.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_promote/zfs_promote_encryptionroot.ksh @@ -1,93 +1,93 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # ZFS must promote clones of an encryption root. # # STRATEGY: # 1. Create an encrypted dataset # 2. Clone the encryption root # 3. Clone the clone # 4. Add children to each of these three datasets # 4. Verify the encryption root of all datasets is the origin # 5. Promote the clone of the clone # 6. Verify the encryption root of all datasets is still the origin # 7. Promote the dataset again, so it is now the encryption root # 8. Verify the encryption root of all datasets is the promoted dataset # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -Rf $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -Rf datasetexists $TESTPOOL/clone1 && \ - log_must zfs destroy -Rf $TESTPOOL/clone1 + destroy_dataset $TESTPOOL/clone1 -Rf datasetexists $TESTPOOL/clone2 && \ - log_must zfs destroy -Rf $TESTPOOL/clone2 + destroy_dataset $TESTPOOL/clone2 -Rf } log_onexit cleanup log_assert "ZFS must promote clones of an encryption root" passphrase="password" snaproot="$TESTPOOL/$TESTFS1@snap1" snapclone="$TESTPOOL/clone1@snap2" log_must eval "echo $passphrase | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1" log_must zfs snap $snaproot log_must zfs clone $snaproot $TESTPOOL/clone1 log_must zfs snap $snapclone log_must zfs clone $snapclone $TESTPOOL/clone2 log_must zfs create $TESTPOOL/$TESTFS1/child0 log_must zfs create $TESTPOOL/clone1/child1 log_must zfs create $TESTPOOL/clone2/child2 log_must verify_encryption_root $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/clone1 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/clone2 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/$TESTFS1/child0 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/clone1/child1 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/clone2/child2 $TESTPOOL/$TESTFS1 log_must zfs promote $TESTPOOL/clone2 log_must verify_encryption_root $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/clone1 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/clone2 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/$TESTFS1/child0 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/clone1/child1 $TESTPOOL/$TESTFS1 log_must verify_encryption_root $TESTPOOL/clone2/child2 $TESTPOOL/$TESTFS1 log_must zfs promote $TESTPOOL/clone2 log_must verify_encryption_root $TESTPOOL/$TESTFS1 $TESTPOOL/clone2 log_must verify_encryption_root $TESTPOOL/clone1 $TESTPOOL/clone2 log_must verify_encryption_root $TESTPOOL/clone2 $TESTPOOL/clone2 log_must verify_encryption_root $TESTPOOL/$TESTFS1/child0 $TESTPOOL/clone2 log_must verify_encryption_root $TESTPOOL/clone1/child1 $TESTPOOL/clone2 log_must verify_encryption_root $TESTPOOL/clone2/child2 $TESTPOOL/clone2 log_pass "ZFS promotes clones of an encryption root" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_property/zfs_written_property_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_property/zfs_written_property_001_pos.ksh index cbbacace1ec6..f31ff48099e9 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_property/zfs_written_property_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_property/zfs_written_property_001_pos.ksh @@ -1,230 +1,230 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2017 by Delphix. All rights reserved. # # # DESCRIPTION # Verify that "zfs list" gives correct values for written and written@ # properties for the dataset when different operations are on done on it # # # STRATEGY # 1) Create recursive datasets # 2) Take snapshots, write data and verify written/ written@ properties for # following cases # a) Delete data # b) Write Data # c) Clone # d) Delete snapshot # e) Recursive datasets . $STF_SUITE/include/libtest.shlib . $STF_SUITE/include/math.shlib function cleanup { for ds in $datasets; do - datasetexists $ds && log_must zfs destroy -R $TESTPOOL/$TESTFS1 + datasetexists $ds && destroy_dataset $TESTPOOL/$TESTFS1 -R done } function get_prop_mb { typeset prop=$1 typeset dataset=$2 typeset -l value=$(get_prop $prop $dataset) ((value = value / mb_block)) echo $value } datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS1/$TESTFS2 \ $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3" log_assert "verify zfs written and written@ property" log_onexit cleanup typeset -l i=1 typeset -l blocks=50 typeset -l expected_written=0 typeset -l expected_writtenat=0 typeset -l written=0 typeset -l total=0 typeset -l snap1_size=0 typeset -l snap2_size=0 typeset -l snap3_size=0 typeset -l mb_block=0 ((mb_block = 1024 * 1024)) log_note "verify written property statistics for dataset" log_must zfs create -p $TESTPOOL/$TESTFS1/$TESTFS2/$TESTFS3 for i in 1 2 3; do log_must zfs snapshot $TESTPOOL/$TESTFS1@snap$i log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS1/testfile.$i bs=1M \ count=$blocks sync_pool written=$(get_prop written $TESTPOOL/$TESTFS1) ((expected_written=blocks * mb_block)) within_percent $written $expected_written 99.5 || \ log_fail "Unexpected written value $written $expected_written" ((total = total + blocks)) ((blocks = blocks + 50)) done log_note "verify written property statistics for snapshots" blocks=0 for i in 1 2 3; do written=$(get_prop written $TESTPOOL/$TESTFS1@snap$i) if [[ $blocks -eq 0 ]]; then # Written value for the first non-clone snapshot is # expected to be equal to the referenced value. expected_written=$( \ get_prop referenced $TESTPOOL/$TESTFS1@snap$i) else ((expected_written = blocks * mb_block)) fi within_percent $written $expected_written 99.5 || \ log_fail "Unexpected written value $written $expected_written $i" ((blocks = blocks + 50)) done snap1_size=$total ((snap2_size = total-50)) ((snap3_size = total-100)) log_note "verify written@ for the same dataset" blocks=50 for i in 1 2 3; do writtenat=$(get_prop written@snap$i $TESTPOOL/$TESTFS1) ((expected_writtenat = total * mb_block)) within_percent $writtenat $expected_writtenat 99.5 || \ log_fail "Unexpected written@ value" ((total = total - blocks)) ((blocks = blocks + 50)) done log_note "delete data" before_written=$(get_prop written $TESTPOOL/$TESTFS1) log_must rm /$TESTPOOL/$TESTFS1/testfile.3 snap3_size=0 sync_pool written=$(get_prop written $TESTPOOL/$TESTFS1) writtenat3=$(get_prop written@snap3 $TESTPOOL/$TESTFS1) [[ $written -eq $writtenat3 ]] || \ log_fail "Written and written@ don't match $written $writtenat3" within_percent $written $before_written 0.1 && \ log_fail "Unexpected written value after delete $written $before_written" writtenat=$(get_prop written@snap1 $TESTPOOL/$TESTFS1) ((snap1_size = snap1_size - 150)) ((expected_writtenat = snap1_size * mb_block)) within_percent $writtenat $expected_writtenat 99.5 || \ log_fail "Unexpected written value after delete $writtenat $expected_writtenat" writtenat=$(get_prop written@snap2 $TESTPOOL/$TESTFS1) ((snap2_size = snap2_size - 150)) ((expected_writtenat = snap2_size * mb_block)) within_percent $writtenat $expected_writtenat 99.5 || \ log_fail "Unexpected written value after delete" log_note "write data" blocks=20 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS1/testfile.3 bs=1M \ count=$blocks sync_pool written=$(get_prop written $TESTPOOL/$TESTFS1) writtenat1=$(get_prop written@snap1 $TESTPOOL/$TESTFS1) writtenat2=$(get_prop written@snap2 $TESTPOOL/$TESTFS1) writtenat3=$(get_prop written@snap3 $TESTPOOL/$TESTFS1) ((snap3_size = snap3_size + blocks)) ((expected_writtenat = snap3_size * mb_block)) [[ $written -eq $writtenat3 ]] || \ log_fail "Unexpected_written value" within_percent $writtenat3 $expected_writtenat 99.5 || \ log_fail "Unexpected_written@ value for snap3" ((snap2_size = snap2_size + blocks)) ((expected_writtenat = snap2_size * mb_block)) within_percent $writtenat2 $expected_writtenat 99.5 || \ log_fail "Unexpected_written@ value for snap2" ((snap1_size = snap1_size + blocks)) ((expected_writtenat = snap1_size * mb_block)) within_percent $writtenat1 $expected_writtenat 99.5 || \ log_fail "Unexpected_written@ value for snap1" log_note "write data to a clone" before_clone=$(get_prop written $TESTPOOL/$TESTFS1) log_must zfs clone $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS1/snap1.clone log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS1/snap1.clone/testfile bs=1M \ count=40 after_clone=$(get_prop written $TESTPOOL/$TESTFS1) within_percent $before_clone $after_clone 99.5 || \ log_fail "unexpected written for clone $before_clone $after_clone" log_note "deleted snapshot" typeset -l before_written1=$(get_prop_mb written@snap1 $TESTPOOL/$TESTFS1) typeset -l before_written3=$(get_prop_mb written@snap3 $TESTPOOL/$TESTFS1) typeset -l snap_before_written2=$(get_prop_mb written $TESTPOOL/$TESTFS1@snap2) typeset -l snap_before_written3=$(get_prop_mb written $TESTPOOL/$TESTFS1@snap3) log_must zfs destroy $TESTPOOL/$TESTFS1@snap2 log_mustnot snapexists $TESTPOOL/$TESTFS1@snap2 sync_pool written1=$(get_prop_mb written@snap1 $TESTPOOL/$TESTFS1) written3=$(get_prop_mb written@snap3 $TESTPOOL/$TESTFS1) [[ $before_written1 -eq $written1 && $before_written3 -eq $written3 ]] || \ log_fail "unexpected written values $before_written1 $written1" typeset -l expected_written3 ((expected_written3 = snap_before_written2 + snap_before_written3)) prev_written=$(get_prop_mb written $TESTPOOL/$TESTFS1@snap3) within_percent $prev_written $expected_written3 99.5 || \ log_fail "unexpected written value $prev_written $expected_written3" log_must zfs destroy $TESTPOOL/$TESTFS1@snap3 log_mustnot snapexists $TESTPOOL/$TESTFS1@snap3 written=$(get_prop written $TESTPOOL/$TESTFS1) writtenat1=$(get_prop written@snap1 $TESTPOOL/$TESTFS1) [[ $written -ne $writtenat1 ]] && \ log_fail "Unexpected last snapshot written value" log_note "verify written@ property for recursive datasets" blocks=10 log_must zfs snapshot -r $TESTPOOL/$TESTFS1@now for ds in $datasets; do writtenat=$(get_prop written@now $ds) [[ $writtenat -ne 0 ]] && \ log_fail "Unexpected written@ value" log_must dd if=/dev/urandom of=/$ds/testfile bs=1M count=$blocks sync_pool writtenat=$(get_prop written@now $ds) ((expected_writtenat = blocks * mb_block)) within_percent $writtenat $expected_writtenat 0.1 || \ log_fail "Unexpected written value" ((blocks = blocks + 10)) done log_note "verify written@ output for recursive datasets" blocks=20 for ds in $datasets; do log_must zfs snapshot $ds@current log_must dd if=/dev/urandom of=/$ds/testfile bs=1M \ count=$blocks sync_pool done recursive_output=$(zfs get -p -r written@current $TESTPOOL | \ grep -v $TESTFS1@ | grep -v $TESTFS2@ | grep -v $TESTFS3@ | \ grep -v "VALUE" | grep -v "-") expected="$((20 * mb_block))" for ds in $datasets; do writtenat=$(echo "$recursive_output" | grep -v $ds/) writtenat=$(echo "$writtenat" | grep $ds | awk '{print $3}') within_percent $writtenat $expected 99.5 || \ log_fail "Unexpected written@ value on $ds" done log_pass "zfs written and written@ property fields print correct values" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_001_pos.ksh index f8439dcbbebd..8a6cd8c409be 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_001_pos.ksh @@ -1,176 +1,173 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib # # DESCRIPTION: # Verifying 'zfs receive [] -d ' works. # # STRATEGY: # 1. Fill in fs with some data # 2. Create full and incremental send stream # 3. Receive the send stream # 4. Verify the restoring results. # verify_runnable "both" function cleanup { typeset -i i=0 - datasetexists $rst_root && \ - log_must zfs destroy -Rf $rst_root + datasetexists $rst_root && destroy_dataset $rst_root -Rf while (( i < 2 )); do - snapexists ${orig_snap[$i]} && \ - log_must zfs destroy -f ${orig_snap[$i]} + snapexists ${orig_snap[$i]} && destroy_dataset ${orig_snap[$i]} -f log_must rm -f ${bkup[$i]} (( i = i + 1 )) done log_must rm -rf $TESTDIR1 } function recreate_root { - datasetexists $rst_root && \ - log_must zfs destroy -Rf $rst_root + datasetexists $rst_root && destroy_dataset $rst_root -Rf if [[ -d $TESTDIR1 ]] ; then log_must rm -rf $TESTDIR1 fi log_must zfs create $rst_root log_must zfs set mountpoint=$TESTDIR1 $rst_root } log_assert "Verifying 'zfs receive [] -d ' works." log_onexit cleanup typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL" set -A bkup "$TEST_BASE_DIR/fullbkup" "$TEST_BASE_DIR/incbkup" orig_sum="" rst_sum="" rst_root=$TESTPOOL/rst_ctr rst_fs=${rst_root}/$TESTFS for orig_fs in $datasets ; do # # Preparations for testing # recreate_root set -A orig_snap "${orig_fs}@init_snap" "${orig_fs}@inc_snap" typeset mntpnt=$(get_prop mountpoint ${orig_fs}) set -A orig_data "${mntpnt}/$TESTFILE1" "${mntpnt}/$TESTFILE2" typeset relative_path="" if [[ ${orig_fs} == *"/"* ]]; then relative_path=${orig_fs#*/} fi typeset leaf_fs=${rst_root}/${relative_path} leaf_fs=${leaf_fs%/} rst_snap=${leaf_fs}@snap set -A rst_snap "$rst_root/$TESTFS@init_snap" "$rst_root/$TESTFS@inc_snap" set -A rst_snap2 "${leaf_fs}@init_snap" "${leaf_fs}@inc_snap" set -A rst_data "$TESTDIR1/$TESTFS/$TESTFILE1" "$TESTDIR1/$TESTFS/$TESTFILE2" set -A rst_data2 "$TESTDIR1/${relative_path}/$TESTFILE1" "$TESTDIR1/${relative_path}/$TESTFILE2" typeset -i i=0 while (( i < ${#orig_snap[*]} )); do file_write -o create -f ${orig_data[$i]} -b 512 \ -c 8 >/dev/null 2>&1 (( $? != 0 )) && \ log_fail "Writing data into zfs filesystem fails." log_must zfs snapshot ${orig_snap[$i]} if (( i < 1 )); then log_must eval "zfs send ${orig_snap[$i]} > ${bkup[$i]}" else log_must eval "zfs send -i ${orig_snap[(( i - 1 ))]} \ ${orig_snap[$i]} > ${bkup[$i]}" fi (( i = i + 1 )) done log_note "Verifying 'zfs receive ' works." i=0 while (( i < ${#bkup[*]} )); do if (( i > 0 )); then log_must zfs rollback ${rst_snap[0]} fi log_must eval "zfs receive $rst_fs < ${bkup[$i]}" snapexists ${rst_snap[$i]} || \ log_fail "Restoring filesystem fails. ${rst_snap[$i]} not exist" compare_cksum ${orig_data[$i]} ${rst_data[$i]} (( i = i + 1 )) done log_must zfs destroy -Rf $rst_fs log_note "Verifying 'zfs receive ' works." i=0 while (( i < ${#bkup[*]} )); do if (( i > 0 )); then log_must zfs rollback ${rst_snap[0]} fi log_must eval "zfs receive ${rst_snap[$i]} <${bkup[$i]}" snapexists ${rst_snap[$i]} || \ log_fail "Restoring filesystem fails. ${rst_snap[$i]} not exist" compare_cksum ${orig_data[$i]} ${rst_data[$i]} (( i = i + 1 )) done log_must zfs destroy -Rf $rst_fs log_note "Verifying 'zfs receive -d ' works." i=0 while (( i < ${#bkup[*]} )); do if (( i > 0 )); then log_must zfs rollback ${rst_snap2[0]} fi log_must eval "zfs receive -d -F $rst_root <${bkup[$i]}" snapexists ${rst_snap2[$i]} || \ log_fail "Restoring filesystem fails. ${rst_snap2[$i]} not exist" compare_cksum ${orig_data[$i]} ${rst_data2[$i]} (( i = i + 1 )) done cleanup done log_pass "Verifying 'zfs receive [] -d ' succeeds." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_002_pos.ksh index 36af37a7576d..ba3fc49bd84c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_002_pos.ksh @@ -1,108 +1,105 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib # # DESCRIPTION: # Verifying 'zfs receive ' works. # # STRATEGY: # 1. Fill in volume with some data # 2. Create full and incremental send stream # 3. Restore the send stream # 4. Verify the restoring results. # verify_runnable "global" function cleanup { typeset -i i=0 typeset ds while (( i < ${#orig_snap[*]} )); do - snapexists ${rst_snap[$i]} && \ - log_must zfs destroy -f ${rst_snap[$i]} - snapexists ${orig_snap[$i]} && \ - log_must zfs destroy -f ${orig_snap[$i]} + snapexists ${rst_snap[$i]} && destroy_dataset ${rst_snap[$i]} -f + snapexists ${orig_snap[$i]} && destroy_dataset ${orig_snap[$i]} -f [[ -e ${bkup[$i]} ]] && \ log_must rm -rf ${bkup[$i]} (( i = i + 1 )) done for ds in $rst_vol $rst_root; do - datasetexists $ds && \ - log_must zfs destroy -Rf $ds + datasetexists $ds && destroy_dataset $ds -Rf done } log_assert "Verifying 'zfs receive ' works." log_onexit cleanup set -A orig_snap "$TESTPOOL/$TESTVOL@init_snap" "$TESTPOOL/$TESTVOL@inc_snap" set -A bkup "$TEST_BASE_DIR/fullbkup" "$TEST_BASE_DIR/incbkup" rst_root=$TESTPOOL/rst_ctr rst_vol=$rst_root/$TESTVOL set -A rst_snap "${rst_vol}@init_snap" "${rst_vol}@inc_snap" # # Preparations for testing # log_must zfs create $rst_root [[ ! -d $TESTDIR1 ]] && \ log_must mkdir -p $TESTDIR1 log_must zfs set mountpoint=$TESTDIR1 $rst_root typeset -i i=0 while (( i < ${#orig_snap[*]} )); do log_must zfs snapshot ${orig_snap[$i]} if (( i < 1 )); then log_must eval "zfs send ${orig_snap[$i]} > ${bkup[$i]}" else log_must eval "zfs send -i ${orig_snap[(( i - 1 ))]} \ ${orig_snap[$i]} > ${bkup[$i]}" fi (( i = i + 1 )) done i=0 while (( i < ${#bkup[*]} )); do log_must eval "zfs receive $rst_vol < ${bkup[$i]}" ! datasetexists $rst_vol || ! snapexists ${rst_snap[$i]} && \ log_fail "Restoring volume fails." (( i = i + 1 )) done log_pass "Verifying 'zfs receive ' succeeds." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_003_pos.ksh index d5f6e0984df5..cce387615315 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_003_pos.ksh @@ -1,93 +1,93 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs recv -F' to force rollback. # # STRATEGY: # 1. Create pool and fs. # 2. Create some files in fs and take a snapshot1. # 3. Create another files in fs and take snapshot2. # 4. Create incremental stream from snapshot1 to snapshot2. # 5. fs rollback to snapshot1 and modify fs. # 6. Verify 'zfs recv -F' can force rollback. # verify_runnable "both" function cleanup { for snap in $snap2 $snap1; do - datasetexists $snap && log_must zfs destroy -rf $snap + datasetexists $snap && destroy_dataset $snap -rf done for file in $ibackup $mntpnt/file1 $mntpnt/file2; do [[ -f $file ]] && log_must rm -f $file done } log_assert "'zfs recv -F' to force rollback." log_onexit cleanup ibackup=$TEST_BASE_DIR/ibackup.$$ fs=$TESTPOOL/$TESTFS; snap1=$fs@snap1; snap2=$fs@snap2 mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs" log_must mkfile 10m $mntpnt/file1 log_must zfs snapshot $snap1 log_must mkfile 10m $mntpnt/file2 log_must zfs snapshot $snap2 log_must eval "zfs send -i $snap1 $snap2 > $ibackup" log_note "Verify 'zfs receive' succeed, if filesystem was not modified." log_must zfs rollback -r $snap1 log_must eval "zfs receive $fs < $ibackup" if [[ ! -f $mntpnt/file1 || ! -f $mntpnt/file2 ]]; then log_fail "'zfs receive' failed." fi log_note "Verify 'zfs receive' failed if filesystem was modified." log_must zfs rollback -r $snap1 log_must rm -rf $mntpnt/file1 log_mustnot eval "zfs receive $fs < $ibackup" # Verify 'zfs receive -F' to force rollback whatever filesystem was modified. log_must zfs rollback -r $snap1 log_must rm -rf $mntpnt/file1 log_must eval "zfs receive -F $fs < $ibackup" if [[ ! -f $mntpnt/file1 || ! -f $mntpnt/file2 ]]; then log_fail "'zfs receive -F' failed." fi log_pass "'zfs recv -F' to force rollback passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_004_neg.ksh index 56f536225d74..7c115ee33b96 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_004_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_004_neg.ksh @@ -1,110 +1,109 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib # # DESCRIPTION: # Verify 'zfs receive' fails with malformed parameters. # # STRATEGY: # 1. Define malformed parameters array # 2. Feed the malformed parameters to 'zfs receive' # 3. Verify the command should be failed # verify_runnable "both" function cleanup { typeset snap typeset bkup for snap in $init_snap $inc_snap $init_topsnap $inc_topsnap ; do - snapexists $snap && \ - log_must zfs destroy -Rf $snap + snapexists $snap && destroy_dataset $snap -Rf done for bkup in $full_bkup $inc_bkup $full_topbkup $inc_topbkup; do [[ -e $bkup ]] && \ log_must rm -f $bkup done } log_assert "Verify that invalid parameters to 'zfs receive' are caught." log_onexit cleanup init_snap=$TESTPOOL/$TESTFS@initsnap inc_snap=$TESTPOOL/$TESTFS@incsnap full_bkup=$TEST_BASE_DIR/full_bkup.$$ inc_bkup=$TEST_BASE_DIR/inc_bkup.$$ init_topsnap=$TESTPOOL@initsnap inc_topsnap=$TESTPOOL@incsnap full_topbkup=$TEST_BASE_DIR/full_topbkup.$$ inc_topbkup=$TEST_BASE_DIR/inc_topbkup.$$ log_must zfs snapshot $init_topsnap log_must eval "zfs send $init_topsnap > $full_topbkup" log_must touch /$TESTPOOL/foo log_must zfs snapshot $inc_topsnap log_must eval "zfs send -i $init_topsnap $inc_topsnap > $inc_topbkup" log_must touch /$TESTPOOL/bar log_must zfs snapshot $init_snap log_must eval "zfs send $init_snap > $full_bkup" log_must touch /$TESTDIR/foo log_must zfs snapshot $inc_snap log_must eval "zfs send -i $init_snap $inc_snap > $inc_bkup" log_must touch /$TESTDIR/bar sync set -A badargs \ "" "nonexistent-snap" "blah@blah" "-d" "-d nonexistent-dataset" \ "$TESTPOOL1" "$TESTPOOL/fs@" "$TESTPOOL/fs@@mysnap" \ "$TESTPOOL/fs@@" "$TESTPOOL/fs/@mysnap" "$TESTPOOL/fs@/mysnap" \ "$TESTPOOL/nonexistent-fs/nonexistent-fs" "-d $TESTPOOL/nonexistent-fs" \ "-d $TESTPOOL/$TESTFS/nonexistent-fs" typeset -i i=0 while (( i < ${#badargs[*]} )) do for bkup in $full_bkup $inc_bkup $full_topbkup $inc_topbkup ; do log_mustnot eval "zfs receive ${badargs[i]} < $bkup" done (( i = i + 1 )) done log_pass "Invalid parameters to 'zfs receive' are caught as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh index ce89c6835775..d8c71f2c2877 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_005_neg.ksh @@ -1,99 +1,97 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib # # DESCRIPTION: # Verify 'zfs receive' fails with unsupported scenarios. # including: # (1) Invalid send streams; # (2) The received incremental send doesn't match the filesystem # latest status. # # STRATEGY: # 1. Preparation for unsupported scenarios # 2. Execute 'zfs receive' # 3. Verify the results are failed # verify_runnable "both" function cleanup { typeset snap typeset bkup for snap in $init_snap $inc_snap; do - snapexists $snap && \ - log_must zfs destroy -f $snap + snapexists $snap && destroy_dataset $snap -f done - datasetexists $rst_root && \ - log_must zfs destroy -Rf $rst_root + datasetexists $rst_root && destroy_dataset $rst_root -Rf for bkup in $full_bkup $inc_bkup; do [[ -e $bkup ]] && \ log_must rm -f $bkup done } log_assert "Verify 'zfs receive' fails with unsupported scenarios." log_onexit cleanup init_snap=$TESTPOOL/$TESTFS@initsnap inc_snap=$TESTPOOL/$TESTFS@incsnap rst_root=$TESTPOOL/rst_ctr rst_init_snap=$rst_root/$TESTFS@init_snap rst_inc_snap=$rst_root/$TESTFS@inc_snap full_bkup=$TEST_BASE_DIR/full_bkup.$$ inc_bkup=$TEST_BASE_DIR/inc_bkup.$$ log_must zfs create $rst_root log_must zfs snapshot $init_snap log_must eval "zfs send $init_snap > $full_bkup" log_note "'zfs receive' fails with invalid send streams." log_mustnot eval "cat $inc_bkup" #make changes on the restoring filesystem log_must touch $ZFSROOT/$rst_root/$TESTFS/tmpfile log_mustnot eval "zfs receive $rst_inc_snap < $inc_bkup" log_mustnot eval "zfs receive -d $rst_root < $inc_bkup" log_pass "Unsupported scenarios to 'zfs receive' fail as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos.ksh index 7338fd2b9fb2..79f34bd3ff8c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos.ksh @@ -1,108 +1,108 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs recv -d ' should create ancestor filesystem if it does not # exist and it should not fail if it exists # # STRATEGY: # 1. Create pool and fs. # 2. Create some files in fs and take snapshots. # 3. Keep the stream and restore the stream to the pool # 4. Verify receiving the stream succeeds, and the ancestor filesystem # is created if it did not exist # 5. Verify receiving the stream still succeeds when ancestor filesystem # exists # verify_runnable "both" function cleanup { for snap in $snap2 $snap1; do - datasetexists $snap && log_must zfs destroy -rf $snap + datasetexists $snap && destroy_dataset $snap -rf done for file in $fbackup1 $fbackup2 $mntpnt/file1 $mntpnt/file2; do [[ -f $file ]] && log_must rm -f $file done if is_global_zone; then datasetexists $TESTPOOL/$TESTFS/$TESTFS1 && \ - log_must zfs destroy -rf $TESTPOOL/$TESTFS/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS/$TESTFS1 -rf else datasetexists $TESTPOOL/${ZONE_CTR}0 && \ - log_must zfs destroy -rf $TESTPOOL/${ZONE_CTR}0 + destroy_dataset $TESTPOOL/${ZONE_CTR}0 -rf fi } log_assert "'zfs recv -d ' should succeed no matter ancestor filesystem \ exists." log_onexit cleanup ancestor_fs=$TESTPOOL/$TESTFS fs=$TESTPOOL/$TESTFS/$TESTFS1 snap1=$fs@snap1 snap2=$fs@snap2 fbackup1=$TEST_BASE_DIR/fbackup1.$$ fbackup2=$TEST_BASE_DIR/fbackup2.$$ datasetexists $ancestor_fs || \ log_must zfs create $ancestor_fs log_must zfs create $fs mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs" log_must mkfile 10m $mntpnt/file1 log_must zfs snapshot $snap1 log_must mkfile 10m $mntpnt/file2 log_must zfs snapshot $snap2 log_must eval "zfs send $snap1 > $fbackup1" log_must eval "zfs send $snap2 > $fbackup2" log_note "Verify 'zfs receive -d' succeed and create ancestor filesystem \ if it did not exist. " log_must zfs destroy -rf $ancestor_fs log_must eval "zfs receive -d $TESTPOOL < $fbackup1" is_global_zone || ancestor_fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS datasetexists $ancestor_fs || \ log_fail "ancestor filesystem is not created" log_note "Verify 'zfs receive -d' still succeed if ancestor filesystem exists" is_global_zone || fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS/$TESTFS1 log_must zfs destroy -rf $fs log_must eval "zfs receive -d $TESTPOOL < $fbackup2" log_pass "'zfs recv -d ' should succeed no matter ancestor filesystem \ exists." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_007_neg.ksh index 57454dcbc6f2..fbf0654e4f23 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_007_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_007_neg.ksh @@ -1,84 +1,84 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs recv -F' should fail if the incremental stream does not match # # STRATEGY: # 1. Create pool and fs. # 2. Create some files in fs and take snapshots. # 3. Keep the incremental stream and restore the stream to the pool # 4. Verify receiving the stream fails # verify_runnable "both" function cleanup { for snap in $snap2 $snap1; do - datasetexists $snap && log_must zfs destroy -rf $snap + datasetexists $snap && destroy_dataset $snap -rf done for file in $ibackup $mntpnt/file1 $mntpnt/file2; do [[ -f $file ]] && log_must rm -f $file done } log_assert "'zfs recv -F' should fail if the incremental stream does not match" log_onexit cleanup fs=$TESTPOOL/$TESTFS snap1=$fs@snap1 snap2=$fs@snap2 ibackup=$TEST_BASE_DIR/ibackup.$$ datasetexists $fs || log_must zfs create $fs mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs" log_must mkfile 10m $mntpnt/file1 log_must zfs snapshot $snap1 log_must mkfile 10m $mntpnt/file2 log_must zfs snapshot $snap2 log_must eval "zfs send -i $snap1 $snap2 > $ibackup" log_must zfs destroy $snap1 log_must zfs destroy $snap2 log_mustnot eval "zfs receive -F $fs < $ibackup" log_must mkfile 20m $mntpnt/file1 log_must rm -rf $mntpnt/file2 log_must zfs snapshot $snap1 log_mustnot eval "zfs receive -F $snap2 < $ibackup" log_pass "'zfs recv -F' should fail if the incremental stream does not match" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh index 1729b59b2bfd..dc4892b5d50e 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_008_pos.ksh @@ -1,148 +1,144 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib # # DESCRIPTION: # Verifying 'zfs receive -vn [] # and zfs receive -vn -d ' # # STRATEGY: # 1. Fill in fs with some data # 2. Create full and incremental send stream # 3. run zfs receive with -v option # 3. Dryrun zfs receive with -vn option # 3. Dryrun zfs receive with -vn -d option # 4. Verify receive output and result # function cleanup { for dset in $rst_snap $rst_fs $orig_snap; do - if datasetexists $dset; then - log_must zfs destroy -fr $dset - fi + datasetexists $dset && destroy_dataset $dset -fr done for file in $fbackup $mnt_file $tmp_out; do if [[ -f $file ]]; then log_must rm -f $file fi done if datasetexists $TESTPOOL/$TESTFS; then - log_must zfs destroy -Rf $TESTPOOL/$TESTFS + destroy_dataset $TESTPOOL/$TESTFS -Rf log_must zfs create $TESTPOOL/$TESTFS log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS fi } verify_runnable "both" log_assert "Verifying 'zfs receive -vn [] " \ "and zfs receive -vn -d '" log_onexit cleanup typeset datasets="$TESTPOOL/$TESTFS $TESTPOOL" typeset rst_fs=$TESTPOOL/$TESTFS/$TESTFS typeset fbackup=$TEST_BASE_DIR/fbackup.$$ typeset tmp_out=$TEST_BASE_DIR/tmpout.$$ for orig_fs in $datasets ; do typeset rst_snap=$rst_fs@snap typeset orig_snap=$orig_fs@snap typeset verb_msg="receiving full stream of ${orig_snap} into ${rst_snap}" typeset dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" if ! datasetexists $orig_fs; then log_must zfs create $orig_fs fi typeset mntpnt mntpnt=$(get_prop mountpoint $orig_fs) if [[ $? -ne 0 ]] ; then log_fail "get_prop mountpoint $orig_fs failed" fi typeset mnt_file=$mntpnt/file1 log_must mkfile 100m $mnt_file log_must zfs snapshot $orig_snap log_must eval "zfs send $orig_snap > $fbackup" for opt in "-v" "-vn"; do - if datasetexists $rst_fs; then - log_must zfs destroy -fr $rst_fs - fi + datasetexists $rst_fs && destroy_dataset $rst_fs -fr log_note "Check ZFS receive $opt []" log_must eval "zfs receive $opt $rst_fs < $fbackup > $tmp_out 2>&1" if [[ $opt == "-v" ]]; then log_must eval "grep \"$verb_msg\" $tmp_out >/dev/null 2>&1" if ! datasetexists $rst_snap; then log_fail "dataset was not received, even though the"\ " -v flag was used." fi else log_must eval "grep \"$dryrun_msg\" $tmp_out >/dev/null 2>&1" if datasetexists $rst_snap; then log_fail "dataset was received, even though the -nv"\ " flag was used." fi fi done log_note "Check ZFS receive -vn -d " if ! datasetexists $rst_fs; then log_must zfs create $rst_fs fi log_must eval "zfs receive -vn -d -F $rst_fs <$fbackup >$tmp_out 2>&1" typeset relative_path="" if [[ ${orig_fs} == *"/"* ]]; then relative_path=${orig_fs#*/} fi typeset leaf_fs=${rst_fs}/${relative_path} leaf_fs=${leaf_fs%/} rst_snap=${leaf_fs}@snap dryrun_msg="would receive full stream of ${orig_snap} into ${rst_snap}" log_must eval "grep \"$dryrun_msg\" $tmp_out > /dev/null 2>&1" if datasetexists $rst_snap; then log_fail "dataset $rst_snap should not existed." fi log_must zfs destroy -Rf $rst_fs cleanup done log_pass "zfs receive -vn [] and " \ "zfs receive -vn -d ' succeed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg.ksh index d028acafada0..37fe515e23f7 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_009_neg.ksh @@ -1,118 +1,115 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib # # DESCRIPTION: # Verify 'zfs receive' fails with bad options, missing argument or too many # arguments. # # STRATEGY: # 1. Set a array of illegal arguments # 2. Execute 'zfs receive' with illegal arguments # 3. Verify the command should be failed # verify_runnable "both" function cleanup { typeset ds - if snapexists $snap; then - log_must zfs destroy $snap - fi + snapexists $snap && destroy_dataset $snap + for ds in $ctr1 $ctr2 $fs1; do - if datasetexists $ds; then - log_must zfs destroy -rf $ds - fi + datasetexists $ds && destroy_dataset $ds -rf done if [[ -d $TESTDIR2 ]]; then rm -rf $TESTDIR2 fi } log_assert "Verify 'zfs receive' fails with bad option, missing or too many arguments" log_onexit cleanup set -A badopts "v" "n" "F" "d" "-V" "-N" "-f" "-D" "-VNfD" "-vNFd" "-vnFD" "-dVnF" \ "-vvvNfd" "-blah" "-12345" "-?" "-*" "-%" set -A validopts "" "-v" "-n" "-F" "-vn" "-nF" "-vnF" "-vd" "-nd" "-Fd" "-vnFd" ctr1=$TESTPOOL/$TESTCTR1 ctr2=$TESTPOOL/$TESTCTR2 fs1=$TESTPOOL/$TESTFS1 fs2=$TESTPOOL/$TESTFS2 fs3=$TESTPOOL/$TESTFS3 snap=$TESTPOOL/$TESTFS@$TESTSNAP bkup=$TESTDIR2/bkup.$$ # Preparations for negative testing for ctr in $ctr1 $ctr2; do log_must zfs create $ctr done if [[ -d $TESTDIR2 ]]; then rm -rf $TESTDIR2 fi log_must zfs create -o mountpoint=$TESTDIR2 $fs1 log_must zfs snapshot $snap log_must eval "zfs send $snap > $bkup" #Testing zfs receive fails with input from terminal log_mustnot eval "zfs recv $fs3 /dev/null 2>&1 if (( $? != 0 )); then log_mustnot eval "zfs recv ${validopts[i]} $fs2 $fs3 < $bkup" else log_mustnot eval "zfs recv ${validopts[i]} $ctr1 $ctr2 < $bkup" fi (( i += 1 )) done # Testing with bad options i=0 while (( i < ${#badopts[*]} )) do log_mustnot eval "zfs recv ${badopts[i]} $ctr1 < $bkup" log_mustnot eval "zfs recv ${badopts[i]} $fs2 < $bkup" (( i = i + 1 )) done log_pass "'zfs receive' as expected with bad options, missing or too many arguments." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_013_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_013_pos.ksh index be8f49809d47..e1e93e9d2a3b 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_013_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_013_pos.ksh @@ -1,75 +1,75 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2015, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib # # DESCRIPTION: # Verifying 'zfs receive' works correctly on deduplicated streams # # STRATEGY: # 1. Create some snapshots with duplicated data # 2. Send a deduplicated stream of the last snapshot # 3. Attempt to receive the deduplicated stream # src_fs=$TESTPOOL/drecvsrc temppool=recvtank dst_fs=$temppool/drecvdest streamfile=$TEST_BASE_DIR/drecvstream.$$ tpoolfile=$TEST_BASE_DIR/temptank.$$ function cleanup { for fs in $src_fs $dst_fs; do - datasetexists $fs && log_must zfs destroy -rf $fs + datasetexists $fs && log_must destroy_dataset $fs -rf done zpool destroy $temppool [[ -f $streamfile ]] && log_must rm -f $streamfile [[ -f $tpoolfile ]] && log_must rm -f $tpoolfile } log_assert "Verifying 'zfs receive' works correctly on deduplicated streams" log_onexit cleanup truncate -s 100M $tpoolfile log_must zpool create $temppool $tpoolfile log_must zfs create $src_fs src_mnt=$(get_prop mountpoint $src_fs) || log_fail "get_prop mountpoint $src_fs" echo blah > $src_mnt/blah zfs snapshot $src_fs@base echo grumble > $src_mnt/grumble echo blah > $src_mnt/blah2 zfs snapshot $src_fs@snap2 echo grumble > $src_mnt/mumble echo blah > $src_mnt/blah3 zfs snapshot $src_fs@snap3 log_must eval "zfs send -D -R $src_fs@snap3 > $streamfile" log_must eval "zfs receive -v $dst_fs < $streamfile" log_must zfs destroy -r $dst_fs log_must eval "zstream redup $streamfile | zfs receive -v $dst_fs" cleanup log_pass "Verifying 'zfs receive' works correctly on deduplicated streams" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_encrypted.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_encrypted.ksh index a1d094bdb4ba..891432685287 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_encrypted.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_encrypted.ksh @@ -1,83 +1,83 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # ZFS should receive an unencrypted stream from an encrypted dataset # # STRATEGY: # 1. Create an unencrypted dataset # 2. Create an encrypted dataset # 3. Create and checksum a file on the encrypted dataset # 4. Snapshot the encrypted dataset # 5. Attempt to receive the snapshot into an unencrypted child # 6. Verify encryption is not enabled # 7. Verify the checksum of the file is the same as the original # 8. Attempt to receive the snapshot into an encrypted child # 9. Verify the checksum of the file is the same as the original # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r } log_onexit cleanup log_assert "ZFS should receive an unencrypted stream from an encrypted dataset" typeset passphrase="password" typeset snap="$TESTPOOL/$TESTFS2@snap" log_must zfs create $TESTPOOL/$TESTFS1 log_must eval "echo $passphrase | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS2" log_must mkfile 1M /$TESTPOOL/$TESTFS2/$TESTFILE0 typeset checksum=$(md5digest /$TESTPOOL/$TESTFS2/$TESTFILE0) log_must zfs snapshot $snap log_note "Verify ZFS can receive into an unencrypted child" log_must eval "zfs send $snap | zfs receive $TESTPOOL/$TESTFS1/c1" crypt=$(get_prop encryption $TESTPOOL/$TESTFS1/c1) [[ "$crypt" == "off" ]] || log_fail "Received unencrypted stream as encrypted" typeset cksum1=$(md5digest /$TESTPOOL/$TESTFS1/c1/$TESTFILE0) [[ "$cksum1" == "$checksum" ]] || \ log_fail "Checksums differ ($cksum1 != $checksum)" log_note "Verify ZFS can receive into an encrypted child" log_must eval "zfs send $snap | zfs receive $TESTPOOL/$TESTFS2/c1" typeset cksum2=$(md5digest /$TESTPOOL/$TESTFS2/c1/$TESTFILE0) [[ "$cksum2" == "$checksum" ]] || \ log_fail "Checksums differ ($cksum2 != $checksum)" log_pass "ZFS can receive an unencrypted stream from an encrypted dataset" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_zstd.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_zstd.ksh index 14a175912bb2..72eebb4f9321 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_zstd.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_from_zstd.ksh @@ -1,112 +1,112 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2020 The FreeBSD Foundation [1] # # [1] Portions of this software were developed by Allan Jude # under sponsorship from the FreeBSD Foundation. . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # ZFS should receive a ZSTD compressed block and be able to determine the level # # STRATEGY: # 1. Create a ZSTD compressed dataset (random level) # 2. Create and checksum a file on the compressed dataset # 3. Snapshot the compressed dataset # 4. Attempt to receive the snapshot into a new dataset # 5. Verify the checksum of the file is the same as the original # 6. Verify the compression level is correctly stored # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r } log_onexit cleanup log_assert "ZFS should track compression level when receiving a ZSTD stream" typeset src_data="$STF_SUITE/tests/functional/cli_root/zfs_receive/zstd_test_data.txt" typeset snap="$TESTPOOL/$TESTFS1@snap" random_level=$((RANDOM%19 + 1)) log_note "Randomly selected ZSTD level: $random_level" log_must zfs create -o compress=zstd-$random_level $TESTPOOL/$TESTFS1 # Make a 5kb compressible file log_must cat $src_data $src_data $src_data $src_data $src_data \ > /$TESTPOOL/$TESTFS1/$TESTFILE0 typeset checksum=$(md5digest /$TESTPOOL/$TESTFS1/$TESTFILE0) log_must zfs snapshot $snap # get object number of file listing=$(ls -i /$TESTPOOL/$TESTFS1/$TESTFILE0) set -A array $listing obj=${array[0]} log_note "file /$TESTPOOL/$TESTFS1/$TESTFILE0 has object number $obj" output=$(zdb -Zddddddbbbbbb $TESTPOOL/$TESTFS1 $obj 2> /dev/null \ |grep -m 1 "L0 DVA" |head -n1) dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*$/\1/p' <<< "$output") log_note "block 0 of /$TESTPOOL/$TESTFS1/$TESTFILE0 has a DVA of $dva" zstd_str=$(sed -Ene 's/^.+ ZSTD:size=([^:]+):version=([^:]+):level=([^:]+):.*$/\1:\2:\3/p' <<< "$output") zstd_size1=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[1]}') zstd_version1=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[2]}') zstd_level1=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[3]}') log_note "ZSTD src: size=$zstd_size1 version=$zstd_version1 level=$zstd_level1" log_note "Verify ZFS can receive the ZSTD compressed stream" log_must eval "zfs send -ec $snap | zfs receive $TESTPOOL/$TESTFS2" typeset cksum1=$(md5digest /$TESTPOOL/$TESTFS2/$TESTFILE0) [[ "$cksum1" == "$checksum" ]] || \ log_fail "Checksums differ ($cksum1 != $checksum)" # get object number of file listing=$(ls -i /$TESTPOOL/$TESTFS2/$TESTFILE0) set -A array $listing obj=${array[0]} log_note "file /$TESTPOOL/$TESTFS2/$TESTFILE0 has object number $obj" output=$(zdb -Zddddddbbbbbb $TESTPOOL/$TESTFS2 $obj 2> /dev/null \ |grep -m 1 "L0 DVA" |head -n1) dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*$/\1/p' <<< "$output") log_note "block 0 of /$TESTPOOL/$TESTFS2/$TESTFILE0 has a DVA of $dva" zstd_str=$(sed -Ene 's/^.+ ZSTD:size=([^:]+):version=([^:]+):level=([^:]+):.*$/\1:\2:\3/p' <<< "$output") zstd_size2=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[1]}') (( $zstd_size2 != $zstd_size1 )) && log_fail \ "ZFS recv failed: compressed size differs ($zstd_size2 != $zstd_size1)" zstd_version2=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[2]}') zstd_level2=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[3]}') log_note "ZSTD dest: size=$zstd_size2 version=$zstd_version2 level=$zstd_level2" (( $zstd_level2 != $zstd_level1 )) && log_fail \ "ZFS recv failed: compression level did not match header level ($zstd_level2 != $zstd_level1)" log_pass "ZFS can receive a ZSTD stream and determine the compression level" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw.ksh index 9740caf72508..32b05e527ad3 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw.ksh @@ -1,94 +1,94 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # ZFS should receive streams from raw sends. # # STRATEGY: # 1. Create an encrypted dataset # 2. Create a file and get its checksum # 3. Snapshot the dataset # 4. Attempt to receive a raw send stream as a child of an unencrypted dataset # 5. Verify the key is unavailable # 6. Attempt to load the key and mount the dataset # 7. Verify the checksum of the file is the same as the original # 8. Attempt to receive a raw send stream as a child of an encrypted dataset # 9. Verify the key is unavailable # 10. Attempt to load the key and mount the dataset # 11. Verify the checksum of the file is the same as the original # 12. Verify 'zfs receive -n' works with the raw stream # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r } log_onexit cleanup log_assert "ZFS should receive streams from raw sends" typeset passphrase="password" typeset snap="$TESTPOOL/$TESTFS1@snap" log_must eval "echo $passphrase | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1" log_must mkfile 1M /$TESTPOOL/$TESTFS1/$TESTFILE0 typeset checksum=$(md5digest /$TESTPOOL/$TESTFS1/$TESTFILE0) log_must zfs snapshot $snap log_note "Verify ZFS can receive a raw send stream from an encrypted dataset" log_must eval "zfs send -w $snap | zfs receive $TESTPOOL/$TESTFS2" keystatus=$(get_prop keystatus $TESTPOOL/$TESTFS2) [[ "$keystatus" == "unavailable" ]] || \ log_fail "Expected keystatus unavailable, got $keystatus" log_must eval "echo $passphrase | zfs mount -l $TESTPOOL/$TESTFS2" typeset cksum1=$(md5digest /$TESTPOOL/$TESTFS2/$TESTFILE0) [[ "$cksum1" == "$checksum" ]] || \ log_fail "Checksums differ ($cksum1 != $checksum)" log_must eval "zfs send -w $snap | zfs receive $TESTPOOL/$TESTFS1/c1" keystatus=$(get_prop keystatus $TESTPOOL/$TESTFS1/c1) [[ "$keystatus" == "unavailable" ]] || \ log_fail "Expected keystatus unavailable, got $keystatus" log_must eval "echo $passphrase | zfs mount -l $TESTPOOL/$TESTFS1/c1" typeset cksum2=$(md5digest /$TESTPOOL/$TESTFS1/c1/$TESTFILE0) [[ "$cksum2" == "$checksum" ]] || \ log_fail "Checksums differ ($cksum2 != $checksum)" log_must eval "zfs send -w $snap | zfs receive -n $TESTPOOL/$TESTFS3" log_pass "ZFS can receive streams from raw sends" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_-d.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_-d.ksh index a909f2788ba1..662f9386ebee 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_-d.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_-d.ksh @@ -1,62 +1,62 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2019 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # zfs receive -d should create the expected encryption hierarchy. # # STRATEGY: # 1. Create an encrypted dataset and a inheriting child # 2. Snapshot the child dataset # 2. Create a recursive raw send file from the snapshot # 3. Destroy the original child filesystem # 4. Receive the snapshot as a child of the second dataset with '-d' # 5. Verify the new child can be mounted # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r rm -f $sendfile } log_onexit cleanup log_assert "zfs receive -d should create the expected encryption hierarchy" typeset passphrase="password1" sendfile=$TEST_BASE_DIR/sendfile.$$ log_must eval "echo $passphrase | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1" log_must zfs create $TESTPOOL/$TESTFS1/child log_must zfs snapshot $TESTPOOL/$TESTFS1/child@snap log_must eval "zfs send -Rw $TESTPOOL/$TESTFS1/child@snap > $sendfile" log_must zfs destroy -r $TESTPOOL/$TESTFS1/child log_must zfs receive -Fd $TESTPOOL < $sendfile log_must eval "echo $passphrase | zfs mount -l $TESTPOOL/$TESTFS1/child" log_pass "zfs receive -d creates the expected encryption hierarchy" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_incremental.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_incremental.ksh index 964c80657da3..7826ec9a4890 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_incremental.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_raw_incremental.ksh @@ -1,96 +1,96 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # ZFS should receive streams from raw incremental sends. # # STRATEGY: # 1. Create an encrypted dataset # 2. Snapshot the dataset # 3. Create a file and get its checksum # 4. Snapshot the dataset # 5. Attempt to receive a raw send stream of the first snapshot # 6. Change the passphrase required to unlock the original filesystem # 7. Attempt and intentionally fail to receive the second snapshot # 8. Verify that the required passphrase hasn't changed on the receive side # 9. Attempt a real raw incremental send stream of the second snapshot # 10. Attempt load the key and mount the dataset # 11. Verify the checksum of the file is the same as the original # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r [[ -f $ibackup ]] && log_must rm -f $ibackup [[ -f $ibackup_trunc ]] && log_must rm -f $ibackup_trunc } log_onexit cleanup log_assert "ZFS should receive streams from raw incremental sends" typeset ibackup="$TEST_BASE_DIR/ibackup.$$" typeset ibackup_trunc="$TEST_BASE_DIR/ibackup_trunc.$$" typeset passphrase="password" typeset passphrase2="password2" typeset snap1="$TESTPOOL/$TESTFS1@snap1" typeset snap2="$TESTPOOL/$TESTFS1@snap2" log_must eval "echo $passphrase | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1" log_must zfs snapshot $snap1 log_must mkfile 1M /$TESTPOOL/$TESTFS1/$TESTFILE0 typeset checksum=$(md5digest /$TESTPOOL/$TESTFS1/$TESTFILE0) log_must zfs snapshot $snap2 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_size $ibackup) trunc_size=$(expr $trunc_size - 64) log_must cp $ibackup $ibackup_trunc log_must truncate -s $trunc_size $ibackup_trunc log_mustnot eval "zfs receive $TESTPOOL/$TESTFS2 < $ibackup_trunc" log_mustnot eval "echo $passphrase2 | zfs load-key $TESTPOOL/$TESTFS2" log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS2" log_must zfs unload-key $TESTPOOL/$TESTFS2 log_must eval "zfs receive $TESTPOOL/$TESTFS2 < $ibackup" log_must eval "echo $passphrase2 | zfs mount -l $TESTPOOL/$TESTFS2" typeset cksum1=$(md5digest /$TESTPOOL/$TESTFS2/$TESTFILE0) [[ "$cksum1" == "$checksum" ]] || \ log_fail "Checksums differ ($cksum1 != $checksum)" log_pass "ZFS can receive streams from raw incremental sends" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_to_encrypted.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_to_encrypted.ksh index f8e53f02c23d..526497401f28 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_to_encrypted.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_to_encrypted.ksh @@ -1,77 +1,77 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # ZFS should receive to an encrypted child dataset. # # STRATEGY: # 1. Snapshot the default dataset # 2. Create an encrypted dataset # 3. Attempt to receive a stream to an encrypted child # 4. Attempt to receive a stream with properties to an encrypted child # 5. Attempt to receive a replication stream to an encrypted child # 6. Unmount and unload the encrypted dataset keys # 7. Attempt to receive a snapshot stream to an encrypted child # verify_runnable "both" function cleanup { - snapexists $snap && log_must_busy zfs destroy -f $snap + snapexists $snap && destroy_dataset $snap -f datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r } log_onexit cleanup log_assert "ZFS should receive encrypted filesystems into child dataset" typeset passphrase="password" typeset snap="$TESTPOOL/$TESTFS@snap" typeset testfile="testfile" log_must zfs snapshot $snap log_must eval "echo $passphrase | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1" log_note "Verifying ZFS will receive to an encrypted child" log_must eval "zfs send $snap | zfs receive $TESTPOOL/$TESTFS1/c1" log_note "Verifying 'send -p' will receive to an encrypted child" log_must eval "zfs send -p $snap | zfs receive $TESTPOOL/$TESTFS1/c2" log_must test "$(get_prop 'encryption' $TESTPOOL/$TESTFS1/c2)" == "off" log_note "Verifying 'send -R' will receive to an encrypted child" log_must eval "zfs send -R $snap | zfs receive $TESTPOOL/$TESTFS1/c3" log_must test "$(get_prop 'encryption' $TESTPOOL/$TESTFS1/c3)" == "off" log_note "Verifying ZFS will not receive to an encrypted child when the" \ "parent key is unloaded" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_mustnot eval "zfs send $snap | zfs receive $TESTPOOL/$TESTFS1/c4" log_pass "ZFS can receive encrypted filesystems into child dataset" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib index 9b8fb6b0edc1..af1c2f7bedaf 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib @@ -1,129 +1,127 @@ # # 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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.cfg function additional_setup { # Create testfile log_must cp $DATA $TESTDIR/$TESTFILE0 log_must cp $DATA $TESTDIR1/$TESTFILE0 # Create snapshot if ! snapexists $TESTPOOL/$TESTFS@snapshot; then log_must zfs snapshot $TESTPOOL/$TESTFS@snapshot log_must zfs clone $TESTPOOL/$TESTFS@snapshot \ $TESTPOOL/$TESTFS-clone fi # Create file system datasetexists $TESTPOOL/$TESTFS1 || \ log_must zfs create $TESTPOOL/$TESTFS1 # Create testfile log_must cp $DATA $(get_prop mountpoint $TESTPOOL/$TESTFS1)/$TESTFILE0 # Create container datasetexists $TESTPOOL/$TESTCTR1 || \ log_must zfs create $TESTPOOL/$TESTCTR1 log_must cp $DATA $(get_prop mountpoint $TESTPOOL/$TESTCTR1)/$TESTFILE0 # Create data in zvol if is_global_zone; then log_must eval "dd if=$DATA of=$VOL_R_PATH bs=$BS count=$CNT \ >/dev/null 2>&1" else log_must cp $DATA $(get_prop mountpoint $TESTPOOL/$TESTVOL)/$TESTFILE0 fi # Create temporary %recv clone create_recv_clone $TESTPOOL/$RECVFS } function rename_dataset # src dest { typeset src=$1 typeset dest=$2 log_must zfs rename $src $dest block_device_wait # # Verify src name no longer in use # log_mustnot datasetexists $src log_must datasetexists $dest } function cleanup { typeset -i i=0 while ((i < ${#dataset[*]} )); do if ! datasetexists ${dataset[i]}-new ; then ((i = i + 1)) continue fi if [[ ${dataset[i]}-new != *@* ]] ; then zfs rename ${dataset[i]}-new ${dataset[i]} if [[ $? -ne 0 ]]; then typeset newfs=${dataset[i]}-new typeset oldfs=${dataset[i]} typeset mntp=$(get_prop mountpoint $newfs) log_must zfs destroy -f $newfs log_must zfs create -p $oldfs log_must zfs set mountpoint=$mntp $oldfs fi else log_must zfs destroy -fR ${dataset[i]}-new fi ((i = i + 1)) done - if snapexists $TESTPOOL/$TESTFS@snapshot; then - log_must zfs destroy -fR $TESTPOOL/$TESTFS@snapshot - fi + snapexists $TESTPOOL/$TESTFS@snapshot && \ + destroy_dataset $TESTPOOL/$TESTFS@snapshot -fR - if datasetexists $TESTPOOL/$RECVFS; then - log_must zfs destroy -r $TESTPOOL/$RECVFS - fi + datasetexists $TESTPOOL/$RECVFS && \ + destroy_dataset $TESTPOOL/$RECVFS -r } function cmp_data #<$1 src data, $2 tgt data> { typeset src=$1 typeset tgt=$2 cmp $src $tgt >/dev/null 2>&1 return $? } diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_003_pos.ksh index 56c06cfe857d..0bd4aca3a7fd 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_003_pos.ksh @@ -1,68 +1,68 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs rename' can address the abbreviated snapshot name. # # STRATEGY: # 1. Create pool, fs and snap. # 2. Verify 'zfs rename' support the abbreviated snapshot name. # verify_runnable "both" function cleanup { - datasetexists $snap && log_must zfs destroy $snap + datasetexists $snap && destroy_dataset $snap } log_assert "'zfs rename' can address the abbreviated snapshot name." log_onexit cleanup fs=$TESTPOOL/$TESTFS; snap=$fs@snap set -A newname "$fs@new-snap" "@new-snap" "new-snap" log_must zfs snapshot $snap log_must datasetexists $snap typeset -i i=0 while ((i < ${#newname[*]} )); do log_must zfs rename $snap ${newname[$i]} log_must datasetexists ${snap%%@*}@${newname[$i]##*@} log_must zfs rename ${snap%%@*}@${newname[$i]##*@} $snap ((i += 1)) done log_pass "'zfs rename' address the abbreviated snapshot name passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh index 0cacb7a98fa2..2a3f8a8ccd7b 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_007_pos.ksh @@ -1,155 +1,154 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib # # DESCRIPTION: # Rename dataset, verify that the data haven't changed. # # STRATEGY: # 1. Create random data and copy to dataset. # 2. Perform renaming commands. # 3. Verify that the data haven't changed. # verify_runnable "both" function cleanup { - if datasetexists $TESTPOOL/$TESTFS ; then - log_must zfs destroy -Rf $TESTPOOL/$TESTFS - fi + datasetexists $TESTPOOL/$TESTFS && \ + destroy_dataset $TESTPOOL/$TESTFS -Rf log_must zfs create $TESTPOOL/$TESTFS log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS rm -f $SRC_FILE $DST_FILE } function target_obj { typeset dtst=$1 typeset obj typeset type=$(get_prop type $dtst) if [[ $type == "filesystem" ]]; then obj=$(get_prop mountpoint $dtst)/${SRC_FILE##*/} elif [[ $type == "volume" ]]; then obj=$ZVOL_DEVDIR/$dtst fi echo $obj } log_assert "Rename dataset, verify that the data haven't changed." log_onexit cleanup # Generate random data # BS=512 ; CNT=2048 SRC_FILE=$TESTDIR/srcfile.$$ DST_FILE=$TESTDIR/dstfile.$$ log_must dd if=/dev/urandom of=$SRC_FILE bs=$BS count=$CNT fs=$TESTPOOL/$TESTFS/fs.$$ fsclone=$TESTPOOL/$TESTFS/fsclone.$$ log_must zfs create $fs obj=$(target_obj $fs) log_must cp $SRC_FILE $obj snap=${fs}@snap.$$ log_must zfs snapshot $snap log_must zfs clone $snap $fsclone # Rename dataset & clone # log_must zfs rename $fs ${fs}-new log_must zfs rename $fsclone ${fsclone}-new # Compare source file and target file # obj=$(target_obj ${fs}-new) log_must diff $SRC_FILE $obj obj=$(target_obj ${fsclone}-new) log_must diff $SRC_FILE $obj # Rename snapshot and re-clone dataset # log_must zfs rename ${fs}-new $fs log_must zfs rename $snap ${snap}-new log_must zfs clone ${snap}-new $fsclone # Compare source file and target file # obj=$(target_obj $fsclone) log_must diff $SRC_FILE $obj if is_global_zone; then vol=$TESTPOOL/$TESTFS/vol.$$ ; volclone=$TESTPOOL/$TESTFS/volclone.$$ log_must zfs create -V 100M $vol obj=$(target_obj $vol) block_device_wait $obj log_must dd if=$SRC_FILE of=$obj bs=$BS count=$CNT snap=${vol}@snap.$$ log_must zfs snapshot $snap log_must zfs clone $snap $volclone # Rename dataset & clone log_must zfs rename $vol ${vol}-new log_must zfs rename $volclone ${volclone}-new # Compare source file and target file obj=$(target_obj ${vol}-new) block_device_wait $obj log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT log_must diff $SRC_FILE $DST_FILE obj=$(target_obj ${volclone}-new) block_device_wait $obj log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT log_must diff $SRC_FILE $DST_FILE # Rename snapshot and re-clone dataset log_must zfs rename ${vol}-new $vol log_must zfs rename $snap ${snap}-new log_must zfs clone ${snap}-new $volclone # Compare source file and target file obj=$(target_obj $volclone) block_device_wait $obj log_must dd if=$obj of=$DST_FILE bs=$BS count=$CNT log_must diff $SRC_FILE $DST_FILE fi log_pass "Rename dataset, the data haven't changed passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_008_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_008_pos.ksh index 3fc099d79f8a..229163839058 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_008_pos.ksh @@ -1,88 +1,87 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # zfs rename -r can rename snapshot recursively. # # STRATEGY: # 1. Create snapshot recursively. # 2. Rename snapshot recursively. # 3. Verify rename -r snapshot correctly. # verify_runnable "both" function cleanup { typeset -i i=0 while ((i < ${#datasets[@]})); do - if datasetexists ${datasets[$i]}@snap ; then - log_must zfs destroy ${datasets[$i]}@snap - fi - if datasetexists ${datasets[$i]}@snap-new ; then - log_must zfs destroy ${datasets[$i]}@snap-new - fi + datasetexists ${datasets[$i]}@snap && \ + destroy_dataset ${datasets[$i]}@snap + + datasetexists ${datasets[$i]}@snap-new && \ + destroy_dataset ${datasets[$i]}@snap-new ((i += 1)) done } log_assert "zfs rename -r can rename snapshot recursively." log_onexit cleanup set -A datasets $TESTPOOL $TESTPOOL/$TESTCTR \ $TESTPOOL/$TESTCTR/$TESTFS1 $TESTPOOL/$TESTFS if is_global_zone; then datasets[${#datasets[@]}]=$TESTPOOL/$TESTVOL fi log_must zfs snapshot -r ${TESTPOOL}@snap typeset -i i=0 while ((i < ${#datasets[@]})); do log_must datasetexists ${datasets[$i]}@snap ((i += 1)) done log_must zfs rename -r ${TESTPOOL}@snap ${TESTPOOL}@snap-new i=0 while ((i < ${#datasets[@]})); do log_must datasetexists ${datasets[$i]}@snap-new ((i += 1)) done log_must zfs destroy -rf ${TESTPOOL}@snap-new log_pass "Verify zfs rename -r passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_011_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_011_pos.ksh index 2d1220e334c9..71d72619d646 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_011_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_011_pos.ksh @@ -1,78 +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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_rename/zfs_rename.kshlib # # DESCRIPTION # 'zfs rename -p' should work as expected # # STRATEGY: # 1. Make sure the upper level of $newdataset does not exist # 2. Make sure without -p option, 'zfs rename' will fail # 3. With -p option, rename works # verify_runnable "both" function additional_cleanup { - if datasetexists $TESTPOOL/notexist ; then - log_must zfs destroy -Rf $TESTPOOL/notexist - fi + datasetexists $TESTPOOL/notexist && \ + destroy_dataset $TESTPOOL/notexist -Rf + + datasetexists $TESTPOOL/$TESTFS && \ + destroy_dataset $TESTPOOL/$TESTFS -Rf - if datasetexists $TESTPOOL/$TESTFS ; then - log_must zfs destroy -Rf $TESTPOOL/$TESTFS - fi log_must zfs create $TESTPOOL/$TESTFS if is_global_zone ; then - if datasetexists $TESTPOOL/$TESTVOL ; then - log_must zfs destroy -Rf $TESTPOOL/$TESTVOL - fi + datasetexists $TESTPOOL/$TESTVOL && \ + destroy_dataset $TESTPOOL/$TESTVOL -Rf + log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL fi } log_onexit additional_cleanup log_assert "'zfs rename -p' should work as expected" log_must verify_opt_p_ops "rename" "fs" "$TESTPOOL/$TESTFS" \ "$TESTPOOL/notexist/new/$TESTFS1" if is_global_zone; then log_must verify_opt_p_ops "rename" "vol" "$TESTPOOL/$TESTVOL" \ "$TESTPOOL/notexist/new/$TESTVOL1" fi log_pass "'zfs rename -p' should work as expected" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_013_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_013_pos.ksh index b2e01006fdd1..73790f58cd45 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_013_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_013_pos.ksh @@ -1,85 +1,81 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # zfs rename -r can rename snapshot when child datasets # don't have a snapshot of the given name. # # STRATEGY: # 1. Create snapshot. # 2. Rename snapshot recursively. # 3. Verify rename -r snapshot correctly. # verify_runnable "both" function cleanup { - if datasetexists $TESTPOOL/$TESTCTR@snap-new ; then - log_must zfs destroy -f $TESTPOOL/$TESTCTR@snap-new - fi + datasetexists $TESTPOOL/$TESTCTR@snap-new && \ + destroy_dataset $TESTPOOL/$TESTCTR@snap-new -f - if datasetexists $TESTPOOL/$TESTCTR@snap ; then - log_must zfs destroy -f $TESTPOOL/$TESTCTR@snap - fi + datasetexists $TESTPOOL/$TESTCTR@snap && \ + destroy_dataset $TESTPOOL/$TESTCTR@snap -f - if datasetexists $TESTPOOL@snap-new ; then - log_must zfs destroy -f $TESTPOOL@snap-new - fi + datasetexists $TESTPOOL@snap-new && \ + destroy_dataset $TESTPOOL@snap-new -f - if datasetexists $TESTPOOL@snap ; then - log_must zfs destroy -f $TESTPOOL@snap - fi + datasetexists $TESTPOOL@snap && \ + destroy_dataset $TESTPOOL@snap -f } log_assert "zfs rename -r can rename snapshot when child datasets" \ "don't have a snapshot of the given name." log_onexit cleanup log_must zfs snapshot $TESTPOOL/$TESTCTR@snap log_must zfs rename -r $TESTPOOL/$TESTCTR@snap $TESTPOOL/$TESTCTR@snap-new log_must datasetexists $TESTPOOL/$TESTCTR@snap-new log_must zfs snapshot $TESTPOOL@snap log_must zfs rename -r $TESTPOOL@snap $TESTPOOL@snap-new log_must datasetexists $TESTPOOL/$TESTCTR@snap-new log_must datasetexists $TESTPOOL@snap-new log_must zfs destroy -f $TESTPOOL/$TESTCTR@snap-new log_must zfs destroy -f $TESTPOOL@snap-new log_pass "Verify zfs rename -r passed when child datasets" \ "don't have a snapshot of the given name." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_encrypted_child.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_encrypted_child.ksh index fa57658f185b..2366cf67655c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_encrypted_child.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_encrypted_child.ksh @@ -1,78 +1,78 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs rename' should not move an encrypted child dataset outside of its # encryption root. # # STRATEGY: # 1. Create two encryption roots, and a child and grandchild of the first # encryption root # 2. Attempt to rename the grandchild under an unencrypted parent # 3. Attempt to rename the grandchild under a different encrypted parent # 4. Attempt to rename the grandchild under the current parent # 5. Verify the encryption root of the dataset # 6. Attempt to rename the grandchild to a child # 7. Verify the encryption root of the dataset # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r datasetexists $TESTPOOL/$TESTFS3 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS3 + destroy_dataset $TESTPOOL/$TESTFS3 -r } log_onexit cleanup log_assert "'zfs rename' should not move an encrypted child outside of its" \ "encryption root" log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS2" log_must zfs create $TESTPOOL/$TESTFS2/child log_must zfs create $TESTPOOL/$TESTFS2/child/grandchild log_must eval "echo $PASSPHRASE1 | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS3" log_mustnot zfs rename $TESTPOOL/$TESTFS2/child/grandchild \ $TESTPOOL/grandchild log_mustnot zfs rename $TESTPOOL/$TESTFS2/child/grandchild \ $TESTPOOL/$TESTFS3/grandchild log_must zfs rename $TESTPOOL/$TESTFS2/child/grandchild \ $TESTPOOL/$TESTFS2/child/grandchild2 log_must verify_encryption_root $TESTPOOL/$TESTFS2/child/grandchild2 \ $TESTPOOL/$TESTFS2 log_must zfs rename $TESTPOOL/$TESTFS2/child/grandchild2 \ $TESTPOOL/$TESTFS2/grandchild2 log_must verify_encryption_root $TESTPOOL/$TESTFS2/grandchild2 \ $TESTPOOL/$TESTFS2 log_pass "'zfs rename' does not move an encrypted child outside of its" \ "encryption root" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_to_encrypted.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_to_encrypted.ksh index 1b9c6e3c704f..ab8e1c89ae86 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_to_encrypted.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rename/zfs_rename_to_encrypted.ksh @@ -1,53 +1,53 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs rename' should be able to move an unencrypted dataset to a child # of an encrypted dataset # # STRATEGY: # 1. Create an encrypted dataset # 2. Rename the default dataset to a child of the encrypted dataset # 3. Confirm the child dataset doesn't have any encryption properties # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r } log_onexit cleanup log_assert "'zfs rename' should allow renaming an unencrypted dataset to a" \ "child of an encrypted dataset" log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS2" log_must zfs rename $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS2/$TESTFS log_must test "$(get_prop 'encryption' $TESTPOOL/$TESTFS2/$TESTFS)" == "off" log_pass "'zfs rename' allows renaming an unencrypted dataset to a child" \ "of an encrypted dataset" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh index 342c72e166a9..607bbf06eafd 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_001_pos.ksh @@ -1,175 +1,175 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib # # DESCRIPTION: # 'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any snapshots # more recent than the one specified. # # STRATEGY: # 1. Create pool, fs & volume. # 2. Separately create three snapshots or clones for fs & volume # 3. Roll back to the second snapshot and check the results. # 4. Create the third snapshot or clones for fs & volume again. # 5. Roll back to the first snapshot and check the results. # 6. Separately create two snapshots for fs & volume. # 7. Roll back to the first snapshot and check the results. # verify_runnable "both" log_assert "'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any " \ "snapshots more recent than the one specified." log_onexit cleanup_env # # Create suitable test environment and run 'zfs rollback', then compare with # expected value to check the system status. # # $1 option. # $2 the number of snapshots or clones. # $3 the number of snapshot point which we want to rollback. # function test_n_check #opt num_snap_clone num_rollback { typeset opt=$1 typeset -i cnt=$2 typeset -i pointcnt=$3 typeset dtst (( cnt > 3 || pointcnt > cnt )) && \ log_fail "Unsupported testing condition." # Clean up the test environment if pgrep -x dd 2>/dev/null; then pkill -x dd fi - datasetexists $FS && log_must zfs destroy -Rf $FS + datasetexists $FS && destroy_dataset $FS -Rf if datasetexists $VOL; then if ismounted $TESTDIR1 $NEWFS_DEFAULT_FS; then log_must umount -f $TESTDIR1 sleep 0.1 fi - log_must zfs destroy -Rf $VOL + destroy_dataset $VOL -Rf fi # Create specified test environment case $opt in *r*) setup_snap_env $cnt ;; *R*) setup_clone_env $cnt ;; esac all_snap="$TESTSNAP $TESTSNAP1 $TESTSNAP2" all_clone="$TESTCLONE $TESTCLONE1 $TESTCLONE2" typeset snap_point typeset exist_snap typeset exist_clone case $pointcnt in 1) snap_point=$TESTSNAP exist_snap=$TESTSNAP [[ $opt == *R* ]] && exist_clone=$TESTCLONE ;; 2) snap_point=$TESTSNAP1 exist_snap="$TESTSNAP $TESTSNAP1" [[ $opt == *R* ]] && exist_clone="$TESTCLONE $TESTCLONE1" ;; esac typeset snap for dtst in $FS $VOL; do # Volume is not available in Local Zone. if [[ $dtst == $VOL ]]; then if ! is_global_zone; then break fi fi if [[ $opt == *f* ]]; then # To write data to the mountpoint directory, write_mountpoint_dir $dtst opt=${opt%f} fi if [[ $dtst == $VOL ]]; then if ismounted $TESTDIR1 $NEWFS_DEFAULT_FS; then log_must umount -f $TESTDIR1 fi log_must zfs rollback $opt $dtst@$snap_point log_must mount \ $ZVOL_DEVDIR/$TESTPOOL/$TESTVOL $TESTDIR1 else log_must zfs rollback $opt $dtst@$snap_point fi for snap in $all_snap; do if [[ " $exist_snap " == *" $snap "* ]]; then log_must datasetexists $dtst@$snap else log_must datasetnonexists $dtst@$snap fi done for clone in $all_clone; do if [[ " $exist_clone " == *" $clone "* ]]; then log_must datasetexists $dtst$clone else log_must datasetnonexists $dtst$clone fi done check_files $dtst@$snap_point done } typeset opt for opt in "-r" "-rf" "-R" "-Rf"; do # # Currently, the test case was limited to create and rollback # in three snapshots # log_note "Create 3 snapshots, rollback to the 2nd snapshot " \ "using $opt." test_n_check "$opt" 3 2 log_note "Create 3 snapshots and rollback to the 1st snapshot " \ "using $opt." test_n_check "$opt" 3 1 log_note "Create 2 snapshots and rollback to the 1st snapshot " \ "using $opt." test_n_check "$opt" 2 1 done log_pass "'zfs rollback -r|-rf|-R|-Rf' recursively destroy any snapshots more "\ "recent than the one specified passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh index 0ae13d3a9bad..1e3109108bae 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_003_neg.ksh @@ -1,84 +1,82 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib # # DESCRIPTION: # Separately verify 'zfs rollback ''|-f|-r|-rf|-R|-rR will fail in # different conditions. # # STRATEGY: # 1. Create pool and file system # 2. Create 'snap' and 'snap1' of this file system. # 3. Run 'zfs rollback ""|-f ' and it should fail. # 4. Create 'clone1' based on 'snap1'. # 5. Run 'zfs rollback -r|-rf ' and it should fail. # verify_runnable "both" function cleanup { pkill ${DD##*/} for snap in $FSSNAP0 $FSSNAP1 $FSSNAP2; do - if snapexists $snap; then - log_must zfs destroy -Rf $snap - fi + snapexists $snap && destroy_dataset $snap -Rf done } log_assert "Separately verify 'zfs rollback ''|-f|-r|-rf will fail in " \ "different conditions." log_onexit cleanup # Create snapshot1 and snapshot2 for this file system. # create_snapshot $TESTPOOL/$TESTFS $TESTSNAP create_snapshot $TESTPOOL/$TESTFS $TESTSNAP1 # Run 'zfs rollback ""|-f ' and it should fail. # log_mustnot zfs rollback $TESTPOOL/$TESTFS@$TESTSNAP log_mustnot zfs rollback -f $TESTPOOL/$TESTFS@$TESTSNAP # Create 'clone1' based on 'snap1'. # create_clone $TESTPOOL/$TESTFS@$TESTSNAP1 $TESTPOOL/$TESTCLONE1 # Run 'zfs rollback -r|-rf ' and it should fail. # log_mustnot zfs rollback -r $TESTPOOL/$TESTFS@$TESTSNAP log_mustnot zfs rollback -rf $TESTPOOL/$TESTFS@$TESTSNAP log_pass "zfs rollback ''|-f|-r|-rf will fail in different conditions " \ "passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh index 0c1bb730e77c..9537d5077b1a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_004_neg.ksh @@ -1,86 +1,85 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib # # DESCRIPTION: # 'zfs rollback' should fail when passing invalid options, too many # arguments,non-snapshot datasets or missing datasets # # STRATEGY: # 1. Create an array of invalid options # 2. Execute 'zfs rollback' with invalid options, too many arguments # or missing datasets # 3. Verify 'zfs rollback' return with errors # verify_runnable "both" function cleanup { typeset ds for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do - if snapexists ${ds}@$TESTSNAP; then - log_must zfs destroy ${ds}@$TESTSNAP - fi + snapexists ${ds}@$TESTSNAP && \ + destroy_dataset ${ds}@$TESTSNAP done } log_assert "'zfs rollback' should fail with bad options,too many arguments," \ "non-snapshot datasets or missing datasets." log_onexit cleanup set -A badopts "r" "R" "f" "-F" "-rF" "-RF" "-fF" "-?" "-*" "-blah" "-1" "-2" for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do log_must zfs snapshot ${ds}@$TESTSNAP done for ds in $TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL; do for opt in "" "-r" "-R" "-f" "-rR" "-rf" "-rRf"; do log_mustnot eval "zfs rollback $opt $ds >/dev/null 2>&1" log_mustnot eval "zfs rollback $opt ${ds}@$TESTSNAP \ ${ds}@$TESTSNAP >/dev/null 2>&1" log_mustnot eval "zfs rollback $opt >/dev/null 2>&1" # zfs rollback should fail with non-existen snapshot log_mustnot eval "zfs rollback $opt ${ds}@nosnap >/dev/null 2>&1" done for badopt in ${badopts[@]}; do log_mustnot eval "zfs rollback $badopt ${ds}@$TESTSNAP \ >/dev/null 2>&1" done done log_pass "'zfs rollback' fails as expected with illegal arguments." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib index b2f4b2b8a3ca..433f240675f3 100644 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib @@ -1,321 +1,319 @@ # # 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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback.cfg # Get file sum # # $1 full file name function getsum #fname { (( ${#1} == 0 )) && \ log_fail "Need give file name." return $(sum $1 | awk '{print $1}') } # Define global variable checksum, get the original file sum. # origsum=$(getsum /etc/passwd) # # Setup or recover the test environment. Firstly, copy /etc/passwd to ZFS file # system or volume, then make a snapshot or clone. Repeat up to three times. # # $1 number of snapshot. Note: Currently only support three snapshots. # $2 indicate if it is necessary to create clone # function setup_snap_env { typeset -i cnt=${1:-3} typeset createclone=${2:-"false"} if datasetnonexists $FS; then log_must zfs create $FS log_must zfs set mountpoint=$TESTDIR $FS fi # Volume can't be created in Local Zone. if datasetnonexists $VOL && is_global_zone; then log_must zfs create -V $VOLSIZE $VOL block_device_wait fi # Make sure $VOL is volume typeset type=$(get_prop type $VOL) if datasetexists $VOL && \ [[ $type == 'volume' ]]; then # # At the first time, Make a UFS file system in volume and # mount it. Otherwise, only check if this ufs|ext file system # was mounted. # log_must new_fs $ZVOL_DEVDIR/$VOL [[ ! -d $TESTDIR1 ]] && log_must mkdir $TESTDIR1 # Make sure the ufs|ext filesystem hasn't been mounted, # then mount the new ufs|ext filesystem. if ! ismounted $TESTDIR1 $NEWFS_DEFAULT_FS; then log_must mount $ZVOL_DEVDIR/$VOL $TESTDIR1 fi fi # Separately Create three snapshots for file system & volume typeset -i ind=0 typeset dtst for dtst in $FS $VOL; do # Volume can be created in Local Zone. if [[ $dtst == $VOL ]]; then if ! is_global_zone; then break fi fi ind=0 while (( ind < cnt )); do case $dtst in $FS) eval typeset snap=\$FSSNAP$ind eval typeset clone=\$FSCLONE$ind eval typeset fname=\$TESTDIR/\$TESTFILE$ind ;; $VOL) eval typeset snap=\$VOLSNAP$ind eval typeset clone=\$VOLCLONE$ind eval typeset fname=\$TESTDIR1/\$TESTFILE$ind ;; esac if datasetnonexists $snap; then log_must cp /etc/passwd $fname if is_linux || is_freebsd; then log_must sync else # # using 'lockfs -f' to flush the writes # to disk before taking a snapshot. # if [[ $dtst == $VOL ]]; then log_must lockfs -f $TESTDIR1 fi fi if is_freebsd && [[ $dtst == $VOL ]]; then # Though sync does start a fs sync on # FreeBSD, it does not wait for it to # finish. We can force a blocking sync # by updating the fs mount instead. # Otherwise, the snapshot might occur # with the fs in an unmountable state. log_must mount -ur \ $ZVOL_DEVDIR/$VOL $TESTDIR1 fi log_must zfs snapshot $snap if is_freebsd && [[ $dtst == $VOL ]]; then log_must mount -uw \ $ZVOL_DEVDIR/$VOL $TESTDIR1 fi fi if [[ $createclone == "true" ]]; then if datasetnonexists $clone; then log_must zfs clone $snap $clone block_device_wait fi fi (( ind += 1 )) done done } function setup_clone_env { setup_snap_env $1 "true" } # # Clean up the test environment # # $1 number of snapshot Note: Currently only support three snapshots. # function cleanup_env { typeset -i cnt=${1:-3} typeset -i ind=0 typeset dtst typeset snap pkill -x dd if ismounted $TESTDIR1 $NEWFS_DEFAULT_FS; then log_must umount -f $TESTDIR1 fi [[ -d $TESTDIR ]] && log_must rm -rf $TESTDIR/* [[ -d $TESTDIR1 ]] && log_must rm -rf $TESTDIR1/* for dtst in $FS $VOL; do for snap in $TESTSNAP $TESTSNAP1 $TESTSNAP2; do - if snapexists $dtst@$snap; then - log_must zfs destroy -Rf $dtst@$snap - fi + snapexists $dtst@$snap && destroy_dataset $dtst@$snap -Rf done done # Restore original test environment if datasetnonexists $FS ; then log_must zfs create $FS fi if datasetnonexists $VOL ; then if is_global_zone ; then log_must zfs create -V $VOLSIZE $VOL else log_must zfs create $VOL fi fi } # # check if the specified files have specified status. # # $1 expected status # $2-n full file name # If it is true return 0, else return 1 # function file_status { (( $# == 0 )) && \ log_fail "The file name is not defined." typeset opt case $1 in exist) opt="-e" ;; nonexist) opt="! -e" ;; *) log_fail "Unsupported file status." ;; esac shift while (( $# > 0 )); do eval [[ $opt $1 ]] || return 1 shift done return 0 } function files_exist { file_status "exist" $@ } function files_nonexist { file_status "nonexist" $@ } # # According to snapshot check if the file system was recovered to the right # point. # # $1 snapshot. fs@snap or vol@snap # function check_files { typeset dtst=$1 if [[ $(get_prop type $dtst) != snapshot ]]; then log_fail "Parameter must be a snapshot." fi typeset fsvol=${dtst%%@*} typeset snap=${dtst##*@} if [[ $(get_prop type $fsvol) == "filesystem" ]]; then ind="" else ind="1" fi eval typeset file0=\$TESTDIR$ind/\$TESTFILE0 eval typeset file1=\$TESTDIR$ind/\$TESTFILE1 eval typeset file2=\$TESTDIR$ind/\$TESTFILE2 case $snap in $TESTSNAP2) log_must files_exist $file0 $file1 $file2 typeset sum0=$(getsum $file0) typeset sum1=$(getsum $file1) typeset sum2=$(getsum $file2) if [[ $sum0 != $origsum || \ $sum1 != $origsum || sum2 != $origsum ]] then log_fail "After rollback, file sum is changed." fi ;; $TESTSNAP1) log_must files_exist $file0 $file1 log_must files_nonexist $file2 typeset sum0=$(getsum $file0) typeset sum1=$(getsum $file1) if [[ $sum0 != $origsum || $sum1 != $origsum ]] then log_fail "After rollback, file sum is changed." fi ;; $TESTSNAP) log_must files_exist $file0 log_must files_nonexist $file1 $file2 typeset sum0=$(getsum $file0) if [[ $sum0 != $origsum ]]; then log_fail "After rollback, file sum is changed." fi ;; esac } # According to dataset type, write file to different directories. # # $1 dataset # function write_mountpoint_dir { typeset dtst=$1 typeset dir if [[ $dtst == $FS ]]; then dir=$TESTDIR log_must ismounted $dir else dir=$TESTDIR1 log_must ismounted $dir $NEWFS_DEFAULT_FS fi dd if=/dev/urandom of=$dir/$TESTFILE1 & log_must sleep 3 } diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send-b.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send-b.ksh index 2105bc4d23e4..f019c2215ecd 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send-b.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send-b.ksh @@ -1,102 +1,102 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2018, loli10K . All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # 'zfs send -b' should works as expected. # # STRATEGY: # 1. Create a source dataset and set some properties # 2. Verify command line options interact with '-b' correctly # 3. Send the dataset and its properties to a new "backup" destination # 4. Set some properties on the new "backup" dataset # 5. Restore the "backup" dataset to a new destination # 6. Verify only original (received) properties are sent from "backup" # verify_runnable "both" function cleanup { for ds in "$SENDFS" "$BACKUP" "$RESTORE"; do - datasetexists $ds && log_must zfs destroy -r $ds + datasetexists $ds && destroy_dataset $ds -r done } log_assert "'zfs send -b' should work as expected." log_onexit cleanup SENDFS="$TESTPOOL/sendfs" BACKUP="$TESTPOOL/backup" RESTORE="$TESTPOOL/restore" # 1. Create a source dataset and set some properties log_must zfs create $SENDFS log_must zfs snapshot "$SENDFS@s1" log_must zfs bookmark "$SENDFS@s1" "$SENDFS#bm" log_must zfs snapshot "$SENDFS@s2" log_must zfs set "compression=gzip" $SENDFS log_must zfs set "org.openzfs:prop=val" $SENDFS log_must zfs set "org.openzfs:snapprop=val" "$SENDFS@s1" # 2. Verify command line options interact with '-b' correctly typeset opts=("" "p" "Rp" "cew" "nv" "D" "DLPRcenpvw") for opt in ${opts[@]}; do log_must eval "zfs send -b$opt $SENDFS@s1 >$TEST_BASE_DIR/devnull" log_must eval "zfs send -b$opt -i $SENDFS@s1 $SENDFS@s2 >$TEST_BASE_DIR/devnull" log_must eval "zfs send -b$opt -I $SENDFS@s1 $SENDFS@s2 >$TEST_BASE_DIR/devnull" done for opt in ${opts[@]}; do log_mustnot eval "zfs send -b$opt $SENDFS >$TEST_BASE_DIR/devnull" log_mustnot eval "zfs send -b$opt $SENDFS#bm >$TEST_BASE_DIR/devnull" done # Do 3..6 in a loop to verify various combination of "zfs send" options typeset opts=("" "p" "R" "pR" "cew") for opt in ${opts[@]}; do # 3. Send the dataset and its properties to a new "backup" destination # NOTE: only need to send properties (-p) here log_must eval "zfs send -p $SENDFS@s1 | zfs recv $BACKUP" # 4. Set some properties on the new "backup" dataset # NOTE: override "received" values and set some new properties as well log_must zfs set "compression=lz4" $BACKUP log_must zfs set "exec=off" $BACKUP log_must zfs set "org.openzfs:prop=newval" $BACKUP log_must zfs set "org.openzfs:newprop=newval" $BACKUP log_must zfs set "org.openzfs:snapprop=newval" "$BACKUP@s1" log_must zfs set "org.openzfs:newsnapprop=newval" "$BACKUP@s1" # 5. Restore the "backup" dataset to a new destination log_must eval "zfs send -b$opt $BACKUP@s1 | zfs recv $RESTORE" # 6. Verify only original (received) properties are sent from "backup" log_must eval "check_prop_source $RESTORE compression gzip received" log_must eval "check_prop_source $RESTORE org.openzfs:prop val received" log_must eval "check_prop_source $RESTORE@s1 org.openzfs:snapprop val received" log_must eval "check_prop_source $RESTORE exec on default" log_must eval "check_prop_missing $RESTORE org.openzfs:newprop" log_must eval "check_prop_missing $RESTORE@s1 org.openzfs:newsnapprop" # cleanup log_must zfs destroy -r $BACKUP log_must zfs destroy -r $RESTORE done log_pass "'zfs send -b' works as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos.ksh index 2c6e3fdd6d2f..b18433085ed5 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_001_pos.ksh @@ -1,127 +1,125 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_send/zfs_send.cfg # # DESCRIPTION: # Verify 'zfs send' can create valid send streams as expected. # # STRATEGY: # 1. Fill in fs with some data # 2. Create a full send streams with the fs # 3. Receive the send stream and verify the data integrity # 4. Fill in fs with some new data # 5. Create an incremental send stream with the fs # 6. Receive the incremental send stream and verify the data integrity. # verify_runnable "both" function cleanup { for snap in $init_snap $inc_snap $rst_snap $rst_inc_snap; do - snapexists $snap && \ - log_must zfs destroy -f $snap + snapexists $snap && destroy_dataset $snap -f done - datasetexists $rst_root && \ - log_must zfs destroy -Rf $rst_root + datasetexists $rst_root && destroy_dataset $rst_root -Rf for file in $full_bkup $inc_bkup \ $init_data $inc_data do [[ -e $file ]] && \ log_must rm -f $file done [[ -d $TESTDIR1 ]] && \ log_must rm -rf $TESTDIR1 } log_assert "Verify 'zfs send' can create valid send streams as expected." log_onexit cleanup init_snap=$TESTPOOL/$TESTFS@init_snap inc_snap=$TESTPOOL/$TESTFS@inc_snap full_bkup=$TEST_BASE_DIR/fullbkup.$$ inc_bkup=$TEST_BASE_DIR/incbkup.$$ init_data=$TESTDIR/$TESTFILE1 inc_data=$TESTDIR/$TESTFILE2 orig_sum="" rst_sum="" rst_root=$TESTPOOL/rst_ctr rst_snap=$rst_root/$TESTFS@init_snap rst_inc_snap=$rst_root/$TESTFS@inc_snap rst_data=$TESTDIR1/$TESTFS/$TESTFILE1 rst_inc_data=$TESTDIR1/$TESTFS/$TESTFILE2 log_note "Verify 'zfs send' can create full send stream." #Pre-paration log_must zfs create $rst_root [[ ! -d $TESTDIR1 ]] && \ log_must mkdir -p $TESTDIR1 log_must zfs set mountpoint=$TESTDIR1 $rst_root file_write -o create -f $init_data -b $BLOCK_SIZE -c $WRITE_COUNT log_must zfs snapshot $init_snap zfs send $init_snap > $full_bkup (( $? != 0 )) && \ log_fail "'zfs send' fails to create full send" log_note "Verify the send stream is valid to receive." log_must zfs receive $rst_snap <$full_bkup receive_check $rst_snap ${rst_snap%%@*} compare_cksum $init_data $rst_data log_note "Verify 'zfs send -i' can create incremental send stream." file_write -o create -f $inc_data -b $BLOCK_SIZE -c $WRITE_COUNT -d 0 log_must zfs snapshot $inc_snap zfs send -i $init_snap $inc_snap > $inc_bkup (( $? != 0 )) && \ log_fail "'zfs send -i' fails to create incremental send" log_note "Verify the incremental send stream is valid to receive." log_must zfs rollback $rst_snap log_must zfs receive $rst_inc_snap <$inc_bkup receive_check $rst_inc_snap compare_cksum $inc_data $rst_inc_data log_pass "Verifying 'zfs receive' succeed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_002_pos.ksh index 6359bb4f7f22..42bdddd2cc18 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_002_pos.ksh @@ -1,139 +1,136 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_send/zfs_send.cfg # # DESCRIPTION: # Verify 'zfs send' can generate valid streams with a property setup. # # STRATEGY: # 1. Setup property for filesystem # 2. Fill in some data into filesystem # 3. Create a full send streams # 4. Receive the send stream # 5. Verify the receive result # verify_runnable "both" function cleanup { - snapexists $snap && \ - log_must zfs destroy $snap - - datasetexists $ctr && \ - log_must zfs destroy -r $ctr + snapexists $snap && destroy_dataset $snap + datasetexists $ctr && destroy_dataset $ctr -r [[ -e $origfile ]] && \ log_must rm -f $origfile [[ -e $stream ]] && \ log_must rm -f $stream } function do_testing # { typeset property=$1 typeset prop_val=$2 log_must zfs set $property=$prop_val $fs file_write -o create -f $origfile -b $BLOCK_SIZE -c $WRITE_COUNT log_must zfs snapshot $snap zfs send $snap > $stream (( $? != 0 )) && \ log_fail "'zfs send' fails to create send streams." zfs receive -d $ctr <$stream (( $? != 0 )) && \ log_fail "'zfs receive' fails to receive send streams." #verify receive result ! datasetexists $rstfs && \ log_fail "'zfs receive' fails to restore $rstfs" ! snapexists $rstfssnap && \ log_fail "'zfs receive' fails to restore $rstfssnap" if [[ ! -e $rstfile ]] || [[ ! -e $rstsnapfile ]]; then log_fail " Data lost after receiving stream" fi compare_cksum $origfile $rstfile compare_cksum $origsnapfile $rstsnapfile #Destroy datasets and stream for next testing log_must zfs destroy $snap if is_global_zone ; then log_must zfs destroy -r $rstfs else log_must zfs destroy -r $ds_path fi log_must rm -f $stream } log_assert "Verify 'zfs send' generates valid streams with a property setup" log_onexit cleanup fs=$TESTPOOL/$TESTFS snap=$fs@$TESTSNAP ctr=$TESTPOOL/$TESTCTR if is_global_zone; then rstfs=$ctr/$TESTFS else ds_path=$ctr/${ZONE_CTR}0 rstfs=$ds_path/$TESTFS fi rstfssnap=$rstfs@$TESTSNAP snapdir=".zfs/snapshot/$TESTSNAP" origfile=$TESTDIR/$TESTFILE1 rstfile=/$rstfs/$TESTFILE1 origsnapfile=$TESTDIR/$snapdir/$TESTFILE1 rstsnapfile=/$rstfs/$snapdir/$TESTFILE1 stream=$TEST_BASE_DIR/streamfile.$$ set -A props "compression" "checksum" "recordsize" set -A propval "on lzjb" "on fletcher2 fletcher4 sha256" \ "512 1k 4k 8k 16k 32k 64k 128k" #Create a dataset to receive the send stream log_must zfs create $ctr typeset -i i=0 while (( i < ${#props[*]} )) do for value in ${propval[i]} do do_testing ${props[i]} $value done (( i = i + 1 )) done log_pass "'zfs send' generates streams with a property setup as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_003_pos.ksh index 0b55254f75d6..caa84886fa12 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_003_pos.ksh @@ -1,69 +1,69 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs send -i' can deal with abbreviated snapshot name. # # STRATEGY: # 1. Create pool, fs and two snapshots. # 2. Make sure 'zfs send -i' support abbreviated snapshot name. # verify_runnable "both" function cleanup { - datasetexists $snap1 && log_must zfs destroy $snap1 - datasetexists $snap2 && log_must zfs destroy $snap2 + datasetexists $snap1 && destroy_dataset $snap1 + datasetexists $snap2 && destroy_dataset $snap2 } log_assert "'zfs send -i' can deal with abbreviated snapshot name." log_onexit cleanup snap1=$TESTPOOL/$TESTFS@snap1; snap2=$TESTPOOL/$TESTFS@snap2 set -A args "$snap1 $snap2" \ "${snap1##*@} $snap2" "@${snap1##*@} $snap2" log_must zfs snapshot $snap1 log_must zfs snapshot $snap2 typeset -i i=0 while (( i < ${#args[*]} )); do log_must eval "zfs send -i ${args[i]} >$TEST_BASE_DIR/devnull" (( i += 1 )) done log_pass "'zfs send -i' deal with abbreviated snapshot name passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_004_neg.ksh index dfa9fc251d6b..af10e3a11faf 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_004_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_004_neg.ksh @@ -1,109 +1,108 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib # # DESCRIPTION: # Verify 'zfs send' fails with malformed parameters. # # STRATEGY: # 1. Define malformed parameters in array # 2. Feed the parameters to 'zfs send' # 3. Verify the result # verify_runnable "both" function cleanup { typeset snap f for snap in $snap1 $snap2 $snap3; do - snapexists $snap && \ - log_must zfs destroy -f $snap + snapexists $snap && destroy_dataset $snap -f done for f in $tmpfile1 $tmpfile2; do if [[ -e $f ]]; then rm -f $f fi done } fs=$TESTPOOL/$TESTFS snap1=$fs@snap1 snap2=$fs@snap2 snap3=$fs@snap3 set -A badargs \ "" "$TESTPOOL" "$TESTFS" "$fs" "$fs@nonexistent_snap" "?" \ "$snap1/blah" "$snap1@blah" "-i" "-x" "-i $fs" \ "-x $snap1 $snap2" "-i $snap1" \ "-i $snap2 $snap1" "$snap1 $snap2" "-i $snap1 $snap2 $snap3" \ "-ii $snap1 $snap2" "-iii $snap1 $snap2" " -i $snap2 $snap1/blah" \ "-i $snap2/blah $snap1" \ "-i $snap2/blah $snap1/blah" \ "-i $snap1 blah@blah" \ "-i blah@blah $snap1" \ "-i $snap1 ${snap2##*@}" "-i $snap1 @${snap2##*@}" \ "-i ${snap1##*@} ${snap2##*@}" "-i @${snap1##*@} @${snap2##*@}" \ "-i ${snap1##*@} $snap2/blah" "-i @${snap1##*@} $snap2/blah" \ "-i @@${snap1##*@} $snap2" "-i $snap1 -i $snap1 $snap2" \ "-i snap1 snap2" "-i $snap1 snap2" \ "-i $snap1 $snap2 -i $snap1 $snap2" \ "-i snap1 $snap2 -i snap1 $snap2" log_assert "Verify that invalid parameters to 'zfs send' are caught." log_onexit cleanup log_must zfs snapshot $snap1 tmpfile1=$TESTDIR/testfile1.$$ log_must touch $tmpfile1 log_must zfs snapshot $snap2 tmpfile2=$TESTDIR/testfile2.$$ log_must touch $tmpfile2 log_must zfs snapshot $snap3 typeset -i i=0 while (( i < ${#badargs[*]} )) do log_mustnot eval "zfs send ${badargs[i]} >$TEST_BASE_DIR/devnull" (( i = i + 1 )) done #Testing zfs send fails by send backup stream to terminal for arg in "$snap1" "-i $snap1 $snap2"; do log_mustnot eval "zfs send $arg >/dev/console" done log_pass "Invalid parameters to 'zfs send' are caught as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_005_pos.ksh index c9e37cbbad8e..c4ab7a6212bc 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_005_pos.ksh @@ -1,66 +1,66 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs send -R' can send from read-only imported pool. It needs to # detect that the pool is read-only and not try to place holds on # datasets being sent. # # STRATEGY: # 1. Create a recursive snapshot on the whole pool. # 2. 'zfs send -R' the recursive snapshots. # verify_runnable "both" function cleanup { poolexists $TESTPOOL && log_must_busy zpool export $TESTPOOL log_must zpool import $TESTPOOL datasetexists $TESTPOOL@snap && \ - log_must zfs destroy -r $TESTPOOL@snap + destroy_dataset $TESTPOOL@snap -r } log_assert "'zfs send -R' can send from read-only pools" log_onexit cleanup log_must zfs snapshot -r $TESTPOOL@snap log_must zpool export $TESTPOOL log_must zpool import -o readonly=on $TESTPOOL log_must eval "zfs send -R $TESTPOOL@snap >$TEST_BASE_DIR/devnull" log_pass "'zfs send -R' can send from read-only pools" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted.ksh index 1e63b29ade1f..a4c332d47dfc 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted.ksh @@ -1,76 +1,76 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017, Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # ZFS should perform unencrypted sends of encrypted datasets, unless the '-p' # or '-R' options are specified. # # STRATEGY: # 1. Create an encrypted dataset # 6. Create a child encryption root # 2. Snapshot the dataset # 3. Attempt a send # 4. Attempt a send with properties # 5. Attempt a replication send # 7. Unmount the parent and unload its key # 8. Attempt a send of the parent dataset # 9. Attempt a send of the child encryption root # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r } log_onexit cleanup log_assert "ZFS should perform unencrypted sends of encrypted datasets, " \ "unless the '-p' or '-R' options are specified" typeset passphrase="password" typeset passphrase1="password1" typeset snap="$TESTPOOL/$TESTFS1@snap" log_must eval "echo $passphrase | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1" log_must eval "echo $passphrase1 | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1/child" log_must zfs snapshot -r $snap log_must eval "zfs send $snap >$TEST_BASE_DIR/devnull" log_mustnot eval "zfs send -p $snap >$TEST_BASE_DIR/devnull" log_mustnot eval "zfs send -R $snap >$TEST_BASE_DIR/devnull" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_mustnot eval "zfs send $snap >$TEST_BASE_DIR/devnull" log_must eval "zfs send $TESTPOOL/$TESTFS1/child@snap >$TEST_BASE_DIR/devnull" log_pass "ZFS performs unencrypted sends of encrypted datasets, unless the" \ "'-p' or '-R' options are specified" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted_unloaded.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted_unloaded.ksh index 9d59494fc635..f268f7b38d4d 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted_unloaded.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_encrypted_unloaded.ksh @@ -1,59 +1,59 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017, Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # ZFS should not perform unencrypted sends from encrypted datasets # with unloaded keys. # # STRATEGY: # 1. Create an encrypted dataset # 2. Snapshot the dataset # 3. Unload the dataset key # 4. Verify sending the stream fails # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r } log_onexit cleanup log_assert "ZFS should not perform unencrypted sends from encrypted datasets" \ "with unloaded keys." typeset passphrase="password" typeset snap="$TESTPOOL/$TESTFS1@snap" log_must eval "echo $passphrase | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1" log_must zfs snapshot $snap log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_mustnot eval "zfs send $snap >$TEST_BASE_DIR/devnull" log_pass "ZFS does not perform unencrypted sends from encrypted datasets" \ "with unloaded keys." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_raw.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_raw.ksh index 065eea3ebd86..03c2e78673d8 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_raw.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_raw.ksh @@ -1,79 +1,77 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017, Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # ZFS should perform raw sends of datasets. # # STRATEGY: # 1. Create an encrypted dataset # 2. Snapshot the default dataset and the encrypted dataset # 3. Attempt a raw send of both datasets # 4. Attempt a raw send with properties of both datasets # 5. Attempt a raw replication send of both datasets # 6. Unmount and unload the encrypted dataset key # 7. Attempt a raw send of the encrypted dataset # verify_runnable "both" function cleanup { - snapexists $snap && \ - log_must zfs destroy $snap - + snapexists $snap && destroy_dataset $snap datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r } log_onexit cleanup log_assert "ZFS should perform raw sends of datasets" typeset passphrase="password" typeset snap="$TESTPOOL/$TESTFS@snap" typeset snap1="$TESTPOOL/$TESTFS1@snap" log_must eval "echo $passphrase | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1" log_must zfs snapshot $snap log_must zfs snapshot $snap1 log_must eval "zfs send -w $snap >$TEST_BASE_DIR/devnull" log_must eval "zfs send -w $snap1 >$TEST_BASE_DIR/devnull" log_note "Verify ZFS can perform raw sends with properties" log_must eval "zfs send -wp $snap >$TEST_BASE_DIR/devnull" log_must eval "zfs send -wp $snap1 >$TEST_BASE_DIR/devnull" log_note "Verify ZFS can perform raw replication sends" log_must eval "zfs send -wR $snap >$TEST_BASE_DIR/devnull" log_must eval "zfs send -wR $snap1 >$TEST_BASE_DIR/devnull" log_note "Verify ZFS can perform a raw send of an encrypted datasets with" \ "its key unloaded" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must eval "zfs send -w $snap1 >$TEST_BASE_DIR/devnull" log_pass "ZFS performs raw sends of datasets" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_skip_missing.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_skip_missing.ksh index b367cef9c4a4..2e12d2534412 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_skip_missing.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_skip_missing.ksh @@ -1,77 +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 (c) 2016, loli10K. All rights reserved. # Copyright (c) 2021, Pablo Correa Gómez. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/cli_common.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_send/zfs_send.cfg # # DESCRIPTION: # Verify 'zfs send' will avoid sending replication send # streams when we're missing snapshots in the dataset # hierarchy, unless -s|--skip-missing provided # # STRATEGY: # 1. Create a parent and child fs and then only snapshot the parent # 2. Verify sending with replication will fail # 3. Verify sending with skip-missing will print a warning but succeed # verify_runnable "both" function cleanup { - snapexists $SNAP && log_must zfs destroy -f $SNAP + snapexists $SNAP && destroy_dataset $SNAP -f - datasetexists $PARENT && log_must zfs destroy -rf $PARENT + datasetexists $PARENT && destroy_dataset $PARENT -rf [[ -e $WARNF ]] && log_must rm -f $WARNF rm -f $TEST_BASE_DIR/devnull } log_assert "Verify 'zfs send -Rs' works as expected." log_onexit cleanup PARENT=$TESTPOOL/parent CHILD=$PARENT/child SNAP=$PARENT@snap WARNF=$TEST_BASE_DIR/warn.2 log_note "Verify 'zfs send -R' fails to generate replication stream"\ " for datasets created before" log_must zfs create $PARENT log_must zfs create $CHILD log_must zfs snapshot $SNAP log_mustnot eval "zfs send -R $SNAP >$TEST_BASE_DIR/devnull" log_note "Verify 'zfs send -Rs' warns about missing snapshots, "\ "but still succeeds" log_must eval "zfs send -Rs $SNAP 2> $WARNF >$TEST_BASE_DIR/devnull" log_must eval "[[ -s $WARNF ]]" log_pass "Verify 'zfs send -Rs' works as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_sparse.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_sparse.ksh index 4878c06108e4..aeb49afd7fc8 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_sparse.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_send/zfs_send_sparse.ksh @@ -1,83 +1,83 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright 2017, loli10K . All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # 'zfs send' should be able to send (big) sparse files correctly. # # STRATEGY: # 1. Create sparse files of various size # 2. Snapshot and send these sparse files # 3. Verify these files are received correctly and we don't trigger any issue # like the one described in https://github.com/openzfs/zfs/pull/6760 # verify_runnable "both" function cleanup { - datasetexists $SENDFS && log_must zfs destroy -r $SENDFS - datasetexists $RECVFS && log_must zfs destroy -r $RECVFS + datasetexists $SENDFS && destroy_dataset $SENDFS -r + datasetexists $RECVFS && destroy_dataset $RECVFS -r } # # Write 1 random byte at $offset of "source" file in $sendfs dataset # Snapshot and send $sendfs dataset to $recvfs # Compare the received file with its source # function write_compare_files # { typeset sendfs="$1" typeset recvfs="$2" typeset offset="$3" # create source filesystem log_must zfs create $sendfs # write sparse file sendfile="$(get_prop mountpoint $sendfs)/data.bin" log_must dd if=/dev/urandom of=$sendfile bs=1 count=1 seek=$offset # send/receive the file log_must zfs snapshot $sendfs@snap log_must eval "zfs send $sendfs@snap | zfs receive $recvfs" # compare sparse files recvfile="$(get_prop mountpoint $recvfs)/data.bin" log_must cmp $sendfile $recvfile $offset $offset sendsz=$(stat_size $sendfile) recvsz=$(stat_size $recvfile) if [[ $sendsz -ne $recvsz ]]; then log_fail "$sendfile ($sendsz) and $recvfile ($recvsz) differ." fi # cleanup - log_must zfs destroy -r $sendfs - log_must zfs destroy -r $recvfs + destroy_dataset $sendfs -r + destroy_dataset $recvfs -r } log_assert "'zfs send' should be able to send (big) sparse files correctly." log_onexit cleanup SENDFS="$TESTPOOL/sendfs" RECVFS="$TESTPOOL/recvfs" OFF_T_MAX="$(echo '2 ^ 40 * 8 - 1' | bc)" for i in {1..60}; do offset=$(echo "2 ^ $i" | bc) [[ is_32bit ]] && [[ $offset -ge $OFF_T_MAX ]] && continue; write_compare_files $SENDFS $RECVFS $offset done log_pass "'zfs send' sends (big) sparse files correctly." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos.ksh index dd3397f01579..ac5fc8188f5a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_001_pos.ksh @@ -1,123 +1,122 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # Setting valid canmount to filesystem, it is successful. # Whatever is set to volume or snapshot, it is failed. # 'zfs set canmount=on|off ' # # STRATEGY: # 1. Setup a pool and create fs, volume, snapshot clone within it. # 2. Loop all the valid mountpoint value. # 3. Check the return value. # verify_runnable "both" set -A dataset_pos \ "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE" if is_global_zone ; then set -A dataset_neg \ "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \ "$TESTPOOL/$TESTVOL@$TESTSNAP" "$TESTPOOL/$TESTCLONE1" else set -A dataset_neg \ "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP" fi set -A values "on" "off" function cleanup { - if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then - log_must zfs destroy -R $TESTPOOL/$TESTFS@$TESTSNAP - fi - if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then - log_must zfs destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP - fi + snapexists $TESTPOOL/$TESTFS@$TESTSNAP && \ + destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP -R + + snapexists $TESTPOOL/$TESTVOL@$TESTSNAP && \ + destroy_dataset $TESTPOOL/$TESTVOL@$TESTSNAP -R [[ -n $old_ctr_canmount ]] && \ log_must zfs set canmount=$old_ctr_canmount $TESTPOOL/$TESTCTR [[ -n $old_fs_canmount ]] && \ log_must zfs set canmount=$old_fs_canmount $TESTPOOL/$TESTFS zfs unmount -a > /dev/null 2>&1 log_must zfs mount -a } log_assert "Setting a valid property of canmount to file system, it must be successful." log_onexit cleanup typeset old_fs_canmount="" old_ctr_canmount="" old_fs_canmount=$(get_prop canmount $TESTPOOL/$TESTFS) [[ $? != 0 ]] && \ log_fail "Get the $TESTPOOL/$TESTFS canmount error." old_ctr_canmount=$(get_prop canmount $TESTPOOL/$TESTCTR) [[ $? != 0 ]] && \ log_fail "Get the $TESTPOOL/$TESTCTR canmount error." log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP log_must zfs snapshot $TESTPOOL/$TESTVOL@$TESTSNAP log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE log_must zfs clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1 for dataset in "${dataset_pos[@]}" ; do for value in "${values[@]}" ; do set_n_check_prop "$value" "canmount" "$dataset" if [[ $value == "off" ]]; then log_mustnot ismounted $dataset log_mustnot zfs mount $dataset log_mustnot ismounted $dataset else if ! ismounted $dataset ; then log_must zfs mount $dataset fi log_must ismounted $dataset fi done done for dataset in "${dataset_neg[@]}" ; do for value in "${values[@]}" ; do set_n_check_prop "$value" "canmount" \ "$dataset" "false" log_mustnot ismounted $dataset done done log_pass "Setting canmount to filesystem pass." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh index 1aeee44e044e..55c71f6ca33a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_002_pos.ksh @@ -1,161 +1,160 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # Setting valid canmount to filesystem, it is successful. # Whatever is set to volume or snapshot, it is failed. # 'zfs set canmount=noauto ' # # STRATEGY: # 1. Setup a pool and create fs, volume, snapshot clone within it. # 2. Set canmount=noauto for each dataset and check the return value # and check if it still can be mounted by mount -a or shared by # share -a # 3. mount each dataset(except volume) to see if it can be mounted. # 4. verify that a mounted dataset can be shared by share -a. # verify_runnable "both" set -A dataset_pos \ "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTCLONE" if is_global_zone ; then set -A dataset_neg \ "$TESTPOOL/$TESTVOL" "$TESTPOOL/$TESTFS@$TESTSNAP" \ "$TESTPOOL/$TESTVOL@$TESTSNAP" "$TESTPOOL/$TESTCLONE1" else set -A dataset_neg \ "$TESTPOOL/$TESTFS@$TESTSNAP" "$TESTPOOL/$TESTVOL@$TESTSNAP" fi function cleanup { i=0 while (( i < ${#dataset_pos[*]} )); do ds=${dataset_pos[i]} if datasetexists $ds; then log_must zfs set mountpoint=${old_mnt[i]} $ds log_must zfs set canmount=${old_canmount[i]} $ds fi (( i = i + 1 )) done ds=$TESTPOOL/$TESTCLONE if datasetexists $ds; then mntp=$(get_prop mountpoint $ds) - log_must zfs destroy $ds + destroy_dataset $ds if [[ -d $mntp ]]; then rm -fr $mntp fi fi - if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then - log_must zfs destroy -R $TESTPOOL/$TESTFS@$TESTSNAP - fi - if snapexists $TESTPOOL/$TESTVOL@$TESTSNAP ; then - log_must zfs destroy -R $TESTPOOL/$TESTVOL@$TESTSNAP - fi + snapexists $TESTPOOL/$TESTFS@$TESTSNAP && \ + destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP -R + + snapexists $TESTPOOL/$TESTVOL@$TESTSNAP && \ + destroy_dataset $TESTPOOL/$TESTVOL@$TESTSNAP -R zfs unmount -a > /dev/null 2>&1 log_must zfs mount -a if [[ -d $tmpmnt ]]; then rm -fr $tmpmnt fi } log_assert "Setting canmount=noauto to file system, it must be successful." log_onexit cleanup set -A old_mnt set -A old_canmount set -A old_sharenfs typeset tmpmnt=/tmpmount$$ typeset ds log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP log_must zfs snapshot $TESTPOOL/$TESTVOL@$TESTSNAP log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE log_must zfs clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1 typeset -i i=0 while (( i < ${#dataset_pos[*]} )); do ds=${dataset_pos[i]} old_mnt[i]=$(get_prop mountpoint $ds) old_canmount[i]=$(get_prop canmount $ds) old_sharenfs[i]=$(get_prop sharenfs $ds) (( i = i + 1 )) done i=0 while (( i < ${#dataset_pos[*]} )) ; do dataset=${dataset_pos[i]} set_n_check_prop "noauto" "canmount" "$dataset" log_must zfs set mountpoint=$tmpmnt $dataset log_must zfs set sharenfs=on $dataset if ismounted $dataset; then zfs unmount -a > /dev/null 2>&1 log_must mounted $dataset log_must zfs unmount $dataset log_must unmounted $dataset log_must zfs mount -a log_must unmounted $dataset log_must zfs share -a log_mustnot is_exported $tmpmnt else log_must zfs mount -a log_must unmounted $dataset zfs unmount -a > /dev/null 2>&1 log_must unmounted $dataset fi log_must zfs mount $dataset log_must mounted $dataset log_must zfs share -a log_must is_exported $tmpmnt log_must zfs set sharenfs="${old_sharenfs[i]}" $dataset log_must zfs set canmount="${old_canmount[i]}" $dataset log_must zfs set mountpoint="${old_mnt[i]}" $dataset (( i = i + 1 )) done for dataset in "${dataset_neg[@]}" ; do set_n_check_prop "noauto" "canmount" "$dataset" "false" log_mustnot ismounted $dataset done log_pass "Setting canmount=noauto to filesystem pass." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh index a11cfb40884b..e4664d03b43c 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/canmount_003_pos.ksh @@ -1,111 +1,110 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # While canmount=noauto and the dataset is mounted, # zfs must not attempt to unmount it. # # STRATEGY: # 1. Setup a pool and create fs, volume, snapshot clone within it. # 2. Set canmount=noauto for each dataset and check the return value # and check if it still can not be unmounted when the dataset is mounted # verify_runnable "both" set -A dataset_pos "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCLONE" function cleanup { i=0 cd $pwd while (( i < ${#dataset_pos[*]} )); do ds=${dataset_pos[i]} if datasetexists $ds; then log_must zfs set mountpoint=${old_mnt[i]} $ds log_must zfs set canmount=${old_canmount[i]} $ds fi (( i = i + 1 )) done ds=$TESTPOOL/$TESTCLONE if datasetexists $ds; then mntp=$(get_prop mountpoint $ds) - log_must zfs destroy $ds + destroy_dataset $ds if [[ -d $mntp ]]; then log_must rm -fr $mntp fi fi - if snapexists $TESTPOOL/$TESTFS@$TESTSNAP ; then - log_must zfs destroy -R $TESTPOOL/$TESTFS@$TESTSNAP - fi + snapexists $TESTPOOL/$TESTFS@$TESTSNAP && \ + destroy_dataset $TESTPOOL/$TESTFS@$TESTSNAP -R zfs unmount -a > /dev/null 2>&1 log_must zfs mount -a } log_assert "While canmount=noauto and the dataset is mounted,"\ " zfs must not attempt to unmount it" log_onexit cleanup set -A old_mnt set -A old_canmount typeset ds typeset pwd=$PWD log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE typeset -i i=0 while (( i < ${#dataset_pos[*]} )); do ds=${dataset_pos[i]} old_mnt[i]=$(get_prop mountpoint $ds) old_canmount[i]=$(get_prop canmount $ds) (( i = i + 1 )) done i=0 while (( i < ${#dataset_pos[*]} )) ; do dataset=${dataset_pos[i]} if ismounted $dataset; then log_must cd ${old_mnt[i]} set_n_check_prop "noauto" "canmount" "$dataset" log_must mounted $dataset fi (( i = i + 1 )) done log_pass "Setting canmount=noauto to filesystem while dataset busy pass." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh index 22fb0a77c9ab..4adac420f748 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/readonly_001_pos.ksh @@ -1,160 +1,160 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2014, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # Setting readonly on a dataset, it should keep the dataset as readonly. # # STRATEGY: # 1. Create pool, then create filesystem and volume within it. # 2. Setting readonly to each dataset. # 3. Check the return value and make sure it is 0. # 4. Verify the stuff under mountpoint is readonly. # verify_runnable "both" function cleanup { for dataset in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL ; do snapexists ${dataset}@$TESTSNAP && \ - log_must zfs destroy -R ${dataset}@$TESTSNAP + destroy_dataset ${dataset}@$TESTSNAP -R done } function initial_dataset # $1 dataset { typeset dataset=$1 typeset fstype=$(get_prop type $dataset) if [[ $fstype == "filesystem" ]] ; then typeset mtpt=$(get_prop mountpoint $dataset) log_must touch $mtpt/$TESTFILE0 log_must mkdir -p $mtpt/$TESTDIR0 fi } function cleanup_dataset # $1 dataset { typeset dataset=$1 typeset fstype=$(get_prop type $dataset) if [[ $fstype == "filesystem" ]] ; then typeset mtpt=$(get_prop mountpoint $dataset) log_must rm -f $mtpt/$TESTFILE0 log_must rm -rf $mtpt/$TESTDIR0 fi } function verify_readonly # $1 dataset, $2 on|off { typeset dataset=$1 typeset value=$2 if datasetnonexists $dataset ; then log_note "$dataset does not exist!" return 1 fi typeset fstype=$(get_prop type $dataset) expect="log_must" if [[ $2 == "on" ]] ; then expect="log_mustnot" fi case $fstype in filesystem) typeset mtpt=$(get_prop mountpoint $dataset) $expect touch $mtpt/$TESTFILE1 $expect mkdir -p $mtpt/$TESTDIR1 $expect eval "echo 'y' | rm $mtpt/$TESTFILE0" $expect rmdir $mtpt/$TESTDIR0 if [[ $expect == "log_must" ]] ; then log_must eval "echo 'y' | rm $mtpt/$TESTFILE1" log_must rmdir $mtpt/$TESTDIR1 log_must touch $mtpt/$TESTFILE0 log_must mkdir -p $mtpt/$TESTDIR0 fi ;; volume) $expect eval "new_fs \ ${ZVOL_DEVDIR}/$dataset > /dev/null 2>&1" ;; *) ;; esac return 0 } log_onexit cleanup log_assert "Setting a valid readonly property on a dataset succeeds." typeset all_datasets log_must zfs mount -a log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP log_must zfs clone $TESTPOOL/$TESTFS@$TESTSNAP $TESTPOOL/$TESTCLONE if is_global_zone ; then log_must zfs snapshot $TESTPOOL/$TESTVOL@$TESTSNAP log_must zfs clone $TESTPOOL/$TESTVOL@$TESTSNAP $TESTPOOL/$TESTCLONE1 all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL " all_datasets+="$TESTPOOL/$TESTCLONE $TESTPOOL/$TESTCLONE1" else all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTCLONE" fi for dataset in $all_datasets; do for value in on off; do set_n_check_prop "off" "readonly" "$dataset" initial_dataset $dataset set_n_check_prop "$value" "readonly" "$dataset" verify_readonly $dataset $value set_n_check_prop "off" "readonly" "$dataset" cleanup_dataset $dataset done done log_pass "Setting a valid readonly property on a dataset succeeds." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/snapdir_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/snapdir_001_pos.ksh index 079fc770a6fe..083a6b1f464f 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/snapdir_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/snapdir_001_pos.ksh @@ -1,112 +1,111 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # Setting a valid snapdir on a dataset, it should be successful. # # STRATEGY: # 1. Create pool, then create filesystem and volume within it. # 2. Create a snapshot for each dataset. # 3. Setting different valid snapdir to each dataset. # 4. Check the return value and make sure it is 0. # 5. Verify .zfs directory is hidden|visible according to the snapdir setting. # verify_runnable "both" function cleanup { for dataset in $all_datasets; do - snapexists ${dataset}@snap && \ - log_must zfs destroy ${dataset}@snap + snapexists ${dataset}@snap && destroy_dataset ${dataset}@snap done } function verify_snapdir_visible # $1 dataset, $2 hidden|visible { typeset dataset=$1 typeset value=$2 typeset mtpt=$(get_prop mountpoint $dataset) typeset name for name in `ls -a $mtpt`; do if [[ $name == ".zfs" ]]; then if [[ $value == "visible" ]]; then return 0 else return 1 fi fi done if [[ $value == "visible" ]]; then return 1 else return 0 fi } typeset all_datasets if is_global_zone ; then all_datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL" else all_datasets="$TESTPOOL $TESTPOOL/$TESTFS" fi log_onexit cleanup for dataset in $all_datasets; do log_must zfs snapshot ${dataset}@snap done log_assert "Setting a valid snapdir property on a dataset succeeds." for dataset in $all_datasets; do for value in hidden visible; do if [[ $dataset == "$TESTPOOL/$TESTVOL" ]] ; then set_n_check_prop "$value" "snapdir" \ "$dataset" "false" else set_n_check_prop "$value" "snapdir" \ "$dataset" verify_snapdir_visible $dataset $value [[ $? -eq 0 ]] || \ log_fail "$dataset/.zfs is not $value as expect." fi done done log_pass "Setting a valid snapdir property on a dataset succeeds." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_004_pos.ksh index 1d197fa25fbd..bd11ea088333 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/user_property_004_pos.ksh @@ -1,101 +1,99 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # User property has no effect to snapshot until 'Snapshot properties' supported. # # STRATEGY: # 1. Verify user properties could be transformed by 'zfs snapshot' # 2. Verify user properties could be set upon snapshot. # verify_runnable "both" function cleanup { for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do typeset fssnap=$fs@snap - if datasetexists $fssnap ; then - log_must zfs destroy -f $fssnap - fi + datasetexists $fssnap && destroy_dataset $fssnap -f done cleanup_user_prop $TESTPOOL } function nonexist_user_prop { typeset user_prop=$1 typeset dtst=$2 typeset source=$(get_source $user_prop $dtst) typeset value=$(get_prop $user_prop $dtst) if [[ $source == '-' && $value == '-' ]]; then return 0 else return 1 fi } log_assert "User property has no effect to snapshot until 'Snapshot properties' supported." log_onexit cleanup typeset snap_property= zpool upgrade -v | grep "Snapshot properties" > /dev/null 2>&1 if (( $? == 0 )) ; then snap_property="true" fi for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do typeset fssnap=$fs@snap prop_name=$(valid_user_property 10) value=$(user_property_value 16) log_must eval "zfs set $prop_name='$value' $fs" log_must eval "check_user_prop $fs $prop_name '$value'" log_must zfs snapshot $fssnap if [[ -n $snap_property ]] ; then log_mustnot nonexist_user_prop $prop_name $fssnap log_must eval "zfs set $prop_name='$value' $fssnap" log_mustnot nonexist_user_prop $prop_name $fssnap else log_must nonexist_user_prop $prop_name $fssnap log_mustnot eval "zfs set $prop_name='$value' $fssnap" log_must nonexist_user_prop $prop_name $fssnap fi done log_pass "User properties has effect upon snapshot." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_003_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_003_neg.ksh index 102e8874294f..fd5f7f285f5b 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_003_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_003_neg.ksh @@ -1,77 +1,76 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # 'zfs set mountpoint/sharenfs' should fail when the mountpoint is invalid # # STRATEGY: # 1. Create invalid scenarios # 2. Run zfs set mountpoint/sharenfs with invalid value # 3. Verify that zfs set returns expected errors # verify_runnable "both" function cleanup { if [ -e $badpath ]; then rm -f $badpath fi - if datasetexists $TESTPOOL/foo; then - log_must zfs destroy $TESTPOOL/foo - fi + + datasetexists $TESTPOOL/foo && destroy_dataset $TESTPOOL/foo } log_assert "'zfs set mountpoint/sharenfs' fails with invalid scenarios" log_onexit cleanup badpath=$TEST_BASE_DIR/foo1.$$ touch $badpath longpath=$(gen_dataset_name 1030 "abcdefg") log_must zfs create -o mountpoint=legacy $TESTPOOL/foo # Do the negative testing about "property may be set but unable to remount filesystem" log_mustnot eval "zfs set mountpoint=$badpath $TESTPOOL/foo >/dev/null 2>&1" # Do the negative testing about "property may be set but unable to reshare filesystem" log_mustnot eval "zfs set sharenfs=on $TESTPOOL/foo >/dev/null 2>&1" # Do the negative testing about "sharenfs property can not be set to null" log_mustnot eval "zfs set sharenfs= $TESTPOOL/foo >/dev/null 2>&1" # Do the too long pathname testing (>1024) log_mustnot eval "zfs set mountpoint=/$longpath $TESTPOOL/foo >/dev/null 2>&1" log_pass "'zfs set mountpoint/sharenfs' fails with invalid scenarios as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_keylocation.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_keylocation.ksh index 0d2e7ab8f298..d8a2fcbdf9b3 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_keylocation.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_set/zfs_set_keylocation.ksh @@ -1,101 +1,102 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # Unencrypted datasets should only allow keylocation of 'none', encryption # roots should only allow keylocation of 'prompt' and file URI, and encrypted # child datasets should not be able to change their keylocation. # # STRATEGY: # 1. Verify the key location of the default dataset is 'none' # 2. Attempt to change the key location of the default dataset # 3. Create an encrypted dataset using a key file # 4. Attempt to change the key location of the encrypted dataset to 'none', # an invalid location, its current location, and 'prompt' # 5. Attempt to reload the encrypted dataset key using the new key location # 6. Create a encrypted child dataset # 7. Verify the key location of the child dataset is 'none' # 8. Attempt to change the key location of the child dataset # 9. Verify the key location of the child dataset has not changed # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r + cleanup_https } log_onexit cleanup log_assert "Key location can only be 'prompt' or a file path for encryption" \ "roots, and 'none' for unencrypted volumes" log_must eval "echo $PASSPHRASE > /$TESTPOOL/pkey" log_must verify_keylocation $TESTPOOL/$TESTFS "none" log_must zfs set keylocation=none $TESTPOOL/$TESTFS log_mustnot zfs set keylocation=/$TESTPOOL/pkey $TESTPOOL/$TESTFS log_mustnot zfs set keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS log_must verify_keylocation $TESTPOOL/$TESTFS "none" 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 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. 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" log_must zfs set keylocation=prompt $TESTPOOL/$TESTFS1 log_must verify_keylocation $TESTPOOL/$TESTFS1 "prompt" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must rm /$TESTPOOL/pkey log_must eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS1" log_must zfs mount $TESTPOOL/$TESTFS1 log_must zfs create $TESTPOOL/$TESTFS1/child log_must verify_keylocation $TESTPOOL/$TESTFS1/child "none" log_mustnot zfs set keylocation=none $TESTPOOL/$TESTFS1/child log_mustnot zfs set keylocation=prompt $TESTPOOL/$TESTFS1/child log_mustnot zfs set keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1/child log_mustnot zfs set keylocation=/$TESTPOOL/pkey $TESTPOOL/$TESTFS1/child log_must verify_keylocation $TESTPOOL/$TESTFS1/child "none" log_pass "Key location can only be 'prompt' or a file path for encryption" \ "roots, and 'none' for unencrypted volumes" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh index fefeb1b1cbd5..6d4396aa1912 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_001_pos.ksh @@ -1,160 +1,159 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016, 2020 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that 'zfs set sharenfs' and 'zfs share' shares a given dataset. # # STRATEGY: # 1. Invoke 'zfs set sharenfs'. # 2. Verify that the file system is shared. # 3. Invoke 'zfs share'. # 4. Verify that the file system is shared. # 5. Verify that a shared filesystem cannot be shared again. # 6. Verify that share -a succeeds. # verify_runnable "global" set -A fs \ "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \ "$TESTDIR2" "$TESTPOOL/$TESTFS-clone" \ "$TESTDIR" "$TESTPOOL/$TESTFS" function cleanup { typeset -i i=0 while (( i < ${#fs[*]} )); do log_must zfs set sharenfs=off ${fs[((i+1))]} unshare_fs ${fs[i]} ((i = i + 2)) done if mounted $TESTPOOL/$TESTFS-clone; then log_must zfs unmount $TESTDIR2 fi datasetexists $TESTPOOL/$TESTFS-clone && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS-clone + destroy_dataset $TESTPOOL/$TESTFS-clone -f - if snapexists "$TESTPOOL/$TESTFS@snapshot"; then - log_must zfs destroy -f $TESTPOOL/$TESTFS@snapshot - fi + snapexists "$TESTPOOL/$TESTFS@snapshot" && \ + destroy_dataset $TESTPOOL/$TESTFS@snapshot -f log_must zfs share -a } # # Main test routine. # # Given a mountpoint and file system this routine will attempt # share the mountpoint and then verify it has been shared. # function test_share # mntp filesystem { typeset mntp=$1 typeset filesystem=$2 not_shared $mntp || \ log_fail "File system $filesystem is already shared." log_must zfs set sharenfs=on $filesystem is_shared $mntp || \ log_fail "File system $filesystem is not shared (set sharenfs)." # # Verify 'zfs share' works as well. # log_must zfs unshare $filesystem is_shared $mntp && \ log_fail "File system $filesystem is still shared." log_must zfs share $filesystem is_shared $mntp || \ log_fail "file system $filesystem is not shared (zfs share)." log_note "Sharing a shared file system fails." log_mustnot zfs share $filesystem } log_assert "Verify that 'zfs share' succeeds as root." log_onexit cleanup log_must zfs snapshot $TESTPOOL/$TESTFS@snapshot log_must zfs clone $TESTPOOL/$TESTFS@snapshot $TESTPOOL/$TESTFS-clone log_must zfs set mountpoint=$TESTDIR2 $TESTPOOL/$TESTFS-clone typeset -i i=0 while (( i < ${#fs[*]} )); do test_share ${fs[i]} ${fs[((i + 1))]} ((i = i + 2)) done log_note "Verify 'zfs share -a' succeeds." # # Unshare each of the file systems. # i=0 while (( i < ${#fs[*]} )); do unshare_fs ${fs[i]} ((i = i + 2)) done # # Try a zfs share -a and verify all file systems are shared. # log_must zfs share -a # # We need to unset __ZFS_POOL_EXCLUDE so that we include all file systems # in the os-specific zfs exports file. This will be reset by the next test. # unset __ZFS_POOL_EXCLUDE i=0 while (( i < ${#fs[*]} )); do is_shared ${fs[i]} || \ log_fail "File system ${fs[i]} is not shared (share -a)" is_exported ${fs[i]} || \ log_fail "File system ${fs[i]} is not exported (share -a)" ((i = i + 2)) done log_pass "'zfs share [ -a ] ' succeeds as root." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_004_pos.ksh index baa5f4e41695..6c48875f5268 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_004_pos.ksh @@ -1,96 +1,95 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_share/zfs_share.cfg # # DESCRIPTION: # Verify that a file system and its snapshot are shared. # # STRATEGY: # 1. Create a file system # 2. Set the sharenfs property on the file system # 3. Create a snapshot # 4. Verify that both are shared. # verify_runnable "global" function cleanup { - if snapexists $TESTPOOL/$TESTFS@snapshot; then - log_must zfs destroy $TESTPOOL/$TESTFS@snapshot - fi + snapexists $TESTPOOL/$TESTFS@snapshot && \ + destroy_dataset $TESTPOOL/$TESTFS@snapshot log_must zfs set sharenfs=off $TESTPOOL/$TESTFS log_must unshare_fs $TESTPOOL/$TESTFS } # # Main test routine. # # Given a mountpoint and file system this routine will attempt # share the mountpoint and then verify a snapshot of the mounpoint # is also shared. # function test_snap_share # mntp filesystem { typeset mntp=$1 typeset filesystem=$2 not_shared $mntp || \ log_fail "File system $filesystem is already shared." log_must zfs set sharenfs=on $filesystem is_shared $mntp || \ log_fail "File system $filesystem is not shared (set sharenfs)." log_must ls -l $mntp/$SNAPROOT/snapshot # # Verify 'zfs share' works as well. # log_must zfs unshare $filesystem log_must zfs share $filesystem is_shared $mntp || \ log_fail "file system $filesystem is not shared (zfs share)." log_must ls -l $mntp/$SNAPROOT/snapshot } log_assert "Verify that a file system and its snapshot are shared." log_onexit cleanup log_must zfs snapshot $TESTPOOL/$TESTFS@snapshot test_snap_share $TESTDIR $TESTPOOL/$TESTFS log_pass "A file system and its snapshot are both shared as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_006_pos.ksh index 6b06589b69e2..d5394017d780 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_006_pos.ksh @@ -1,105 +1,105 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that a dataset could not be shared but filesystems are shared. # # STRATEGY: # 1. Create a dataset and file system # 2. Set the sharenfs property on the dataset # 3. Verify that the dataset is unable be shared. # 4. Add a new file system to the dataset. # 5. Verify that the newly added file system be shared. # verify_runnable "global" function cleanup { log_must zfs set sharenfs=off $TESTPOOL/$TESTCTR if mounted $TESTDIR2; then log_must zfs unmount $TESTDIR2 fi datasetexists $TESTPOOL/$TESTCTR/$TESTFS2 && \ - log_must zfs destroy $TESTPOOL/$TESTCTR/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTCTR/$TESTFS2 typeset fs="" for fs in $mntp $TESTDIR1 $TESTDIR2 do log_must unshare_fs $fs done } # # Main test routine. # # Given a mountpoint and a dataset, this routine will set the # sharenfs property on the dataset and verify that dataset # is unable to be shared but the existing contained file systems # could be shared. # function test_ctr_share # mntp ctr { typeset mntp=$1 typeset ctr=$2 not_shared $mntp || \ log_fail "Mountpoint: $mntp is already shared." log_must zfs set sharenfs=on $ctr not_shared $mntp || \ log_fail "File system $mntp is shared (set sharenfs)." # # Add a new file system to the dataset and verify it is shared. # typeset mntp2=$TESTDIR2 log_must zfs create $ctr/$TESTFS2 log_must zfs set mountpoint=$mntp2 $ctr/$TESTFS2 is_shared $mntp2 || \ log_fail "File system $mntp2 was not shared (set sharenfs)." } log_assert "Verify that a dataset could not be shared, " \ "but its sub-filesystems could be shared." log_onexit cleanup typeset mntp=$(get_prop mountpoint $TESTPOOL/$TESTCTR) test_ctr_share $mntp $TESTPOOL/$TESTCTR log_pass "A dataset could not be shared, " \ "but its sub-filesystems could be shared as expect." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_011_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_011_pos.ksh index f75877ee89db..131b039e1cd2 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_011_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_011_pos.ksh @@ -1,89 +1,87 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that umount and destroy fail, and do not unshare the shared # file system # # STRATEGY: # 1. Share the filesystem via 'zfs set sharenfs'. # 2. Try umount failure, and verify that the file system is still shared. # 3. Try destroy failure, and verify that the file system is still shared. # verify_runnable "global" function cleanup { log_must cd $origdir log_must zfs set sharenfs=off $TESTPOOL/$TESTFS unshare_fs $TESTPOOL/$TESTFS - if snapexists "$TESTPOOL/$TESTFS@snapshot"; then - log_must zfs destroy -f $TESTPOOL/$TESTFS@snapshot - fi + snapexists "$TESTPOOL/$TESTFS@snapshot" && \ + destroy_dataset $TESTPOOL/$TESTFS@snapshot -f - if datasetexists $TESTPOOL/$TESTFS/fs2 ; then - log_must zfs destroy -f $TESTPOOL/$TESTFS/fs2 - fi + datasetexists $TESTPOOL/$TESTFS/fs2 && \ + destroy_dataset $TESTPOOL/$TESTFS/fs2 -f } log_assert "Verify that umount and destroy fail, and do not unshare the shared" \ "file system" log_onexit cleanup typeset origdir=$PWD # unmount fails will not unshare the shared filesystem log_must zfs set sharenfs=on $TESTPOOL/$TESTFS log_must is_shared $TESTDIR if cd $TESTDIR ; then log_mustnot zfs umount $TESTPOOL/$TESTFS else log_fail "cd $TESTDIR fails" fi log_must is_shared $TESTDIR # destroy fails will not unshare the shared filesystem log_must zfs create $TESTPOOL/$TESTFS/fs2 if cd $TESTDIR/fs2 ; then log_mustnot zfs destroy $TESTPOOL/$TESTFS/fs2 else log_fail "cd $TESTDIR/fs2 fails" fi log_must is_shared $TESTDIR/fs2 log_pass "Verify that umount and destroy fail, and do not unshare the shared" \ "file system" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_concurrent_shares.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_concurrent_shares.ksh index 762436678dcb..dbaaf39b65d4 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_concurrent_shares.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_share/zfs_share_concurrent_shares.ksh @@ -1,201 +1,201 @@ #!/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 (c) 2020 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that 'zfs set sharenfs=on', 'zfs share', and 'zfs unshare' can # run concurrently. The test creates 50 filesystem and 50 threads. # Each thread will run through the test strategy in parallel. # # STRATEGY: # 1. Verify that the file system is not shared. # 2. Enable the 'sharenfs' property # 3. Invoke 'zfs unshare' and verify filesystem is no longer shared # 4. Invoke 'zfs share'. # 4. Verify that the file system is shared. # 5. Verify that a shared filesystem cannot be shared again. # 6. Verify that share -a succeeds. # verify_runnable "global" function cleanup { wait for fs in $(seq 0 50) do log_must zfs set sharenfs=off $TESTPOOL/$TESTFS1/$fs log_must zfs set sharenfs=off $TESTPOOL/$TESTFS2/$fs log_must zfs set sharenfs=off $TESTPOOL/$TESTFS3/$fs unshare_fs $TESTPOOL/$TESTFS1/$fs unshare_fs $TESTPOOL/$TESTFS2/$fs unshare_fs $TESTPOOL/$TESTFS3/$fs if mounted $TESTPOOL/$TESTFS1/$fs; then log_must zfs unmount $TESTPOOL/$TESTFS1/$fs fi if mounted $TESTPOOL/$TESTFS2/$fs; then log_must zfs unmount $TESTPOOL/$TESTFS2/$fs fi if mounted $TESTPOOL/$TESTFS3/$fs; then log_must zfs unmount $TESTPOOL/$TESTFS3/$fs fi datasetexists $TESTPOOL/$TESTFS1/$fs && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1/$fs + destroy_dataset $TESTPOOL/$TESTFS1/$fs -f datasetexists $TESTPOOL/$TESTFS2/$fs && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS2/$fs + destroy_dataset $TESTPOOL/$TESTFS2/$fs -f datasetexists $TESTPOOL/$TESTFS3/$fs && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS3/$fs + destroy_dataset $TESTPOOL/$TESTFS3/$fs -f done log_must zfs share -a } function create_filesystems { for fs in $(seq 0 50) do log_must zfs create -p $TESTPOOL/$TESTFS1/$fs log_must zfs create -p $TESTPOOL/$TESTFS2/$fs log_must zfs create -p $TESTPOOL/$TESTFS3/$fs done } # # Main test routine. # # Given a file system this routine will attempt # share the mountpoint and then verify it has been shared. # function test_share # filesystem { typeset filesystem=$1 typeset mntp=$(get_prop mountpoint $filesystem) not_shared $mntp || \ log_fail "File system $filesystem is already shared." zfs set sharenfs=on $filesystem || \ log_fail "zfs set sharenfs=on $filesystem failed." is_shared $mntp || \ log_fail "File system $filesystem is not shared (set sharenfs)." # # Verify 'zfs share' works as well. # zfs unshare $filesystem || \ log_fail "zfs unshare $filesystem failed." is_shared $mntp && \ log_fail "File system $filesystem is still shared." zfs share $filesystem || \ log_fail "zfs share $filesystem failed." is_shared $mntp || \ log_fail "file system $filesystem is not shared (zfs share)." #log_note "Sharing a shared file system fails." zfs share $filesystem && \ log_fail "zfs share $filesystem did not fail" return 0 } # # Set the main process id so that we know to capture # failures from child processes and allow the parent process # to report the failure. # set_main_pid $$ log_assert "Verify that 'zfs share' succeeds as root." log_onexit cleanup create_filesystems child_pids=() for fs in $(seq 0 50) do test_share $TESTPOOL/$TESTFS1/$fs & child_pids+=($!) log_note "$TESTPOOL/$TESTFS1/$fs ==> $!" test_share $TESTPOOL/$TESTFS2/$fs & child_pids+=($!) log_note "$TESTPOOL/$TESTFS2/$fs ==> $!" test_share $TESTPOOL/$TESTFS3/$fs & child_pids+=($!) log_note "$TESTPOOL/$TESTFS3/$fs ==> $!" done wait_for_children "${child_pids[@]}" || log_fail "multithreaded share test failed" log_note "Verify 'zfs share -a' succeeds." # # Unshare each of the file systems. # child_pids=() for fs in $(seq 0 50) do unshare_fs $TESTPOOL/$TESTFS1/$fs & child_pids+=($!) unshare_fs $TESTPOOL/$TESTFS2/$fs & child_pids+=($!) unshare_fs $TESTPOOL/$TESTFS3/$fs & child_pids+=($!) done wait_for_children "${child_pids[@]}" || log_fail "multithreaded unshare failed" # # Try a zfs share -a and verify all file systems are shared. # log_must zfs share -a # # We need to unset __ZFS_POOL_EXCLUDE so that we include all file systems # in the os-specific zfs exports file. This will be reset by the next test. # unset __ZFS_POOL_EXCLUDE for fs in $(seq 0 50) do is_shared $TESTPOOL/$TESTFS1/$fs || \ log_fail "File system $TESTPOOL/$TESTFS1/$fs is not shared" is_shared $TESTPOOL/$TESTFS2/$fs || \ log_fail "File system $TESTPOOL/$TESTFS2/$fs is not shared" is_shared $TESTPOOL/$TESTFS3/$fs || \ log_fail "File system $TESTPOOL/$TESTFS3/$fs is not shared" is_exported $TESTPOOL/$TESTFS1/$fs || \ log_fail "File system $TESTPOOL/$TESTFS1/$fs is not exported" is_exported $TESTPOOL/$TESTFS2/$fs || \ log_fail "File system $TESTPOOL/$TESTFS2/$fs is not exported" is_exported $TESTPOOL/$TESTFS3/$fs || \ log_fail "File system $TESTPOOL/$TESTFS3/$fs is not exported" done log_pass "'zfs share [ -a ] ' succeeds as root." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh index 8708d8b62432..2b89af9e5a43 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_001_neg.ksh @@ -1,117 +1,117 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_snapshot/zfs_snapshot.cfg # # DESCRIPTION: # Try each 'zfs snapshot' with inapplicable scenarios to make sure # it returns an error. include: # * No arguments given. # * The argument contains invalid characters for the ZFS namesapec # * Leading slash in snapshot name # * The argument contains an empty component. # * Missing '@' delimiter. # * Multiple '@' delimiters in snapshot name. # * The snapshot already exist. # * Create snapshot upon the pool. # (Be removed since pool is treated as filesystem as well) # * Create snapshot upon a non-existent filesystem. # * Too many arguments. # # STRATEGY: # 1. Create an array of parameters # 2. For each parameter in the array, execute the sub-command # 3. Verify an error is returned. # verify_runnable "both" set -A args "" \ "$TESTPOOL/$TESTFS@blah*" "$TESTPOOL/$TESTFS@blah?" \ "$TESTPOOL/$TESTVOL@blah*" "$TESTPOOL/$TESTVOL@blah?" \ "/$TESTPOOL/$TESTFS@$TESTSNAP" "/$TESTPOOL/$TESTVOL@$TESTSNAP" \ "@$TESTSNAP" "$TESTPOOL/$TESTFS@" "$TESTPOOL/$TESTVOL@" \ "$TESTPOOL//$TESTFS@$TESTSNAP" "$TESTPOOL//$TESTVOL@$TESTSNAP" \ "$TESTPOOL/$TESTFS/$TESTSNAP" "$TESTPOOL/$TESTVOL/$TESTSNAP" \ "$TESTPOOL/$TESTFS@$TESTSNAP@$TESTSNAP1" \ "$TESTPOOL/$TESTVOL@$TESTSNAP@$TESTSNAP1" \ "$SNAPFS" "$SNAPFS1" \ "blah/blah@$TESTSNAP" function setup_all { log_note "Create snapshots and mount them..." for snap in $SNAPFS $SNAPFS1; do if ! snapexists $snap; then log_must zfs snapshot $snap fi done return 0 } function cleanup_all { typeset -i i=0 while (( i < ${#args[*]} )); do for snap in ${args[i]}; do - snapexists $snap && log_must zfs destroy -f $snap + snapexists $snap && destroy_dataset $snap -f done (( i = i + 1 )) done for mtpt in $SNAPDIR $SNAPDIR1; do [[ -d $mtpt ]] && log_must rm -rf $mtpt done return 0 } log_assert "Badly-formed 'zfs snapshot' with inapplicable scenarios " \ "should return an error." log_onexit cleanup_all setup_all typeset -i i=0 while (( i < ${#args[*]} )); do log_mustnot zfs snapshot ${args[i]} ((i = i + 1)) done log_pass "Badly formed 'zfs snapshot' with inapplicable scenarios " \ "fail as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh index 5d8b6e2750f5..4ae68d411dd0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_002_neg.ksh @@ -1,98 +1,97 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # "zfs snapshot -r" fails with invalid arguments or scenarios. # The invalid scenarios may include: # (1) The child filesystem already has snapshot with the same name # (2) The child volume already has snapshot with the same name # # STRATEGY: # 1. Create an array of invalid arguments # 2. Execute 'zfs snapshot -r' with each argument in the array, # 3. Verify an error is returned. # verify_runnable "both" function cleanup { typeset snap for snap in $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP \ $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP; do - snapexists $snap && \ - log_must zfs destroy $snap + snapexists $snap && destroy_dataset $snap done datasetexists $TESTPOOL/$TESTCTR/$TESTVOL && \ - log_must zfs destroy -rf $TESTPOOL/$TESTCTR/$TESTVOL + destroy_dataset $TESTPOOL/$TESTCTR/$TESTVOL -rf } log_assert "'zfs snapshot -r' fails with invalid arguments or scenarios. " log_onexit cleanup set -A args "" \ "$TESTPOOL/$TESTCTR@$TESTSNAP" "$TESTPOOL/$TESTCTR@blah?" \ "$TESTPOOL/$TESTCTR@blah*" "@$TESTSNAP" "$TESTPOOL/$TESTCTR@" \ "$TESTPOOL/$TESTFS/$TESTSNAP" "blah/blah@$TESTSNAP" \ "$TESTPOOL/$TESTCTR@$TESTSNAP@$TESTSNAP" # setup preparations log_must zfs snapshot $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP # testing typeset -i i=0 while (( i < ${#args[*]} )); do log_mustnot zfs snapshot -r ${args[i]} ((i = i + 1)) done # Testing the invalid scenario: the child volume already has an # identical name snapshot, zfs snapshot -r should fail when # creating snapshot with -r for the parent log_must zfs destroy $TESTPOOL/$TESTCTR/$TESTFS1@$TESTSNAP if is_global_zone; then log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTCTR/$TESTVOL else log_must zfs create $TESTPOOL/$TESTCTR/$TESTVOL fi log_must zfs snapshot $TESTPOOL/$TESTCTR/$TESTVOL@$TESTSNAP log_mustnot zfs snapshot -r $TESTPOOL/$TESTCTR@$TESTSNAP log_pass "'zfs snapshot -r' fails with invalid arguments or scenarios as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh index 96121f1c136d..16926a48ddc4 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_004_neg.ksh @@ -1,96 +1,92 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify recursive snapshotting could not break ZFS. # # STRATEGY: # 1. Create deeply-nested filesystems until it is too long to create snap # 2. Verify zfs snapshot -r pool@snap will not break ZFS # verify_runnable "both" function cleanup { - if datasetexists $initfs ; then - log_must zfs destroy -rf $initfs - fi + datasetexists $initfs && destroy_dataset $initfs -rf } log_assert "Verify recursive snapshotting could not break ZFS." log_onexit cleanup initfs=$TESTPOOL/$TESTFS/$TESTFS basefs=$initfs typeset -i ret=0 len snaplen while ((ret == 0)); do zfs create $basefs zfs snapshot $basefs@snap1 ret=$? if ((ret != 0)); then len=$(echo $basefs| wc -c) log_note "The deeply-nested filesystem len: $len" # # Make sure there are at lease 2 characters left # for snapshot name space, otherwise snapshot name # is incorrect # if ((len >= 255)); then - if datasetexists $basefs; then - log_must zfs destroy -r $basefs - fi + datasetexists $basefs && destroy_dataset $basefs -r basefs=${basefs%/*} len=$(echo $basefs| wc -c) fi break fi basefs=$basefs/$TESTFS done # Make snapshot name is longer than the max length ((snaplen = 256 - len + 10)) snap=$(gen_dataset_name $snaplen "s") log_mustnot zfs snapshot -r $TESTPOOL@$snap log_must datasetnonexists $TESTPOOL@$snap while [[ $basefs != $TESTPOOL ]]; do log_must datasetnonexists $basefs@$snap basefs=${basefs%/*} done log_pass "Verify recursive snapshotting could not break ZFS." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh index d97dc0f82265..c133403ac84a 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_005_neg.ksh @@ -1,96 +1,92 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Long name filesystem with snapshot should not break ZFS. # # STRATEGY: # 1. Create filesystem and snapshot. # 2. When the snapshot length is 256, rename the filesystem. # 3. Verify it does not break ZFS # verify_runnable "both" function cleanup { - if datasetexists $initfs ; then - log_must zfs destroy -rf $initfs - fi + datasetexists $initfs && destroy_dataset $initfs -rf } log_assert "Verify long name filesystem with snapshot should not break ZFS." log_onexit cleanup initfs=$TESTPOOL/$TESTFS/$TESTFS basefs=$initfs typeset -i ret=0 len snaplen while ((ret == 0)); do zfs create $basefs zfs snapshot $basefs@snap1 ret=$? if ((ret != 0)); then len=$(echo $basefs | wc -c) log_note "The deeply-nested filesystem len: $len" # # Make sure there are at lease 2 characters left # for snapshot name space, otherwise snapshot name # is incorrect # if ((len >= 255)); then - if datasetexists $basefs; then - log_must zfs destroy -r $basefs - fi + datasetexists $basefs && destroy_dataset $basefs -r basefs=${basefs%/*} len=$(echo $basefs| wc -c) fi break fi basefs=$basefs/$TESTFS done # Make snapshot name length match the longest one ((snaplen = 256 - len - 1)) # 1: @ snap=$(gen_dataset_name $snaplen "s") log_must zfs snapshot $basefs@$snap log_mustnot zfs rename $basefs ${basefs}a log_mustnot zfs rename $basefs ${basefs}-new log_mustnot zfs rename $initfs ${initfs}-new log_mustnot zfs rename $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS-new log_pass "Verify long name filesystem with snapshot should not break ZFS." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh index 089ebdb97924..6b711286c68d 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_006_pos.ksh @@ -1,124 +1,122 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # User property could be set via creation time by 'zfs snapshot -o' # # STRATEGY: # 1. Create snapshot and give '-o property=value' # 2. Verify the snapshot be created and user property have been set. # verify_runnable "both" function cleanup { for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do typeset fssnap=$fs@snap - if datasetexists $fssnap ; then - log_must zfs destroy -rf $fssnap - fi + datasetexists $fssnap && destroy_dataset $fssnap -rf done cleanup_user_prop $TESTPOOL } function nonexist_user_prop { typeset user_prop=$1 typeset dtst=$2 typeset source=$(get_source $user_prop $dtst) typeset value=$(get_prop $user_prop $dtst) if [[ $source == '-' && $value == '-' ]]; then return 0 else return 1 fi } log_assert "User property could be set upon snapshot via 'zfs snapshot -o'." log_onexit cleanup typeset snap_property= for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do typeset fssnap=$fs@snap prop_name=$(valid_user_property 10) value=$(user_property_value 16) log_must eval "zfs snapshot -o $prop_name='$value' $fssnap" log_must snapexists $fssnap log_mustnot nonexist_user_prop $prop_name $fssnap log_must zfs destroy -f $fssnap prop_name2=$(valid_user_property 10) value2=$(user_property_value 16) log_must eval "zfs snapshot -o $prop_name='$value' -o $prop_name2='$value2' $fssnap" log_must snapexists $fssnap log_mustnot nonexist_user_prop $prop_name $fssnap log_mustnot nonexist_user_prop $prop_name2 $fssnap done cleanup prop_name=$(valid_user_property 10) value=$(user_property_value 16) log_must eval "zfs snapshot -r -o $prop_name='$value' $TESTPOOL@snap" for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do typeset fssnap=$fs@snap log_must snapexists $fssnap log_mustnot nonexist_user_prop $prop_name $fssnap log_must zfs destroy -rf $fssnap done cleanup prop_name2=$(valid_user_property 10) value2=$(user_property_value 16) log_must eval "zfs snapshot -r -o $prop_name='$value' -o $prop_name2='$value2' $TESTPOOL@snap" for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL ; do typeset fssnap=$fs@snap log_must snapexists $fssnap log_mustnot nonexist_user_prop $prop_name $fssnap log_mustnot nonexist_user_prop $prop_name2 $fssnap log_must zfs destroy -rf $fssnap done log_pass "User property could be set upon snapshot via 'zfs snapshot -o'." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh index 9d8c1373f91e..9499dca21e78 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_007_neg.ksh @@ -1,137 +1,135 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib # # DESCRIPTION: # 'zfs snapshot -o' cannot set properties other than user property # # STRATEGY: # 1. Create snapshot and give '-o property=value' with regular property. # 2. Verify the snapshot creation failed. # verify_runnable "both" function cleanup { for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do typeset fssnap=$fs@snap - if datasetexists $fssnap ; then - log_must zfs destroy -rf $fssnap - fi + datasetexists $fssnap && destroy_dataset $fssnap -rf done cleanup_user_prop $TESTPOOL } function nonexist_user_prop { typeset user_prop=$1 typeset dtst=$2 typeset source=$(get_source $user_prop $dtst) typeset value=$(get_prop $user_prop $dtst) if [[ $source == '-' && $value == '-' ]]; then return 0 else return 1 fi } log_assert "'zfs snapshot -o' cannot set properties other than user property." log_onexit cleanup typeset ro_props="type used available avail creation referenced refer compressratio \ mounted origin" typeset snap_ro_props="volsize recordsize recsize quota reservation reserv mountpoint \ sharenfs checksum compression compress atime devices exec readonly rdonly \ setuid" if is_freebsd; then snap_ro_props+=" jailed" else snap_ro_props+=" zoned" fi zfs upgrade -v > /dev/null 2>&1 if [[ $? -eq 0 ]]; then snap_ro_props="$snap_ro_props version" fi for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do typeset fssnap=$fs@snap prop_name=$(valid_user_property 10) value=$(user_property_value 16) log_must eval "zfs snapshot -o $prop_name='$value' $fssnap" log_must snapexists $fssnap log_mustnot nonexist_user_prop $prop_name $fssnap log_must zfs destroy -f $fssnap prop_name2=$(valid_user_property 10) value2=$(user_property_value 16) log_must eval "zfs snapshot -o $prop_name='$value' -o $prop_name2='$value2' $fssnap" log_must snapexists $fssnap log_mustnot nonexist_user_prop $prop_name $fssnap log_mustnot nonexist_user_prop $prop_name2 $fssnap log_must zfs destroy -f $fssnap done cleanup prop_name=$(valid_user_property 10) value=$(user_property_value 16) log_must eval "zfs snapshot -r -o $prop_name='$value' $TESTPOOL@snap" for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do typeset fssnap=$fs@snap log_must snapexists $fssnap log_mustnot nonexist_user_prop $prop_name $fssnap done cleanup prop_name2=$(valid_user_property 10) value2=$(user_property_value 16) log_must eval "zfs snapshot -r -o $prop_name='$value' -o $prop_name2='$value2' $TESTPOOL@snap" for fs in $TESTPOOL/$TESTFS $TESTPOOL/$TESTVOL $TESTPOOL/$TESTCTR $TESTPOOL ; do typeset fssnap=$fs@snap log_must snapexists $fssnap log_mustnot nonexist_user_prop $prop_name $fssnap log_mustnot nonexist_user_prop $prop_name2 $fssnap done log_pass "'zfs snapshot -o' cannot set properties other than user property." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos.ksh index a20fcc4ce224..6fedba9e5b27 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_snapshot/zfs_snapshot_009_pos.ksh @@ -1,132 +1,131 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # Copyright (c) 2020 by Datto Inc. All rights reserved. # # # DESCRIPTION # verify 'zfs snapshot ' works correctly # # STRATEGY # 1. Create multiple datasets # 2. Create multiple snapshots with a list of valid and invalid # snapshot names # 3. Verify the valid snapshot creation # 4. Verify creation of snapshots report the correct numbers by # performing a snapshot directory listing . $STF_SUITE/include/libtest.shlib ZFS_MAX_DATASET_NAME_LEN=256 function cleanup { for ds in $datasets; do - datasetexists $ds && log_must zfs destroy -r $ds + datasetexists $ds && destroy_dataset $ds -r done - zfs destroy -r $TESTPOOL/TESTFS4 - zfs destroy -r $TESTPOOL/TESTFS5 + destroy_dataset $TESTPOOL/TESTFS4 -r + destroy_dataset $TESTPOOL/TESTFS5 -r } datasets="$TESTPOOL/$TESTFS1 $TESTPOOL/$TESTFS2 $TESTPOOL/$TESTFS3" # We subtract 3 for slash (/), at (@), and the terminating nul (\0) SNAPSHOT_XXX=$(printf 'x%.0s' \ {1..$(($ZFS_MAX_DATASET_NAME_LEN - ${#TESTPOOL} - ${#TESTFS1} - 3))}) invalid_args=("$TESTPOOL/$TESTFS1@now $TESTPOOL/$TESTFS2@now \ $TESTPOOL/$TESTFS@blah?" "$TESTPOOL/$TESTFS1@blah* \ $TESTPOOL/$TESTFS2@blah? $TESTPOOL/$TESTFS3@blah%" \ "$TESTPOOL/$TESTFS1@x$SNAPSHOT_XXX $TESTPOOL/$TESTFS2@300 \ $TESTPOOL/$TESTFS3@300") valid_args=("$TESTPOOL/$TESTFS1@snap $TESTPOOL/$TESTFS2@snap \ $TESTPOOL/$TESTFS3@snap" "$TESTPOOL/$TESTFS1@$SNAPSHOT_XXX \ $TESTPOOL/$TESTFS2@2 $TESTPOOL/$TESTFS3@s") log_assert "verify zfs supports multiple consistent snapshots" log_onexit cleanup typeset -i i=1 test_data=$STF_SUITE/tests/functional/cli_root/zpool_upgrade/blockfiles/*.bz2 log_note "destroy a list of valid snapshots" for ds in $datasets; do log_must zfs create $ds log_must cp -r $test_data /$ds done i=0 while (( i < ${#valid_args[*]} )); do log_must zfs snapshot ${valid_args[i]} for token in ${valid_args[i]}; do - log_must snapexists $token && \ - log_must zfs destroy $token + snapexists $token && destroy_dataset $token done ((i = i + 1)) done log_note "destroy a list of invalid snapshots" i=0 while (( i < ${#invalid_args[*]} )); do log_mustnot zfs snapshot ${invalid_args[i]} for token in ${invalid_args[i]}; do log_mustnot snapexists $token done ((i = i + 1)) done log_note "verify multiple snapshot transaction group" txg_group=$(zdb -Pd $TESTPOOL | grep snap | awk '{print $7}') for i in 1 2 3; do txg_tag=$(echo "$txg_group" | nawk -v j=$i 'FNR == j {print}') [[ $txg_tag != $(echo "$txg_group" | \ nawk -v j=$i 'FNR == j {print}') ]] \ && log_fail "snapshots belong to different transaction groups" done log_note "verify snapshot contents" for ds in $datasets; do diff -q -r /$ds /$ds/.zfs/snapshot/snap > /dev/null 2>&1 if [[ $? -eq 1 ]]; then log_fail "snapshot contents are different from" \ "the filesystem" fi done # We subtract 3 + 7 + 7 + 1 = 18 for three slashes (/), strlen("TESTFSA") == 7, # strlen("TESTFSB") == 7, and the terminating nul (\0) DATASET_XXX=$(printf 'x%.0s' \ {1..$(($ZFS_MAX_DATASET_NAME_LEN - ${#TESTPOOL} - ${#TESTFS3} - 18))}) log_note "verify multiple snapshot with -r option" log_must zfs create $TESTPOOL/TESTFS4 log_must zfs create -p $TESTPOOL/$TESTFS3/TESTFSA$DATASET_XXX/TESTFSB log_mustnot zfs snapshot -r $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS2@snap1 \ $TESTPOOL/$TESTFS3@snap1 $TESTPOOL/TESTFS4@snap1 log_must zfs rename $TESTPOOL/$TESTFS3/TESTFSA$DATASET_XXX \ $TESTPOOL/$TESTFS3/TESTFSA log_must zfs snapshot -r $TESTPOOL/$TESTFS1@snap1 $TESTPOOL/$TESTFS2@snap1 \ $TESTPOOL/$TESTFS3@snap1 $TESTPOOL/TESTFS4@snap1 MYTEST="TESTFS5" ITERATIONS=10 NUM_SNAPS=5 for x in {1..$ITERATIONS}; do log_must zfs create $TESTPOOL/$MYTEST for y in {1..$NUM_SNAPS}; do log_must zfs snapshot $TESTPOOL/$MYTEST@$y done; n=$(ls -1 /$TESTPOOL/$MYTEST/.zfs/snapshot | wc -l) verify_eq $n $NUM_SNAPS "count" zfs destroy -r $TESTPOOL/$MYTEST; done; log_pass "zfs multiple snapshot verified correctly" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key.ksh index 9e08ac69d4de..55cfb5cade03 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key.ksh @@ -1,69 +1,69 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs unload-key' should only unload the key of an unmounted dataset. # # STRATEGY: # 1. Attempt to unload the default dataset's key # 2. Unmount the dataset # 3. Attempt to unload the default dataset's key # 4. Create an encrypted dataset # 5. Attempt to unload the dataset's key # 6. Verify the key is loaded # 7. Unmount the dataset # 8. Attempt to unload the dataset's key # 9. Verify the key is not loaded # 10. Attempt to unload the dataset's key # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 } log_onexit cleanup log_assert "'zfs unload-key' should unload the key for an unmounted" \ "encrypted dataset" log_mustnot zfs unload-key $TESTPOOL/$TESTFS log_must zfs unmount $TESTPOOL/$TESTFS log_mustnot zfs unload-key $TESTPOOL/$TESTFS log_must eval "echo $PASSPHRASE | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS1" log_mustnot zfs unload-key $TESTPOOL/$TESTFS1 log_must key_available $TESTPOOL/$TESTFS1 log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unload-key $TESTPOOL/$TESTFS1 log_must key_unavailable $TESTPOOL/$TESTFS1 log_mustnot zfs unload-key $TESTPOOL/$TESTFS1 log_pass "'zfs unload-key' unloads the key for an unmounted encrypted dataset" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key_all.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key_all.ksh index ecb98d189424..55da68262019 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key_all.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key_all.ksh @@ -1,76 +1,75 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs unload-key -a' should unload keys for all datasets. # # STRATEGY: # 1. Create an encrypted filesystem, encrypted child dataset, an encrypted # zvol, and an encrypted pool # 2. Unmount all datasets # 3. Attempt to unload all dataset keys # 4. Verify each dataset has its key unloaded # 5. Attempt to mount each dataset # verify_runnable "both" function cleanup { - datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 - datasetexists $TESTPOOL/zvol && log_must zfs destroy $TESTPOOL/zvol + datasetexists $TESTPOOL/$TESTFS1 && destroy_dataset $TESTPOOL/$TESTFS1 -r + datasetexists $TESTPOOL/zvol && destroy_dataset $TESTPOOL/zvol poolexists $TESTPOOL1 && log_must destroy_pool $TESTPOOL1 } log_onexit cleanup log_assert "'zfs unload-key -a' should unload keys for all datasets" log_must eval "echo $PASSPHRASE1 > /$TESTPOOL/pkey" log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 log_must zfs create $TESTPOOL/$TESTFS1/child log_must zfs create -V 64M -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/zvol typeset DISK2="$(echo $DISKS | awk '{ print $2}')" log_must zpool create -O encryption=on -O keyformat=passphrase \ -O keylocation=file:///$TESTPOOL/pkey $TESTPOOL1 $DISK2 log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unmount $TESTPOOL1 -log_must zfs unload-key -a +log_must_busy zfs unload-key -a log_must key_unavailable $TESTPOOL/$TESTFS1 log_must key_unavailable $TESTPOOL/$TESTFS1/child log_must key_unavailable $TESTPOOL/zvol log_must key_unavailable $TESTPOOL1 log_mustnot zfs mount $TESTPOOL log_mustnot zfs mount $TESTPOOL/zvol log_mustnot zfs mount $TESTPOOL/$TESTFS1 log_pass "'zfs unload-key -a' unloads keys for all datasets" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key_recursive.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key_recursive.ksh index 9766b590587f..01c720c04b58 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key_recursive.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unload-key/zfs_unload-key_recursive.ksh @@ -1,72 +1,72 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # 'zfs unload-key -r' should recursively unload keys. # # STRATEGY: # 1. Create a parent encrypted dataset # 2. Create a sibling encrypted dataset # 3. Create a child dataset as an encryption root # 4. Unmount all datasets # 5. Attempt to unload all dataset keys under parent # 6. Verify parent and child have their keys unloaded # 7. Verify sibling has its key loaded # 8. Attempt to mount all datasets # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r } log_onexit cleanup log_assert "'zfs unload-key -r' should recursively unload keys" log_must eval "echo $PASSPHRASE > /$TESTPOOL/pkey" log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1 log_must zfs create -o keyformat=passphrase \ -o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/$TESTFS1/child log_must eval "echo $PASSPHRASE1 | zfs create -o encryption=on" \ "-o keyformat=passphrase -o keylocation=prompt $TESTPOOL/$TESTFS2" log_must zfs unmount $TESTPOOL/$TESTFS1 log_must zfs unmount $TESTPOOL/$TESTFS2 log_must zfs unload-key -r $TESTPOOL/$TESTFS1 log_must key_unavailable $TESTPOOL/$TESTFS1 log_must key_unavailable $TESTPOOL/$TESTFS1/child log_must key_available $TESTPOOL/$TESTFS2 log_mustnot zfs mount $TESTPOOL/$TESTFS1 log_mustnot zfs mount $TESTPOOL/$TESTFS1/child log_must zfs mount $TESTPOOL/$TESTFS2 log_pass "'zfs unload-key -r' recursively unloads keys" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh index fb4d1d937895..6036eb27a062 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_001_pos.ksh @@ -1,117 +1,117 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Creates a file system and verifies that it can be unmounted # using each of the various unmount options and sub-command # variants. # # STRATEGY: # 1. Create and mount a file system as necessary. # 2. Umount the file system using the various combinations. # - With force option. # - Without force option. # - Using the unmount sub-command. # - Using the umount sub-command. # verify_runnable "both" function cleanup { mounted $TESTDIR2 && \ log_must zfs umount -f $TESTDIR2 datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 [[ -d $TESTDIR2 ]] && \ log_must rm -rf $TESTDIR2 } function do_unmount { typeset cmd=$1 typeset opt=$2 typeset mnt=$3 [[ ! -d $TESTDIR2 ]] && \ log_must mkdir $TESTDIR2 if ! datasetexists $TESTPOOL/$TESTFS2 ; then log_must zfs create $TESTPOOL/$TESTFS2 log_must zfs set mountpoint=$TESTDIR2 \ $TESTPOOL/$TESTFS2 fi unmounted $TESTPOOL/$TESTFS2 && \ log_must zfs mount $TESTPOOL/$TESTFS2 log_must zfs $cmd $options $mnt unmounted "$mnt" || \ log_fail "Unable to unmount $options $mnt" log_note "Successfully unmounted $options $mnt" } log_onexit cleanup set -A cmd "umount" "unmount" set -A options "" "-f" set -A dev "$TESTPOOL/$TESTFS2" "$TESTDIR2" log_assert "Verify the u[n]mount [-f] sub-command." typeset -i i=0 typeset -i j=0 typeset -i k=0 while [[ $i -lt ${#cmd[*]} ]]; do j=0 while [[ $j -lt ${#options[*]} ]]; do k=0 while [[ $k -lt ${#dev[*]} ]]; do do_unmount "${cmd[i]}" "${options[j]}" \ "${dev[k]}" ((k = k + 1)) done ((j = j + 1)) done ((i = i + 1)) done log_pass "zfs u[n]mount [-f] completed successfully." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh index 209497d9c454..e85a0f3cbf68 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_008_neg.ksh @@ -1,146 +1,142 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that zfs unmount should fail with bad parameters or scenarios: # 1. bad option; # 2. too many arguments; # 3. null arguments; # 4. invalid datasets; # 5. invalid mountpoint; # 6. already unmounted zfs filesystem; # 7. legacy mounted zfs filesystem # # STRATEGY: # 1. Make an array of bad parameters # 2. Use zfs unmount to unmount the filesystem # 3. Verify that zfs unmount returns error # verify_runnable "both" function cleanup { for ds in $vol $fs1; do - if datasetexists $ds; then - log_must zfs destroy -f $ds - fi + datasetexists $ds && destroy_dataset $ds -f done - if snapexists $snap; then - log_must zfs destroy $snap - fi + snapexists $snap && destroy_dataset $snap if [[ -e /tmp/$file ]]; then rm -f /tmp/$file fi if [[ -d /tmp/$dir ]]; then rm -rf /tmp/$dir fi } log_assert "zfs unmount fails with bad parameters or scenarios" log_onexit cleanup fs=$TESTPOOL/$TESTFS vol=$TESTPOOL/vol.$$ snap=$TESTPOOL/$TESTFS@snap.$$ set -A badargs "A" "-A" "F" "-F" "-" "-x" "-?" if ! ismounted $fs; then log_must zfs mount $fs fi log_must zfs snapshot $snap if is_global_zone; then log_must zfs create -V 10m $vol else vol="" fi # Testing bad options for arg in ${badargs[@]}; do log_mustnot eval "zfs unmount $arg $fs >/dev/null 2>&1" done # Testing invalid datasets for ds in $snap $vol "blah"; do for opt in "" "-f"; do log_mustnot eval "zfs unmount $opt $ds >/dev/null 2>&1" done done # Testing invalid mountpoint dir=foodir.$$ file=foo.$$ fs1=$TESTPOOL/fs.$$ mkdir /tmp/$dir touch /tmp/$file log_must zfs create -o mountpoint=/tmp/$dir $fs1 curpath=`dirname $0` cd /tmp for mpt in "./$dir" "./$file" "/tmp"; do for opt in "" "-f"; do log_mustnot eval "zfs unmount $opt $mpt >/dev/null 2>&1" done done cd $curpath # Testing null argument and too many arguments for opt in "" "-f"; do log_mustnot eval "zfs unmount $opt >/dev/null 2>&1" log_mustnot eval "zfs unmount $opt $fs $fs1 >/dev/null 2>&1" done # Testing already unmounted filesystem log_must zfs unmount $fs1 for opt in "" "-f"; do log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1" log_mustnot eval "zfs unmount /tmp/$dir >/dev/null 2>&1" done # Testing legacy mounted filesystem log_must zfs set mountpoint=legacy $fs1 if is_linux || is_freebsd; then log_must mount -t zfs $fs1 /tmp/$dir else log_must mount -F zfs $fs1 /tmp/$dir fi for opt in "" "-f"; do log_mustnot eval "zfs unmount $opt $fs1 >/dev/null 2>&1" done umount /tmp/$dir log_pass "zfs unmount fails with bad parameters or scenarios as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh index 3575875c2767..814d603db5e0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_009_pos.ksh @@ -1,142 +1,140 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that zfs unmount and destroy in a snapshot directory will not cause error. # # STRATEGY: # 1. Create a file in a zfs filesystem, snapshot it and change directory to snapshot directory # 2. Verify that 'zfs unmount -a' will fail and 'zfs unmount -fa' will succeed # 3. Verify 'ls' and 'cd /' will succeed # 4. 'zfs mount -a' and change directory to snapshot directory again # 5. Verify that zfs destroy snapshot will succeed # 6. Verify 'ls' and 'cd /' will succeed # 7. Create zfs filesystem, create a file, snapshot it and change to snapshot directory # 8. Verify that zpool destroy the pool will succeed # 9. Verify 'ls' 'cd /' 'zpool list' and etc will succeed # verify_runnable "both" function cleanup { DISK=${DISKS%% *} for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do typeset snap=$fs@$TESTSNAP - if snapexists $snap; then - log_must zfs destroy $snap - fi + snapexists $snap && destroy_dataset $snap done if ! poolexists $TESTPOOL && is_global_zone; then log_must zpool create $TESTPOOL $DISK fi if ! datasetexists $TESTPOOL/$TESTFS; then log_must zfs create $TESTPOOL/$TESTFS log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS fi } function restore_dataset { if ! datasetexists $TESTPOOL/$TESTFS ; then log_must zfs create $TESTPOOL/$TESTFS log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS log_must cd $TESTDIR echo hello > world log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP log_must cd .zfs/snapshot/$TESTSNAP fi } log_assert "zfs force unmount and destroy in snapshot directory will not cause error." log_onexit cleanup for fs in $TESTPOOL/$TESTFS $TESTPOOL ; do typeset snap=$fs@$TESTSNAP typeset mtpt=$(get_prop mountpoint $fs) log_must cd $mtpt echo hello > world log_must zfs snapshot $snap log_must cd .zfs/snapshot/$TESTSNAP log_mustnot zfs unmount -a if is_linux; then log_mustnot zfs unmount -fa log_must ls else log_must zfs unmount -fa log_mustnot ls fi log_must cd / log_must zfs mount -a log_must cd $mtpt log_must cd .zfs/snapshot/$TESTSNAP if is_global_zone || [[ $fs != $TESTPOOL ]] ; then if is_linux; then log_mustnot zfs destroy -rf $fs log_must ls else log_must zfs destroy -rf $fs log_mustnot ls fi log_must cd / fi restore_dataset done if is_global_zone ; then if is_linux; then log_mustnot zpool destroy -f $TESTPOOL log_must ls else log_must zpool destroy -f $TESTPOOL log_mustnot ls fi log_must cd / fi log_must eval zfs list > /dev/null 2>&1 log_must eval zpool list > /dev/null 2>&1 log_must eval zpool status > /dev/null 2>&1 zpool iostat > /dev/null 2>&1 log_pass "zfs force unmount and destroy in snapshot directory will not cause error." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_unload_keys.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_unload_keys.ksh index d6d0a7e9a1b6..c92287ad75e4 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_unload_keys.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unmount/zfs_unmount_unload_keys.ksh @@ -1,79 +1,79 @@ #!/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 (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_unmount/zfs_unmount.kshlib . $STF_SUITE/tests/functional/cli_root/zfs_load-key/zfs_load-key_common.kshlib # # DESCRIPTION: # "zfs unmount -u" should allow the user to unload their encryption # keys while unmounting one or more datasets # # STRATEGY: # 1. Create a hierarchy of encrypted datasets # 2. Test that 'zfs unmount -u' unloads keys as it unmounts a dataset # 3. Test that 'zfs unmount -u' unloads keys as it unmounts multiple datasets # 4. Test that 'zfs unmount -u' returns an error if the key is still in # use by a clone. # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r datasetexists $TESTPOOL/$TESTFS2/newroot && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2/newroot + destroy_dataset $TESTPOOL/$TESTFS2/newroot -r datasetexists $TESTPOOL/$TESTFS2/child && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2/child + destroy_dataset $TESTPOOL/$TESTFS2/child -r } log_onexit cleanup log_assert "'zfs unmount -u' should unload keys for datasets as they are unmounted" log_must eval "echo 'password' | zfs create -o encryption=on -o keyformat=passphrase $TESTPOOL/$TESTFS2" log_must eval "echo 'password' | zfs create -o encryption=on -o keyformat=passphrase $TESTPOOL/$TESTFS2/newroot" log_must zfs create $TESTPOOL/$TESTFS2/child log_must zfs umount -u $TESTPOOL/$TESTFS2/newroot log_must key_unavailable $TESTPOOL/$TESTFS2/newroot log_must eval "echo 'password' | zfs mount -l $TESTPOOL/$TESTFS2/newroot" log_must zfs umount -u $TESTPOOL/$TESTFS2 log_must key_unavailable $TESTPOOL/$TESTFS2 log_must key_unavailable $TESTPOOL/$TESTFS2/newroot log_must key_unavailable $TESTPOOL/$TESTFS2/child log_must eval "echo 'password' | zfs mount -l $TESTPOOL/$TESTFS2/newroot" log_must zfs snap $TESTPOOL/$TESTFS2/newroot@1 log_must zfs clone $TESTPOOL/$TESTFS2/newroot@1 $TESTPOOL/$TESTFS2/clone log_mustnot zfs umount -u $TESTPOOL/$TESTFS2/newroot log_must key_available $TESTPOOL/$TESTFS2/newroot log_must mounted $TESTPOOL/$TESTFS2/newroot log_pass "'zfs unmount -u' unloads keys for datasets as they are unmounted" diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh index ca625bd2278a..ac16fe97b928 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_001_pos.ksh @@ -1,177 +1,174 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that 'zfs unshare ' unshares a given shared # filesystem. # # STRATEGY: # 1. Share filesystems # 2. Invoke 'zfs unshare ' to unshare zfs file system # 3. Verify that the file system is unshared # 4. Verify that unsharing an unshared file system fails # 5. Verify that "zfs unshare -a" succeeds to unshare all zfs file systems. # verify_runnable "global" function cleanup { typeset -i i=0 while (( i < ${#mntp_fs[*]} )); do log_must zfs set sharenfs=off ${mntp_fs[((i+1))]} ((i = i + 2)) done if mounted $TESTPOOL/$TESTCLONE; then log_must zfs unmount $TESTDIR2 fi [[ -d $TESTDIR2 ]] && \ log_must rm -rf $TESTDIR2 - if datasetexists "$TESTPOOL/$TESTCLONE"; then - log_must zfs destroy -f $TESTPOOL/$TESTCLONE - fi + datasetexists "$TESTPOOL/$TESTCLONE" && \ + destroy_dataset $TESTPOOL/$TESTCLONE -f - if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then - log_must zfs destroy -f $TESTPOOL/$TESTFS2@snapshot - fi + snapexists "$TESTPOOL/$TESTFS2@snapshot" && \ + destroy_dataset $TESTPOOL/$TESTFS2@snapshot -f - if datasetexists "$TESTPOOL/$TESTFS2"; then - log_must zfs destroy -f $TESTPOOL/$TESTFS2 - fi + datasetexists "$TESTPOOL/$TESTFS2" && \ + destroy_dataset $TESTPOOL/$TESTFS2 -f } # # Main test routine. # # Given a mountpoint and file system this routine will attempt # unshare the filesystem via argument # and then verify it has been unshared. # function test_unshare # { typeset mntp=$1 typeset filesystem=$2 typeset prop_value prop_value=$(get_prop "sharenfs" $filesystem) if [[ $prop_value == "off" ]]; then not_shared $mntp || log_must eval "unshare_nfs $mntp" log_must zfs set sharenfs=on $filesystem is_shared $mntp || \ log_fail "'zfs set sharenfs=on' fails to make" \ "file system $filesystem shared." fi is_shared $mntp || log_must zfs share $filesystem # # Verify 'zfs unshare ' works as well. # log_must zfs unshare $filesystem not_shared $mntp || log_fail "'zfs unshare ' fails" log_must zfs share $filesystem log_must zfs unshare $mntp not_shared $mntp || log_fail "'zfs unshare ' fails" log_note "Unsharing an unshared file system fails." log_mustnot zfs unshare $filesystem log_mustnot zfs unshare $mntp } set -A mntp_fs \ "$TESTDIR" "$TESTPOOL/$TESTFS" \ "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \ "$TESTDIR2" "$TESTPOOL/$TESTCLONE" log_assert "Verify that 'zfs unshare [-a] ' succeeds as root." log_onexit cleanup log_must zfs create $TESTPOOL/$TESTFS2 log_must zfs snapshot $TESTPOOL/$TESTFS2@snapshot log_must zfs clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE log_must zfs set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE # # Invoke 'test_unshare' routine to test 'zfs unshare '. # typeset -i i=0 while (( i < ${#mntp_fs[*]} )); do test_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]} ((i = i + 2)) done log_note "Verify 'zfs unshare -a' succeeds as root." i=0 typeset sharenfs_val while (( i < ${#mntp_fs[*]} )); do sharenfs_val=$(get_prop "sharenfs" ${mntp_fs[((i+1))]}) if [[ $sharenfs_val == "on" ]]; then not_shared ${mntp_fs[i]} && \ log_must zfs share ${mntp_fs[((i+1))]} else log_must zfs set sharenfs=on ${mntp_fs[((i+1))]} is_shared ${mntp_fs[i]} || \ log_fail "'zfs set sharenfs=on' fails to share filesystem." fi ((i = i + 2)) done # # test 'zfs unshare -a ' # log_must zfs unshare -a # # verify all shared filesystems become unshared # i=0 while (( i < ${#mntp_fs[*]} )); do not_shared ${mntp_fs[i]} || \ log_fail "'zfs unshare -a' fails to unshare all shared zfs filesystems." ((i = i + 2)) done log_pass "'zfs unshare [-a] ' succeeds as root." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh index 6a9c72311c74..1ded1b42c7ec 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_002_pos.ksh @@ -1,185 +1,182 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that 'zfs unshare [-a] ' is aware of legacy share. # # STRATEGY: # 1. Set 'zfs set sharenfs=off' # 2. Use 'share' to share given filesystem # 3. Verify that 'zfs unshare ' is aware of legacy share # 4. Verify that 'zfs unshare -a' is aware of legacy share. # verify_runnable "global" if is_linux; then log_unsupported "zfs set sharenfs=off won't unshare if already off" fi function cleanup { typeset -i i=0 while (( i < ${#mntp_fs[*]} )); do is_shared ${mntp_fs[i]} && \ log_must eval "unshare_nfs ${mntp_fs[i]}" ((i = i + 2)) done if mounted $TESTPOOL/$TESTCLONE; then log_must zfs unmount $TESTDIR2 fi [[ -d $TESTDIR2 ]] && \ log_must rm -rf $TESTDIR2 - if datasetexists "$TESTPOOL/$TESTCLONE"; then - log_must zfs destroy -f $TESTPOOL/$TESTCLONE - fi + datasetexists "$TESTPOOL/$TESTCLONE" && \ + destroy_dataset $TESTPOOL/$TESTCLONE -f - if snapexists "$TESTPOOL/$TESTFS2@snapshot"; then - log_must zfs destroy -f $TESTPOOL/$TESTFS2@snapshot - fi + snapexists "$TESTPOOL/$TESTFS2@snapshot" && \ + destroy_dataset $TESTPOOL/$TESTFS2@snapshot -f - if datasetexists "$TESTPOOL/$TESTFS2"; then - log_must zfs destroy -f $TESTPOOL/$TESTFS2 - fi + datasetexists "$TESTPOOL/$TESTFS2" && \ + destroy_dataset $TESTPOOL/$TESTFS2 -f } # # Main test routine. # # Given a mountpoint and file system this routine will attempt # to verify 'zfs unshare' is aware of legacy share. # function test_legacy_unshare # { typeset mntp=$1 typeset filesystem=$2 log_must zfs set sharenfs=off $filesystem not_shared $mntp || \ log_fail "'zfs set sharenfs=off' fails to make ZFS " \ "filesystem $filesystem unshared." log_must eval "share_nfs $mntp" is_shared $mntp || \ log_fail "'share' command fails to share ZFS file system." # # Verify 'zfs unshare ' is aware of legacy share. # log_mustnot zfs unshare $filesystem is_shared $mntp || \ log_fail "'zfs unshare ' fails to be aware" \ "of legacy share." # # Verify 'zfs unshare ' is aware of legacy share. # log_mustnot zfs unshare $mntp is_shared $mntp || \ log_fail "'zfs unshare ' fails to be aware" \ "of legacy share." } set -A mntp_fs \ "$TESTDIR" "$TESTPOOL/$TESTFS" \ "$TESTDIR1" "$TESTPOOL/$TESTCTR/$TESTFS1" \ "$TESTDIR2" "$TESTPOOL/$TESTCLONE" log_assert "Verify that 'zfs unshare [-a]' is aware of legacy share." log_onexit cleanup log_must zfs create $TESTPOOL/$TESTFS2 log_must zfs snapshot $TESTPOOL/$TESTFS2@snapshot log_must zfs clone $TESTPOOL/$TESTFS2@snapshot $TESTPOOL/$TESTCLONE log_must zfs set mountpoint=$TESTDIR2 $TESTPOOL/$TESTCLONE # # Invoke 'test_legacy_unshare' routine to verify. # typeset -i i=0 while (( i < ${#mntp_fs[*]} )); do test_legacy_unshare ${mntp_fs[i]} ${mntp_fs[((i + 1 ))]} ((i = i + 2)) done log_note "Verify 'zfs unshare -a' is aware of legacy share." # # set the 'sharenfs' property to 'off' for each filesystem # i=0 while (( i < ${#mntp_fs[*]} )); do log_must zfs set sharenfs=off ${mntp_fs[((i + 1))]} not_shared ${mntp_fs[i]} || \ log_fail "'zfs set sharenfs=off' unshares file system failed." ((i = i + 2)) done # # Share each of the file systems via legacy share. # i=0 while (( i < ${#mntp_fs[*]} )); do share_nfs ${mntp_fs[i]} is_shared ${mntp_fs[i]} || \ log_fail "'share' shares ZFS filesystem failed." ((i = i + 2)) done # # Verify that 'zfs unshare -a' is aware of legacy share # log_must zfs unshare -a # # verify ZFS filesystems are still shared # i=0 while (( i < ${#mntp_fs[*]} )); do is_shared ${mntp_fs[i]} || \ log_fail "'zfs unshare -a' fails to be aware of legacy share." ((i = i + 2)) done log_pass "'zfs unshare [-a]' succeeds to be aware of legacy share." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh index 66a7e80eb783..6e66deda9bee 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_003_pos.ksh @@ -1,94 +1,93 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that a file system and its dependent are unshared when turn off sharenfs # property. # # STRATEGY: # 1. Create a file system # 2. Set the sharenfs property on the file system # 3. Create a snapshot # 4. Verify that both are shared # 5. Turn off the sharenfs property # 6. Verify that both are unshared. # verify_runnable "global" function cleanup { - if snapexists $TESTPOOL/$TESTFS@snapshot; then - log_must zfs destroy $TESTPOOL/$TESTFS@snapshot - fi + snapexists $TESTPOOL/$TESTFS@snapshot && \ + destroy_dataset $TESTPOOL/$TESTFS@snapshot log_must zfs set sharenfs=off $TESTPOOL/$TESTFS } # # Main test routine. # # Given a mountpoint and file system this routine will attempt # unshare the mountpoint and then verify a snapshot of the mounpoint # is also unshared. # function test_snap_unshare # { typeset mntp=$1 typeset filesystem=$2 typeset prop_value prop_value=$(get_prop "sharenfs" $filesystem) if [[ $prop_value == "off" ]]; then is_shared $mntp || unshare_nfs $mntp log_must zfs set sharenfs=on $filesystem fi log_must zfs set sharenfs=off $filesystem not_shared $mntp || \ log_fail "File system $filesystem is shared (set sharenfs)." not_shared $mntp@snapshot || \ log_fail "Snapshot $mntpt@snapshot is shared (set sharenfs)." } log_assert "Verify that a file system and its dependent are unshared." log_onexit cleanup log_must zfs snapshot $TESTPOOL/$TESTFS@snapshot test_snap_unshare $TESTDIR $TESTPOOL/$TESTFS log_pass "A file system and its dependent are both unshared as expected." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_007_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_007_pos.ksh index a5b29a89618a..36817a092099 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_unshare/zfs_unshare_007_pos.ksh @@ -1,68 +1,67 @@ #!/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 2016, loli10K. All rights reserved. # Copyright (c) 2018 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that 'zfs destroy' on a shared dataset, will unshare it. # # STRATEGY: # 1. Create and share a dataset with sharenfs. # 2. Verify the dataset is shared. # 3. Invoke 'zfs destroy' on the dataset. # 4. Verify the dataset is not shared. # verify_runnable "global" function cleanup { - if datasetexists "$TESTPOOL/$TESTFS/shared1"; then - log_must zfs destroy -f $TESTPOOL/$TESTFS/shared1 - fi + datasetexists "$TESTPOOL/$TESTFS/shared1" && \ + destroy_dataset $TESTPOOL/$TESTFS/shared1 -f } log_assert "Verify 'zfs destroy' will unshare the dataset" log_onexit cleanup # 1. Create and share a dataset with sharenfs. log_must zfs create \ -o sharenfs=on -o mountpoint=$TESTDIR/1 $TESTPOOL/$TESTFS/shared1 # # 2. Verify the datasets is shared. # log_must is_shared $TESTDIR/1 # 3. Invoke 'zfs destroy' on the dataset. log_must zfs destroy -f $TESTPOOL/$TESTFS/shared1 # 4. Verify the dataset is not shared. log_mustnot is_shared $TESTDIR/1 log_pass "'zfs destroy' will unshare the dataset." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh index d3ed4a736cc9..ab76461638b9 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_001_pos.ksh @@ -1,139 +1,135 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib # # DESCRIPTION: # Executing 'zfs upgrade' command succeeds, it should report # the current system version and list all old-version filesystems. # If no old-version filesystems be founded, it prints out # "All filesystems are formatted with the current version." # # STRATEGY: # 1. Prepare a set of datasets which contain old-version and current version. # 2. Execute 'zfs upgrade', verify return 0, and it prints out # the current system version and list all old-version filesystems. # 3. Remove all old-version filesystems, then execute 'zfs upgrade' again, # verify return 0, and get the expected message. # verify_runnable "both" function cleanup { - if datasetexists $rootfs ; then - log_must zfs destroy -Rf $rootfs - fi + datasetexists $rootfs && destroy_dataset $rootfs -Rf log_must zfs create $rootfs for file in $output $oldoutput ; do if [[ -f $file ]]; then log_must rm -f $file fi done } log_assert "Executing 'zfs upgrade' command succeeds." log_onexit cleanup rootfs=$TESTPOOL/$TESTFS typeset output=$TEST_BASE_DIR/zfs-versions.$$ typeset oldoutput=$TEST_BASE_DIR/zfs-versions-old.$$ typeset expect_str1="This system is currently running ZFS filesystem version" typeset expect_str2="All filesystems are formatted with the current version" typeset expect_str3="The following filesystems are out of date, and can be upgraded" typeset -i COUNT OLDCOUNT zfs upgrade | nawk '$1 ~ "^[0-9]+$" {print $2}'> $oldoutput OLDCOUNT=$( wc -l $oldoutput | awk '{print $1}' ) old_datasets="" for version in $ZFS_ALL_VERSIONS ; do typeset verfs eval verfs=\$ZFS_VERSION_$version typeset current_fs=$rootfs/$verfs typeset current_snap=${current_fs}@snap typeset current_clone=$rootfs/clone$verfs log_must zfs create -o version=${version} ${current_fs} log_must zfs snapshot ${current_snap} log_must zfs clone ${current_snap} ${current_clone} if (( version != $ZFS_VERSION )); then old_datasets="$old_datasets ${current_fs} ${current_clone}" fi done if is_global_zone; then log_must zfs create -V 100m $rootfs/$TESTVOL fi log_must eval 'zfs upgrade > $output 2>&1' # we also check that the usage message contains at least a description # of the current ZFS version. log_must eval 'grep "${expect_str1} $ZFS_VERSION" $output > /dev/null 2>&1' zfs upgrade | nawk '$1 ~ "^[0-9]+$" {print $2}'> $output COUNT=$( wc -l $output | awk '{print $1}' ) typeset -i i=0 for fs in ${old_datasets}; do log_must grep "^$fs$" $output (( i = i + 1 )) done if (( i != COUNT - OLDCOUNT )); then cat $output log_fail "More old-version filesystems print out than expect." fi for fs in $old_datasets ; do - if datasetexists $fs ; then - log_must zfs destroy -Rf $fs - fi + datasetexists $fs && destroy_dataset $fs -Rf done log_must eval 'zfs upgrade > $output 2>&1' log_must eval 'grep "${expect_str1} $ZFS_VERSION" $output > /dev/null 2>&1' if (( OLDCOUNT == 0 )); then log_must eval 'grep "${expect_str2}" $output > /dev/null 2>&1' else log_must eval 'grep "${expect_str3}" $output > /dev/null 2>&1' fi zfs upgrade | nawk '$1 ~ "^[0-9]+$" {print $2}'> $output COUNT=$( wc -l $output | awk '{print $1}' ) if (( COUNT != OLDCOUNT )); then cat $output log_fail "Unexpected old-version filesystems print out." fi log_pass "Executing 'zfs upgrade' command succeeds." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh index 6df47b450d00..57f74ca28513 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_003_pos.ksh @@ -1,104 +1,102 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib # # DESCRIPTION: # Executing 'zfs upgrade [-V version] filesystem' command succeeds, # it could upgrade a filesystem to specific version or current version. # # STRATEGY: # 1. Prepare a set of datasets which contain old-version and current version. # 2. Execute 'zfs upgrade [-V version] filesystem', verify return 0, # 3. Verify the filesystem be updated as expected. # verify_runnable "both" function cleanup { - if datasetexists $rootfs ; then - log_must zfs destroy -Rf $rootfs - fi + datasetexists $rootfs && destroy_dataset $rootfs -Rf log_must zfs create $rootfs } function setup_datasets { datasets="" for version in $ZFS_ALL_VERSIONS ; do typeset verfs eval verfs=\$ZFS_VERSION_$version typeset current_fs=$rootfs/$verfs typeset current_snap=${current_fs}@snap typeset current_clone=$rootfs/clone$verfs log_must zfs create -o version=${version} ${current_fs} log_must zfs snapshot ${current_snap} log_must zfs clone ${current_snap} ${current_clone} datasets="$datasets ${current_fs} ${current_clone}" done } log_assert "Executing 'zfs upgrade [-V version] filesystem' command succeeds." log_onexit cleanup rootfs=$TESTPOOL/$TESTFS typeset datasets typeset newv for newv in "" "current" $ZFS_ALL_VERSIONS; do setup_datasets for fs in $datasets ; do typeset -i oldv=$(get_prop version $fs) if [[ -n $newv ]]; then opt="-V $newv" if [[ $newv == current ]]; then newv=$ZFS_VERSION fi else newv=$ZFS_VERSION fi if (( newv >= oldv )); then log_must eval 'zfs upgrade $opt $fs > /dev/null 2>&1' log_must check_fs_version $fs $newv else log_mustnot eval 'zfs upgrade $opt $fs > /dev/null 2>&1' log_must check_fs_version $fs $oldv fi done cleanup done log_pass "Executing 'zfs upgrade [-V version] filesystem' command succeeds." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh index e3ff4f4b9073..0b8fef5cd043 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_004_pos.ksh @@ -1,108 +1,106 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib # # DESCRIPTION: # Executing 'zfs upgrade -r [-V version] filesystem' command succeeds, # it upgrade filesystem recursively to specific or current version. # # STRATEGY: # 1. Prepare a set of datasets which contain old-version and current version. # 2. Execute 'zfs upgrade -r [-V version] filesystem', verify return 0, # 3. Verify the filesystem be updated recursively as expected. # verify_runnable "both" function cleanup { - if datasetexists $rootfs ; then - log_must zfs destroy -Rf $rootfs - fi + datasetexists $rootfs && destroy_dataset $rootfs -Rf log_must zfs create $rootfs } function setup_datasets { datasets="" for version in $ZFS_ALL_VERSIONS ; do typeset verfs eval verfs=\$ZFS_VERSION_$version typeset current_fs=$rootfs/$verfs typeset current_snap=${current_fs}@snap typeset current_clone=$rootfs/clone$verfs log_must zfs create -o version=${version} ${current_fs} log_must zfs snapshot ${current_snap} log_must zfs clone ${current_snap} ${current_clone} for subversion in $ZFS_ALL_VERSIONS ; do typeset subverfs eval subverfs=\$ZFS_VERSION_$subversion log_must zfs create -o version=${subversion} \ ${current_fs}/$subverfs done datasets="$datasets ${current_fs}" done } log_assert "Executing 'zfs upgrade -r [-V version] filesystem' command succeeds." log_onexit cleanup rootfs=$TESTPOOL/$TESTFS typeset datasets typeset newv for newv in "" "current" $ZFS_VERSION; do setup_datasets for topfs in $datasets ; do if [[ -n $newv ]]; then opt="-V $newv" if [[ $newv == current ]]; then newv=$ZFS_VERSION fi else newv=$ZFS_VERSION fi log_must eval 'zfs upgrade -r $opt $topfs > /dev/null 2>&1' for fs in $(zfs list -rH -t filesystem -o name $topfs) ; do log_must check_fs_version $fs $newv done done cleanup done log_pass "Executing 'zfs upgrade -r [-V version] filesystem' command succeeds." diff --git a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh index 1a929918bf10..5fcdc6e26852 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zfs_upgrade/zfs_upgrade_005_pos.ksh @@ -1,108 +1,106 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_upgrade/zfs_upgrade.kshlib # # DESCRIPTION: # Executing 'zfs upgrade [-V version] -a' command succeeds, # it upgrade all filesystems to specific or current version. # # STRATEGY: # 1. Prepare a set of datasets which contain old-version and current version. # 2. Execute 'zfs upgrade [-V version] -a', verify return 0, # 3. Verify all the filesystems be updated as expected. # verify_runnable "both" function cleanup { - if datasetexists $rootfs ; then - log_must zfs destroy -Rf $rootfs - fi + datasetexists $rootfs && destroy_dataset $rootfs -Rf log_must zfs create $rootfs } function setup_datasets { datasets="" for version in $ZFS_ALL_VERSIONS ; do typeset verfs eval verfs=\$ZFS_VERSION_$version typeset current_fs=$rootfs/$verfs typeset current_snap=${current_fs}@snap typeset current_clone=$rootfs/clone$verfs log_must zfs create -o version=${version} ${current_fs} log_must zfs snapshot ${current_snap} log_must zfs clone ${current_snap} ${current_clone} for subversion in $ZFS_ALL_VERSIONS ; do typeset subverfs eval subverfs=\$ZFS_VERSION_$subversion log_must zfs create -o version=${subversion} \ ${current_fs}/$subverfs done datasets="$datasets ${current_fs}" done } log_assert "Executing 'zfs upgrade [-V version] -a' command succeeds." log_onexit cleanup rootfs=$TESTPOOL/$TESTFS typeset datasets typeset newv for newv in "" "current" $ZFS_VERSION; do setup_datasets if [[ -n $newv ]]; then opt="-V $newv" if [[ $newv == current ]]; then newv=$ZFS_VERSION fi else newv=$ZFS_VERSION fi export __ZFS_POOL_RESTRICT="$TESTPOOL" log_must zfs upgrade $opt -a unset __ZFS_POOL_RESTRICT for fs in $(zfs list -rH -t filesystem -o name $rootfs) ; do log_must check_fs_version $fs $newv done cleanup done log_pass "Executing 'zfs upgrade [-V version] -a' command succeeds." diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh index 3323f1db0caf..c25b6c9230a7 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_001_pos.ksh @@ -1,86 +1,85 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg # # DESCRIPTION: # 'zpool destroy ' can successfully destroy the specified pool. # # STRATEGY: # 1. Create a storage pool # 2. Destroy the pool # 3. Verify the is destroyed successfully # verify_runnable "global" function cleanup { poolexists $TESTPOOL2 && destroy_pool $TESTPOOL2 - datasetexists $TESTPOOL1/$TESTVOL && \ - log_must zfs destroy -f $TESTPOOL1/$TESTVOL + datasetexists $TESTPOOL1/$TESTVOL && destroy_dataset $TESTPOOL1/$TESTVOL -f typeset pool for pool in $TESTPOOL1 $TESTPOOL; do poolexists $pool && destroy_pool $pool done [ -n "$recursive" ] && set_tunable64 VOL_RECURSIVE $recursive } set -A datasets "$TESTPOOL" "$TESTPOOL2" log_assert "'zpool destroy ' can destroy a specified pool." log_onexit cleanup create_pool $TESTPOOL $DISK0 create_pool $TESTPOOL1 $DISK1 log_must zfs create -s -V $VOLSIZE $TESTPOOL1/$TESTVOL block_device_wait if is_freebsd; then typeset recursive=$(get_tunable VOL_RECURSIVE) log_must set_tunable64 VOL_RECURSIVE 1 fi create_pool $TESTPOOL2 $ZVOL_DEVDIR/$TESTPOOL1/$TESTVOL typeset -i i=0 while (( i < ${#datasets[*]} )); do log_must poolexists "${datasets[i]}" log_must zpool destroy "${datasets[i]}" log_mustnot poolexists "${datasets[i]}" ((i = i + 1)) done log_pass "'zpool destroy ' executes successfully" diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh index 794a6c37c37a..a634f10f1114 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh @@ -1,117 +1,117 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg # # DESCRIPTION: # 'zpool destroy -f ' can forcely destroy the specified pool. # # STRATEGY: # 1. Create a storage pool # 2. Create some datasets within the pool # 3. Change directory to any mountpoint of these datasets, # Verify 'zpool destroy' without '-f' will fail. # 4. 'zpool destroy -f' the pool # 5. Verify the pool is destroyed successfully # verify_runnable "global" function cleanup { [[ -n $cwd ]] && log_must cd $cwd if [[ -d $TESTDIR ]]; then ismounted $TESTDIR && log_must umount $TESTDIR log_must rm -rf $TESTDIR fi typeset -i i=0 while (( $i < ${#datasets[*]} )); do datasetexists ${datasets[i]} && \ - log_must zfs destroy ${datasets[i]} + destroy_dataset ${datasets[i]} (( i = i + 1 )) done poolexists $TESTPOOL && destroy_pool $TESTPOOL } set -A datasets "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR/$TESTFS1" \ "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" \ log_assert "'zpool destroy -f ' can forcely destroy the specified pool" log_onexit cleanup create_pool $TESTPOOL $DISK0 log_must zfs create $TESTPOOL/$TESTFS log_must mkdir -p $TESTDIR log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS log_must zfs create $TESTPOOL/$TESTCTR log_must zfs create $TESTPOOL/$TESTCTR/$TESTFS1 log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL typeset -i i=0 while (( $i < ${#datasets[*]} )); do datasetexists "${datasets[i]}" || \ log_fail "Create datasets fail." ((i = i + 1)) done log_note "'zpool destroy' without '-f' will fail " \ "while pool is busy." for dir in $TESTDIR /$TESTPOOL/$TESTCTR /$TESTPOOL/$TESTCTR/$TESTFS1 ; do log_must cd $dir log_mustnot zpool destroy $TESTPOOL # Need mount here, otherwise some dataset may be unmounted. log_must zfs mount -a i=0 while (( i < ${#datasets[*]} )); do datasetexists "${datasets[i]}" || \ log_fail "Dataset ${datasets[i]} removed unexpected." ((i = i + 1)) done done # 4. 'zpool destroy -f' the pool (unsupported behavior in Linux) if is_linux; then log_must cd $cwd fi destroy_pool $TESTPOOL log_mustnot poolexists "$TESTPOOL" log_pass "'zpool destroy -f ' success." diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_001_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_001_neg.ksh index a2b73182bf4c..b5cd8d529ed0 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_001_neg.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_history/zpool_history_001_neg.ksh @@ -1,69 +1,69 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify 'zpool history' can deal with non-existent pools and garbage # to the command. # # STRATEGY: # 1. Create pool, volume & snap # 2. Verify 'zpool history' can cope with incorrect arguments. # verify_runnable "global" snap=$TESTPOOL/$TESTFS@snap clone=$TESTPOOL/clone set -A neg_opt "$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" "-t $TESTPOOL" \ "-v $TESTPOOL" "$snap" "$clone" "nonexist" "TESTPOOL" function cleanup { - datasetexists $clone && log_must zfs destroy $clone - datasetexists $snap && log_must zfs destroy $snap + datasetexists $clone && destroy_dataset $clone + datasetexists $snap && destroy_dataset $snap } log_assert "Verify 'zpool history' can deal with non-existent pools and " \ "garbage to the command." log_onexit cleanup log_must zfs snapshot $snap log_must zfs clone $snap $clone for opt in "${neg_opt[@]}"; do log_mustnot eval "zpool history $opt > /dev/null" done log_pass "'zpool history' command line negation test passed." diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/cleanup.ksh index d5717ee1561e..bee0e11a4ff4 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_import/cleanup.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_import/cleanup.ksh @@ -1,50 +1,49 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg verify_runnable "global" log_must set_tunable32 SCAN_SUSPEND_PROGRESS 0 for pool in "$TESTPOOL" "$TESTPOOL1"; do - datasetexists $pool/$TESTFS && \ - log_must zfs destroy -Rf $pool/$TESTFS + datasetexists $pool/$TESTFS && destroy_dataset $pool/$TESTFS -Rf destroy_pool "$pool" done for dir in "$TESTDIR" "$TESTDIR1" "$DEVICE_DIR" ; do [[ -d $dir ]] && \ log_must rm -rf $dir done log_pass diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_pos.ksh index a568948e37c4..ec387b225665 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_pos.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_012_pos.ksh @@ -1,211 +1,211 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib . $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg # # DESCRIPTION: # Once a pool has been exported, it should be recreated after a # successful import, all the sub-filesystems within it should all be restored, # include mount & share status. Verify that is true. # # STRATEGY: # 1. Create the test pool and hierarchical filesystems. # 2. Export the test pool, or destroy the test pool, # depend on testing import [-Df]. # 3. Import it using the various combinations. # - Regular import # - Alternate Root Specified # 4. Verify the mount & share status is restored. # verify_runnable "global" set -A pools "$TESTPOOL" "$TESTPOOL1" set -A devs "" "-d $DEVICE_DIR" set -A options "" "-R $ALTER_ROOT" set -A mtpts "$TESTDIR" "$TESTDIR1" function cleanup { typeset -i i=0 while ((i < ${#pools[*]})); do if poolexists ${pools[i]}; then log_must zpool export ${pools[i]} log_note "Try to import ${devs[i]} ${pools[i]}" zpool import ${devs[i]} ${pools[i]} else log_note "Try to import $option ${devs[i]} ${pools[i]}" zpool import $option ${devs[i]} ${pools[i]} fi if poolexists ${pools[i]}; then is_shared ${pools[i]} && \ log_must zfs set sharenfs=off ${pools[i]} ismounted "${pools[i]}/$TESTFS" || \ log_must zfs mount ${pools[i]}/$TESTFS fi ((i = i + 1)) done destroy_pool $TESTPOOL1 - if datasetexists $TESTPOOL/$TESTFS; then - log_must zfs destroy -Rf $TESTPOOL/$TESTFS - fi + datasetexists $TESTPOOL/$TESTFS && \ + destroy_dataset $TESTPOOL/$TESTFS -Rf + log_must zfs create $TESTPOOL/$TESTFS log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS [[ -d $ALTER_ROOT ]] && \ log_must rm -rf $ALTER_ROOT } log_onexit cleanup log_assert "Verify all mount & share status of sub-filesystems within a pool \ can be restored after import [-Df]." setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 # create a hierarchy of filesystem for pool in ${pools[@]} ; do log_must zfs create $pool/$TESTFS/$TESTCTR log_must zfs create $pool/$TESTFS/$TESTCTR/$TESTCTR1 log_must zfs set canmount=off $pool/$TESTFS/$TESTCTR log_must zfs set canmount=off $pool/$TESTFS/$TESTCTR/$TESTCTR1 log_must zfs create $pool/$TESTFS/$TESTCTR/$TESTFS1 log_must zfs create $pool/$TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1 log_must zfs create $pool/$TESTFS/$TESTFS1 log_must zfs snapshot $pool/$TESTFS/$TESTFS1@snap log_must zfs clone $pool/$TESTFS/$TESTFS1@snap $pool/$TESTCLONE1 done typeset mount_fs="$TESTFS $TESTFS/$TESTFS1 $TESTCLONE1 \ $TESTFS/$TESTCTR/$TESTFS1 $TESTFS/$TESTCTR/$TESTCTR1/$TESTFS1" typeset nomount_fs="$TESTFS/$TESTCTR $TESTFS/$TESTCTR/$TESTCTR1" typeset -i i=0 typeset -i j=0 typeset -i nfs_share_bit=0 typeset -i guid_bit=0 typeset basedir for option in "" "-Df"; do i=0 while ((i < ${#pools[*]})); do pool=${pools[i]} guid=$(get_pool_prop guid $pool) j=0 while ((j < ${#options[*]})); do # set sharenfs property off/on nfs_share_bit=0 while ((nfs_share_bit <= 1)); do typeset f_share="" typeset nfs_flag="sharenfs=off" if ((nfs_share_bit == 1)); then log_note "Set sharenfs=on $pool" log_must zfs set sharenfs=on $pool ! is_freebsd && log_must is_shared $pool f_share="true" nfs_flag="sharenfs=on" fi # for every off/on nfs bit import guid/pool_name guid_bit=0 while ((guid_bit <= 1)); do typeset guid_flag="pool name" if [[ -z $option ]]; then log_must_busy zpool export $pool else log_must_busy zpool destroy $pool fi typeset target=$pool if ((guid_bit == 1)); then log_note "Import by guid." if [[ -z $guid ]]; then log_fail "guid should "\ "not be empty!" else target=$guid guid_flag="$guid" fi fi log_note "Import with $nfs_flag and " \ "$guid_flag" zpool import $option ${devs[i]} \ ${options[j]} $target #import by GUID if import by pool name fails if [[ $? != 0 ]]; then log_note "Possible pool name" \ "duplicates. Try GUID import" target=$guid log_must zpool import $option \ ${devs[i]} ${options[j]} \ $target fi log_must poolexists $pool 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 ! 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 ! is_freebsd && log_mustnot is_shared $pool fi ((nfs_share_bit = nfs_share_bit + 1)) done ((j = j + 1)) done ((i = i + 1)) done done log_pass "All mount & share status of sub-filesystems within a pool \ can be restored after import [-Df]." diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_encrypted_unloaded.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_encrypted_unloaded.ksh index a8c15424db27..b1f7c6264b01 100755 --- a/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_encrypted_unloaded.ksh +++ b/tests/zfs-tests/tests/functional/cli_root/zpool_scrub/zpool_scrub_encrypted_unloaded.ksh @@ -1,67 +1,67 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2017 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Scrubs must work on an encrypted dataset with an unloaded key. # # STRATEGY: # 1. Create an encrypted dataset # 2. Generate data on the dataset # 3. Unmount the encrypted dataset and unload its key # 4. Start a scrub # 5. Wait for the scrub to complete # 6. Verify the scrub had no errors # 7. Load the dataset key and mount it # verify_runnable "global" function cleanup { datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 } log_onexit cleanup log_assert "Scrubs must work on an encrypted dataset with an unloaded key" log_must eval "echo 'password' | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS2" typeset mntpnt=$(get_prop mountpoint $TESTPOOL/$TESTFS2) log_must mkfile 10m $mntpnt/file1 for i in 2..10; do log_must mkfile 512b $mntpnt/file$i done log_must zfs unmount $TESTPOOL/$TESTFS2 log_must zfs unload-key $TESTPOOL/$TESTFS2 log_must zpool scrub -w $TESTPOOL log_must check_pool_status $TESTPOOL "scan" "with 0 errors" log_must eval "echo 'password' | zfs mount -l $TESTPOOL/$TESTFS2" log_pass "Scrubs work on an encrypted dataset with an unloaded key" diff --git a/tests/zfs-tests/tests/functional/features/async_destroy/async_destroy_001_pos.ksh b/tests/zfs-tests/tests/functional/features/async_destroy/async_destroy_001_pos.ksh index 23fb16d6ed5a..ad0e49f8fb40 100755 --- a/tests/zfs-tests/tests/functional/features/async_destroy/async_destroy_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/features/async_destroy/async_destroy_001_pos.ksh @@ -1,102 +1,102 @@ #!/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 (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Exercise the traversal suspend/resume code in async_destroy by # destroying a file system that has more blocks than we can free # in a single txg. # # STRATEGY: # 1. Create a file system # 2. Set recordsize to 512 to create the maximum number of blocks # 3. Set compression to off to force zero-ed blocks to be written # 4. dd a lot of data from /dev/zero to the file system # 5. Destroy the file system # 6. Wait for the freeing property to go to 0 # 7. Use zdb to check for leaked blocks # TEST_FS=$TESTPOOL/async_destroy verify_runnable "both" function cleanup { - datasetexists $TEST_FS && log_must zfs destroy $TEST_FS + datasetexists $TEST_FS && destroy_dataset $TEST_FS log_must set_tunable64 ASYNC_BLOCK_MAX_BLOCKS 100000 } log_onexit cleanup log_assert "async_destroy can suspend and resume traversal" log_must zfs create -o recordsize=1k -o compression=off $TEST_FS # Fill with 128,000 blocks. log_must dd bs=1024k count=128 if=/dev/zero of=/$TEST_FS/file # # Decrease the max blocks to free each txg, so that freeing takes # long enough that we can observe it. # log_must set_tunable64 ASYNC_BLOCK_MAX_BLOCKS 100 log_must sync log_must zfs destroy $TEST_FS # # We monitor the freeing property, to verify we can see blocks being # freed while the suspend/resume code is exercised. # t0=$SECONDS count=0 while [[ $((SECONDS - t0)) -lt 10 ]]; do [[ "0" != "$(zpool list -Ho freeing $TESTPOOL)" ]] && ((count++)) [[ $count -gt 1 ]] && break sleep 1 done [[ $count -eq 0 ]] && log_fail "Freeing property remained empty" # # After a bit, go back to allowing an unlimited amount of freeing # per txg. # sleep 10 log_must set_tunable64 ASYNC_BLOCK_MAX_BLOCKS 100000 # Wait for everything to be freed. while [[ "0" != "$(zpool list -Ho freeing $TESTPOOL)" ]]; do [[ $((SECONDS - t0)) -gt 180 ]] && \ log_fail "Timed out waiting for freeing to drop to zero" done # Check for leaked blocks. log_must zdb -b $TESTPOOL log_pass "async_destroy can suspend and resume traversal" diff --git a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_001_pos.ksh b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_001_pos.ksh index d3530292e81a..cb1e940a7d73 100755 --- a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_001_pos.ksh @@ -1,82 +1,82 @@ #!/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 (c) 2016 by Lawrence Livermore National Security, LLC. # Use is subject to license terms. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that the dnode sizes of newly created files are consistent # with the dnodesize dataset property. # # STRATEGY: # 1. Create a file system # 2. Set dnodesize to a legal literal value # 3. Create a file # 4. Repeat 2-3 for all legal literal values of dnodesize values # 5. Unmount the file system # 6. Use zdb to check expected dnode sizes # TEST_FS=$TESTPOOL/large_dnode verify_runnable "both" function cleanup { - datasetexists $TEST_FS && log_must zfs destroy $TEST_FS + datasetexists $TEST_FS && destroy_dataset $TEST_FS } log_onexit cleanup log_assert "dnode sizes are consistent with dnodesize dataset property" log_must zfs create $TEST_FS set -A dnsizes "512" "1k" "2k" "4k" "8k" "16k" set -A inodes for ((i=0; i < ${#dnsizes[*]}; i++)) ; do size=${dnsizes[$i]} if [[ $size == "512" ]] ; then size="legacy" fi file=/$TEST_FS/file.$size log_must zfs set dnsize=$size $TEST_FS touch $file inodes[$i]=$(ls -li $file | awk '{print $1}') done log_must zfs umount $TEST_FS for ((i=0; i < ${#dnsizes[*]}; i++)) ; do dnsize=$(zdb -dddd $TEST_FS ${inodes[$i]} | awk '/ZFS plain file/ {print $6}' | tr K k) if [[ "$dnsize" != "${dnsizes[$i]}" ]]; then log_fail "dnode size is $dnsize (expected ${dnsizes[$i]})" fi done log_pass "dnode sizes are consistent with dnodesize dataset property" diff --git a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_002_pos.ksh b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_002_pos.ksh index c2b32ad66217..9a00ceeb3cef 100755 --- a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_002_pos.ksh @@ -1,83 +1,83 @@ #!/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 (c) 2016 by Lawrence Livermore National Security, LLC. # Use is subject to license terms. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that extended attributes can use extra bonus space of a large # dnode without kicking in a spill block. # # STRATEGY: # 1. Create a file system with xattr=sa # 2. Set dnodesize to a legal literal value # 3. Create a file # 4 Store an xattr that fits within the dnode size # 4. Repeat 2-3 for all legal literal values of dnodesize values # 5. Unmount the file system # 6. Use zdb to check for missing SPILL_BLKPTR flag # TEST_FS=$TESTPOOL/large_dnode verify_runnable "both" function cleanup { - datasetexists $TEST_FS && log_must zfs destroy $TEST_FS + datasetexists $TEST_FS && destroy_dataset $TEST_FS } log_onexit cleanup log_assert "extended attributes use extra bonus space of a large dnode" log_must zfs create -o xattr=sa $TEST_FS # Store dnode size minus 512 in an xattr set -A xattr_sizes "512" "1536" "3584" "7680" "15872" set -A prop_values "1k" "2k" "4k" "8k" "16k" set -A inodes for ((i=0; i < ${#prop_values[*]}; i++)) ; do prop_val=${prop_values[$i]} file=/$TEST_FS/file.$prop_val log_must zfs set dnsize=$prop_val $TEST_FS touch $file xattr_size=${xattr_sizes[$i]} xattr_name=user.foo xattr_val=$(dd if=/dev/urandom bs=1 count=$xattr_size | openssl enc -a -A) log_must setfattr -n $xattr_name -v 0s$xattr_val $file inodes[$i]=$(ls -li $file | awk '{print $1}') done log_must zfs umount $TEST_FS for ((i=0; i < ${#inodes[*]}; i++)) ; do log_mustnot eval "zdb -dddd $TEST_FS ${inodes[$i]} | grep SPILL_BLKPTR" done log_pass "extended attributes use extra bonus space of a large dnode" diff --git a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_004_neg.ksh b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_004_neg.ksh index 3fa1cabe063a..2cc587b47879 100755 --- a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_004_neg.ksh +++ b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_004_neg.ksh @@ -1,73 +1,71 @@ #!/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 (c) 2016 by Lawrence Livermore National Security, LLC. # Use is subject to license terms. # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib verify_runnable "both" TEST_FS=$TESTPOOL/large_dnode TEST_SNAP=$TESTPOOL/large_dnode@ldnsnap TEST_STREAM=$TESTDIR/ldnsnap function cleanup { - if datasetexists $TEST_FS ; then - log_must zfs destroy -r $TEST_FS - fi + datasetexists $TEST_FS && destroy_dataset $TEST_FS -r if datasetexists $LGCYPOOL ; then log_must zpool destroy -f $LGCYPOOL fi rm -f $TEST_STREAM } log_onexit cleanup log_assert "zfs send stream with large dnodes not accepted by legacy pool" log_must zfs create -o dnodesize=1k $TEST_FS log_must touch /$TEST_FS/foo log_must zfs umount $TEST_FS log_must zfs snap $TEST_SNAP log_must eval "zfs send $TEST_SNAP > $TEST_STREAM" LGCYPOOL=ldnpool LGCYFS=$LGCYPOOL/legacy log_must mkfile 64M $TESTDIR/$LGCYPOOL log_must zpool create -d $LGCYPOOL $TESTDIR/$LGCYPOOL log_mustnot eval "zfs recv $LGCYFS < $TEST_STREAM" log_pass diff --git a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_005_pos.ksh b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_005_pos.ksh index a2d92673b180..2be98942634f 100755 --- a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_005_pos.ksh @@ -1,80 +1,75 @@ #!/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 (c) 2016 by Lawrence Livermore National Security, LLC. # Use is subject to license terms. # . $STF_SUITE/include/libtest.shlib verify_runnable "both" TEST_SEND_FS=$TESTPOOL/send_large_dnode TEST_RECV_FS=$TESTPOOL/recv_large_dnode TEST_SNAP=$TEST_SEND_FS@ldnsnap TEST_SNAPINCR=$TEST_SEND_FS@ldnsnap_incr TEST_STREAM=$TESTDIR/ldnsnap TEST_STREAMINCR=$TESTDIR/ldnsnap_incr TEST_FILE=foo TEST_FILEINCR=bar function cleanup { - if datasetexists $TEST_SEND_FS ; then - log_must zfs destroy -r $TEST_SEND_FS - fi - - if datasetexists $TEST_RECV_FS ; then - log_must zfs destroy -r $TEST_RECV_FS - fi + datasetexists $TEST_SEND_FS && destroy_dataset $TEST_SEND_FS -r + datasetexists $TEST_RECV_FS && destroy_dataset $TEST_RECV_FS -r rm -f $TEST_STREAM rm -f $TEST_STREAMINCR } log_onexit cleanup log_assert "zfs send stream with large dnodes accepted by new pool" log_must zfs create -o dnodesize=1k $TEST_SEND_FS log_must touch /$TEST_SEND_FS/$TEST_FILE log_must zfs snap $TEST_SNAP log_must zfs send $TEST_SNAP > $TEST_STREAM log_must rm -f /$TEST_SEND_FS/$TEST_FILE log_must touch /$TEST_SEND_FS/$TEST_FILEINCR log_must zfs snap $TEST_SNAPINCR log_must zfs send -i $TEST_SNAP $TEST_SNAPINCR > $TEST_STREAMINCR log_must eval "zfs recv $TEST_RECV_FS < $TEST_STREAM" inode=$(ls -li /$TEST_RECV_FS/$TEST_FILE | awk '{print $1}') dnsize=$(zdb -dddd $TEST_RECV_FS $inode | awk '/ZFS plain file/ {print $6}') if [[ "$dnsize" != "1K" ]]; then log_fail "dnode size is $dnsize (expected 1K)" fi log_must eval "zfs recv -F $TEST_RECV_FS < $TEST_STREAMINCR" log_must diff -r /$TEST_SEND_FS /$TEST_RECV_FS log_must zfs umount $TEST_SEND_FS log_must zfs umount $TEST_RECV_FS log_pass diff --git a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_006_pos.ksh b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_006_pos.ksh index 38b4ac52e5d6..3727bd5c11d2 100755 --- a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_006_pos.ksh @@ -1,72 +1,72 @@ #!/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 (c) 2016 by Lawrence Livermore National Security, LLC. # Use is subject to license terms. # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Run xattrtest on a dataset with large dnodes and xattr=sa # to stress xattr usage of the extra bonus space and verify # contents # TEST_FS=$TESTPOOL/large_dnode verify_runnable "both" function cleanup { - datasetexists $TEST_FS && log_must zfs destroy $TEST_FS + datasetexists $TEST_FS && destroy_dataset $TEST_FS } log_onexit cleanup log_assert "xattrtest runs cleanly on dataset with large dnodes" log_must zfs create $TEST_FS set -A xattr_sizes "512" "1536" "3584" "7680" "15872" set -A prop_values "1k" "2k" "4k" "8k" "16k" for ((i=0; i < ${#prop_values[*]}; i++)) ; do prop_val=${prop_values[$i]} dir=/$TEST_FS/$prop_val xattr_size=${xattr_sizes[$i]} log_must zfs set dnsize=$prop_val $TEST_FS log_must mkdir $dir log_must xattrtest -R -y -s $xattr_size -f 1024 -p $dir done log_pass diff --git a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_009_pos.ksh b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_009_pos.ksh index fa746c52e5c5..1e42202069eb 100755 --- a/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_009_pos.ksh +++ b/tests/zfs-tests/tests/functional/features/large_dnode/large_dnode_009_pos.ksh @@ -1,71 +1,71 @@ #!/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 (c) 2017 by Lawrence Livermore National Security, LLC. # Use is subject to license terms. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Run many xattrtests on a dataset with large dnodes and xattr=sa to # stress concurrent allocation of large dnodes. # TEST_FS=$TESTPOOL/large_dnode verify_runnable "both" function cleanup { - datasetexists $TEST_FS && log_must zfs destroy $TEST_FS + datasetexists $TEST_FS && destroy_dataset $TEST_FS } log_onexit cleanup log_assert "xattrtest runs concurrently on dataset with large dnodes" log_must zfs create $TEST_FS log_must zfs set dnsize=auto $TEST_FS log_must zfs set xattr=sa $TEST_FS for ((i=0; i < 100; i++)); do dir="/$TEST_FS/dir.$i" log_must mkdir "$dir" do_unlink="" if [ $((RANDOM % 2)) -eq 0 ]; then do_unlink="-k -f 1024" else do_unlink="-f $((RANDOM % 1024))" fi log_must eval "xattrtest -R -r -y -x 1 $do_unlink -p $dir >/dev/null 2>&1 &" done log_must wait -log_must zpool export $TESTPOOL +log_must_busy zpool export $TESTPOOL log_must zpool import $TESTPOOL log_must ls -lR "/$TEST_FS/" >/dev/null 2>&1 log_must zdb -d $TESTPOOL log_pass diff --git a/tests/zfs-tests/tests/functional/history/history_002_pos.ksh b/tests/zfs-tests/tests/functional/history/history_002_pos.ksh index a53bcaf4ec64..b431cdc5f144 100755 --- a/tests/zfs-tests/tests/functional/history/history_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/history/history_002_pos.ksh @@ -1,199 +1,199 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/history/history_common.kshlib # # DESCRIPTION: # Create a scenario to verify the following zfs subcommands are logged. # create, destroy, clone, rename, snapshot, rollback, set, inherit, # receive, promote, hold and release. # # STRATEGY: # 1. Verify that all the zfs commands listed (barring send) produce an # entry in the pool history. # verify_runnable "global" function cleanup { [[ -f $tmpfile ]] && rm -f $tmpfile [[ -f $tmpfile2 ]] && rm -f $tmpfile2 for dataset in $fs $newfs $fsclone $vol $newvol $volclone; do - datasetexists $dataset && zfs destroy -Rf $dataset + datasetexists $dataset && destroy_dataset $dataset -Rf done rm -rf /history.$$ } log_assert "Verify zfs sub-commands which modify state are logged." log_onexit cleanup fs=$TESTPOOL/$TESTFS1; newfs=$TESTPOOL/newfs; fsclone=$TESTPOOL/clone vol=$TESTPOOL/$TESTVOL ; newvol=$TESTPOOL/newvol; volclone=$TESTPOOL/volclone fssnap=$fs@fssnap; fssnap2=$fs@fssnap2 volsnap=$vol@volsnap; volsnap2=$vol@volsnap2 tmpfile=$TEST_BASE_DIR/tmpfile.$$ ; tmpfile2=$TEST_BASE_DIR/tmpfile2.$$ if is_linux; then # property value property value # props=( quota 64M recordsize 512 reservation 32M reservation none mountpoint /history.$$ mountpoint legacy mountpoint none compression lz4 compression on compression off compression lzjb acltype off acltype posix acltype nfsv4 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)) compression zstd compression zstd-$((RANDOM%9 + 1)) compression zstd-fast copies $((RANDOM%3 + 1)) compression zstd-fast-$((RANDOM%9 + 1)) xattr sa xattr on xattr off ) 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 jailed on jailed off snapdir hidden snapdir visible aclinherit discard aclinherit noallow aclinherit secure aclinherit passthrough canmount off canmount on compression gzip compression gzip-$((RANDOM%9 + 1)) compression zstd compression zstd-$((RANDOM%9 + 1)) compression zstd-fast copies $((RANDOM%3 + 1)) compression zstd-fast-$((RANDOM%9 + 1)) acltype off acltype posix acltype nfsv4 ) else # 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 xattr on xattr off compression gzip compression gzip-$((RANDOM%9 + 1)) copies $((RANDOM%3 + 1)) ) fi run_and_verify "zfs create $fs" # Set all the property for filesystem typeset -i i=0 while ((i < ${#props[@]})) ; do run_and_verify "zfs set ${props[$i]}=${props[((i+1))]} $fs" # quota, reservation, canmount can not be inherited. # if [[ ${props[$i]} != "quota" && ${props[$i]} != "reservation" && \ ${props[$i]} != "canmount" ]]; then run_and_verify "zfs inherit ${props[$i]} $fs" fi ((i += 2)) done run_and_verify "zfs create -V 64M $vol" run_and_verify "zfs set volsize=32M $vol" run_and_verify "zfs snapshot $fssnap" run_and_verify "zfs hold tag $fssnap" run_and_verify "zfs release tag $fssnap" run_and_verify "zfs snapshot $volsnap" run_and_verify "zfs snapshot $fssnap2" run_and_verify "zfs snapshot $volsnap2" # Send isn't logged... log_must eval "zfs send -i $fssnap $fssnap2 > $tmpfile" log_must eval "zfs send -i $volsnap $volsnap2 > $tmpfile2" # Verify that's true zpool history $TESTPOOL | grep 'zfs send' >/dev/null 2>&1 && \ log_fail "'zfs send' found in history of \"$TESTPOOL\"" run_and_verify "zfs destroy $fssnap2" run_and_verify "zfs destroy $volsnap2" run_and_verify "zfs receive $fs < $tmpfile" run_and_verify "zfs receive $vol < $tmpfile2" run_and_verify "zfs rollback -r $fssnap" run_and_verify "zfs rollback -r $volsnap" run_and_verify "zfs clone $fssnap $fsclone" run_and_verify "zfs clone $volsnap $volclone" run_and_verify "zfs rename $fs $newfs" run_and_verify "zfs rename $vol $newvol" run_and_verify "zfs promote $fsclone" run_and_verify "zfs promote $volclone" run_and_verify "zfs destroy $newfs" run_and_verify "zfs destroy $newvol" run_and_verify "zfs destroy -rf $fsclone" run_and_verify "zfs destroy -rf $volclone" log_pass "zfs sub-commands which modify state are logged passed." diff --git a/tests/zfs-tests/tests/functional/history/history_006_neg.ksh b/tests/zfs-tests/tests/functional/history/history_006_neg.ksh index e97adc4e3ce0..19b7114faf5b 100755 --- a/tests/zfs-tests/tests/functional/history/history_006_neg.ksh +++ b/tests/zfs-tests/tests/functional/history/history_006_neg.ksh @@ -1,88 +1,86 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/history/history_common.kshlib . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify the following zfs subcommands are not logged. # list, get, holds, mount, unmount, share, unshare, send # # STRATEGY: # 1. Create a test pool. # 2. Separately invoke zfs list|get|holds|mount|unmount|share|unshare|send # 3. Verify they were not recorded in pool history. # verify_runnable "global" function cleanup { - if datasetexists $fs ; then - log_must zfs destroy -rf $fs - fi + datasetexists $fs && destroy_dataset $fs -rf log_must zfs create $fs } log_assert "Verify 'zfs list|get|holds|mount|unmount|share|unshare|send' " \ "will not be logged." log_onexit cleanup # Create initial test environment fs=$TESTPOOL/$TESTFS; snap1=$fs@snap1; snap2=$fs@snap2 if ! is_linux; then log_must zfs set sharenfs=on $fs fi log_must zfs snapshot $snap1 log_must zfs hold tag $snap1 log_must zfs snapshot $snap2 # Save initial TESTPOOL history log_must eval "zpool history $TESTPOOL > $OLD_HISTORY" log_must zfs list $fs > /dev/null log_must zfs get mountpoint $fs > /dev/null log_must zfs unmount $fs log_must zfs mount $fs if ! is_linux; then log_must zfs share $fs log_must zfs unshare $fs fi log_must zfs send -i $snap1 $snap2 > /dev/null log_must zfs holds $snap1 log_must eval "zpool history $TESTPOOL > $NEW_HISTORY" log_must diff $OLD_HISTORY $NEW_HISTORY log_must zfs release tag $snap1 log_pass "Verify 'zfs list|get|mount|unmount|share|unshare|send' passed." diff --git a/tests/zfs-tests/tests/functional/history/history_007_pos.ksh b/tests/zfs-tests/tests/functional/history/history_007_pos.ksh index 0504e1765c63..591d5b85e885 100755 --- a/tests/zfs-tests/tests/functional/history/history_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/history/history_007_pos.ksh @@ -1,112 +1,112 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/history/history_common.kshlib # # DESCRIPTION: # Verify command history moves with pool while pool being migrated # # STRATEGY: # 1. Import uniform platform and cross platform pools # 2. Contract the command history of the imported pool # 3. Compare imported history log with the previous log. # verify_runnable "global" function cleanup { poolexists $migratedpoolname && \ log_must zpool destroy -f $migratedpoolname [[ -d $import_dir ]] && rm -rf $import_dir } log_assert "Verify command history moves with migrated pool." log_onexit cleanup tst_dir=$STF_SUITE/tests/functional/history import_dir=$TESTDIR/importdir.$$ migrated_cmds_f=$import_dir/migrated_history.$$ migratedpoolname=$MIGRATEDPOOLNAME typeset -i RET=1 typeset -i linenum=0 -[[ ! -d $import_dir ]] && log_must mkdir $import_dir +[[ ! -d $import_dir ]] && log_must mkdir -p $import_dir # We test the migrations on both uniform platform and cross platform for arch in "i386" "sparc"; do log_must cp $tst_dir/${arch}.orig_history.txt $import_dir orig_cmds_f=$import_dir/${arch}.orig_history.txt # remove blank line orig_cmds_f1=$import_dir/${arch}.orig_history_1.txt cat $orig_cmds_f | grep -v "^$" > $orig_cmds_f1 log_must cp $tst_dir/${arch}.migratedpool.DAT.Z $import_dir log_must uncompress -f $import_dir/${arch}.migratedpool.DAT.Z # destroy the pool with same name, so that import operation succeeds. poolexists $migratedpoolname && \ log_must zpool destroy -f $migratedpoolname log_must zpool import -d $import_dir $migratedpoolname TZ=$TIMEZONE zpool history $migratedpoolname | grep -v "^$" \ >$migrated_cmds_f RET=$? (( $RET != 0 )) && log_fail "zpool history $migratedpoolname fails." # The migrated history file should differ with original history file on # two commands -- 'export' and 'import', which are included in migrated # history file but not in original history file. so, check the two # commands firstly in migrated history file and then delete them, and # then compare this filtered file with the original history file. They # should be identical at this time. for subcmd in "export" "import"; do grep "$subcmd" $migrated_cmds_f >/dev/null 2>&1 RET=$? (( $RET != 0 )) && log_fail "zpool $subcmd is not logged for" \ "the imported pool $migratedpoolname." done tmpfile=$import_dir/cmds_tmp.$$ linenum=`cat $migrated_cmds_f | wc -l` (( linenum = linenum - 2 )) head -n $linenum $migrated_cmds_f > $tmpfile log_must diff $tmpfile $orig_cmds_f1 # cleanup for next loop testing log_must zpool destroy -f $migratedpoolname log_must rm -f `ls $import_dir` done log_pass "Verify command history moves with migrated pool." diff --git a/tests/zfs-tests/tests/functional/history/history_008_pos.ksh b/tests/zfs-tests/tests/functional/history/history_008_pos.ksh index 996c7658c32c..8e174dcb7ebf 100755 --- a/tests/zfs-tests/tests/functional/history/history_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/history/history_008_pos.ksh @@ -1,74 +1,72 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/history/history_common.kshlib # # DESCRIPTION: # Pool history records all recursive operations. # # STRATEGY: # 1. Create a filesystem and several sub-filesystems in it. # 2. Make a recursive snapshot. # 3. Verify pool history records all the recursive operations. # 4. Do the same verification for hold, release, inherit, rollback and # destroy. # verify_runnable "global" function cleanup { - if datasetexists $root_testfs; then - log_must zfs destroy -rf $root_testfs - fi + datasetexists $root_testfs && destroy_dataset $root_testfs -rf log_must zfs create $root_testfs } log_assert "Pool history records all recursive operations." log_onexit cleanup root_testfs=$TESTPOOL/$TESTFS fs1=$root_testfs/fs1; fs2=$root_testfs/fs2; fs3=$root_testfs/fs3 for fs in $fs1 $fs2 $fs3; do log_must zfs create $fs done run_and_verify "zfs snapshot -r $root_testfs@snap" "-i" run_and_verify "zfs hold -r tag $root_testfs@snap" "-i" run_and_verify "zfs release -r tag $root_testfs@snap" "-i" log_must zfs snapshot $root_testfs@snap2 log_must zfs snapshot $root_testfs@snap3 run_and_verify "zfs rollback -r $root_testfs@snap" "-i" run_and_verify "zfs inherit -r mountpoint $root_testfs" "-i" run_and_verify "zfs destroy -r $root_testfs" "-i" log_pass "Pool history records all recursive operations." diff --git a/tests/zfs-tests/tests/functional/history/history_010_pos.ksh b/tests/zfs-tests/tests/functional/history/history_010_pos.ksh index 31fe8ec54d0e..2c32b1b6cefa 100755 --- a/tests/zfs-tests/tests/functional/history/history_010_pos.ksh +++ b/tests/zfs-tests/tests/functional/history/history_010_pos.ksh @@ -1,88 +1,88 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/history/history_common.kshlib # # DESCRIPTION: # Verify internal long history information are correct. # # STRATEGY: # 1. Create non-root test user and group. # 2. Do some zfs operations as a root and non-root user. # 3. Verify the long history information is correct. # verify_runnable "global" function cleanup { del_user $HIST_USER del_group $HIST_GROUP - datasetexists $root_testfs && log_must zfs destroy -rf $root_testfs + datasetexists $root_testfs && destroy_dataset $root_testfs -rf } log_assert "Verify internal long history information are correct." log_onexit cleanup root_testfs=$TESTPOOL/$TESTFS1 # Create history test group and user and get user id and group id add_group $HIST_GROUP add_user $HIST_GROUP $HIST_USER # # Verify the test user can execute the zfs utilities. This may not # be possible due to default permissions on the user home directory. # This can be resolved granting group read access. # # chmod 0750 $HOME # user_run $HIST_USER zfs list if [ $? -ne 0 ]; then log_unsupported "Test user $HIST_USER cannot execute zfs utilities" fi run_and_verify "zfs create $root_testfs" "-l" run_and_verify "zfs allow $HIST_GROUP snapshot,mount $root_testfs" "-l" run_and_verify "zfs allow $HIST_USER destroy,mount $root_testfs" "-l" run_and_verify "zfs allow $HIST_USER reservation $root_testfs" "-l" run_and_verify "zfs allow $HIST_USER allow $root_testfs" "-l" run_and_verify -u "$HIST_USER" "zfs snapshot $root_testfs@snap" "-l" run_and_verify -u "$HIST_USER" "zfs destroy $root_testfs@snap" "-l" run_and_verify -u "$HIST_USER" "zfs set reservation=64M $root_testfs" "-l" run_and_verify -u "$HIST_USER" \ "zfs allow $HIST_USER reservation $root_testfs" "-l" run_and_verify "zfs unallow $HIST_USER create $root_testfs" "-l" run_and_verify "zfs unallow $HIST_GROUP snapshot $root_testfs" "-l" run_and_verify "zfs destroy -r $root_testfs" "-l" log_pass "Verify internal long history information pass." diff --git a/tests/zfs-tests/tests/functional/history/history_common.kshlib b/tests/zfs-tests/tests/functional/history/history_common.kshlib index 8ac34b2de909..ff3260f3c0f2 100644 --- a/tests/zfs-tests/tests/functional/history/history_common.kshlib +++ b/tests/zfs-tests/tests/functional/history/history_common.kshlib @@ -1,422 +1,422 @@ # # 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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/history/history.cfg function run_and_verify { typeset user pool while getopts "p:u:" opt; do case $opt in p) pool=$OPTARG ;; u) user=$OPTARG ;; esac done shift $(($OPTIND - 1)) pool=${pool:-$TESTPOOL} user=${user:-"root"} fullcmd="$1" flags="$2" if is_illumos; then histcmd=$(echo $fullcmd | sed 's/\/usr\/sbin\///g') else histcmd=$(echo $fullcmd | sed 's/^.*\/\(zpool .*\).*$/\1/') histcmd=$(echo $histcmd | sed 's/^.*\/\(zfs .*\).*$/\1/') fi cmd=$(echo $histcmd | awk '{print $1}') subcmd=$(echo $histcmd | awk '{print $2}') # If we aren't running zpool or zfs, something is wrong [[ $cmd == "zpool" || $cmd == "zfs" ]] || \ log_fail "run_and_verify called with \"$cmd ($fullcmd)\"" # If this is a 'zfs receive' truncate the stdin redirect [[ $subcmd == "receive" || $subcmd == "recv" ]] && \ histcmd=${histcmd%% <*} # Run the command as the specified user, and find the new history. zpool history $flags $pool > $OLD_HISTORY 2>/dev/null if [[ $user == "root" ]]; then - log_must eval "$fullcmd" + log_must_busy eval "$fullcmd" else - log_must user_run $user "$fullcmd" + log_must_busy user_run $user "$fullcmd" fi zpool history $flags $pool > $TMP_HISTORY 2>/dev/null diff $OLD_HISTORY $TMP_HISTORY | grep "^> " | sed 's/^> //g' \ > $NEW_HISTORY # Verify what's common to every case, regardless of zpool history flags. grep "$histcmd" $NEW_HISTORY >/dev/null 2>&1 || \ log_fail "Didn't find \"$histcmd\" in pool history" # If 'zpool history' was called without any flags, then we're done. [[ -z $flags ]] && return # Verify the new history in cases that are more interesting because # additional information is logged with -i or -l. [[ $flags =~ "i" ]] && log_must verify_$subcmd "$histcmd" "$subcmd" \ "$flags" [[ $flags =~ "l" ]] && log_must verify_long "$histcmd" "$user" "$flags" } function verify_long { typeset cmd=$1 typeset user=$2 typeset flags=$3 [[ $flags =~ "l" ]] || return 1 typeset uid=$(id -u $user) typeset hname=$(hostname) if ! is_global_zone; then hname=$hname:$(zonename) fi typeset suffix="" if is_linux; then suffix=":linux" elif is_freebsd; then suffix=":freebsd" fi grep -q "$cmd \[user $uid ($user) on $hname$suffix\]" $NEW_HISTORY if [[ $? != 0 ]]; then log_note "Couldn't find long information for \"$cmd\"" return 1 fi return 0 } function verify_hold { typeset cmd=$1 typeset subcmd=$2 typeset flags=$3 [[ $flags =~ "i" ]] || return 1 typeset tag=$(echo $cmd | awk '{print $4}') typeset fullname=${cmd##* } typeset dsname=${fullname%%@*} typeset snapname=${fullname##*@} # This works whether or not the hold was recursive for ds in $(zfs list -r -Ho name -t snapshot $dsname | \ grep "@$snapname"); do grep "$subcmd $ds ([0-9]*) tag=$tag" $NEW_HISTORY \ >/dev/null 2>&1 if [[ $? != 0 ]]; then log_note "Didn't find hold on $ds with $tag" return 1 fi done return 0 } function verify_release { # hold and release formats only differ by the subcommand name, so # simply reuse the hold function. verify_hold "$1" "release" "$3" } function verify_rollback { typeset cmd=$1 typeset flags=$3 [[ $flags =~ "i" ]] || return 1 typeset fullname=${cmd##* } typeset dsname=${fullname%%@*} typeset parent_fs=${dsname##*/} typeset rb_fs=${dsname}/%rollback typeset snapname=${fullname##*@} grep "clone swap $rb_fs ([0-9]*) parent=$parent_fs" $NEW_HISTORY \ >/dev/null 2>&1 if [[ $? != 0 ]]; then log_note "Didn't find rollback clone swap in pool history" return 1 fi grep "destroy $rb_fs" $NEW_HISTORY >/dev/null 2>&1 if [[ $? != 0 ]]; then log_note "Didn't find rollback destroy in pool history" return 1 fi return 0 } function verify_inherit { typeset cmd=$1 typeset flags=$3 [[ $flags =~ "i" ]] || return 1 typeset dsname=${cmd##* } typeset prop=${cmd% *} prop=${prop##* } # This works whether or not the inherit was recursive for ds in $(zfs list -r -Ho name -t filesystem $dsname); do grep "$subcmd $ds ([0-9]*) ${prop}=" $NEW_HISTORY >/dev/null \ 2>&1 if [[ $? != 0 ]]; then log_note "Didn't find inherit history for $ds" return 1 fi done return 0 } function verify_allow { typeset cmd=$1 typeset subcmd=$2 typeset flags=$3 [[ $flags =~ "i" ]] || return 1 [[ $subcmd == "allow" ]] && subcmd="update" [[ $subcmd == "unallow" ]] && subcmd="remove" typeset is_set lflag dflag dsname gname gid uname uid opt str code tmp # # Here, we determine three things: # - Whether we're operating on a set or an individual permission (which # dictates the case of the first character in the code) # - The name of the dataset we're operating on. # - Whether the operation applies locally or to descendent datasets (or # both) # echo $cmd | awk '{i = NF - 1; print $i}' | grep '@' >/dev/null \ 2>&1 && is_set=1 dsname=${cmd##* } [[ $cmd =~ "-l " ]] && lflag=1 [[ $cmd =~ "-d " ]] && dflag=1 if [[ -z $lflag && -z $dflag ]]; then lflag=1 dflag=1 fi # # For each of the five cases below, the operation is essentially the # same. First, use the command passed in to determine what the code at # the end of the pool history will be. The specifics of the code are # described in a block comment at the top of dsl_deleg.c. Once that's # been assembled, check for its presence in the history, and return # success or failure accordingly. # if [[ $cmd =~ "-s " ]]; then str="s-\$@" [[ -n $is_set ]] && str="S-\$@" tmp=${cmd#*@} code="$str${tmp% *}" grep "permission $subcmd $dsname ([0-9]*) $code" \ $NEW_HISTORY >/dev/null 2>&1 if [[ $? != 0 ]]; then log_note "Couldn't find $code in $NEW_HISTORY" return 1 fi elif [[ $cmd =~ "-c " ]]; then str="c-\$" [[ -n $is_set ]] && str="C-\$" tmp=${cmd#*-c} code="$str${tmp% *}" grep "permission $subcmd $dsname ([0-9]*) $code" \ $NEW_HISTORY >/dev/null 2>&1 if [ $? != 0 ]]; then log_note "Couldn't find $code in $NEW_HISTORY" return 1 fi elif [[ $cmd =~ "-u " ]]; then str="u" [[ -n $is_set ]] && str="U" tmp=${cmd##*-u } opt=$(echo $tmp | awk '{print $2}') uid=$(id -u ${tmp%% *}) if [[ -n $lflag ]]; then code="${str}l\$$uid $opt" grep "permission $subcmd $dsname ([0-9]*) $code" \ $NEW_HISTORY >/dev/null 2>&1 if [ $? != 0 ]]; then log_note "Couldn't find $code in $NEW_HISTORY" return 1 fi fi if [[ -n $dflag ]]; then code="${str}d\$$uid $opt" grep "permission $subcmd $dsname ([0-9]*) $code" \ $NEW_HISTORY >/dev/null 2>&1 if [ $? != 0 ]]; then log_note "Couldn't find $code in $NEW_HISTORY" return 1 fi fi elif [[ $cmd =~ "-g " ]]; then str="g" [[ -n $is_set ]] && str="G" tmp=${cmd##*-g } opt=$(echo $tmp | awk '{print $2}') gid=$(awk -F: "/^${tmp%% *}:/ {print \$3}" /etc/group) if [[ -n $lflag ]]; then code="${str}l\$$gid $opt" grep "permission $subcmd $dsname ([0-9]*) $code" \ $NEW_HISTORY >/dev/null 2>&1 if [ $? != 0 ]]; then log_note "Couldn't find $code in $NEW_HISTORY" return 1 fi fi if [[ -n $dflag ]]; then code="${str}d\$$gid $opt" grep "permission $subcmd $dsname ([0-9]*) $code" \ $NEW_HISTORY >/dev/null 2>&1 if [ $? != 0 ]]; then log_note "Couldn't find $code in $NEW_HISTORY" return 1 fi fi elif [[ $cmd =~ "-e " ]]; then str="e" [[ -n $is_set ]] && str="E" opt=${cmd##*-e } opt=${opt%% *} if [[ -n $lflag ]]; then code="${str}l\$ $opt" grep "permission $subcmd $dsname ([0-9]*) $code" \ $NEW_HISTORY >/dev/null 2>&1 if [ $? != 0 ]]; then log_note "Couldn't find $code in $NEW_HISTORY" return 1 fi fi if [[ -n $dflag ]]; then code="${str}d\$ $opt" grep "permission $subcmd $dsname ([0-9]*) $code" \ $NEW_HISTORY >/dev/null 2>&1 if [ $? != 0 ]]; then log_note "Couldn't find $code in $NEW_HISTORY" return 1 fi fi else log_note "Can't parse command \"$cmd\"" return 1 fi return 0 } function verify_unallow { # # The unallow and allow history have the same format, except the former # logs "permission removed" and the latter "permission updated" so # simply reuse the allow function. # verify_allow "$1" "unallow" "$3" } function verify_destroy { typeset cmd=$1 typeset flags=$3 # This function doesn't currently verify the zpool command. [[ ${cmd%% *} == "zfs" ]] || return 1 [[ $flags =~ "i" ]] || return 1 typeset dsname=${cmd##* } [[ $dsname =~ "@" ]] && typeset is_snap=1 if [[ -n $is_snap ]]; then grep "ioctl destroy_snaps" $NEW_HISTORY >/dev/null 2>&1 if [[ $? != 0 ]]; then log_note "Didn't find ioctl while destroying $dsname" return 1 fi fi # This should be present for datasets and snapshots alike grep "destroy $dsname" $NEW_HISTORY >/dev/null 2>&1 if [[ $? != 0 ]]; then log_note "Didn't find \"destroy\" for $dsname" return 1 fi return 0 } function verify_snapshot { typeset cmd=$1 typeset flags=$3 [[ $flags =~ "i" ]] || return 1 typeset fullname=${cmd##* } typeset dsname=${fullname%%@*} typeset snapname=${fullname##*@} grep "\[txg:[0-9]*\] $subcmd $fullname ([0-9]*)" $NEW_HISTORY \ >/dev/null 2>&1 if [[ $? != 0 ]]; then log_note "Didn't find snapshot command for $fullname" return 1 fi # This works whether or not the snapshot was recursive for ds in $(zfs list -r -Ho name -t snapshot $dsname | \ grep "@$snapname"); do grep "^[ ]* $ds$" $NEW_HISTORY >/dev/null 2>&1 if [[ $? != 0 ]]; then log_note "Didn't find \"ioctl snapshot\" for $ds" return 1 fi done return 0 } diff --git a/tests/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos.ksh b/tests/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos.ksh index a8934159b244..6b51598d7cca 100755 --- a/tests/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/largest_pool/largest_pool_001_pos.ksh @@ -1,161 +1,161 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/largest_pool/largest_pool.cfg # DESCRIPTION: # The largest pool can be created and a dataset in that # pool can be created and mounted. # # STRATEGY: # create a pool which will contain a volume device. # create a volume device of desired sizes. # create the largest pool allowed using the volume vdev. # create and mount a dataset in the largest pool. # create some files in the zfs file system. # do some zpool list commands and parse the output. verify_runnable "global" # # Parse the results of zpool & zfs creation with specified size # # $1: volume size # # return value: # 0 -> success # 1 -> failure # function parse_expected_output { UNITS=`echo $1 | sed -e 's/^\([0-9].*\)\([a-z].\)/\2/'` case "$UNITS" in 'mb') CHKUNIT="M" ;; 'gb') CHKUNIT="G" ;; 'tb') CHKUNIT="T" ;; 'pb') CHKUNIT="P" ;; 'eb') CHKUNIT="E" ;; *) CHKUNIT="M" ;; esac log_note "Detect zpool $TESTPOOL in this test machine." log_must eval "zpool list $TESTPOOL > $TEST_BASE_DIR/j.$$" log_must eval "grep $TESTPOOL $TEST_BASE_DIR/j.$$ | \ awk '{print $2}' | grep $CHKUNIT" log_note "Detect the file system in this test machine." log_must eval "df -F zfs -h > $TEST_BASE_DIR/j.$$" log_must eval "grep $TESTPOOL $TEST_BASE_DIR/j.$$ | \ awk '{print $2}' | grep $CHKUNIT" return 0 } # # Check and destroy zfs, volume & zpool remove the temporary files # function cleanup { log_note "Start cleanup the zfs and pool" if datasetexists $TESTPOOL/$TESTFS ; then if ismounted $TESTPOOL/$TESTFS ; then log_must zfs unmount $TESTPOOL/$TESTFS fi - log_must zfs destroy $TESTPOOL/$TESTFS + destroy_dataset $TESTPOOL/$TESTFS fi destroy_pool $TESTPOOL datasetexists $TESTPOOL2/$TESTVOL && \ - log_must zfs destroy $TESTPOOL2/$TESTVOL + destroy_dataset $TESTPOOL2/$TESTVOL destroy_pool $TESTPOOL2 rm -f $TEST_BASE_DIR/j.* > /dev/null } log_assert "The largest pool can be created and a dataset in that" \ "pool can be created and mounted." # Set trigger. When the test case exit, cleanup is executed. log_onexit cleanup # ----------------------------------------------------------------------- # volume sizes with unit designations. # # Note: specifying the number '1' as size will not give the correct # units for 'df'. It must be greater than one. # ----------------------------------------------------------------------- typeset str typeset -i ret for volsize in $VOLSIZES; do log_note "Create a pool which will contain a volume device" create_pool $TESTPOOL2 "$DISKS" log_note "Create a volume device of desired sizes: $volsize" str=$(zfs create -sV $volsize $TESTPOOL2/$TESTVOL 2>&1) ret=$? if (( ret != 0 )); then if [[ is_32bit && \ $str == *${VOL_LIMIT_KEYWORD1}* || \ $str == *${VOL_LIMIT_KEYWORD2}* || \ $str == *${VOL_LIMIT_KEYWORD3}* ]] then log_unsupported \ "Max volume size is 1TB on 32-bit systems." else log_fail "zfs create -sV $volsize $TESTPOOL2/$TESTVOL" fi fi block_device_wait log_note "Create the largest pool allowed using the volume vdev" create_pool $TESTPOOL "$VOL_PATH" log_note "Create a zfs file system in the largest pool" log_must zfs create $TESTPOOL/$TESTFS log_note "Parse the execution result" parse_expected_output $volsize log_note "unmount this zfs file system $TESTPOOL/$TESTFS" log_must zfs unmount $TESTPOOL/$TESTFS log_note "Destroy zfs, volume & zpool" log_must zfs destroy $TESTPOOL/$TESTFS destroy_pool $TESTPOOL - log_must zfs destroy $TESTPOOL2/$TESTVOL + log_must_busy zfs destroy $TESTPOOL2/$TESTVOL destroy_pool $TESTPOOL2 done log_pass "Dataset can be created, mounted & destroy in largest pool succeeded." diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_copies.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_copies.ksh index 3971820966f1..2a61f605b21d 100755 --- a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_copies.ksh +++ b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_copies.ksh @@ -1,71 +1,71 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib # # Description: # Verify that nopwrite is not enabled if the copies property changes # # Strategy: # 1. Create a clone with copies set higher than the origin fs # 2. Verify that nopwrite is in use. # 3. Repeat with the number of copies decreased. # verify_runnable "global" origin="$TESTPOOL/$TESTFS" log_onexit cleanup function cleanup { - datasetexists $origin && log_must zfs destroy -R $origin + datasetexists $origin && destroy_dataset $origin -R log_must zfs create -o mountpoint=$TESTDIR $origin } log_assert "nopwrite requires copies property to remain constant" # Verify nopwrite is disabled with increased redundancy log_must zfs set compress=on $origin log_must zfs set checksum=sha256 $origin dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone $origin@a $origin/clone zfs set copies=3 $origin/clone dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." log_mustnot verify_nopwrite $origin $origin@a $origin/clone # Verify nopwrite is disabled with decreased redundancy zfs destroy -R $origin || log_fail "Couldn't destroy $origin" zfs create -o mountpoint=$TESTDIR $origin || \ log_fail "Couldn't recreate $origin" log_must zfs set compress=on $origin log_must zfs set copies=3 $origin log_must zfs set checksum=sha256 $origin dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone $origin@a $origin/clone zfs set copies=1 $origin/clone dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." log_mustnot verify_nopwrite $origin $origin@a $origin/clone log_pass "nopwrite requires copies property to remain constant" diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh index 039b661e2fb9..0422bbaca1c8 100755 --- a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh +++ b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_mtime.ksh @@ -1,89 +1,89 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib # # Description: # Verify that nopwrite still updates file metadata correctly # # Strategy: # 1. Create a clone with nopwrite enabled. # 2. Write to the file in that clone and verify the mtime and ctime change, # but the atime does not. # verify_runnable "global" origin="$TESTPOOL/$TESTFS" log_onexit cleanup function cleanup { - datasetexists $origin && log_must zfs destroy -R $origin + datasetexists $origin && destroy_dataset $origin -R log_must zfs create -o mountpoint=$TESTDIR $origin } log_assert "nopwrite updates file metadata correctly" log_must zfs set compress=on $origin log_must zfs set checksum=sha256 $origin dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone $origin@a $origin/clone if is_linux; then o_atime=$(stat -c %X $TESTDIR/clone/file) o_ctime=$(stat -c %Z $TESTDIR/clone/file) o_mtime=$(stat -c %Y $TESTDIR/clone/file) elif is_freebsd; then o_atime=$(stat -f "%a" $TESTDIR/clone/file) o_ctime=$(stat -f "%c" $TESTDIR/clone/file) o_mtime=$(stat -f "%m" $TESTDIR/clone/file) else o_atime=$(ls -E% all $TESTDIR/clone/file | awk '/atime/ {print $4}') o_ctime=$(ls -E% all $TESTDIR/clone/file | awk '/ctime/ {print $4}') o_mtime=$(ls -E% all $TESTDIR/clone/file | awk '/mtime/ {print $4}') fi sleep 1 dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." sleep 1 if is_linux; then atime=$(stat -c %X $TESTDIR/clone/file) ctime=$(stat -c %Z $TESTDIR/clone/file) mtime=$(stat -c %Y $TESTDIR/clone/file) elif is_freebsd; then atime=$(stat -f "%a" $TESTDIR/clone/file) ctime=$(stat -f "%c" $TESTDIR/clone/file) mtime=$(stat -f "%m" $TESTDIR/clone/file) else atime=$(ls -E% all $TESTDIR/clone/file | awk '/atime/ {print $4}') ctime=$(ls -E% all $TESTDIR/clone/file | awk '/ctime/ {print $4}') mtime=$(ls -E% all $TESTDIR/clone/file | awk '/mtime/ {print $4}') fi [[ $o_atime = $atime ]] || log_fail "atime changed: $o_atime $atime" [[ $o_ctime = $ctime ]] && log_fail "ctime unchanged: $o_ctime $ctime" [[ $o_mtime = $mtime ]] && log_fail "mtime unchanged: $o_mtime $mtime" log_must verify_nopwrite $origin $origin@a $origin/clone log_pass "nopwrite updates file metadata correctly" diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_negative.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_negative.ksh index 8b0b9b549920..617c34602beb 100755 --- a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_negative.ksh +++ b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_negative.ksh @@ -1,90 +1,90 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib # # Description: # Verify that duplicate writes to a clone are accounted as new data if the # prerequisites for nopwrite are not met. # # Scenarios: # 1. The file in the origin ds is written without compression or sha256. # 2. The file in the origin ds is written before sha256 checksum is turned on. # 3. The clone does not have compression. # 4. The clone does not have the appropriate checksum. # verify_runnable "global" origin="$TESTPOOL/$TESTFS" log_onexit cleanup function cleanup { - datasetexists $origin && log_must zfs destroy -R $origin + datasetexists $origin && destroy_dataset $origin -R log_must zfs create -o mountpoint=$TESTDIR $origin } log_assert "nopwrite isn't enabled without the prerequisites" # Data written into origin fs without compression or sha256 dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ >/dev/null 2>&1 || log_fail "dd of $TESTDIR/file failed." zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone -o compress=on $origin@a $origin/clone log_must zfs set checksum=sha256 $origin/clone dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." log_mustnot verify_nopwrite $origin $origin@a $origin/clone zfs destroy -R $origin@a || log_fail "zfs destroy failed" log_must rm -f $TESTDIR/file # Data written to origin fs before checksum enabled log_must zfs set compress=on $origin dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." log_must zfs set checksum=sha256 $origin zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone $origin@a $origin/clone dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." log_mustnot verify_nopwrite $origin $origin@a $origin/clone zfs destroy -R $origin@a || log_fail "zfs destroy failed" log_must rm -f $TESTDIR/file # Clone with compression=off dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone -o compress=off $origin@a $origin/clone dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." log_mustnot verify_nopwrite $origin $origin@a $origin/clone zfs destroy -R $origin@a || log_fail "zfs destroy failed" log_must rm -f $TESTDIR/file # Clone with fletcher4, rather than sha256 dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone -o checksum=fletcher4 $origin@a $origin/clone dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." log_mustnot verify_nopwrite $origin $origin@a $origin/clone log_pass "nopwrite isn't enabled without the prerequisites" diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_promoted_clone.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_promoted_clone.ksh index f9e6e83b7a8d..057c59a3801c 100755 --- a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_promoted_clone.ksh +++ b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_promoted_clone.ksh @@ -1,58 +1,58 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib # # Description: # Verify that nopwrite still works for a dataset that becomes a clone via # promotion. # # Strategy: # 1. Create a clone suitable for nopwrite. # 2. Disable compression and checksum on the clone, and promote it. # 3. Overwrite the file in the clone (former origin fs) and verify it # consumes no additional space. # verify_runnable "global" origin="$TESTPOOL/$TESTFS" log_onexit cleanup function cleanup { - datasetexists $origin && log_must zfs destroy -R $TESTPOOL/clone + datasetexists $origin && destroy_dataset $TESTPOOL/clone -R log_must zfs create -o mountpoint=$TESTDIR $origin } log_assert "nopwrite works on a dataset that becomes a clone via promotion." log_must zfs set compress=on $origin log_must zfs set checksum=sha256 $origin dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone $origin@a $TESTPOOL/clone log_must zfs set compress=off $TESTPOOL/clone log_must zfs set checksum=off $TESTPOOL/clone log_must zfs promote $TESTPOOL/clone dd if=/$TESTPOOL/clone/file of=/$TESTDIR/file bs=1024k count=$MEGS \ conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." log_must verify_nopwrite $TESTPOOL/clone $TESTPOOL/clone@a $origin log_pass "nopwrite works on a dataset that becomes a clone via promotion." diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_recsize.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_recsize.ksh index 205b3357d8d0..38e7ec1ff219 100755 --- a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_recsize.ksh +++ b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_recsize.ksh @@ -1,57 +1,57 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib # # Description: # Verify that nopwrite works regardless of recsize property setting. # # Strategy: # 1. Create an origin fs that's suitable to make nopwrite clones. # 2. For each possible recsize, create a clone that inherits the compress and # checksum, and verify overwriting the origin file consumes no new space. # verify_runnable "global" origin="$TESTPOOL/$TESTFS" log_onexit cleanup function cleanup { - datasetexists $origin && log_must zfs destroy -R $origin + datasetexists $origin && destroy_dataset $origin -R log_must zfs create -o mountpoint=$TESTDIR $origin } log_assert "nopwrite updates file metadata correctly" log_must zfs set compress=on $origin log_must zfs set checksum=sha256 $origin dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone $origin@a $origin/clone for rs in 512 1024 2048 4096 8192 16384 32768 65536 131072 ; do log_must zfs set recsize=$rs $origin/clone dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." log_must verify_nopwrite $origin $origin@a $origin/clone done log_pass "nopwrite updates file metadata correctly" diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_sync.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_sync.ksh index bd38883d7578..e0721cac198c 100755 --- a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_sync.ksh +++ b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_sync.ksh @@ -1,55 +1,55 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib # # Description: # Verify that nopwrite works for sync writes # # Strategy: # 1. Create an origin fs with compression and sha256. # 2. Clone origin such that it inherits the properties. # 3. Use dd with the sync flag to test the sync write path. # verify_runnable "global" origin="$TESTPOOL/$TESTFS" log_onexit cleanup function cleanup { - datasetexists $origin && log_must zfs destroy -R $origin + datasetexists $origin && destroy_dataset $origin -R log_must zfs create -o mountpoint=$TESTDIR $origin } log_assert "nopwrite works for sync writes" log_must zfs set compress=on $origin log_must zfs set checksum=sha256 $origin dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS oflag=sync \ conv=notrunc >/dev/null 2>&1 || log_fail "dd into $TESTDIR/file failed." zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone $origin@a $origin/clone dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ oflag=sync conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." log_must verify_nopwrite $origin $origin@a $origin/clone log_pass "nopwrite works for sync writes" diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression.ksh index d256876a9c45..190bdbd6c6db 100755 --- a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression.ksh +++ b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_varying_compression.ksh @@ -1,65 +1,65 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016, Delphix. All rights reserved. # Copyright (c) 2019, Kjeld Schouten-Lebbing. All Rights Reserved. # . $STF_SUITE/include/properties.shlib . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib # # Description: # Verify that if the checksum on the origin and clone is sha256, any compression # algorithm enables nopwrite. # # Strategy: # 1. Create an origin dataset with compression and sha256 checksum. # 2. Write a 64M file into the origin dataset. # 3. For each of 4 randomly chosen compression types: # 3a. Create a snap and clone (inheriting the checksum property) of the origin. # 3b. Apply the compression property to the clone. # 3c. Write the same 64M of data into the file that exists in the clone. # 3d. Verify that no new space was consumed. # verify_runnable "global" origin="$TESTPOOL/$TESTFS" log_onexit cleanup function cleanup { - datasetexists $origin && log_must zfs destroy -R $origin + datasetexists $origin && destroy_dataset $origin -R log_must zfs create -o mountpoint=$TESTDIR $origin } log_assert "nopwrite works with sha256 and any compression algorithm" log_must zfs set compress=on $origin log_must zfs set checksum=sha256 $origin dd if=/dev/urandom of=$TESTDIR/file bs=1024k count=$MEGS conv=notrunc \ >/dev/null 2>&1 || log_fail "initial dd failed." # Verify nop_write for all compression algorithms except "off" for i in "${compress_prop_vals[@]:1}"; do zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone -o compress=$i $origin@a $origin/clone dd if=/$TESTDIR/file of=/$TESTDIR/clone/file bs=1024k count=$MEGS \ conv=notrunc >/dev/null 2>&1 || log_fail "dd failed." log_must verify_nopwrite $origin $origin@a $origin/clone zfs destroy -R $origin@a || log_fail "zfs destroy failed" done log_pass "nopwrite works with sha256 and any compression algorithm" diff --git a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh index a118b982240c..1efe0b772868 100755 --- a/tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh +++ b/tests/zfs-tests/tests/functional/nopwrite/nopwrite_volume.ksh @@ -1,59 +1,59 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2012, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/nopwrite/nopwrite.shlib # # Description: # Verify that nopwrite cannot be enabled on volumes # # Strategy: # 1. Create a clone of a volume that fits the criteria for nopwrite. # 2. Overwrite the same blocks from the origin vol and verify that # new space is consumed. # verify_runnable "global" origin="$TESTPOOL/$TESTVOL" clone="$TESTPOOL/clone" vol="${ZVOL_RDEVDIR}/$origin" volclone="${ZVOL_RDEVDIR}/$clone" log_onexit cleanup function cleanup { - datasetexists $origin && log_must zfs destroy -R $origin + datasetexists $origin && destroy_dataset $origin -R # No need to recreate the volume as no other tests expect it. } log_assert "nopwrite works on volumes" log_must zfs set compress=on $origin log_must zfs set checksum=sha256 $origin dd if=/dev/urandom of=$vol bs=8192 count=4096 conv=notrunc >/dev/null \ 2>&1 || log_fail "dd into $origin failed." zfs snapshot $origin@a || log_fail "zfs snap failed" log_must zfs clone $origin@a $clone log_must zfs set compress=on $clone log_must zfs set checksum=sha256 $clone block_device_wait dd if=$vol of=$volclone bs=8192 count=4096 conv=notrunc >/dev/null 2>&1 || \ log_fail "dd into $clone failed." log_must verify_nopwrite $origin $origin@a $clone log_pass "nopwrite works on volumes" diff --git a/tests/zfs-tests/tests/functional/procfs/procfs_list_basic.ksh b/tests/zfs-tests/tests/functional/procfs/procfs_list_basic.ksh index 88911aac6e8e..dfc1f1ee0497 100755 --- a/tests/zfs-tests/tests/functional/procfs/procfs_list_basic.ksh +++ b/tests/zfs-tests/tests/functional/procfs/procfs_list_basic.ksh @@ -1,95 +1,95 @@ #!/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 (c) 2018 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Test that we can read from and write to a file in procfs whose contents is # backed by a linked list. # # STRATEGY: # 1. Take some snapshots of a filesystem, which will cause some messages to be # written to the zfs dbgmsgs. # 2. Read the dbgmsgs via procfs and verify that the expected messages are # present. # 3. Write to the dbgmsgs file to clear the messages. # 4. Read the dbgmsgs again, and make sure the messages are no longer present. # function cleanup { - datasetexists $FS && log_must zfs destroy -r $FS + datasetexists $FS && destroy_dataset $FS -r } function count_snap_cmds { typeset expected_count=$1 count=$(grep -E "command: (lt-)?zfs snapshot $FS@testsnapshot" | wc -l) log_must eval "[[ $count -eq $expected_count ]]" } typeset -r ZFS_DBGMSG=/proc/spl/kstat/zfs/dbgmsg typeset -r FS=$TESTPOOL/fs typeset snap_msgs log_onexit cleanup # Clear out old messages echo 0 >$ZFS_DBGMSG || log_fail "failed to write to $ZFS_DBGMSG" log_must zfs create $FS for i in {1..20}; do log_must zfs snapshot "$FS@testsnapshot$i" done log_must zpool sync $TESTPOOL # # Read the debug message file in small chunks to make sure that the read is # split up into multiple syscalls. This tests that when a syscall begins we # correctly pick up in the list of messages where the previous syscall left # off. The size of the read can affect how many bytes the seq_file code has # left in its internal buffer, which in turn can affect the relative pos that # the seq_file code picks up at when the next read starts. Try a few # different size reads to make sure we can handle each case. # # Check that the file has the right contents by grepping for some of the # messages that we expect to be present. # for chunk_sz in {1,64,256,1024,4096}; do dd if=$ZFS_DBGMSG bs=$chunk_sz | count_snap_cmds 20 done # Clear out old messages and check that they really are gone echo 0 >$ZFS_DBGMSG || log_fail "failed to write to $ZFS_DBGMSG" cat $ZFS_DBGMSG | count_snap_cmds 0 # # Even though we don't expect any messages in the file, reading should still # succeed. # log_must cat $ZFS_DBGMSG log_pass "Basic reading/writing of procfs file backed by linked list successful" diff --git a/tests/zfs-tests/tests/functional/procfs/procfs_list_concurrent_readers.ksh b/tests/zfs-tests/tests/functional/procfs/procfs_list_concurrent_readers.ksh index 6ca7fd7d6f42..1af1c2c07089 100755 --- a/tests/zfs-tests/tests/functional/procfs/procfs_list_concurrent_readers.ksh +++ b/tests/zfs-tests/tests/functional/procfs/procfs_list_concurrent_readers.ksh @@ -1,82 +1,82 @@ #!/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 (c) 2018 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Make sure that interleaving reads from different readers does not affect the # results that are returned. # # STRATEGY: # 1. Make sure a few debug messages have been logged. # 2. Open the procfs file and start reading from it. # 3. Open the file again, and read its entire contents. # 4. Resume reading from the first instance. # 5. Check that the contents read by the two instances are identical. # function cleanup { [[ -z $msgs1 ]] || log_must rm $msgs1 [[ -z $msgs2 ]] || log_must rm $msgs2 - datasetexists $FS && log_must zfs destroy -r $FS + datasetexists $FS && destroy_dataset $FS -r } typeset -r ZFS_DBGMSG=/proc/spl/kstat/zfs/dbgmsg typeset -r FS=$TESTPOOL/fs typeset msgs1 msgs2 log_onexit cleanup # Clear out old messages echo 0 >$ZFS_DBGMSG || log_fail "failed to write to $ZFS_DBGMSG" # Add some new messages log_must zfs create $FS for i in {1..20}; do log_must zfs snapshot "$FS@testsnapshot$i" done log_must zpool sync $TESTPOOL msgs1=$(mktemp) || log_fail msgs2=$(mktemp) || log_fail # # Start reading file, pause and read it from another process, and then finish # reading. # { dd bs=512 count=4; cat $ZFS_DBGMSG >$msgs1; cat; } <$ZFS_DBGMSG >$msgs2 # # Truncate the result of the read that completed second in case it picked up an # extra message that was logged after the first read completed. # log_must truncate -s $(stat_size $msgs1) $msgs2 log_must diff $msgs1 $msgs2 log_pass "Concurrent readers receive identical results" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_004_neg.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_004_neg.ksh index a975d2a19f0c..7ca81c3fbc81 100755 --- a/tests/zfs-tests/tests/functional/projectquota/projectquota_004_neg.ksh +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_004_neg.ksh @@ -1,87 +1,85 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2017 by Fan Yong. All rights reserved. # . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib # # DESCRIPTION: # Check the invalid parameter of zfs set project{obj}quota # # # STRATEGY: # 1. check the invalid zfs set project{obj}quota to fs # 2. check the valid zfs set project{obj}quota to snapshots # function cleanup { - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs log_must cleanup_projectquota } log_onexit cleanup log_assert "Check the invalid parameter of zfs set project{obj}quota" typeset snap_fs=$QFS@snap log_must zfs snapshot $snap_fs set -A no_prjs "mms1234" "ss@#" "root-122" "-1" for prj in "${no_prjs[@]}"; do log_mustnot zfs set projectquota@$prj=100m $QFS done log_note "can set all numeric id even if that id does not exist" log_must zfs set projectquota@12345678=100m $QFS set -A sizes "100mfsd" "m0.12m" "GGM" "-1234-m" "123m-m" for size in "${sizes[@]}"; do log_note "can not set projectquota with invalid size parameter" log_mustnot zfs set projectquota@$PRJID1=$size $QFS done log_note "can not set projectquota to snapshot $snap_fs" log_mustnot zfs set projectquota@$PRJID1=100m $snap_fs for prj in "${no_prjs[@]}"; do log_mustnot zfs set projectobjquota@$prj=100 $QFS done log_note "can not set projectobjquota with invalid size parameter" log_mustnot zfs set projectobjquota@$PRJID2=100msfsd $QFS log_note "can not set projectobjquota to snapshot $snap_fs" log_mustnot zfs set projectobjquota@$PRJID2=100m $snap_fs log_pass "Check the invalid parameter of zfs set project{obj}quota" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_005_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_005_pos.ksh index b52f302f7892..0736648f1ed6 100755 --- a/tests/zfs-tests/tests/functional/projectquota/projectquota_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_005_pos.ksh @@ -1,68 +1,66 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2017 by Fan Yong. All rights reserved. # . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib # # DESCRIPTION: # Check the invalid parameter of zfs get project{obj}quota # # # STRATEGY: # 1. check the invalid zfs get project{obj}quota to fs # 2. check the valid zfs get project{obj}quota to snapshots # function cleanup { - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs log_must cleanup_projectquota } log_onexit cleanup log_assert "Check the invalid parameter of zfs get project{obj}quota" typeset snap_fs=$QFS@snap log_must zfs snapshot $snap_fs set -A no_prjs "mms1234" "ss@#" "root-122" for prj in "${no_prjs[@]}"; do log_must eval "zfs get projectquota@$prj $QFS >/dev/null 2>&1" log_must eval "zfs get projectquota@$prj $snap_fs >/dev/null 2>&1" log_must eval "zfs get projectobjquota@$prj $QFS >/dev/null 2>&1" log_must eval "zfs get projectobjquota@$prj $snap_fs >/dev/null 2>&1" done log_pass "Check the invalid parameter of zfs get project{obj}quota" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_008_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_008_pos.ksh index 365b5627e801..b045b2c5fce3 100755 --- a/tests/zfs-tests/tests/functional/projectquota/projectquota_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_008_pos.ksh @@ -1,91 +1,89 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2017 by Fan Yong. All rights reserved. # . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib # # DESCRIPTION: # Check project{obj}quota to snapshot that: # 1) can not set project{obj}quota to snapshot directly # 2) snapshot can inherit the parent fs's project{obj}quota # 3) the project{obj}quota will not change even the parent quota changed. # # # STRATEGY: # 1. create a snapshot of a fs # 2. set the project{obj}quota to snapshot and expect fail # 3. set project{obj}quota to fs and check the snapshot # 4. re-set project{obj}quota to fs and check the snapshot's value # function cleanup { - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs log_must cleanup_projectquota } log_onexit cleanup log_assert "Check the snapshot's project{obj}quota" typeset snap_fs=$QFS@snap log_must zfs set projectquota@$PRJID1=$PQUOTA_LIMIT $QFS log_must check_quota "projectquota@$PRJID1" $QFS "$PQUOTA_LIMIT" log_must zfs set projectobjquota@$PRJID2=$PQUOTA_OBJLIMIT $QFS log_must check_quota "projectobjquota@$PRJID2" $QFS "$PQUOTA_OBJLIMIT" log_must zfs snapshot $snap_fs log_note "check the snapshot $snap_fs project{obj}quota" log_must check_quota "projectquota@$PRJID1" $snap_fs "$PQUOTA_LIMIT" log_must check_quota "projectobjquota@$PRJID2" $snap_fs "$PQUOTA_OBJLIMIT" log_note "set project{obj}quota to $snap_fs which will fail" log_mustnot zfs set projectquota@$PRJID1=100m $snap_fs log_mustnot zfs set projectobjquota@$PRJID2=100 $snap_fs log_note "change the parent's project{obj}quota" log_must zfs set projectquota@$PRJID1=$((PQUOTA_LIMIT * 2)) $QFS log_must zfs set projectobjquota@$PRJID2=50 $QFS log_must check_quota "projectquota@$PRJID1" $QFS $((PQUOTA_LIMIT * 2)) log_must check_quota "projectobjquota@$PRJID2" $QFS 50 log_note "check the snapshot $snap_fs project{obj}quota" log_must check_quota "projectquota@$PRJID1" $snap_fs "$PQUOTA_LIMIT" log_must check_quota "projectobjquota@$PRJID2" $snap_fs "$PQUOTA_OBJLIMIT" log_pass "Check the snapshot's project{obj}quota" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectquota_009_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectquota_009_pos.ksh index a867b538c120..da44e731a92d 100755 --- a/tests/zfs-tests/tests/functional/projectquota/projectquota_009_pos.ksh +++ b/tests/zfs-tests/tests/functional/projectquota/projectquota_009_pos.ksh @@ -1,131 +1,129 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2017 by Fan Yong. All rights reserved. # . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib # # DESCRIPTION: # The project{obj}quota will not change during zfs actions, such as # snapshot,clone,rename,upgrade,send,receive. # # # STRATEGY: # 1. Create a pool, and create fs with preset project{obj}quota # 2. Check set project{obj}quota via zfs snapshot|clone|list -o # 3. Check the project{obj}quota can not change during zfs # rename|upgrade|promote # 4. Check the project{obj}quota can not change during zfs clone # 5. Check the project{obj}quota can not change during zfs send/receive # function cleanup { for ds in $TESTPOOL/fs $TESTPOOL/fs-rename $TESTPOOL/fs-clone; do - if datasetexists $ds; then - log_must zfs destroy -rRf $ds - fi + datasetexists $ds && destroy_dataset $ds -rRf done } log_onexit cleanup log_assert "the project{obj}quota can't change during zfs actions" cleanup log_must zfs create -o projectquota@$PRJID1=$PQUOTA_LIMIT \ -o projectobjquota@$PRJID2=$PQUOTA_OBJLIMIT $TESTPOOL/fs log_must zfs snapshot $TESTPOOL/fs@snap log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs@snap "$PQUOTA_LIMIT" log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs@snap \ "$PQUOTA_OBJLIMIT" log_note "clone fs gets its parent's project{obj}quota initially" log_must zfs clone -o projectquota@$PRJID1=$PQUOTA_LIMIT \ -o projectobjquota@$PRJID2=$PQUOTA_OBJLIMIT \ $TESTPOOL/fs@snap $TESTPOOL/fs-clone log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs-clone "$PQUOTA_LIMIT" log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs-clone \ "$PQUOTA_OBJLIMIT" log_must eval "zfs list -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ $TESTPOOL/fs-clone >/dev/null 2>&1" log_note "zfs promote can not change the previously set project{obj}quota" log_must zfs promote $TESTPOOL/fs-clone log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs-clone "$PQUOTA_LIMIT" log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs-clone \ "$PQUOTA_OBJLIMIT" log_note "zfs send receive can not change the previously set project{obj}quota" log_must zfs send $TESTPOOL/fs-clone@snap | zfs receive $TESTPOOL/fs-rev log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs-rev "$PQUOTA_LIMIT" log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs-rev \ "$PQUOTA_OBJLIMIT" log_note "zfs rename can not change the previously set project{obj}quota" log_must zfs rename $TESTPOOL/fs-rev $TESTPOOL/fs-rename log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs-rename "$PQUOTA_LIMIT" log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs-rename \ "$PQUOTA_OBJLIMIT" log_note "zfs upgrade can not change the previously set project{obj}quota" log_must zfs upgrade $TESTPOOL/fs-rename log_must eval "zfs list -r -o projectquota@$PRJID1,projectobjquota@$PRJID2 \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "projectquota@$PRJID1" $TESTPOOL/fs-rename "$PQUOTA_LIMIT" log_must check_quota "projectobjquota@$PRJID2" $TESTPOOL/fs-rename \ "$PQUOTA_OBJLIMIT" log_pass "the project{obj}quota can't change during zfs actions" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectspace_001_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectspace_001_pos.ksh index a84ff9f89a0d..b7707ea522c4 100755 --- a/tests/zfs-tests/tests/functional/projectquota/projectspace_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/projectquota/projectspace_001_pos.ksh @@ -1,93 +1,91 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2017 by Fan Yong. Fan rights reserved. # . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib # # DESCRIPTION: # Check the zfs projectspace with kinds of parameters # # # STRATEGY: # 1. set zfs projectspace to a fs # 2. write some data to the fs with specified project ID # 3. use zfs projectspace with all possible parameters to check the result # 4. use zfs projectspace with some bad parameters to check the result # function cleanup { - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs log_must cleanup_projectquota } if ! lsattr -pd > /dev/null 2>&1; then log_unsupported "Current e2fsprogs does not support set/show project ID" fi log_onexit cleanup log_assert "Check the zfs projectspace with all possible parameters" set -A good_params -- "-H" "-p" "-o type,name,used,quota" "-o name,used,quota" \ "-o used,quota" "-o objused" "-o quota" "-s type" "-s name" "-s used" \ "-s quota" "-S type" "-S name" "-S used" "-S quota" typeset snap_fs=$QFS@snap log_must zfs set projectquota@$PRJID1=100m $QFS log_must zfs set projectobjquota@$PRJID1=100 $QFS mkmount_writable $QFS log_must user_run $PUSER mkdir $PRJDIR log_must chattr +P -p $PRJID1 $PRJDIR log_must user_run $PUSER mkfile 50m $PRJDIR/qf sync log_must zfs snapshot $snap_fs for param in "${good_params[@]}"; do log_must eval "zfs projectspace $param $QFS >/dev/null 2>&1" log_must eval "zfs projectspace $param $snap_fs >/dev/null 2>&1" done log_assert "Check the zfs projectspace with some bad parameters" set -A bad_params -- "-i" "-n" "-P" "-t posixuser" for param in "${bad_params[@]}"; do log_mustnot eval "zfs projectspace $param $QFS >/dev/null 2>&1" log_mustnot eval "zfs projectspace $param $snap_fs >/dev/null 2>&1" done log_pass "zfs projectspace with kinds of parameters pass" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectspace_002_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectspace_002_pos.ksh index 216855e94dc9..10edae771e99 100755 --- a/tests/zfs-tests/tests/functional/projectquota/projectspace_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/projectquota/projectspace_002_pos.ksh @@ -1,85 +1,83 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2017 by Fan Yong. All rights reserved. # . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib # # DESCRIPTION: # Check the project used size and quota in zfs projectspace # # # STRATEGY: # 1. set zfs projectquota to a fs # 2. write some data to the fs with specified project and size # 3. use zfs projectspace to check the used size and quota size # function cleanup { - if datasetexists $snapfs; then - log_must zfs destroy $snapfs - fi + datasetexists $snapfs && destroy_dataset $snapfs log_must cleanup_projectquota } if ! lsattr -pd > /dev/null 2>&1; then log_unsupported "Current e2fsprogs does not support set/show project ID" fi log_onexit cleanup log_assert "Check the zfs projectspace used and quota" log_must zfs set projectquota@$PRJID1=100m $QFS mkmount_writable $QFS log_must user_run $PUSER mkdir $PRJDIR log_must chattr +P -p $PRJID1 $PRJDIR log_must user_run $PUSER mkfile 50m $PRJDIR/qf sync typeset snapfs=$QFS@snap log_must zfs snapshot $snapfs log_must eval "zfs projectspace $QFS >/dev/null 2>&1" log_must eval "zfs projectspace $snapfs >/dev/null 2>&1" for fs in "$QFS" "$snapfs"; do log_note "check the quota size in zfs projectspace $fs" log_must eval "zfs projectspace $fs | grep $PRJID1 | grep 100M" log_note "check the project used size in zfs projectspace $fs" log_must eval "zfs projectspace $fs | grep $PRJID1 | grep 50\\.\*M" done log_pass "Check the zfs projectspace used and quota" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectspace_003_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectspace_003_pos.ksh index 629b3b3e57e2..8db5d0d89970 100755 --- a/tests/zfs-tests/tests/functional/projectquota/projectspace_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/projectquota/projectspace_003_pos.ksh @@ -1,118 +1,116 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2017 by Fan Yong. All rights reserved. # . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib # # DESCRIPTION: # Check the project used object accounting in zfs projectspace # # # STRATEGY: # 1. create a bunch of files by specific project # 2. use zfs projectspace to check the used objects # 3. change the project ID of test files and verify object count # 4. delete files and verify object count # function cleanup { - if datasetexists $snapfs; then - log_must zfs destroy $snapfs - fi + datasetexists $snapfs && destroy_dataset $snapfs log_must cleanup_projectquota } if ! lsattr -pd > /dev/null 2>&1; then log_unsupported "Current e2fsprogs does not support set/show project ID" fi log_onexit cleanup log_assert "Check the zfs projectspace object used" mkmount_writable $QFS log_must zfs set xattr=sa $QFS log_must user_run $PUSER mkdir $PRJDIR1 log_must user_run $PUSER mkdir $PRJDIR2 log_must chattr +P -p $PRJID1 $PRJDIR1 log_must chattr +P -p $PRJID2 $PRJDIR2 ((prj_cnt1 = RANDOM % 100 + 2)) ((prj_cnt2 = RANDOM % 100 + 2)) log_must user_run $PUSER mkfiles $PRJDIR1/qf $((prj_cnt1 - 1)) log_must user_run $PUSER mkfiles $PRJDIR2/qf $((prj_cnt2 - 1)) sync_pool typeset snapfs=$QFS@snap log_must zfs snapshot $snapfs log_must eval "zfs projectspace $QFS >/dev/null 2>&1" log_must eval "zfs projectspace $snapfs >/dev/null 2>&1" for fs in "$QFS" "$snapfs"; do log_note "check the project used objects in zfs projectspace $fs" prjused=$(project_obj_count $fs $PRJID1) [[ $prjused -eq $prj_cnt1 ]] || log_fail "($PRJID1) expected $prj_cnt1, got $prjused" prjused=$(project_obj_count $fs $PRJID2) [[ $prjused -eq $prj_cnt2 ]] || log_fail "($PRJID2) expected $prj_cnt2, got $prjused" done log_note "change the project of files" log_must chattr -p $PRJID2 $PRJDIR1/qf* sync_pool prjused=$(project_obj_count $QFS $PRJID1) [[ $prjused -eq 1 ]] || log_fail "expected 1 for project $PRJID1, got $prjused" prjused=$(project_obj_count $snapfs $PRJID1) [[ $prjused -eq $prj_cnt1 ]] || log_fail "expected $prj_cnt1 for $PRJID1 in snapfs, got $prjused" prjused=$(project_obj_count $QFS $PRJID2) [[ $prjused -eq $((prj_cnt1 + prj_cnt2 - 1)) ]] || log_fail "($PRJID2) expected $((prj_cnt1 + prj_cnt2 - 1)), got $prjused" log_note "file removal" log_must rm -rf $PRJDIR1 sync_pool prjused=$(project_obj_count $QFS $PRJID1) [[ $prjused -eq 0 ]] || log_fail "expected 0 for $PRJID1, got $prjused" cleanup log_pass "Check the zfs projectspace object used" diff --git a/tests/zfs-tests/tests/functional/projectquota/projectspace_004_pos.ksh b/tests/zfs-tests/tests/functional/projectquota/projectspace_004_pos.ksh index ec299e0e7f93..fc4a93f04463 100755 --- a/tests/zfs-tests/tests/functional/projectquota/projectspace_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/projectquota/projectspace_004_pos.ksh @@ -1,76 +1,74 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2017 by Fan Yong. Fan rights reserved. # . $STF_SUITE/tests/functional/projectquota/projectquota_common.kshlib # # DESCRIPTION: # Check 'df' command on the directory with INHERIT (project ID) flag # # # STRATEGY: # 1. set project [obj]quota on the directory # 2. set project ID and inherit flag on the directory # 3. run 'df [-i]' on the directory and check the result # function cleanup { - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs log_must cleanup_projectquota } if ! lsattr -pd > /dev/null 2>&1; then log_unsupported "Current e2fsprogs does not support set/show project ID" fi log_onexit cleanup log_assert "Check 'df' on dir with inherit project shows the project quota/used" log_must zfs set projectquota@$PRJID1=100m $QFS log_must zfs set projectobjquota@$PRJID1=100 $QFS mkmount_writable $QFS log_must user_run $PUSER mkdir $PRJDIR log_must chattr +P -p $PRJID1 $PRJDIR log_must user_run $PUSER mkfile 50m $PRJDIR/qf sync_pool total=$(df $PRJDIR | tail -n 1 | awk '{ print $2 }') [[ $total -eq 102400 ]] || log_fail "expect '102400' resource, but got '$total'" used=$(df -i $PRJDIR | tail -n 1 | awk '{ print $5 }') [[ "$used" == "2%" ]] || log_fail "expect '2%' used, but got '$used'" log_pass "'df' on the directory with inherit project ID flag pass as expect" diff --git a/tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh b/tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh index ed28cc1f0c9b..e87139a58f69 100755 --- a/tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/quota/quota_005_pos.ksh @@ -1,76 +1,75 @@ #! /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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/quota/quota.kshlib # # DESCRIPTION: # # Verify that quota doesn't inherit its value from parent. # # STRATEGY: # 1) Set quota for parents # 2) Create a filesystem tree # 3) Verify that the 'quota' for descendent doesnot inherit the value. # ############################################################################### verify_runnable "both" function cleanup { - datasetexists $fs_child && \ - log_must zfs destroy $fs_child + datasetexists $fs_child && destroy_dataset $fs_child log_must zfs set quota=$quota_val $fs } log_onexit cleanup log_assert "Verify that quota doesnot inherit its value from parent." log_onexit cleanup fs=$TESTPOOL/$TESTFS fs_child=$TESTPOOL/$TESTFS/$TESTFS space_avail=$(get_prop available $fs) quota_val=$(get_prop quota $fs) typeset -i quotasize=$space_avail ((quotasize = quotasize * 2 )) log_must zfs set quota=$quotasize $fs log_must zfs create $fs_child quota_space=$(get_prop quota $fs_child) [[ $quota_space == $quotasize ]] && \ log_fail "The quota of child dataset inherits its value from parent." log_pass "quota doesnot inherit its value from parent as expected." diff --git a/tests/zfs-tests/tests/functional/refreserv/refreserv_002_pos.ksh b/tests/zfs-tests/tests/functional/refreserv/refreserv_002_pos.ksh index d4c0a4faebdc..a8f58631f7b6 100755 --- a/tests/zfs-tests/tests/functional/refreserv/refreserv_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/refreserv/refreserv_002_pos.ksh @@ -1,114 +1,112 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/refreserv/refreserv.cfg # # DESCRIPTION: # Setting full size as refreservation, verify no snapshot can be created. # # STRATEGY: # 1. Setting full size as refreservation on pool # 2. Verify no snapshot can be created on this pool # 3. Setting full size as refreservation on filesystem # 4. Verify no snapshot can be created on it and its subfs # verify_runnable "both" function cleanup { if is_global_zone ; then log_must zfs set refreservation=none $TESTPOOL - if datasetexists $TESTPOOL@snap ; then - log_must zfs destroy -f $TESTPOOL@snap - fi + datasetexists $TESTPOOL@snap && destroy_dataset $TESTPOOL@snap -f fi - log_must zfs destroy -rf $TESTPOOL/$TESTFS + destroy_dataset $TESTPOOL/$TESTFS -rf log_must zfs create $TESTPOOL/$TESTFS log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS } # This function iteratively increases refreserv to its highest possible # value. Simply setting refreserv == quota can allow enough writes to # complete that the test fails. function max_refreserv { typeset ds=$1 typeset -i incsize=131072 typeset -i rr=$(get_prop available $ds) log_must zfs set refreserv=$rr $ds while :; do zfs set refreserv=$((rr + incsize)) $ds >/dev/null 2>&1 if [[ $? == 0 ]]; then ((rr += incsize)) continue else ((incsize /= 2)) ((incsize == 0)) && break fi done } log_assert "Setting full size as refreservation, verify no snapshot " \ "can be created." log_onexit cleanup log_must zfs create $TESTPOOL/$TESTFS/subfs typeset datasets if is_global_zone; then datasets="$TESTPOOL $TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs" else datasets="$TESTPOOL/$TESTFS $TESTPOOL/$TESTFS/subfs" fi for ds in $datasets; do # # Verify refreservation on dataset # log_must zfs set quota=25M $ds max_refreserv $ds log_mustnot zfs snapshot $ds@snap if datasetexists $ds@snap ; then log_fail "ERROR: $ds@snap should not exists." fi log_must zfs set quota=none $ds log_must zfs set refreservation=none $ds done log_pass "Setting full size as refreservation, verify no snapshot " \ "can be created." diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_002_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_002_pos.ksh index 8ae3593613f0..e0fed6389c35 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_002_pos.ksh @@ -1,100 +1,100 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # Reservation values cannot exceed the amount of space available # in the pool. Verify that attempting to set a reservation greater # than this value fails. # # STRATEGY: # 1) Create a filesystem, regular and sparse volume # 2) Get the space available in the pool # 3) Attempt to set a reservation greater than the available space # on the filesystem and verify it fails. # 4) Verify that the reservation is still set to 'none' (or 0) on # the filesystem. # 5) Repeat 3-4 for regular and sparse volume # verify_runnable "both" function cleanup { for obj in $OBJ_LIST; do - datasetexists $obj && log_must_busy zfs destroy -f $obj + datasetexists $obj && destroy_dataset $obj -f done log_must zero_reservation $TESTPOOL/$TESTFS } log_onexit cleanup log_assert "Reservation values cannot exceed the amount of space" \ " available in the pool" space_avail=`get_prop available $TESTPOOL` if ! is_global_zone ; then OBJ_LIST="" else OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" ((vol_set_size = space_avail / 4)) vol_set_size=$(floor_volsize $vol_set_size) ((sparse_vol_set_size = space_avail * 4)) sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) log_must zfs create -V $vol_set_size $TESTPOOL/$TESTVOL log_must zfs set reservation=none $TESTPOOL/$TESTVOL log_must zfs create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 fi for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do space_avail=`get_prop available $obj` resv_size_set=`expr $space_avail + $RESV_DELTA` log_must zero_reservation $obj log_mustnot zfs set reservation=$resv_size_set $obj resv_size_get=`get_prop reservation $obj` if (($resv_size_get != 0)); then log_fail "Reservation value non-zero ($resv_size_get)" fi done log_pass "Attempting to set too large reservation failed as expected" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_003_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_003_pos.ksh index 48adabe72ffd..ee303b53bedd 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_003_pos.ksh @@ -1,134 +1,134 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # Verify that it's possible to set a reservation on a filesystem, # or volume multiple times, without resetting the reservation # to none. # # STRATEGY: # 1) Create a regular volume and a sparse volume # 2) Get the space available in the pool # 3) Set a reservation on the filesystem less than the space available. # 4) Verify that the 'reservation' property for the filesystem has # the correct value. # 5) Repeat 2-4 for different reservation values # 6) Repeat 3-5 for regular and sparse volume # verify_runnable "both" log_assert "Verify it is possible to set reservations multiple times " \ "on a filesystem regular and sparse volume" function cleanup { log_must zero_reservation $TESTPOOL/$TESTFS for obj in $OBJ_LIST; do - datasetexists $obj && log_must zfs destroy -f $obj + datasetexists $obj && destroy_dataset $obj -f done } log_onexit cleanup # # Set a reservation $RESV_ITER times on a dataset and verify that # the reservation is correctly set each time. # function multiple_resv { #dataset typeset -i i=0 dataset=$1 log_must zero_reservation $dataset space_avail=`get_prop available $TESTPOOL` ((resv_size = (space_avail - RESV_DELTA) / RESV_ITER)) # # For regular (non-sparse) volumes the upper limit is determined # not by the space available in the pool but rather by the size # of the volume itself. # [[ $obj == $TESTPOOL/$TESTVOL ]] && \ ((resv_size = (vol_set_size - RESV_DELTA) / RESV_ITER)) resv_size_set=$resv_size while (($i < $RESV_ITER)); do ((i = i + 1)) ((resv_size_set = resv_size * i)) log_must zfs set reservation=$resv_size_set $dataset resv_size_get=`get_prop reservation $dataset` if [[ $resv_size_set != $resv_size_get ]]; then log_fail "Reservation not the expected value " \ "($resv_size_set != $resv_size_get)" fi done log_must zero_reservation $dataset } space_avail=`get_prop available $TESTPOOL` if ! is_global_zone ; then OBJ_LIST="" else OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" ((vol_set_size = space_avail / 4)) vol_set_size=$(floor_volsize $vol_set_size) ((sparse_vol_set_size = space_avail * 4)) sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) log_must zfs create -V $vol_set_size $TESTPOOL/$TESTVOL log_must zfs set reservation=none $TESTPOOL/$TESTVOL log_must zfs create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 fi for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do multiple_resv $obj done log_pass "Multiple reservations successfully set on filesystem" \ " and both volume types" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_004_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_004_pos.ksh index f8342ff29488..eb606a762432 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_004_pos.ksh @@ -1,130 +1,130 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # When a dataset which has a reservation set on it is destroyed, # the space consumed or reserved by that dataset should be released # back into the pool. # # STRATEGY: # 1) Create a filesystem, regular and sparse volume # 2) Get the space used and available in the pool # 3) Set a reservation on the filesystem less than the space available. # 4) Verify that the 'reservation' property for the filesystem has # the correct value. # 5) Destroy the filesystem without resetting the reservation value. # 6) Verify that the space used and available totals for the pool have # changed by the expected amounts (within tolerances). # 7) Repeat steps 3-6 for a regular volume and sparse volume # verify_runnable "both" function cleanup { for obj in $OBJ_LIST; do - datasetexists $obj && log_must_busy zfs destroy -f $obj + datasetexists $obj && destroy_dataset $obj -f done } log_assert "Verify space released when a dataset with reservation is destroyed" log_onexit cleanup log_must zfs create $TESTPOOL/$TESTFS2 space_avail=`get_prop available $TESTPOOL` if ! is_global_zone ; then OBJ_LIST="$TESTPOOL/$TESTFS2" else OBJ_LIST="$TESTPOOL/$TESTFS2 \ $TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" ((vol_set_size = space_avail / 4)) vol_set_size=$(floor_volsize $vol_set_size) ((sparse_vol_set_size = space_avail * 4)) sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) log_must zfs create -V $vol_set_size $TESTPOOL/$TESTVOL log_must zfs set refreservation=none $TESTPOOL/$TESTVOL log_must zfs set reservation=none $TESTPOOL/$TESTVOL log_must zfs create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 fi # re-calculate space available. space_avail=`get_prop available $TESTPOOL` # Calculate a large but valid reservation value. resv_size_set=`expr $space_avail - $RESV_DELTA` for obj in $OBJ_LIST ; do space_avail=`get_prop available $TESTPOOL` space_used=`get_prop used $TESTPOOL` # # For regular (non-sparse) volumes the upper limit is determined # not by the space available in the pool but rather by the size # of the volume itself. # [[ $obj == $TESTPOOL/$TESTVOL ]] && \ ((resv_size_set = vol_set_size - RESV_DELTA)) log_must zfs set reservation=$resv_size_set $obj resv_size_get=`get_prop reservation $obj` if [[ $resv_size_set != $resv_size_get ]]; then log_fail "Reservation not the expected value " \ "($resv_size_set != $resv_size_get)" fi log_must_busy zfs destroy -f $obj new_space_avail=`get_prop available $TESTPOOL` new_space_used=`get_prop used $TESTPOOL` # # Recent changes to metaslab logic have caused these tests to expand # outside of their previous tolerance. If this is discovered to be a # bug, rather than a side effect of some interactions, the reservation # should be halved again. # log_must within_limits $space_used $new_space_used $RESV_TOLERANCE log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE done log_pass "Space correctly released when dataset is destroyed" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_005_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_005_pos.ksh index 4047fab0d7f9..535d652dafab 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_005_pos.ksh @@ -1,118 +1,118 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # When a reservation property of a filesystem, regular volume # or sparse volume is set to 'none' the space previously consumed by the # reservation should be released back to the pool # # STRATEGY: # 1) Create a filesystem, regular volume and sparse volume # 2) Get the space used and available in the pool # 3) Set a reservation on the filesystem less than the space available. # 4) Verify that the 'reservation' property for the filesystem has # the correct value. # 5) Reset the reservation value back to zero (or 'none') # 6) Verify that the space used and available totals for the pool have # changed by the expected amounts (within tolerances). # 7) Repeat steps 3-6 for a regular volume, sparse volume # verify_runnable "both" log_assert "Verify space released when reservation on a dataset is set "\ "to 'none'" function cleanup { for obj in $OBJ_LIST; do - datasetexists $obj && log_must zfs destroy -f $obj + datasetexists $obj && destroy_dataset $obj -f done } log_onexit cleanup space_avail=`get_prop available $TESTPOOL` if ! is_global_zone ; then OBJ_LIST="" else OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" ((vol_set_size = space_avail / 4)) vol_set_size=$(floor_volsize $vol_set_size) ((sparse_vol_set_size = space_avail * 4)) sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) log_must zfs create -V $vol_set_size $TESTPOOL/$TESTVOL log_must zfs set reservation=none $TESTPOOL/$TESTVOL log_must zfs create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 fi space_avail=`get_prop available $TESTPOOL` space_used=`get_prop used $TESTPOOL` # Calculate a large but valid reservation value. resv_size_set=`expr $space_avail - $RESV_DELTA` for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do # # For regular (non-sparse) volumes the upper limit is determined # not by the space available in the pool but rather by the size # of the volume itself. # [[ $obj == $TESTPOOL/$TESTVOL ]] && \ ((resv_size_set = vol_set_size - RESV_DELTA)) log_must zfs set reservation=$resv_size_set $obj resv_size_get=`get_prop reservation $obj` if [[ $resv_size_set != $resv_size_get ]]; then log_fail "Reservation not the expected value "\ "($resv_size_set != $resv_size_get)" fi log_must zfs set reservation=none $obj new_space_avail=`get_prop available $TESTPOOL` new_space_used=`get_prop used $TESTPOOL` log_must within_limits $space_used $new_space_used $RESV_TOLERANCE log_must within_limits $space_avail $new_space_avail $RESV_TOLERANCE done log_pass "Space correctly released when dataset reservation set to 'none'" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_007_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_007_pos.ksh index 48d6b40ad05a..a1fffd362427 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_007_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_007_pos.ksh @@ -1,128 +1,128 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # Setting a reservation on dataset should have no effect on any other # dataset at the same level in the hierarchy beyond using up available # space in the pool. # # STRATEGY: # 1) Create a filesystem # 2) Set a reservation on the filesystem # 3) Create another filesystem at the same level # 4) Set a reservation on the second filesystem # 5) Destroy both the filesystems # 6) Verify space accounted for correctly # verify_runnable "both" log_assert "Verify reservations on data sets doesn't affect other data sets " \ "at same level except for consuming space from common pool" function cleanup { datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -f datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup space_avail=`get_prop available $TESTPOOL` space_used=`get_prop used $TESTPOOL` resv_size_set=`expr $space_avail / 3` # # Function which creates two datasets, sets reservations on them, # then destroys them and ensures that space is correctly accounted # for. # # Any special arguments for create are passed in via the args # parameter. # function create_resv_destroy { # args1 dataset1 args2 dataset2 args1=$1 dataset1=$2 args2=$3 dataset2=$4 log_must zfs create $args1 $dataset1 log_must zfs set reservation=$RESV_SIZE $dataset1 avail_aft_dset1=`get_prop available $TESTPOOL` used_aft_dset1=`get_prop used $TESTPOOL` log_must zfs create $args2 $dataset2 log_must zfs set reservation=$RESV_SIZE $dataset2 # # After destroying the second dataset the space used and # available totals should revert back to the values they # had after creating the first dataset. # - log_must zfs destroy -f $dataset2 + log_must_busy zfs destroy -f $dataset2 avail_dest_dset2=`get_prop available $TESTPOOL` used_dest_dset2=`get_prop used $TESTPOOL` log_must within_limits $avail_aft_dset1 $avail_dest_dset2 $RESV_TOLERANCE log_must within_limits $used_aft_dset1 $used_dest_dset2 $RESV_TOLERANCE # After destroying the first dataset the space used and # space available totals should revert back to the values # they had when the pool was first created. - log_must zfs destroy -f $dataset1 + log_must_busy zfs destroy -f $dataset1 avail_dest_dset1=`get_prop available $TESTPOOL` used_dest_dset1=`get_prop used $TESTPOOL` log_must within_limits $avail_dest_dset1 $space_avail $RESV_TOLERANCE log_must within_limits $used_dest_dset1 $space_used $RESV_TOLERANCE } create_resv_destroy "" $TESTPOOL/$TESTFS1 "" $TESTPOOL/$TESTFS2 create_resv_destroy "" $TESTPOOL/$TESTFS2 "" $TESTPOOL/$TESTFS1 log_pass "Verify reservations on data sets doesn't affect other data sets at" \ " same level except for consuming space from common pool" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_008_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_008_pos.ksh index a0cd039b1839..cfc30f47421b 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_008_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_008_pos.ksh @@ -1,124 +1,124 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # Setting a reservation reserves a defined minimum amount of space for # a dataset, and prevents other datasets using that space. Verify that # reducing the reservation on a filesystem allows other datasets in # the pool to use that space. # # STRATEGY: # 1) Create multiple filesystems # 2) Set reservations on all bar one of the filesystems # 3) Fill up the one non-reserved filesystem # 4) Reduce one of the reservations and verify can write more # data into the non-reserved filesystem # verify_runnable "both" log_assert "Verify reducing reservation allows other datasets to use space" function cleanup { typeset -i loop=0 while (($loop < $RESV_NUM_FS)); do datasetexists $TESTPOOL/${TESTFS}$loop && \ - log_must zfs destroy -f $TESTPOOL/${TESTFS}$loop + destroy_dataset $TESTPOOL/${TESTFS}$loop -f [[ -d ${TESTDIR}$loop ]] && log_must rm -r ${TESTDIR}$loop ((loop = loop + 1)) done } log_onexit cleanup log_must create_multiple_fs $RESV_NUM_FS $TESTPOOL/$TESTFS $TESTDIR space_avail=`get_prop available $TESTPOOL` space_used=`get_prop used $TESTPOOL` # # To make sure this test doesn't take too long to execute on # large pools, we calculate a reservation setting which when # applied to all bar one of the filesystems (RESV_NUM_FS-1) will # ensure we have RESV_FREE_SPACE left free in the pool, which we will # be able to quickly fill. # resv_space_avail=`expr $space_avail - $RESV_FREE_SPACE` num_resv_fs=`expr $RESV_NUM_FS - 1` # Number of FS to which resv will be applied resv_size_set=`expr $resv_space_avail / $num_resv_fs` # # We set the reservations now, rather than when we created the filesystems # to allow us to take into account space used by the filesystem metadata # # Note we don't set a reservation on the first filesystem we created, # hence num=1 rather than zero below. # typeset -i num=1 while (($num < $RESV_NUM_FS)); do log_must zfs set reservation=$resv_size_set $TESTPOOL/$TESTFS$num ((num = num + 1)) done space_avail_still=`get_prop available $TESTPOOL` fill_size=`expr $space_avail_still + $RESV_TOLERANCE` write_count=`expr $fill_size / $BLOCK_SIZE` # Now fill up the first filesystem (which doesn't have a reservation set # and thus will use up whatever free space is left in the pool). num=0 log_note "Writing to $TESTDIR$num/$TESTFILE1" file_write -o create -f $TESTDIR$num/$TESTFILE1 -b $BLOCK_SIZE \ -c $write_count -d 0 ret=$? if (($ret != $ENOSPC)); then log_fail "Did not get ENOSPC as expected (got $ret)." fi # Remove the reservation on one of the other filesystems and verify # can write more data to the original non-reservation filesystem. num=1 log_must zfs set reservation=none $TESTPOOL/${TESTFS}$num num=0 log_must file_write -o create -f ${TESTDIR}$num/$TESTFILE2 \ -b $(getconf PAGESIZE) -c 1000 -d 0 log_pass "reducing reservation allows other datasets to use space" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_009_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_009_pos.ksh index 171577def5ef..a639abf8960a 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_009_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_009_pos.ksh @@ -1,100 +1,102 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # In pool with a full filesystem and another filesystem with a reservation # setting the reservation on the second filesystem to 'none' should allow more # data to be written to the first filesystem. # # # STRATEGY: # 1) Create a filesystem as a dataset # 2) Create a filesystem at the same level # 3) Set a reservation on the dataset filesystem # 4) Fill up the filesystem # 5) Set the reservation on the dataset filesystem to 'none' # 6) Verify we can write more data to the first filesystem # verify_runnable "both" log_assert "Setting top level dataset reservation to 'none' allows more data " \ "to be written to top level filesystem" function cleanup { log_must rm -rf $TESTDIR/$TESTFILE1 log_must rm -rf $TESTDIR/$TESTFILE2 - log_must zfs destroy -f $TESTPOOL/$TESTFS1 + + datasetexists $TESTPOOL/$TESTFS1 && \ + destroy_dataset $TESTPOOL/$TESTFS1 -f } log_onexit cleanup log_must zfs create $TESTPOOL/$TESTFS1 space_avail=`get_prop available $TESTPOOL` # # To make sure this test doesn't take too long to execute on # large pools, we calculate a reservation setting which when # applied to the dataset will ensure we have RESV_FREE_SPACE # left free in the pool which we can quickly fill. # ((resv_size_set = space_avail - RESV_FREE_SPACE)) log_must zfs set reservation=$resv_size_set $TESTPOOL/$TESTFS1 space_avail_still=`get_prop available $TESTPOOL` fill_size=`expr $space_avail_still + $RESV_TOLERANCE` write_count=`expr $fill_size / $BLOCK_SIZE` # Now fill up the filesystem (which doesn't have a reservation set # and thus will use up whatever free space is left in the pool). file_write -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE \ -c $write_count -d 0 ret=$? if (($ret != $ENOSPC)); then log_fail "Did not get ENOSPC as expected (got $ret)." fi log_must zfs set reservation=none $TESTPOOL/$TESTFS1 log_must file_write -o create -f $TESTDIR/$TESTFILE2 \ -b $(getconf PAGESIZE) -c 1000 -d 0 log_pass "Setting top level dataset reservation to 'none' allows more " \ "data to be written to the top level filesystem" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_010_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_010_pos.ksh index 2ca279a4a437..f3a64a0bea8c 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_010_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_010_pos.ksh @@ -1,101 +1,101 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # In pool with a full filesystem and a filesystem with a reservation # destroying another filesystem should allow more data to be written to # the full filesystem # # # STRATEGY: # 1) Create a filesystem as dataset # 2) Create a filesystem at the same level # 3) Set a reservation on the dataset filesystem # 4) Fill up the second filesystem # 5) Destroy the dataset filesystem # 6) Verify can write more data to the full filesystem # verify_runnable "both" log_assert "Destroying top level filesystem with reservation allows more " \ "data to be written to another top level filesystem" function cleanup { datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 [[ -e $TESTDIR/$TESTFILE1 ]] && log_must rm -rf $TESTDIR/$TESTFILE1 [[ -e $TESTDIR/$TESTFILE2 ]] && log_must rm -rf $TESTDIR/$TESTFILE2 } log_onexit cleanup log_must zfs create $TESTPOOL/$TESTFS1 space_avail=`get_prop available $TESTPOOL` # # To make sure this test doesn't take too long to execute on # large pools, we calculate a reservation setting which when # applied to the dataset filesystem will ensure we have # RESV_FREE_SPACE left free in the pool. # ((resv_size_set = space_avail - RESV_FREE_SPACE)) log_must zfs set reservation=$resv_size_set $TESTPOOL/$TESTFS1 space_avail_still=`get_prop available $TESTPOOL` fill_size=`expr $space_avail_still + $RESV_TOLERANCE` write_count=`expr $fill_size / $BLOCK_SIZE` # Now fill up the filesystem (which doesn't have a reservation set # and thus will use up whatever free space is left in the pool). file_write -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0 ret=$? if (($ret != $ENOSPC)); then log_fail "Did not get ENOSPC as expected (got $ret)." fi log_must zfs destroy -f $TESTPOOL/$TESTFS1 log_must file_write -o create -f $TESTDIR/$TESTFILE2 \ -b $(getconf PAGESIZE) -c 1000 -d 0 log_pass "Destroying top level filesystem with reservation allows more data " \ "to be written to another top level filesystem" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_013_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_013_pos.ksh index 6a80bb575dc4..bf0955223490 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_013_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_013_pos.ksh @@ -1,112 +1,112 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # Reservation properties on data objects should be preserved when the # pool within which they are contained is exported and then re-imported. # # # STRATEGY: # 1) Create a filesystem as dataset # 2) Create another filesystem at the same level # 3) Create a regular volume at the same level # 4) Create a sparse volume at the same level # 5) Create a filesystem within the dataset filesystem # 6) Set reservations on all filesystems # 7) Export the pool # 8) Re-import the pool # 9) Verify that the reservation settings are correct # verify_runnable "global" log_assert "Reservation properties preserved across exports and imports" function cleanup { for obj in $OBJ_LIST; do - datasetexists $obj && log_must zfs destroy -f $obj + datasetexists $obj && destroy_dataset $obj -f done log_must zero_reservation $TESTPOOL/$TESTFS } log_onexit cleanup OBJ_LIST="$TESTPOOL/$TESTFS1/$TESTFS2 $TESTPOOL/$TESTFS1 $TESTPOOL/$TESTVOL \ $TESTPOOL/$TESTVOL2" log_must zfs create $TESTPOOL/$TESTFS1 log_must zfs create $TESTPOOL/$TESTFS1/$TESTFS2 space_avail=$(get_prop available $TESTPOOL) [[ $? -ne 0 ]] && \ log_fail "Unable to get space available property for $TESTPOOL" typeset -il resv_set=space_avail/5 resv_set=$(floor_volsize $resv_set) typeset -il sparse_vol_set_size=space_avail*5 sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) # When initially created, a regular volume's reservation property is set # equal to its size (unlike a sparse volume), so we don't need to set it # explicitly later on log_must zfs create -V $resv_set $TESTPOOL/$TESTVOL log_must zfs create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 log_must zfs set reservation=$resv_set $TESTPOOL/$TESTFS log_must zfs set reservation=$resv_set $TESTPOOL/$TESTFS1 log_must zfs set reservation=$resv_set $TESTPOOL/$TESTFS1/$TESTFS2 log_must zfs set reservation=$resv_set $TESTPOOL/$TESTVOL2 -log_must zpool export $TESTPOOL +log_must_busy zpool export $TESTPOOL log_must zpool import $TESTPOOL for obj in $TESTPOOL/$TESTFS $OBJ_LIST; do if [[ $obj == $TESTPOOL/$TESTVOL ]]; then expected=$(volsize_to_reservation $obj $resv_set) found=$(get_prop refreservation $obj) else expected=$resv_set found=$(get_prop reservation $obj) fi [[ $found != $expected ]] && \ log_fail "Reservation property for $obj incorrect. Expected " \ "$expected but got $found." done log_pass "Reservation properties preserved across exports and imports" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_014_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_014_pos.ksh index e8bd91d00e68..3b7f384da365 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_014_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_014_pos.ksh @@ -1,116 +1,116 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # A reservation cannot exceed the quota on a dataset # # STRATEGY: # 1) Create a filesystem and volume # 2) Set a quota on the filesystem # 3) Attempt to set a reservation larger than the quota. Verify # that the attempt fails. # 4) Repeat 2-3 for volume # verify_runnable "both" log_assert "Verify cannot set reservation larger than quota" function cleanup { # # Note we don't destroy $TESTFS as it's used by other tests for obj in $OBJ_LIST ; do - datasetexists $obj && log_must zfs destroy -f $obj + datasetexists $obj && destroy_dataset $obj -f done log_must zero_reservation $TESTPOOL/$TESTFS } log_onexit cleanup space_avail=`get_prop available $TESTPOOL` if ! is_global_zone ; then OBJ_LIST="" else OBJ_LIST="$TESTPOOL/$TESTVOL $TESTPOOL/$TESTVOL2" ((vol_set_size = space_avail / 4)) vol_set_size=$(floor_volsize $vol_set_size) ((sparse_vol_set_size = space_avail * 4)) sparse_vol_set_size=$(floor_volsize $sparse_vol_set_size) log_must zfs create -V $vol_set_size $TESTPOOL/$TESTVOL log_must zfs create -s -V $sparse_vol_set_size $TESTPOOL/$TESTVOL2 fi for obj in $TESTPOOL/$TESTFS $OBJ_LIST ; do space_avail=`get_prop available $obj` ((quota_set_size = space_avail / 3)) # # Volumes do not support quota so only need to explicitly # set quotas for filesystems. # # The maximum reservation value that can be set on a volume # is determined by the quota set on its parent filesystems or # the amount of space in the pool, whichever is smaller. # if [[ $obj == $TESTPOOL/$TESTFS ]]; then log_must zfs set quota=$quota_set_size $obj ((resv_set_size = quota_set_size + RESV_SIZE)) elif [[ $obj == $TESTPOOL/$TESTVOL || $obj == $TESTPOOL/$TESTVOL2 ]] then resv_set_size=`expr $space_avail + $RESV_DELTA` fi orig_quota=`get_prop quota $obj` log_mustnot zfs set reservation=$resv_set_size $obj new_quota=`get_prop quota $obj` if [[ $orig_quota != $new_quota ]]; then log_fail "Quota value changed from $orig_quota " \ "to $new_quota" fi if [[ $obj == $TESTPOOL/$TESTFS ]]; then log_must zfs set quota=none $obj fi done log_pass "As expected cannot set reservation larger than quota" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_015_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_015_pos.ksh index d67f8c7ec2f6..7067a7810590 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_015_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_015_pos.ksh @@ -1,99 +1,100 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # In pool with a full filesystem and a regular volume with an implicit # reservation, setting the reservation on the volume to 'none' should allow # more data to be written to the filesystem. # # # STRATEGY: # 1) Create a regular non-sparse volume (which implicitly sets the reservation # property to a value equal to the volume size) # 2) Create a filesystem at the same level # 3) Fill up the filesystem # 4) Set the reservation on the volume to 'none' # 5) Verify can write more data to the filesystem # verify_runnable "global" log_assert "Setting volume reservation to 'none' allows more data to be " \ "written to top level filesystem" function cleanup { datasetexists $TESTPOOL/$TESTVOL && \ - log_must zfs destroy $TESTPOOL/$TESTVOL + destroy_dataset $TESTPOOL/$TESTVOL [[ -e $TESTDIR/$TESTFILE1 ]] && log_must rm -rf $TESTDIR/$TESTFILE1 [[ -e $TESTDIR/$TESTFILE2 ]] && log_must rm -rf $TESTDIR/$TESTFILE2 } log_onexit cleanup space_avail=$(largest_volsize_from_pool $TESTPOOL) # # To make sure this test doesn't take too long to execute on # large pools, we calculate a volume size which when applied # to the volume will ensure we have RESV_FREE_SPACE # left free in the pool which we can quickly fill. # ((resv_size_set = space_avail - RESV_FREE_SPACE)) resv_size_set=$(floor_volsize $resv_size_set) log_must zfs create -V $resv_size_set $TESTPOOL/$TESTVOL +block_device_wait $TESTPOOL/$TESTVOL space_avail_still=`get_prop available $TESTPOOL` fill_size=$((space_avail_still + $RESV_TOLERANCE)) write_count=$((fill_size / BLOCK_SIZE)) # Now fill up the filesystem (which doesn't have a reservation set # and thus will use up whatever free space is left in the pool). file_write -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0 ret=$? if (($ret != $ENOSPC)); then log_fail "Did not get ENOSPC as expected (got $ret)." fi log_must zfs set refreservation=none $TESTPOOL/$TESTVOL log_must file_write -o create -f $TESTDIR/$TESTFILE2 \ -b $(getconf PAGESIZE) -c 1000 -d 0 log_pass "Setting top level volume reservation to 'none' allows more " \ "data to be written to the top level filesystem" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_016_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_016_pos.ksh index cbb1db658b33..82bbcde4a3b7 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_016_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_016_pos.ksh @@ -1,98 +1,99 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # In pool with a full filesystem and a regular volume (with implicit # reservation) destroying the volume should allow more data to be written # to the filesystem # # # STRATEGY: # 1) Create a regular (non-sparse) volume # 2) Create a filesystem at the same level # 3) Fill up the filesystem # 4) Destroy the volume # 5) Verify can write more data to the filesystem # verify_runnable "global" log_assert "Destroying a regular volume with reservation allows more data to" \ " be written to top level filesystem" function cleanup { datasetexists $TESTPOOL/$TESTVOL && \ - log_must zfs destroy $TESTPOOL/$TESTVOL + destroy_dataset $TESTPOOL/$TESTVOL [[ -e $TESTDIR/$TESTFILE1 ]] && log_must rm -rf $TESTDIR/$TESTFILE1 [[ -e $TESTDIR/$TESTFILE2 ]] && log_must rm -rf $TESTDIR/$TESTFILE2 } log_onexit cleanup space_avail=$(largest_volsize_from_pool $TESTPOOL) # # To make sure this test doesn't take too long to execute on # large pools, we calculate a volume size which will ensure we # have RESV_FREE_SPACE left free in the pool. # ((vol_set_size = space_avail - RESV_FREE_SPACE)) vol_set_size=$(floor_volsize $vol_set_size) # Creating a regular volume implicitly sets its reservation # property to the same value. log_must zfs create -V $vol_set_size $TESTPOOL/$TESTVOL +block_device_wait $TESTPOOL/$TESTVOL space_avail_still=$(get_prop available $TESTPOOL) fill_size=$((space_avail_still + $RESV_TOLERANCE)) write_count=$((fill_size / BLOCK_SIZE)) # Now fill up the filesystem (which doesn't have a reservation set # and thus will use up whatever free space is left in the pool). file_write -o create -f $TESTDIR/$TESTFILE1 -b $BLOCK_SIZE -c $write_count -d 0 ret=$? if (($ret != $ENOSPC)); then log_fail "Did not get ENOSPC as expected (got $ret)." fi log_must zfs destroy -f $TESTPOOL/$TESTVOL log_must file_write -o create -f $TESTDIR/$TESTFILE2 \ -b $(getconf PAGESIZE) -c 1000 -d 0 log_pass "Destroying volume with reservation allows more data to be written " \ "to top level filesystem" diff --git a/tests/zfs-tests/tests/functional/reservation/reservation_018_pos.ksh b/tests/zfs-tests/tests/functional/reservation/reservation_018_pos.ksh index 0969a6877316..1f92c8898562 100755 --- a/tests/zfs-tests/tests/functional/reservation/reservation_018_pos.ksh +++ b/tests/zfs-tests/tests/functional/reservation/reservation_018_pos.ksh @@ -1,72 +1,72 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/reservation/reservation.shlib # # DESCRIPTION: # # Verify that reservation doesn't inherit its value from parent. # # STRATEGY: # 1) Create a filesystem tree # 2) Set reservation for parents # 3) Verify that the 'reservation' for descendent doesnot inherit the value. # verify_runnable "both" function cleanup { - datasetexists $fs_child && log_must zfs destroy $fs_child + datasetexists $fs_child && destroy_dataset $fs_child log_must zfs set reservation=$reserv_val $fs } log_onexit cleanup log_assert "Verify that reservation doesnot inherit its value from parent." fs=$TESTPOOL/$TESTFS fs_child=$TESTPOOL/$TESTFS/$TESTFS space_avail=$(get_prop available $fs) reserv_val=$(get_prop reservation $fs) typeset reservsize=$space_avail ((reservsize = reservsize / 2)) log_must zfs set reservation=$reservsize $fs log_must zfs create $fs_child rsv_space=$(get_prop reservation $fs_child) [[ $rsv_space == $reservsize ]] && \ log_fail "The reservation of child dataset inherits its value from parent." log_pass "reservation doesnot inherit its value from parent as expected." diff --git a/tests/zfs-tests/tests/functional/rsend/send-c_lz4_disabled.ksh b/tests/zfs-tests/tests/functional/rsend/send-c_lz4_disabled.ksh index 666e11f702f8..bc706bab25b8 100755 --- a/tests/zfs-tests/tests/functional/rsend/send-c_lz4_disabled.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send-c_lz4_disabled.ksh @@ -1,73 +1,73 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2015 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/rsend/rsend.kshlib # # Description: # Verify a pool without the lz4 feature enabled can create compressed send # streams, and that they can be received into pools with or without the # lz4 feature. # # Strategy: # 1. For each of an uncompressed, and gzip dataset created from a pool with # the lz4 feature disabled, receive the stream into a pool with and without # the feature enabled. # verify_runnable "both" log_assert "Verify compressed streams are rejected if incompatible." typeset send_ds=$POOL2/testds typeset recv_ds=$POOL3/testds function cleanup { poolexists $POOL2 && destroy_pool $POOL2 poolexists $POOL3 && destroy_pool $POOL3 log_must zpool create $POOL2 $DISK2 } log_onexit cleanup datasetexists $POOL2 && log_must zpool destroy $POOL2 log_must zpool create -d $POOL2 $DISK2 for compress in off gzip; do for pool_opt in '' -d; do poolexists $POOL3 && destroy_pool $POOL3 log_must zpool create $pool_opt $POOL3 $DISK3 - datasetexists $send_ds && log_must_busy zfs destroy -r $send_ds - datasetexists $recv_ds && log_must_busy zfs destroy -r $recv_ds + datasetexists $send_ds && destroy_dataset $send_ds -r + datasetexists $recv_ds && destroy_dataset $recv_ds -r log_must zfs create -o compress=$compress $send_ds typeset dir=$(get_prop mountpoint $send_ds) write_compressible $dir 16m log_must zfs snapshot $send_ds@full log_must eval "zfs send -c $send_ds@full >$BACKDIR/full-c" log_must eval "zfs recv $recv_ds <$BACKDIR/full-c" log_must_busy zfs destroy -r $recv_ds log_must eval "zfs send $send_ds@full >$BACKDIR/full" log_must eval "zfs recv $recv_ds <$BACKDIR/full" done done log_pass "Compressed streams are rejected if incompatible." diff --git a/tests/zfs-tests/tests/functional/rsend/send-c_recv_lz4_disabled.ksh b/tests/zfs-tests/tests/functional/rsend/send-c_recv_lz4_disabled.ksh index 20a8c5481224..15873ed12f1e 100755 --- a/tests/zfs-tests/tests/functional/rsend/send-c_recv_lz4_disabled.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send-c_recv_lz4_disabled.ksh @@ -1,68 +1,68 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2015, Delphix. All rights reserved. # . $STF_SUITE/tests/functional/rsend/rsend.kshlib . $STF_SUITE/include/properties.shlib # # Description: # Verify a pool without the lz4 feature gracefully rejects a compressed stream # because on any sending pool that supports it, metadata will be compressed # with lz4 even if user data is not compressed. # # Strategy: # 1. For each of an uncompressed, gzip and lz4 dataset, do the following # receives into a pool without the lz4 feature: # 2. Attempt to receive the compressed stream (should fail) # 3. Attempt to receive the uncompressed stream (should succeed) # verify_runnable "both" log_assert "Verify compressed streams are rejected if incompatible." typeset send_ds=$POOL2/testds typeset recv_ds=$POOL3/testds function cleanup { poolexists $POOL2 && destroy_pool $POOL2 poolexists $POOL3 && destroy_pool $POOL3 log_must zpool create $POOL2 $DISK2 } log_onexit cleanup datasetexists $POOL3 && log_must zpool destroy $POOL3 log_must zpool create -d $POOL3 $DISK3 for compress in "${compress_prop_vals[@]}"; do - datasetexists $send_ds && log_must_busy zfs destroy -r $send_ds - datasetexists $recv_ds && log_must_busy zfs destroy -r $recv_ds + datasetexists $send_ds && destroy_dataset $send_ds -r + datasetexists $recv_ds && destroy_dataset $recv_ds -r log_must zfs create -o compress=$compress $send_ds typeset dir=$(get_prop mountpoint $send_ds) write_compressible $dir 16m log_must zfs snapshot $send_ds@full log_must eval "zfs send -c $send_ds@full >$BACKDIR/full-c" log_mustnot eval "zfs recv $recv_ds <$BACKDIR/full-c" log_must eval "zfs send $send_ds@full >$BACKDIR/full" log_must eval "zfs recv $recv_ds <$BACKDIR/full" done log_pass "Compressed streams are rejected if incompatible." diff --git a/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh b/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh index b3edb1c45788..056fc2cc2584 100755 --- a/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send-c_stream_size_estimate.ksh @@ -1,97 +1,97 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2015, Delphix. All rights reserved. # . $STF_SUITE/tests/functional/rsend/rsend.kshlib . $STF_SUITE/include/properties.shlib # # Description: # Verify the stream size estimate given by -P accounts for compressed send. # Verify the stream size given by -P accounts for compressed send." # # Strategy: # 1. For datasets of varied compression types do the following: # 2. Write data, verify stream size estimates with and without -c # verify_runnable "both" typeset send_ds="$POOL2/testfs" typeset send_vol="$POOL2/vol" typeset send_voldev="$ZVOL_DEVDIR/$POOL2/vol" typeset file="$BACKDIR/file.0" typeset megs="16" typeset compress function get_estimated_size { typeset cmd=$1 typeset ds=${cmd##* } if is_freebsd; then mkdir -p $BACKDIR typeset tmpfile=$(TMPDIR=$BACKDIR mktemp) else typeset tmpfile=$(mktemp -p $BACKDIR) fi eval "$cmd >$tmpfile" [[ $? -eq 0 ]] || log_fail "get_estimated_size: $cmd" typeset size=$(eval "awk '\$2 == \"$ds\" {print \$3}' $tmpfile") rm -f $tmpfile echo $size } log_assert "Verify the stream size given by -P accounts for compressed send." log_onexit cleanup_pool $POOL2 write_compressible $BACKDIR ${megs}m for compress in "${compress_prop_vals[@]}"; do - datasetexists $send_ds && log_must_busy zfs destroy -r $send_ds - datasetexists $send_vol && log_must_busy zfs destroy -r $send_vol + datasetexists $send_ds && destroy_dataset $send_ds -r + datasetexists $send_vol && destroy_dataset $send_vol -r log_must zfs create -o compress=$compress $send_ds log_must zfs create -V 1g -o compress=$compress $send_vol block_device_wait $send_voldev typeset dir=$(get_prop mountpoint $send_ds) log_must cp $file $dir log_must zfs snapshot $send_ds@snap log_must dd if=$file of=$send_voldev log_must zfs snapshot $send_vol@snap typeset ds_size=$(get_estimated_size "zfs send -nP $send_ds@snap") typeset ds_lrefer=$(get_prop lrefer $send_ds) within_percent $ds_size $ds_lrefer 90 || log_fail \ "$ds_size and $ds_lrefer differed by too much" typeset vol_size=$(get_estimated_size "zfs send -nP $send_vol@snap") typeset vol_lrefer=$(get_prop lrefer $send_vol) within_percent $vol_size $vol_lrefer 90 || log_fail \ "$vol_size and $vol_lrefer differed by too much" typeset ds_csize=$(get_estimated_size "zfs send -nP -c $send_ds@snap") typeset ds_refer=$(get_prop refer $send_ds) within_percent $ds_csize $ds_refer 90 || log_fail \ "$ds_csize and $ds_refer differed by too much" typeset vol_csize=$(get_estimated_size "zfs send -nP -c $send_vol@snap") typeset vol_refer=$(get_prop refer $send_vol) within_percent $vol_csize $vol_refer 90 || log_fail \ "$vol_csize and $vol_refer differed by too much" done log_pass "The stream size given by -P accounts for compressed send." diff --git a/tests/zfs-tests/tests/functional/rsend/send-cpL_varied_recsize.ksh b/tests/zfs-tests/tests/functional/rsend/send-cpL_varied_recsize.ksh index e2810651a60e..25ad8e0820d1 100755 --- a/tests/zfs-tests/tests/functional/rsend/send-cpL_varied_recsize.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send-cpL_varied_recsize.ksh @@ -1,203 +1,203 @@ #!/bin/ksh -p # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2015 by Delphix. All rights reserved. # . $STF_SUITE/tests/functional/rsend/rsend.kshlib # # Description: # Verify compressed send works correctly with datasets of varying recsize. # # Strategy: # 1. Check the recv behavior (into pools with features enabled and disabled) # of all combinations of -c -p and -L. Verify the stream is compressed, # and that the recsize property and that of a received file is correct # according to this matrix: # # +---------+--------+------------+------------+-----------+-----------+ # | send | send | received | received | received | received | # | stream | stream | file bs | prop | file bs | props | # | recsize | flags | (disabled) | (disabled) | (enabled) | (enabled) | # +---------+--------+------------+------------+-----------+-----------+ # | 128k | | 128k | 128k | 128k | 128k | # | 128k | -c | Fails | Fails | 128k | 128k | # | 128k | -p | 128k | 128k | 128k | 128k | # | 128k | -L | 128k | 128k | 128k | 128k | # | 128k | -cp | Fails | Fails | 128k | 128k | # | 128k | -cL | Fails | Fails | 128k | 128k | # | 128k | -pL | 128k | 128k | 128k | 128k | # | 128k | -cpL | Fails | Fails | 128k | 128k | # | 1m | | Fails | Fails | 128k | 128k | # | 1m | -c | Fails | Fails | 128k | 128k | # | 1m | -p | 128k | 128k | 128k | 1m | # | 1m | -L | Fails | Fails | 1m | 128k | # | 1m | -cp | Fails | Fails | 128k | 1m | # | 1m | -cL | Fails | Fails | 1m | 128k | # | 1m | -pL | Fails | Fails | 1m | 1m | # | 1m | -cpL | Fails | Fails | 1m | 1m | # +---------+--------+------------+------------+-----------+-----------+ # verify_runnable "both" function cleanup { - datasetexists $TESTPOOL/128k && log_must_busy zfs destroy $TESTPOOL/128k - datasetexists $TESTPOOL/1m && log_must_busy zfs destroy $TESTPOOL/1m + datasetexists $TESTPOOL/128k && destroy_dataset $TESTPOOL/128k + datasetexists $TESTPOOL/1m && destroy_dataset $TESTPOOL/1m cleanup_pool $POOL2 destroy_pool $POOL3 } # For a received stream, verify the recsize (prop and file) match expectations. function check_recsize { typeset recv_ds=$1 typeset expected_file_bs=$2 typeset expected_recsize=$3 typeset file="$(get_prop mountpoint $recv_ds)/testfile" [[ -f $file ]] || log_fail "file '$file' doesn't exist" typeset read_recsize=$(get_prop recsize $recv_ds) if is_freebsd; then typeset read_file_bs=$(stat -f "%k" $file) else typeset read_file_bs=$(stat $file | sed -n \ 's/.*IO Block: \([0-9]*\).*/\1/p') fi [[ $read_recsize = $expected_recsize ]] || log_fail \ "read_recsize: $read_recsize expected_recsize: $expected_recsize" [[ $read_file_bs = $expected_file_bs ]] || log_fail \ "read_file_bs: $read_file_bs expected_file_bs: $expected_file_bs" } # # This function does a zfs send and receive according to the parameters # below, and verifies the data shown in the strategy section. # # -[cpL] flags to pass through to 'zfs send' # -d Receive into a pool with all features disabled # # $1 The recordsize of the send dataset # $2 Whether or not the recv should work. # $3 The blocksize expected in a received file (default 128k) # $4 The recordsize property expected in a received dataset (default 128k) # function check { typeset recv_pool=$POOL2 typeset flags='-' while getopts "cdpL" opt; do case $opt in c) flags+='c' ;; d) recv_pool=$POOL3 ;; p) flags+='p' ;; L) flags+='L' ;; esac done shift $(($OPTIND - 1)) [[ ${#flags} -eq 1 ]] && flags='' typeset recsize=$1 typeset verify=$2 typeset expected_file_bs=${3-131072} typeset expected_recsize=${4-131072} typeset send_ds=$TESTPOOL/$recsize typeset send_snap=$send_ds@snap typeset recv_ds=$recv_pool/$recsize typeset stream=$BACKDIR/stream.out datasetexists $send_ds || log_fail "send ds: $send_ds doesn't exist" [[ -f $stream ]] && log_must rm $stream log_must eval "zfs send $flags $send_snap >$stream" $verify eval "zfs recv $recv_ds <$stream" typeset stream_size=$(cat $stream | zstream dump | sed -n \ 's/ Total write size = \(.*\) (0x.*)/\1/p') # # Special case: For a send dataset with large blocks, don't try to # verify the stream size is correct if the compress flag is present # but the large blocks flag isn't. In these cases, the user data # isn't compressed in the stream (though metadata is) so the # verification would fail. # typeset do_size_test=true [[ $recsize = $large && $flags =~ 'c' && ! $flags =~ 'L' ]] && \ do_size_test=false $do_size_test && verify_stream_size $stream $send_ds if [[ $verify = "log_mustnot" ]]; then datasetnonexists $recv_ds || log_fail "$recv_ds shouldn't exist" return fi check_recsize $recv_ds $expected_file_bs $expected_recsize $do_size_test && verify_stream_size $stream $recv_ds log_must_busy zfs destroy -r $recv_ds } log_assert "Verify compressed send works with datasets of varying recsize." log_onexit cleanup typeset recsize opts dir typeset small=$((128 * 1024)) typeset large=$((1024 * 1024)) # Create POOL3 with features disabled and datasets to create test send streams datasetexists $POOL3 && log_must zpool destroy $POOL3 log_must zpool create -d $POOL3 $DISK3 write_compressible $BACKDIR 32m for recsize in $small $large; do log_must zfs create -o compress=gzip -o recsize=$recsize \ $TESTPOOL/$recsize dir=$(get_prop mountpoint $TESTPOOL/$recsize) log_must cp $BACKDIR/file.0 $dir/testfile log_must zfs snapshot $TESTPOOL/$recsize@snap done # Run tests for send streams without large blocks for opts in '' -d -c -p -dp -L -dL -cp -cL -pL -dpL -cpL; do check $opts $small log_must done for opts in -dc -dcp -dcL -dcpL; do check $opts $small log_mustnot done # Run tests for send streams with large blocks for opts in '' -d -dp -c; do check $opts $large log_must done for opts in -dc -dL -dcp -dcL -dpL -dcpL; do check $opts $large log_mustnot done check -p $large log_must $small $large check -L $large log_must $large $small check -cp $large log_must $small $large check -cL $large log_must $large $small check -pL $large log_must $large $large check -cpL $large log_must $large $large log_pass "Compressed send works with datasets of varying recsize." diff --git a/tests/zfs-tests/tests/functional/rsend/send_encrypted_files.ksh b/tests/zfs-tests/tests/functional/rsend/send_encrypted_files.ksh index 1fd21cbf7eff..370f5382ebae 100755 --- a/tests/zfs-tests/tests/functional/rsend/send_encrypted_files.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send_encrypted_files.ksh @@ -1,120 +1,120 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2018 by Datto Inc. All rights reserved. # . $STF_SUITE/tests/functional/rsend/rsend.kshlib # # DESCRIPTION: # Verify that a raw zfs send and receive can deal with several different # types of file layouts. # # STRATEGY: # 1. Create a new encrypted filesystem # 2. Add an empty file to the filesystem # 3. Add a small 512 byte file to the filesystem # 4. Add a larger 32M file to the filesystem # 5. Add a large sparse file to the filesystem # 6. Add 1000 empty files to the filesystem # 7. Add a file with a large xattr value # 8. Use xattrtest to create files with random xattrs (with and without xattrs=on) # 9. Take a snapshot of the filesystem # 10. Remove the 1000 empty files to the filesystem # 11. Take another snapshot of the filesystem # 12. Send and receive both snapshots # 13. Mount the filesystem and check the contents # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r datasetexists $TESTPOOL/recv && \ - log_must zfs destroy -r $TESTPOOL/recv + destroy_dataset $TESTPOOL/recv -r [[ -f $keyfile ]] && log_must rm $keyfile [[ -f $sendfile ]] && log_must rm $sendfile } log_onexit cleanup log_assert "Verify 'zfs send -w' works with many different file layouts" typeset keyfile=/$TESTPOOL/pkey typeset sendfile=/$TESTPOOL/sendfile typeset sendfile2=/$TESTPOOL/sendfile2 # Create an encrypted dataset log_must eval "echo 'password' > $keyfile" log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file://$keyfile $TESTPOOL/$TESTFS2 # Create files with varied layouts on disk log_must touch /$TESTPOOL/$TESTFS2/empty log_must mkfile 512 /$TESTPOOL/$TESTFS2/small log_must mkfile 32M /$TESTPOOL/$TESTFS2/full log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/sparse \ bs=512 count=1 seek=1048576 >/dev/null 2>&1 log_must mkdir -p /$TESTPOOL/$TESTFS2/dir for i in {1..1000}; do log_must mkfile 512 /$TESTPOOL/$TESTFS2/dir/file-$i done log_must mkdir -p /$TESTPOOL/$TESTFS2/xattrondir log_must zfs set xattr=on $TESTPOOL/$TESTFS2 log_must xattrtest -f 10 -x 3 -s 32768 -r -k -p /$TESTPOOL/$TESTFS2/xattrondir log_must mkdir -p /$TESTPOOL/$TESTFS2/xattrsadir log_must zfs set xattr=sa $TESTPOOL/$TESTFS2 log_must xattrtest -f 10 -x 3 -s 32768 -r -k -p /$TESTPOOL/$TESTFS2/xattrsadir # OpenZFS issue #7432 log_must zfs set compression=on xattr=sa $TESTPOOL/$TESTFS2 log_must touch /$TESTPOOL/$TESTFS2/attrs log_must eval "python -c 'print \"a\" * 4096' | \ set_xattr_stdin bigval /$TESTPOOL/$TESTFS2/attrs" log_must zfs set compression=off xattr=on $TESTPOOL/$TESTFS2 log_must zfs snapshot $TESTPOOL/$TESTFS2@snap1 # Remove the empty files created in the first snapshot for i in {1..1000}; do log_must rm /$TESTPOOL/$TESTFS2/dir/file-$i done sync log_must zfs snapshot $TESTPOOL/$TESTFS2@snap2 expected_cksum=$(recursive_cksum /$TESTPOOL/$TESTFS2) log_must eval "zfs send -wp $TESTPOOL/$TESTFS2@snap1 > $sendfile" log_must eval "zfs send -wp -i @snap1 $TESTPOOL/$TESTFS2@snap2 > $sendfile2" log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile" log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile2" log_must zfs load-key $TESTPOOL/recv log_must zfs mount -a actual_cksum=$(recursive_cksum /$TESTPOOL/recv) [[ "$expected_cksum" != "$actual_cksum" ]] && \ log_fail "Recursive checksums differ ($expected_cksum != $actual_cksum)" log_must xattrtest -f 10 -o3 -y -p /$TESTPOOL/recv/xattrondir log_must xattrtest -f 10 -o3 -y -p /$TESTPOOL/recv/xattrsadir log_pass "Verified 'zfs send -w' works with many different file layouts" diff --git a/tests/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files.ksh b/tests/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files.ksh index c710b3d911e7..5760bf9b902a 100755 --- a/tests/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files.ksh @@ -1,126 +1,126 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2018 by Datto Inc. All rights reserved. # . $STF_SUITE/tests/functional/rsend/rsend.kshlib # # DESCRIPTION: # # # STRATEGY: # 1. Create a new encrypted filesystem # 2. Add a 4 files that are to be truncated later # 3. Take a snapshot of the filesystem # 4. Truncate one of the files from 32M to 128k # 5. Truncate one of the files from 512k to 384k # 6. Truncate one of the files from 512k to 0 to 384k via reallocation # 7. Truncate one of the files from 1k to 0 to 512b via reallocation # 8. Take another snapshot of the filesystem # 9. Send and receive both snapshots # 10. Mount the filesystem and check the contents # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r datasetexists $TESTPOOL/recv && \ - log_must zfs destroy -r $TESTPOOL/recv + destroy_dataset $TESTPOOL/recv -r [[ -f $keyfile ]] && log_must rm $keyfile [[ -f $sendfile ]] && log_must rm $sendfile } log_onexit cleanup function recursive_cksum { case "$(uname)" in FreeBSD) find $1 -type f -exec sha256 -q {} \; | \ sort | sha256digest ;; *) find $1 -type f -exec sha256sum {} \; | \ sort -k 2 | awk '{ print $1 }' | sha256digest ;; esac } log_assert "Verify 'zfs send -w' works with many different file layouts" typeset keyfile=/$TESTPOOL/pkey typeset sendfile=/$TESTPOOL/sendfile typeset sendfile2=/$TESTPOOL/sendfile2 # Create an encrypted dataset log_must eval "echo 'password' > $keyfile" log_must zfs create -o encryption=on -o keyformat=passphrase \ -o keylocation=file://$keyfile $TESTPOOL/$TESTFS2 # Explicitly set the recordsize since the truncation sizes below depend on # this value being 128k. This is currently same as the default recordsize. log_must zfs set recordsize=128k $TESTPOOL/$TESTFS2 # Create files with varied layouts on disk log_must mkfile 32M /$TESTPOOL/$TESTFS2/truncated log_must mkfile 524288 /$TESTPOOL/$TESTFS2/truncated2 log_must mkfile 524288 /$TESTPOOL/$TESTFS2/truncated3 log_must mkfile 1024 /$TESTPOOL/$TESTFS2/truncated4 log_must zfs snapshot $TESTPOOL/$TESTFS2@snap1 # # Truncate files created in the first snapshot. The first tests # truncating a large file to a single block. The second tests # truncating one block off the end of a file without changing # the required nlevels to hold it. The third tests handling # of a maxblkid that is dropped and then raised again. The # fourth tests an object that is truncated from a single block # to a smaller single block. # log_must truncate -s 131072 /$TESTPOOL/$TESTFS2/truncated log_must truncate -s 393216 /$TESTPOOL/$TESTFS2/truncated2 log_must rm -f /$TESTPOOL/$TESTFS2/truncated3 log_must rm -f /$TESTPOOL/$TESTFS2/truncated4 log_must zpool sync $TESTPOOL log_must zfs umount $TESTPOOL/$TESTFS2 log_must zfs mount $TESTPOOL/$TESTFS2 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/truncated3 \ bs=128k count=3 iflag=fullblock log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/truncated4 \ bs=512 count=1 iflag=fullblock log_must zfs snapshot $TESTPOOL/$TESTFS2@snap2 expected_cksum=$(recursive_cksum /$TESTPOOL/$TESTFS2) log_must eval "zfs send -wp $TESTPOOL/$TESTFS2@snap1 > $sendfile" log_must eval "zfs send -wp -i @snap1 $TESTPOOL/$TESTFS2@snap2 > $sendfile2" log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile" log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile2" log_must zfs load-key $TESTPOOL/recv log_must zfs mount -a actual_cksum=$(recursive_cksum /$TESTPOOL/recv) [[ "$expected_cksum" != "$actual_cksum" ]] && \ log_fail "Recursive checksums differ ($expected_cksum != $actual_cksum)" log_pass "Verified 'zfs send -w' works with many different file layouts" diff --git a/tests/zfs-tests/tests/functional/rsend/send_mixed_raw.ksh b/tests/zfs-tests/tests/functional/rsend/send_mixed_raw.ksh index eea535af1100..59b08ccf723b 100755 --- a/tests/zfs-tests/tests/functional/rsend/send_mixed_raw.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send_mixed_raw.ksh @@ -1,118 +1,118 @@ #!/bin/ksh -p # # CDDL HEADER START # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # CDDL HEADER END # # # Copyright (c) 2019 Datto, Inc. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that 'zfs receive' produces an error when mixing # raw and non-raw sends in a way that would break IV set # consistency. # # STRATEGY: # 1. Create an initial dataset with 3 snapshots. # 2. Perform a raw send of the first snapshot to 2 other datasets. # 3. Perform a non-raw send of the second snapshot to one of # the other datasets. Perform a raw send from this dataset to # the last one. # 4. Attempt to raw send the final snapshot of the first dataset # to the other 2 datasets, which should fail. # 5. Repeat steps 1-4, but using bookmarks for incremental sends. # # # A B C notes # ------------------------------------------------------------------------------ # snap1 ---raw---> snap1 --raw--> snap1 # all snaps initialized via raw send # snap2 -non-raw-> snap2 --raw--> snap2 # A sends non-raw to B, B sends raw to C # snap3 ------------raw---------> snap3 # attempt send to C (should fail) # verify_runnable "both" function cleanup { datasetexists $TESTPOOL/$TESTFS3 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS3 + destroy_dataset $TESTPOOL/$TESTFS3 -r datasetexists $TESTPOOL/$TESTFS2 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS2 + destroy_dataset $TESTPOOL/$TESTFS2 -r datasetexists $TESTPOOL/$TESTFS1 && \ - log_must zfs destroy -r $TESTPOOL/$TESTFS1 + destroy_dataset $TESTPOOL/$TESTFS1 -r } log_onexit cleanup log_assert "Mixing raw and non-raw receives should fail" typeset passphrase="password" log_must eval "echo $passphrase | zfs create -o encryption=on" \ "-o keyformat=passphrase $TESTPOOL/$TESTFS1" log_must zfs snapshot $TESTPOOL/$TESTFS1@1 log_must touch /$TESTPOOL/$TESTFS1/a log_must zfs snapshot $TESTPOOL/$TESTFS1@2 log_must touch /$TESTPOOL/$TESTFS1/b log_must zfs snapshot $TESTPOOL/$TESTFS1@3 # Testing with snapshots log_must eval "zfs send -w $TESTPOOL/$TESTFS1@1 |" \ "zfs receive $TESTPOOL/$TESTFS2" log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS2" log_must eval "zfs send -w $TESTPOOL/$TESTFS2@1 |" \ "zfs receive $TESTPOOL/$TESTFS3" log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS3" log_must eval "zfs send -i $TESTPOOL/$TESTFS1@1 $TESTPOOL/$TESTFS1@2 |" \ "zfs receive $TESTPOOL/$TESTFS2" log_must eval "zfs send -w -i $TESTPOOL/$TESTFS2@1 $TESTPOOL/$TESTFS2@2 |" \ "zfs receive $TESTPOOL/$TESTFS3" log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS1@2 $TESTPOOL/$TESTFS1@3 |" \ "zfs receive $TESTPOOL/$TESTFS2" log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS2@2 $TESTPOOL/$TESTFS2@3 |" \ "zfs receive $TESTPOOL/$TESTFS3" log_must zfs destroy -r $TESTPOOL/$TESTFS3 log_must zfs destroy -r $TESTPOOL/$TESTFS2 # Testing with bookmarks log_must zfs bookmark $TESTPOOL/$TESTFS1@1 $TESTPOOL/$TESTFS1#b1 log_must zfs bookmark $TESTPOOL/$TESTFS1@2 $TESTPOOL/$TESTFS1#b2 log_must eval "zfs send -w $TESTPOOL/$TESTFS1@1 |" \ "zfs receive $TESTPOOL/$TESTFS2" log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS2" log_must zfs bookmark $TESTPOOL/$TESTFS2@1 $TESTPOOL/$TESTFS2#b1 log_must eval "zfs send -w $TESTPOOL/$TESTFS2@1 |" \ "zfs receive $TESTPOOL/$TESTFS3" log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS3" log_must eval "zfs send -i $TESTPOOL/$TESTFS1#b1 $TESTPOOL/$TESTFS1@2 |" \ "zfs receive $TESTPOOL/$TESTFS2" log_must eval "zfs send -w -i $TESTPOOL/$TESTFS2#b1 $TESTPOOL/$TESTFS2@2 |" \ "zfs receive $TESTPOOL/$TESTFS3" log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS1#b2" \ "$TESTPOOL/$TESTFS1@3 | zfs receive $TESTPOOL/$TESTFS2" log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS2#b2" \ "$TESTPOOL/$TESTFS2@3 | zfs receive $TESTPOOL/$TESTFS3" log_pass "Mixing raw and non-raw receives fail as expected" diff --git a/tests/zfs-tests/tests/functional/rsend/send_realloc_dnode_size.ksh b/tests/zfs-tests/tests/functional/rsend/send_realloc_dnode_size.ksh index 394fe95bb9b7..551ed15db254 100755 --- a/tests/zfs-tests/tests/functional/rsend/send_realloc_dnode_size.ksh +++ b/tests/zfs-tests/tests/functional/rsend/send_realloc_dnode_size.ksh @@ -1,112 +1,107 @@ #!/bin/ksh # # This file and its contents are supplied under the terms of the # Common Development and Distribution License ("CDDL"), version 1.0. # You may only use this file in accordance with the terms of version # 1.0 of the CDDL. # # A full copy of the text of the CDDL should have accompanied this # source. A copy of the CDDL is also available via the Internet at # http://www.illumos.org/license/CDDL. # # # Copyright (c) 2017 by Lawrence Livermore National Security, LLC. # Copyright (c) 2018 Datto Inc. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/rsend/rsend.kshlib # # Description: # Verify incremental receive properly handles objects with changed # dnode slot count. # # Strategy: # 1. Populate a dataset with 1k byte dnodes and snapshot # 2. Remove objects, set dnodesize=legacy, and remount dataset so new objects # get recycled numbers and formerly "interior" dnode slots get assigned # to new objects # 3. Remove objects, set dnodesize=2k, and remount dataset so new objects # overlap with recently recycled and formerly "normal" dnode slots get # assigned to new objects # 4. Create an empty file and add xattrs to it to exercise reclaiming a # dnode that requires more than 1 slot for its bonus buffer (Zol #7433) # 5. Generate initial and incremental streams # 6. Verify initial and incremental streams can be received # verify_runnable "both" log_assert "Verify incremental receive handles objects with changed dnode size" function cleanup { rm -f $BACKDIR/fs-dn-legacy rm -f $BACKDIR/fs-dn-1k rm -f $BACKDIR/fs-dn-2k rm -f $BACKDIR/fs-attr - if datasetexists $POOL/fs ; then - log_must zfs destroy -rR $POOL/fs - fi - - if datasetexists $POOL/newfs ; then - log_must zfs destroy -rR $POOL/newfs - fi + datasetexists $POOL/fs && destroy_dataset $POOL/fs -rR + datasetexists $POOL/newfs && destroy_dataset $POOL/newfs -rR } log_onexit cleanup # 1. Populate a dataset with 1k byte dnodes and snapshot log_must zfs create -o dnodesize=1k $POOL/fs log_must mk_files 200 262144 0 $POOL/fs log_must zfs snapshot $POOL/fs@a # 2. Remove objects, set dnodesize=legacy, and remount dataset so new objects # get recycled numbers and formerly "interior" dnode slots get assigned # to new objects rm /$POOL/fs/* log_must zfs unmount $POOL/fs log_must zfs set dnodesize=legacy $POOL/fs log_must zfs mount $POOL/fs log_must mk_files 200 262144 0 $POOL/fs log_must zfs snapshot $POOL/fs@b # 3. Remove objects, set dnodesize=2k, and remount dataset so new objects # overlap with recently recycled and formerly "normal" dnode slots get # assigned to new objects rm /$POOL/fs/* log_must zfs unmount $POOL/fs log_must zfs set dnodesize=2k $POOL/fs log_must zfs mount $POOL/fs log_must touch /$POOL/fs/attrs mk_files 200 262144 0 $POOL/fs log_must zfs snapshot $POOL/fs@c # 4. Create an empty file and add xattrs to it to exercise reclaiming a # dnode that requires more than 1 slot for its bonus buffer (Zol #7433) log_must zfs set compression=on xattr=sa $POOL/fs log_must eval "python -c 'print \"a\" * 512' | set_xattr_stdin bigval /$POOL/fs/attrs" log_must zfs snapshot $POOL/fs@d # 5. Generate initial and incremental streams log_must eval "zfs send $POOL/fs@a > $BACKDIR/fs-dn-1k" log_must eval "zfs send -i $POOL/fs@a $POOL/fs@b > $BACKDIR/fs-dn-legacy" log_must eval "zfs send -i $POOL/fs@b $POOL/fs@c > $BACKDIR/fs-dn-2k" log_must eval "zfs send -i $POOL/fs@c $POOL/fs@d > $BACKDIR/fs-attr" # 6. Verify initial and incremental streams can be received log_must eval "zfs recv $POOL/newfs < $BACKDIR/fs-dn-1k" log_must eval "zfs recv $POOL/newfs < $BACKDIR/fs-dn-legacy" log_must eval "zfs recv $POOL/newfs < $BACKDIR/fs-dn-2k" log_must eval "zfs recv $POOL/newfs < $BACKDIR/fs-attr" log_pass "Verify incremental receive handles objects with changed dnode size" diff --git a/tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh index 3abdff8c3bc7..1c8a3b2a6c20 100755 --- a/tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapshot/clone_001_pos.ksh @@ -1,171 +1,171 @@ #! /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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapshot/snapshot.cfg # # DESCRIPTION: # Create a snapshot from regular filesystem, volume, # or filesystem upon volume, Build a clone file system # from the snapshot and verify new files can be written. # # STRATEGY: # 1. Create snapshot use 3 combination: # - Regular filesystem # - Regular volume # - Filesystem upon volume # 2. Clone a new file system from the snapshot # 3. Verify the cloned file system is writable # verify_runnable "both" # Setup array, 4 elements as a group, refer to: # i+0: name of a snapshot # i+1: mountpoint of the snapshot # i+2: clone created from the snapshot # i+3: mountpoint of the clone set -A args "$SNAPFS" "$SNAPDIR" "$TESTPOOL/$TESTCLONE" "$TESTDIR.0" \ "$SNAPFS1" "$SNAPDIR3" "$TESTPOOL/$TESTCLONE1" "" \ "$SNAPFS2" "$SNAPDIR2" "$TESTPOOL1/$TESTCLONE2" "$TESTDIR.2" function setup_all { if is_freebsd; then # Pool creation on zvols is forbidden by default. # Save and the current setting. typeset _saved=$(get_tunable VOL_RECURSIVE) log_must set_tunable64 VOL_RECURSIVE 1 fi create_pool $TESTPOOL1 ${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL if is_freebsd; then # Restore the previous setting. log_must set_tunable64 VOL_RECURSIVE $_saved fi log_must zfs create $TESTPOOL1/$TESTFS log_must zfs set mountpoint=$TESTDIR2 $TESTPOOL1/$TESTFS return 0 } function cleanup_all { typeset -i i=0 i=0 while (( i < ${#args[*]} )); do snapexists ${args[i]} && \ destroy_dataset "${args[i]}" "-Rf" [[ -d ${args[i+3]} ]] && \ log_must rm -rf ${args[i+3]} [[ -d ${args[i+1]} ]] && \ log_must rm -rf ${args[i+1]} (( i = i + 4 )) done - datasetexists $TESTPOOL1/$TESTFS && \ - log_must zfs destroy -f $TESTPOOL1/$TESTFS + datasetexists $TESTPOOL1/$TESTFS && \ + destroy_dataset $TESTPOOL1/$TESTFS -f destroy_pool $TESTPOOL1 [[ -d $TESTDIR2 ]] && \ log_must rm -rf $TESTDIR2 return 0 } log_assert "Verify a cloned file system is writable." log_onexit cleanup_all setup_all [[ -n $TESTDIR ]] && \ log_must rm -rf $TESTDIR/* > /dev/null 2>&1 typeset -i COUNT=10 typeset -i i=0 for mtpt in $TESTDIR $TESTDIR2 ; do log_note "Populate the $mtpt directory (prior to snapshot)" typeset -i j=1 while [[ $j -le $COUNT ]]; do log_must file_write -o create -f $mtpt/before_file$j \ -b $BLOCKSZ -c $NUM_WRITES -d $j (( j = j + 1 )) done done while (( i < ${#args[*]} )); do # # Take a snapshot of the test file system. # log_must zfs snapshot ${args[i]} # # Clone a new file system from the snapshot # log_must zfs clone ${args[i]} ${args[i+2]} if [[ -n ${args[i+3]} ]] ; then log_must zfs set mountpoint=${args[i+3]} ${args[i+2]} FILE_COUNT=`ls -Al ${args[i+3]} | grep -v "total" \ | grep -v "\.zfs" | wc -l` if [[ $FILE_COUNT -ne $COUNT ]]; then ls -Al ${args[i+3]} log_fail "AFTER: ${args[i+3]} contains $FILE_COUNT files(s)." fi log_note "Verify the ${args[i+3]} directory is writable" j=1 while [[ $j -le $COUNT ]]; do log_must file_write -o create -f ${args[i+3]}/after_file$j \ -b $BLOCKSZ -c $NUM_WRITES -d $j (( j = j + 1 )) done FILE_COUNT=`ls -Al ${args[i+3]}/after* | grep -v "total" | wc -l` if [[ $FILE_COUNT -ne $COUNT ]]; then ls -Al ${args[i+3]} log_fail "${args[i+3]} contains $FILE_COUNT after* files(s)." fi fi (( i = i + 4 )) done log_pass "The clone file system is writable." diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_011_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_011_pos.ksh index 44e5943bcd2f..7e0a7f4ce1d8 100755 --- a/tests/zfs-tests/tests/functional/snapshot/snapshot_011_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapshot/snapshot_011_pos.ksh @@ -1,113 +1,112 @@ #! /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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapshot/snapshot.cfg # # DESCRIPTION: # use 'snapshot -r' to create a snapshot tree, add some files to one child # filesystem, rollback the child filesystem snapshot, verify that the child # filesystem gets back to the status while taking the snapshot. # # STRATEGY: # 1. Add some files to a target child filesystem # 2. snapshot -r the parent filesystem # 3. Add some other files to the target child filesystem # 4. rollback the child filesystem snapshot # 5. verify that the child filesystem get back to the status while being # snapshot'd # verify_runnable "both" function cleanup { - snapexists $SNAPPOOL && \ - log_must zfs destroy -r $SNAPPOOL + snapexists $SNAPPOOL && destroy_dataset $SNAPPOOL -r [[ -e $TESTDIR ]] && \ log_must rm -rf $TESTDIR/* > /dev/null 2>&1 } log_assert "Verify that rollback to a snapshot created by snapshot -r succeeds." log_onexit cleanup [[ -n $TESTDIR ]] && \ log_must rm -rf $TESTDIR/* > /dev/null 2>&1 typeset -i COUNT=10 log_note "Populate the $TESTDIR directory (prior to snapshot)" typeset -i i=0 while (( i < COUNT )); do log_must file_write -o create -f $TESTDIR/before_file$i \ -b $BLOCKSZ -c $NUM_WRITES -d $i (( i = i + 1 )) done log_must zfs snapshot -r $SNAPPOOL FILE_COUNT=`ls -Al $SNAPDIR | grep -v "total" | wc -l` if (( FILE_COUNT != COUNT )); then ls -Al $SNAPDIR log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)." fi log_note "Populate the $TESTDIR directory (post snapshot)" typeset -i i=0 while (( i < COUNT )); do log_must file_write -o create -f $TESTDIR/after_file$i \ -b $BLOCKSZ -c $NUM_WRITES -d $i (( i = i + 1 )) done # # Now rollback to latest snapshot # log_must zfs rollback $SNAPFS FILE_COUNT=`ls -Al $TESTDIR/after* 2> /dev/null | grep -v "total" | wc -l` if (( FILE_COUNT != 0 )); then ls -Al $TESTDIR log_fail "$TESTDIR contains $FILE_COUNT after* files(s)." fi FILE_COUNT=`ls -Al $TESTDIR/before* 2> /dev/null \ | grep -v "total" | wc -l` if (( FILE_COUNT != $COUNT )); then ls -Al $TESTDIR log_fail "$TESTDIR contains $FILE_COUNT before* files(s)." fi log_pass "Rollback with child snapshot works as expected." diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_012_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_012_pos.ksh index c5717e452686..92db9b53a7b8 100755 --- a/tests/zfs-tests/tests/functional/snapshot/snapshot_012_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapshot/snapshot_012_pos.ksh @@ -1,104 +1,103 @@ #! /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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapshot/snapshot.cfg # # DESCRIPTION: # Verify 'snapshot -r' can create snapshot for promoted clone, and vice # versa, a clone filesystem from the snapshot created by 'snapshot -r' # can be correctly promoted. # # STRATEGY: # 1. Create a dataset tree # 2. snapshot a filesystem and clone the snapshot # 3. promote the clone # 4. snapshot -r the dataset tree # 5. verify that the snapshot of cloned filesystem is created correctly # 6. clone a snapshot from the snapshot tree # 7. promote the clone # 8. verify that the clone is promoted correctly. # verify_runnable "both" function cleanup { if datasetexists $clone1; then log_must zfs promote $ctrfs - log_must zfs destroy $clone1 + destroy_dataset $clone1 fi - snapexists $snapctr && \ - log_must zfs destroy -r $snapctr + snapexists $snapctr && destroy_dataset $snapctr -r if snapexists $clone@$TESTSNAP1; then log_must zfs promote $ctrfs - log_must zfs destroy -rR $ctrfs@$TESTSNAP1 + destroy_dataset $ctrfs@$TESTSNAP1 -rR fi } log_assert "Verify that 'snapshot -r' can work with 'zfs promote'." log_onexit cleanup ctr=$TESTPOOL/$TESTCTR ctrfs=$ctr/$TESTFS1 clone=$ctr/$TESTCLONE clone1=$ctr/$TESTCLONE1 snappool=$SNAPPOOL snapfs=$SNAPFS snapctr=$ctr@$TESTSNAP snapctrclone=$clone@$TESTSNAP snapctrclone1=$clone1@$TESTSNAP snapctrfs=$SNAPCTR #preparation for testing log_must zfs snapshot $ctrfs@$TESTSNAP1 log_must zfs clone $ctrfs@$TESTSNAP1 $clone log_must zfs promote $clone log_must zfs snapshot -r $snapctr ! snapexists $snapctrclone && \ log_fail "'snapshot -r' fails to create $snapctrclone for $ctr/$TESTCLONE." log_must zfs clone $snapctrfs $clone1 log_must zfs promote $clone1 #verify the origin value is correct. orig_value=$(get_prop origin $ctrfs) if ! snapexists $snapctrclone1 || [[ "$orig_value" != "$snapctrclone1" ]]; then log_fail "'zfs promote' fails to promote $clone which is cloned from \ $snapctrfs." fi log_pass "'snapshot -r' can work with 'zfs promote' as expected." diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_013_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_013_pos.ksh index 31aedb224515..e02f6eb30042 100755 --- a/tests/zfs-tests/tests/functional/snapshot/snapshot_013_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapshot/snapshot_013_pos.ksh @@ -1,99 +1,96 @@ #! /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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapshot/snapshot.cfg # # DESCRIPTION: # verify that the snapshots created by 'snapshot -r' can be used for # zfs send/recv # # STRATEGY: # 1. create a dataset tree and populate a filesystem # 2. snapshot -r the dataset tree # 3. select one snapshot used for zfs send/recv # 4. verify the data integrity after zfs send/recv # verify_runnable "both" function cleanup { - datasetexists $ctrfs && \ - zfs destroy -r $ctrfs - - snapexists $snappool && \ - log_must zfs destroy -r $snappool + datasetexists $ctrfs && destroy_dataset $ctrfs -r + snapexists $snappool && destroy_dataset $snappool -r [[ -e $TESTDIR ]] && \ log_must rm -rf $TESTDIR/* > /dev/null 2>&1 } log_assert "Verify snapshots from 'snapshot -r' can be used for zfs send/recv" log_onexit cleanup ctr=$TESTPOOL/$TESTCTR ctrfs=$ctr/$TESTFS snappool=$SNAPPOOL snapfs=$SNAPFS snapctr=$ctr@$TESTSNAP snapctrfs=$ctrfs@$TESTSNAP fsdir=/$ctrfs snapdir=$fsdir/.zfs/snapshot/$TESTSNAP [[ -n $TESTDIR ]] && \ log_must rm -rf $TESTDIR/* > /dev/null 2>&1 typeset -i COUNT=10 log_note "Populate the $TESTDIR directory (prior to snapshot)" typeset -i i=0 while (( i < COUNT )); do log_must file_write -o create -f $TESTDIR/file$i \ -b $BLOCKSZ -c $NUM_WRITES -d $i (( i = i + 1 )) done log_must zfs snapshot -r $snappool zfs send $snapfs | zfs receive $ctrfs >/dev/null 2>&1 if ! datasetexists $ctrfs || ! snapexists $snapctrfs; then log_fail "zfs send/receive fails with snapshot $snapfs." fi for dir in $fsdir $snapdir; do FILE_COUNT=`ls -Al $dir | grep -v "total" | wc -l` (( FILE_COUNT != COUNT )) && log_fail "Got $FILE_COUNT expected $COUNT" done log_pass "'zfs send/receive' works as expected with snapshots from 'snapshot -r'" diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_014_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_014_pos.ksh index 3579fbebb4b8..d48d404b6d14 100755 --- a/tests/zfs-tests/tests/functional/snapshot/snapshot_014_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapshot/snapshot_014_pos.ksh @@ -1,78 +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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapshot/snapshot.cfg # # DESCRIPTION: # verify that creating/destroying snapshots do things clean # # STRATEGY: # 1. create a dataset and set a quota with 500m # 2. create file of size 400m on the dataset # 3. take a snapshot and destroy it # 4. then create file to use all spaces in the dataset # 5. verify removing the first file should succeed # verify_runnable "both" function cleanup { [[ -e $TESTDIR1 ]] && \ log_must rm -rf $TESTDIR1/* > /dev/null 2>&1 - snapexists $SNAPCTR && \ - log_must zfs destroy $SNAPCTR + snapexists $SNAPCTR && destroy_dataset $SNAPCTR datasetexists $TESTPOOL/$TESTCTR/$TESTFS1 && \ log_must zfs set quota=none $TESTPOOL/$TESTCTR/$TESTFS1 } log_assert "Verify creating/destroying snapshots do things clean" log_onexit cleanup log_must zfs set quota=$FSQUOTA $TESTPOOL/$TESTCTR/$TESTFS1 log_must mkfile $FILESIZE $TESTDIR1/$TESTFILE log_must zfs snapshot $SNAPCTR log_must zfs destroy $SNAPCTR log_note "Make the quota of filesystem is reached" log_mustnot mkfile $FILESIZE1 $TESTDIR1/$TESTFILE1 log_note "Verify removing the first file should succeed after the snapshot is \ removed" log_must rm $TESTDIR1/$TESTFILE log_pass "Verify creating/destroying snapshots do things clean" diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_015_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_015_pos.ksh index 1091bcb13ea7..5a4d2ccaf62e 100755 --- a/tests/zfs-tests/tests/functional/snapshot/snapshot_015_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapshot/snapshot_015_pos.ksh @@ -1,121 +1,121 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapshot/snapshot.cfg . $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib # # DESCRIPTION: # Verify snapshot can be created or destroy via mkdir or rm # in .zfs/snapshot. # # STRATEGY: # 1. Verify make directories only successfully in .zfs/snapshot. # 2. Verify snapshot can be created and destroy via mkdir and remove # directories in .zfs/snapshot. # 3. Verify rollback to previous snapshot can succeed. # 4. Verify remove directory in snapdir can destroy snapshot. # verify_runnable "both" function cleanup { typeset -i i=0 while ((i < snap_cnt)); do typeset snap=$fs@snap.$i - datasetexists $snap && log_must zfs destroy -f $snap + datasetexists $snap && destroy_dataset $snap -f ((i += 1)) done } zfs 2>&1 | grep "allow" > /dev/null (($? != 0)) && log_unsupported log_assert "Verify snapshot can be created via mkdir in .zfs/snapshot." log_onexit cleanup fs=$TESTPOOL/$TESTFS # Verify all the other directories are readonly. mntpnt=$(get_prop mountpoint $fs) snapdir=$mntpnt/.zfs set -A ro_dirs "$snapdir" "$snapdir/snap" "$snapdir/snapshot" for dir in ${ro_dirs[@]}; do if [[ -d $dir ]]; then log_mustnot rm -rf $dir log_mustnot touch $dir/testfile else log_mustnot mkdir $dir fi done # Verify snapshot can be created via mkdir in .zfs/snapshot typeset -i snap_cnt=5 typeset -i cnt=0 while ((cnt < snap_cnt)); do testfile=$mntpnt/testfile.$cnt log_must mkfile 1M $testfile log_must mkdir $snapdir/snapshot/snap.$cnt if ! datasetexists $fs@snap.$cnt ; then log_fail "ERROR: $fs@snap.$cnt should exists." fi ((cnt += 1)) done # Verify rollback to previous snapshot succeed. ((cnt = RANDOM % snap_cnt)) log_must zfs rollback -r $fs@snap.$cnt typeset -i i=0 while ((i < snap_cnt)); do testfile=$mntpnt/testfile.$i if ((i <= cnt)); then if [[ ! -f $testfile ]]; then log_fail "ERROR: $testfile should exists." fi else if [[ -f $testfile ]]; then log_fail "ERROR: $testfile should not exists." fi fi ((i += 1)) done # Verify remove directory in snapdir can destroy snapshot. log_must rmdir $snapdir/snapshot/snap.$cnt log_mustnot datasetexists $fs@snap.$cnt log_pass "Verify snapshot can be created via mkdir in .zfs/snapshot passed." diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_016_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_016_pos.ksh index b460c2b0c5dc..b66023cc85e6 100755 --- a/tests/zfs-tests/tests/functional/snapshot/snapshot_016_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapshot/snapshot_016_pos.ksh @@ -1,103 +1,96 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapshot/snapshot.cfg # # DESCRIPTION: # Verify renamed snapshots via mv can be destroyed # # STRATEGY: # 1. Create snapshot # 2. Rename the snapshot via mv command # 2. Verify destroying the renamed snapshot via 'zfs destroy' succeeds # verify_runnable "both" function cleanup { - datasetexists $SNAPFS && \ - log_must zfs destroy -Rf $SNAPFS - datasetexists $TESTPOOL/$TESTFS@snap_a && \ - log_must zfs destroy -Rf $TESTPOOL/$TESTFS@snap_a - datasetexists $TESTPOOL/$TESTFS@snap_b && \ - log_must zfs destroy -Rf $TESTPOOL/$TESTFS@snap_b - datasetexists $TESTPOOL/$TESTCLONE@snap_a && \ - log_must zfs destroy -Rf $TESTPOOL/$TESTCLONE@snap_a - - datasetexists $TESTPOOL/$TESTCLONE && \ - log_must zfs destroy $TESTPOOL/$TESTCLONE - datasetexists $TESTPOOL/$TESTFS && \ - log_must zfs destroy $TESTPOOL/$TESTFS + datasetexists $SNAPFS && destroy_dataset $SNAPFS -Rf + datasetexists $TESTPOOL/$TESTFS@snap_a && destroy_dataset $TESTPOOL/$TESTFS@snap_a -Rf + datasetexists $TESTPOOL/$TESTFS@snap_b && destroy_dataset $TESTPOOL/$TESTFS@snap_b -Rf + datasetexists $TESTPOOL/$TESTCLONE@snap_a && destroy_dataset $TESTPOOL/$TESTCLONE@snap_a -Rf + datasetexists $TESTPOOL/$TESTCLONE && destroy_dataset $TESTPOOL/$TESTCLONE + datasetexists $TESTPOOL/$TESTFS && destroy_dataset $TESTPOOL/$TESTFS log_must zfs create $TESTPOOL/$TESTFS log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS } log_assert "Verify renamed snapshots via mv can be destroyed." log_onexit cleanup # scenario 1 log_must zfs snapshot $SNAPFS log_must mv $TESTDIR/$SNAPROOT/$TESTSNAP $TESTDIR/$SNAPROOT/snap_a datasetexists $TESTPOOL/$TESTFS@snap_a || \ log_fail "rename snapshot via mv in .zfs/snapshot fails." log_must zfs destroy $TESTPOOL/$TESTFS@snap_a # scenario 2 log_must zfs snapshot $SNAPFS log_must zfs clone $SNAPFS $TESTPOOL/$TESTCLONE log_must mv $TESTDIR/$SNAPROOT/$TESTSNAP $TESTDIR/$SNAPROOT/snap_b datasetexists $TESTPOOL/$TESTFS@snap_b || \ log_fail "rename snapshot via mv in .zfs/snapshot fails." log_must zfs promote $TESTPOOL/$TESTCLONE # promote back to $TESTPOOL/$TESTFS for scenario 3 log_must zfs promote $TESTPOOL/$TESTFS log_must zfs destroy $TESTPOOL/$TESTCLONE log_must zfs destroy $TESTPOOL/$TESTFS@snap_b # scenario 3 log_must zfs snapshot $SNAPFS log_must zfs clone $SNAPFS $TESTPOOL/$TESTCLONE log_must zfs rename $SNAPFS $TESTPOOL/$TESTFS@snap_a log_must zfs promote $TESTPOOL/$TESTCLONE log_must zfs destroy $TESTPOOL/$TESTFS log_must zfs destroy $TESTPOOL/$TESTCLONE@snap_a log_pass "Verify renamed snapshots via mv can be destroyed." diff --git a/tests/zfs-tests/tests/functional/snapshot/snapshot_017_pos.ksh b/tests/zfs-tests/tests/functional/snapshot/snapshot_017_pos.ksh index a21f8750d697..6e5b8973cf4f 100755 --- a/tests/zfs-tests/tests/functional/snapshot/snapshot_017_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapshot/snapshot_017_pos.ksh @@ -1,202 +1,201 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapshot/snapshot.cfg # # DESCRIPTION: # # Directory structure of snapshots reflects filesystem structure. # # STRATEGY: # # This test makes sure that the directory structure of snapshots is # a proper reflection of the filesystem the snapshot was taken of. # # 1. Create a simple directory structure of files and directories # 2. Take a snapshot of the filesystem # 3. Modify original filesystem # 4. Walk down the snapshot directory structure verifying it # checking with both absolute and relative paths # verify_runnable "both" function cleanup { cd $SAVED_DIR - if datasetexists $TESTPOOL/$TESTFS ; then - log_must zfs destroy -Rf $TESTPOOL/$TESTFS - fi + datasetexists $TESTPOOL/$TESTFS && \ + destroy_dataset $TESTPOOL/$TESTFS -Rf log_must zfs create $TESTPOOL/$TESTFS log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS } function verify_structure { # check absolute paths DIR=$PWD verify_file $DIR/file1 verify_file $DIR/file2 verify_file $DIR/dir1/file3 verify_file $DIR/dir1/file4 verify_file $DIR/dir1/dir2/file5 verify_file $DIR/dir1/dir2/file6 verify_no_file $DIR/file99 # check relative paths verify_file ./file1 verify_file ./file2 verify_file ./dir1/file3 verify_file ./dir1/file4 verify_file ./dir1/dir2/file5 verify_file ./dir1/dir2/file6 cd dir1 verify_file ../file1 verify_file ../file2 verify_file ./file3 verify_file ./file4 verify_no_file ../file99 cd dir2 verify_file ./file5 verify_file ./file6 verify_file ../file3 verify_file ../file4 verify_no_file ../file99 verify_file ../../file1 verify_file ../../file2 verify_no_file ../../file99 } function verify_file { if [ ! -e $1 ] then log_note "Working dir is $PWD" log_fail "File $1 does not exist!" fi } function verify_no_file { if [ -e $1 ] then log_note "Working dir is $PWD" log_fail "File $1 exists when it should not!" fi } function verify_dir { if [ ! -d $1 ] then log_note "Working dir is $PWD" log_fail "Directory $1 does not exist!" fi } log_assert "Directory structure of snapshots reflects filesystem structure." log_onexit cleanup SAVED_DIR=$PWD # # Create a directory structure with the following files # # ./file1 # ./file2 # ./dir1/file3 # ./dir1/file4 # ./dir1/dir2/file5 # ./dir1/dir2/file6 cd $TESTDIR mkfile 10m file1 mkfile 20m file2 mkdir dir1 cd dir1 mkfile 10m file3 mkfile 20m file4 mkdir dir2 cd dir2 mkfile 10m file5 mkfile 20m file6 # Now walk the directory structure verifying it cd $TESTDIR verify_structure # Take snapshots log_must zfs snapshot $TESTPOOL/$TESTFS@snap_a log_must zfs snapshot $TESTPOOL/$TESTFS@snap_b # Change the filesystem structure by renaming files in the original structure # The snapshot file structure should not change cd $TESTDIR log_must mv file2 file99 cd dir1 log_must mv file4 file99 cd dir2 log_must mv file6 file99 # verify the top level snapshot directories verify_dir $TESTDIR/.zfs verify_dir $TESTDIR/.zfs/snapshot verify_dir $TESTDIR/.zfs/snapshot/snap_a verify_dir $TESTDIR/.zfs/snapshot/snap_b cd $TESTDIR/.zfs/snapshot/snap_a verify_structure cd $TESTDIR/.zfs/snapshot/snap_b verify_structure cd $TESTDIR/.zfs verify_dir snapshot cd $TESTDIR/.zfs/snapshot verify_dir snap_a verify_dir snap_b cd snap_a verify_dir ../snap_a verify_dir ../snap_b cd .. verify_dir snap_a verify_dir snap_b log_pass "Directory structure of snapshots reflects filesystem structure." diff --git a/tests/zfs-tests/tests/functional/snapused/snapused_001_pos.ksh b/tests/zfs-tests/tests/functional/snapused/snapused_001_pos.ksh index 302ba40c38a3..c1277f2b4e2f 100755 --- a/tests/zfs-tests/tests/functional/snapused/snapused_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapused/snapused_001_pos.ksh @@ -1,91 +1,91 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapused/snapused.kshlib # # DESCRIPTION: # Verify used is correct. # # STRATEGY: # 1. Create a filesystem. # 2. Set refreservation of the filesystem. # 3. Make file in the filesystem. # 4. Create sub filesystem and make file in it. # 5. Create volume under it. # 6. Snapshot it. # 7. Check used=usedbychildren+usedbydataset+ # usedbyrefreservation+usedbysnapshots. # verify_runnable "both" function cleanup { - log_must zfs destroy -rR $USEDTEST + datasetexists $USEDTEST && destroy_dataset $USEDTEST -rR } log_assert "Verify used is correct." log_onexit cleanup log_must zfs create $USEDTEST check_used $USEDTEST typeset -i i=0 typeset -i r_size=0 mntpnt=$(get_prop mountpoint $USEDTEST) while ((i < 5)); do ((r_size=(i+1)*16)) #usedbyrefreservation log_must zfs set refreservation="$r_size"M $USEDTEST #usedbydataset log_must mkfile 16M $mntpnt/file$i #usedbychildren log_must zfs create $USEDTEST/fs$i log_must mkfile 16M $mntpnt/fs$i/file$i if is_global_zone; then log_must zfs create -V 16M $USEDTEST/vol$i fi #usedbysnapshots log_must zfs snapshot -r $USEDTEST@snap$i check_used $USEDTEST ((i = i + 1)) done log_pass "Verify used is correct." diff --git a/tests/zfs-tests/tests/functional/snapused/snapused_002_pos.ksh b/tests/zfs-tests/tests/functional/snapused/snapused_002_pos.ksh index 96d2df6c6522..a41ca1d70f19 100755 --- a/tests/zfs-tests/tests/functional/snapused/snapused_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapused/snapused_002_pos.ksh @@ -1,82 +1,82 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapused/snapused.kshlib # # DESCRIPTION: # Verify usedbychildren is correct. # # STRATEGY: # 1. Create a filesystem. # 2. Create sub filesystem and make file in it. # 3. Set reservation of the sub filesystem. # 4. Create volume under it. # 5. Snapshot it. # 6. Check usedbychildren is correct. # verify_runnable "both" function cleanup { - log_must zfs destroy -rR $USEDTEST + datasetexists $USEDTEST && destroy_dataset $USEDTEST -rR } log_assert "Verify usedbychildren is correct." log_onexit cleanup log_must zfs create $USEDTEST check_usedbychildren $USEDTEST typeset -i i=0 typeset -i r_size=0 mntpnt=$(get_prop mountpoint $USEDTEST) while ((i < 5)); do ((r_size=(i+1)*16)) log_must zfs create $USEDTEST/fs$i log_must zfs set reservation="$r_size"M $USEDTEST/fs$i log_must mkfile 48M $mntpnt/fs$i/file$i if is_global_zone; then log_must zfs create -V 32M $USEDTEST/vol$i fi log_must zfs snapshot -r $USEDTEST@snap$i check_usedbychildren $USEDTEST ((i = i + 1)) done log_pass "Verify usedbychildren is correct." diff --git a/tests/zfs-tests/tests/functional/snapused/snapused_003_pos.ksh b/tests/zfs-tests/tests/functional/snapused/snapused_003_pos.ksh index d4726ff40cbd..ff54cbaa1aec 100755 --- a/tests/zfs-tests/tests/functional/snapused/snapused_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapused/snapused_003_pos.ksh @@ -1,82 +1,82 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapused/snapused.kshlib # # DESCRIPTION: # Verify usedbydataset is correct. # # STRATEGY: # 1. Create a filesystem. # 2. Make file in the filesystem. # 3. Snapshot it. # 4. Clone it and make file in the cloned filesystem. # 5. Check usedbydataset is correct. # verify_runnable "both" function cleanup { - log_must zfs destroy -rR $USEDTEST + datasetexists $USEDTEST && destroy_dataset $USEDTEST -rR } log_assert "Verify usedbydataset is correct." log_onexit cleanup log_must zfs create $USEDTEST check_usedbydataset $USEDTEST typeset -i i=0 typeset -i r_size=0 mntpnt=$(get_prop mountpoint $USEDTEST) while ((i < 5)); do ((r_size=(i+1)*16)) log_must mkfile 16M $mntpnt/file$i log_must mkfile "$r_size"M $mntpnt/file_var$i log_must zfs snapshot -r $USEDTEST@snap$i log_must zfs clone $USEDTEST@snap$i $USEDTEST/cln$i log_must zfs set is:cloned=yes $USEDTEST/cln$i mntpnt_cln=$(get_prop mountpoint $USEDTEST/cln$i) log_must mkfile 16M $mntpnt_cln/file_cln$i log_must mkfile "$r_size"M $mntpnt_cln/file_cln_var$i check_usedbydataset $USEDTEST ((i = i + 1)) done log_pass "Verify usedbydataset is correct." diff --git a/tests/zfs-tests/tests/functional/snapused/snapused_004_pos.ksh b/tests/zfs-tests/tests/functional/snapused/snapused_004_pos.ksh index 64ca3e2b3508..8fb8b6be5b47 100755 --- a/tests/zfs-tests/tests/functional/snapused/snapused_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapused/snapused_004_pos.ksh @@ -1,95 +1,95 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapused/snapused.kshlib # # DESCRIPTION: # Verify usedbyrefreservation is correct. # # STRATEGY: # 1. Create a filesystem. # 2. Set refreservation of the filesystem. # 3. Make file in the filesystem. # 4. Create sub filesystem and make file in it. # 5. Set refreservation of the sub filesystem. # 6. Create volume under it. # 7. Snapshot it. # 8. Clone it and set refreservation of the cloned filesystem. # 9. Makefile the cloned filesystem. # 10. Check usedbyrefreservation is correct. # verify_runnable "both" function cleanup { - log_must zfs destroy -rR $USEDTEST + datasetexists $USEDTEST && destroy_dataset $USEDTEST -rR } log_assert "Verify usedbyrefreservation is correct." log_onexit cleanup log_must zfs create $USEDTEST check_usedbyrefreservation $USEDTEST typeset -i i=0 typeset -i r_size=0 mntpnt=$(get_prop mountpoint $USEDTEST) while ((i < 5)); do ((r_size=(i+1)*16)) log_must zfs set refreservation="$r_size"M $USEDTEST log_must mkfile 16M $mntpnt/file$i log_must zfs create $USEDTEST/fs$i log_must zfs set refreservation="$r_size"M $USEDTEST/fs$i log_must mkfile 16M $mntpnt/fs$i/file$i if is_global_zone; then log_must zfs create -V 16M $USEDTEST/vol$i fi log_must zfs snapshot -r $USEDTEST@snap$i log_must zfs clone $USEDTEST@snap$i $USEDTEST/cln$i mntpnt_cln=$(get_prop mountpoint $USEDTEST/cln$i) log_must zfs set refreservation="$r_size"M $USEDTEST/cln$i log_must mkfile 16M $mntpnt_cln/file_cln$i check_usedbyrefreservation $USEDTEST ((i = i + 1)) done log_pass "Verify usedbyrefreservation is correct." diff --git a/tests/zfs-tests/tests/functional/snapused/snapused_005_pos.ksh b/tests/zfs-tests/tests/functional/snapused/snapused_005_pos.ksh index ac5224caf6dc..9d21e1d23d87 100755 --- a/tests/zfs-tests/tests/functional/snapused/snapused_005_pos.ksh +++ b/tests/zfs-tests/tests/functional/snapused/snapused_005_pos.ksh @@ -1,73 +1,73 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/snapused/snapused.kshlib # # DESCRIPTION: # Verify usedbysnapshots is correct. # # STRATEGY: # 1. Create a filesystem. # 2. Make file in the filesystem. # 3. Snapshot it. # 4. Check check_usedbysnapshots is correct. # verify_runnable "both" function cleanup { - log_must zfs destroy -rR $USEDTEST + datasetexists $USEDTEST && destroy_dataset $USEDTEST -rR } log_assert "Verify usedbysnapshots is correct." log_onexit cleanup log_must zfs create $USEDTEST check_usedbysnapshots $USEDTEST typeset -i i=0 typeset -i r_size=0 mntpnt=$(get_prop mountpoint $USEDTEST) while ((i < 5)); do ((r_size=(i+1)*16)) log_must mkfile "$r_size"M $mntpnt/file$i log_must zfs snapshot $USEDTEST@snap$i check_usedbysnapshots $USEDTEST ((i = i + 1)) done log_pass "Verify usedbysnapshots is correct." diff --git a/tests/zfs-tests/tests/functional/userquota/groupspace_001_pos.ksh b/tests/zfs-tests/tests/functional/userquota/groupspace_001_pos.ksh index fb7a19057acf..762f561b834f 100755 --- a/tests/zfs-tests/tests/functional/userquota/groupspace_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/userquota/groupspace_001_pos.ksh @@ -1,79 +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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # Check the zfs groupspace with all parameters # # # STRATEGY: # 1. set zfs groupquota to a fs # 2. write some data to the fs with specified user and group # 3. use zfs groupspace with all possible parameters to check the result # function cleanup { - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs log_must cleanup_quota } log_onexit cleanup log_assert "Check the zfs groupspace with all possible parameters" set -A params -- "-n" "-H" "-p" "-o type,name,used,quota" \ "-o name,used,quota" "-o used,quota" "-o used" "-o quota" "-s type" \ "-s name" "-s used" "-s quota" "-S type" "-S name" "-S used" "-S quota" \ "-t posixuser" "-t posixgroup" "-t all" "-i" "-t smbuser" "-t smbgroup" typeset snap_fs=$QFS@snap log_must zfs set groupquota@$QGROUP=500m $QFS mkmount_writable $QFS log_must user_run $QUSER1 mkfile 50m $QFILE sync log_must zfs snapshot $snap_fs for param in "${params[@]}"; do log_must eval "zfs groupspace $param $QFS >/dev/null 2>&1" log_must eval "zfs groupspace $param $snap_fs >/dev/null 2>&1" done log_pass "Check the zfs groupspace with all possible parameters" diff --git a/tests/zfs-tests/tests/functional/userquota/groupspace_002_pos.ksh b/tests/zfs-tests/tests/functional/userquota/groupspace_002_pos.ksh index 20d0f7319df1..27feafa2b6a2 100755 --- a/tests/zfs-tests/tests/functional/userquota/groupspace_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/userquota/groupspace_002_pos.ksh @@ -1,79 +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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # Check the user used and groupspace size in zfs groupspace # # # STRATEGY: # 1. set zfs groupquota to a fs # 2. write some data to the fs with specified user and size # 3. use zfs groupspace to check the used size and quota size # function cleanup { - if datasetexists $snapfs; then - log_must zfs destroy $snapfs - fi + datasetexists $snapfs && destroy_dataset $snapfs log_must cleanup_quota } log_onexit cleanup log_assert "Check the zfs groupspace used and quota" log_must zfs set groupquota@$QGROUP=500m $QFS mkmount_writable $QFS log_must user_run $QUSER1 mkfile 100m $QFILE sync typeset snapfs=$QFS@snap log_must zfs snapshot $snapfs log_must eval "zfs groupspace $QFS >/dev/null 2>&1" log_must eval "zfs groupspace $snapfs >/dev/null 2>&1" for fs in "$QFS" "$snapfs"; do log_note "check the quota size in zfs groupspace $fs" log_must eval "zfs groupspace $fs | grep $QGROUP | grep 500M" log_note "check the user used size in zfs groupspace $fs" log_must eval "zfs groupspace $fs | grep $QGROUP | grep 100M" done log_pass "Check the zfs groupspace used and quota pass as expect" diff --git a/tests/zfs-tests/tests/functional/userquota/groupspace_003_pos.ksh b/tests/zfs-tests/tests/functional/userquota/groupspace_003_pos.ksh index 56b7af031550..37fd389377ec 100755 --- a/tests/zfs-tests/tests/functional/userquota/groupspace_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/userquota/groupspace_003_pos.ksh @@ -1,109 +1,107 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/include/math.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # Check the user used and groupspace object counts in zfs groupspace # # # STRATEGY: # 1. set zfs groupquota to a fs # 2. create objects for different users in the same group # 3. use zfs groupspace to check the object count # function cleanup { - if datasetexists $snapfs; then - log_must zfs destroy $snapfs - fi + datasetexists $snapfs && destroy_dataset $snapfs log_must rm -f ${QFILE}_* log_must cleanup_quota } function group_object_count { typeset fs=$1 typeset group=$2 typeset -i groupspacecnt=$(zfs groupspace -oname,objused $fs | awk /$group/'{print $2}') typeset -i zfsgetcnt=$(zfs get -H -ovalue groupobjused@$group $fs) # 'zfs groupspace' and 'zfs get groupobjused@' should be equal verify_eq "$groupspacecnt" "$zfsgetcnt" "groupobjused@$group" echo $groupspacecnt } log_onexit cleanup log_assert "Check the zfs groupspace object used" mkmount_writable $QFS log_must zfs set xattr=sa $QFS ((user1_cnt = RANDOM % 100 + 1)) ((user2_cnt = RANDOM % 100 + 1)) log_must user_run $QUSER1 mkfiles ${QFILE}_1 $user1_cnt log_must user_run $QUSER2 mkfiles ${QFILE}_2 $user2_cnt ((grp_cnt = user1_cnt + user2_cnt)) sync_pool typeset snapfs=$QFS@snap log_must zfs snapshot $snapfs log_must eval "zfs groupspace $QFS >/dev/null 2>&1" log_must eval "zfs groupspace $snapfs >/dev/null 2>&1" for fs in "$QFS" "$snapfs"; do log_note "check the object count in zfs groupspace $fs" [[ $(group_object_count $fs $QGROUP) -eq $grp_cnt ]] || log_fail "expected $grp_cnt" done log_note "file removal" log_must rm ${QFILE}_* sync_pool [[ $(group_object_count $QFS $QGROUP) -eq 0 ]] || log_fail "expected 0 files for $QGROUP" [[ $(group_object_count $snapfs $QGROUP) -eq $grp_cnt ]] || log_fail "expected $grp_cnt files for $QGROUP" cleanup log_pass "Check the zfs groupspace object used pass as expect" diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_005_neg.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_005_neg.ksh index 5684b05b7e4b..b8e956164f73 100755 --- a/tests/zfs-tests/tests/functional/userquota/userquota_005_neg.ksh +++ b/tests/zfs-tests/tests/functional/userquota/userquota_005_neg.ksh @@ -1,94 +1,92 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # Check the invalid parameter of zfs set user|group quota # # # STRATEGY: # 1. check the invalid zfs set user|group quota to fs # 1. check the valid zfs set user|group quota to snapshots # function cleanup { - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs log_must cleanup_quota } log_onexit cleanup log_assert "Check the invalid parameter of zfs set user|group quota" typeset snap_fs=$QFS@snap log_must zfs snapshot $snap_fs set -A no_users "mms1234" "ss@#" "root-122" for user in "${no_users[@]}"; do log_mustnot id $user log_mustnot zfs set userquota@$user=100m $QFS done log_note "can set all numeric id even if that id does not exist" log_must zfs set userquota@12345678=100m $QFS log_mustnot zfs set userquota@12345678=100m $snap_fs set -A sizes "100mfsd" "m0.12m" "GGM" "-1234-m" "123m-m" for size in "${sizes[@]}"; do log_note "can not set user quota with invalid size parameter" log_mustnot zfs set userquota@root=$size $QFS done log_note "can not set user quota to snapshot $snap_fs" log_mustnot zfs set userquota@root=100m $snap_fs set -A no_groups "aidsf@dfsd@" "123223-dsfds#sdfsd" "mss_#ss" "@@@@" for group in "${no_groups[@]}"; do log_mustnot eval "grep $group /etc/group" log_mustnot zfs set groupquota@$group=100m $QFS done log_note "can not set group quota with invalid size parameter" log_mustnot zfs set groupquota@root=100msfsd $QFS log_note "can not set group quota to snapshot $snap_fs" log_mustnot zfs set groupquota@root=100m $snap_fs log_pass "Check the invalid parameter of zfs set user|group quota pas as expect" diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_006_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_006_pos.ksh index 7848a924bde8..1c2509c83705 100755 --- a/tests/zfs-tests/tests/functional/userquota/userquota_006_pos.ksh +++ b/tests/zfs-tests/tests/functional/userquota/userquota_006_pos.ksh @@ -1,79 +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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # Check the invalid parameter of zfs get user|group quota # # # STRATEGY: # 1. check the invalid zfs get user|group quota to fs # 2. check the valid zfs get user|group quota to snapshots # function cleanup { - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs log_must cleanup_quota } log_onexit cleanup log_assert "Check the invalid parameter of zfs get user|group quota" typeset snap_fs=$QFS@snap log_must zfs snapshot $snap_fs set -A no_users "mms1234" "ss@#" "root-122" "1234" for user in "${no_users[@]}"; do log_mustnot eval "id $user >/dev/null 2>&1" log_must eval "zfs get userquota@$user $QFS >/dev/null 2>&1" log_must eval "zfs get userquota@$user $snap_fs >/dev/null 2>&1" done set -A no_groups "aidsf@dfsd@" "123223-dsfds#sdfsd" "mss_#ss" "1234" for group in "${no_groups[@]}"; do if is_freebsd; then log_mustnot eval "pw groupdel -n $group >/dev/null 2>&1" else log_mustnot eval "groupdel $group >/dev/null 2>&1" fi log_must eval "zfs get groupquota@$group $QFS >/dev/null 2>&1" log_must eval "zfs get groupquota@$group $snap_fs >/dev/null 2>&1" done log_pass "Check the invalid parameter of zfs get user|group quota pass as expect" diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_009_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_009_pos.ksh index 1c0fdde3fa46..b6f2727806c4 100755 --- a/tests/zfs-tests/tests/functional/userquota/userquota_009_pos.ksh +++ b/tests/zfs-tests/tests/functional/userquota/userquota_009_pos.ksh @@ -1,92 +1,90 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # Check user|group quota to snapshot that: # 1) can not set user|group quota to snapshot directly # 2) snapshot can inherit the parent fs's user|groupquota # 3) the user|group quota will not change even the parent fs's quota changed. # # # STRATEGY: # 1. create a snapshot of a fs # 2. set the user|group quota to snapshot and expect fail # 3. set user|group quota to fs and check the snapshot # 4. re-set user|group quota to fs and check the snapshot's value # function cleanup { - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs log_must cleanup_quota } log_onexit cleanup log_assert "Check the snapshot's user|group quota" typeset snap_fs=$QFS@snap log_must zfs set userquota@$QUSER1=$UQUOTA_SIZE $QFS log_must check_quota "userquota@$QUSER1" $QFS "$UQUOTA_SIZE" log_must zfs set groupquota@$QGROUP=$GQUOTA_SIZE $QFS log_must check_quota "groupquota@$QGROUP" $QFS "$GQUOTA_SIZE" log_must zfs snapshot $snap_fs log_note "check the snapshot $snap_fs user|group quota" log_must check_quota "userquota@$QUSER1" $snap_fs "$UQUOTA_SIZE" log_must check_quota "groupquota@$QGROUP" $snap_fs "$GQUOTA_SIZE" log_note "set userquota and groupquota to $snap_fs which will fail" log_mustnot zfs set userquota@$QUSER1=$SNAP_QUOTA $snap_fs log_mustnot zfs set groupquota@$QGROUP=$SNAP_QUOTA $snap_fs log_note "change the parent's userquota and groupquota" log_must zfs set userquota@$QUSER1=$TEST_QUOTA $QFS log_must zfs set groupquota@$QGROUP=$TEST_QUOTA $QFS log_must check_quota "userquota@$QUSER1" $QFS $TEST_QUOTA log_must check_quota "groupquota@$QGROUP" $QFS $TEST_QUOTA log_note "check the snapshot $snap_fs userquota and groupquota" log_must check_quota "userquota@$QUSER1" $snap_fs "$UQUOTA_SIZE" log_must check_quota "groupquota@$QGROUP" $snap_fs "$GQUOTA_SIZE" log_pass "Check the snapshot's user|group quota pass as expect" diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_011_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_011_pos.ksh index 93020ae8ded6..8917b3be2865 100755 --- a/tests/zfs-tests/tests/functional/userquota/userquota_011_pos.ksh +++ b/tests/zfs-tests/tests/functional/userquota/userquota_011_pos.ksh @@ -1,127 +1,125 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # the userquota and groupquota will not change during zfs actions, such as # snapshot,clone,rename,upgrade,send,receive. # # # STRATEGY: # 1. Create a pool, and create fs with preset user,group quota # 2. Check set user|group quota via zfs snapshot|clone|list -o # 3. Check the user|group quota can not change during zfs rename|upgrade|promote # 4. Check the user|group quota can not change during zfs clone # 5. Check the user|group quota can not change during zfs send/receive # function cleanup { for ds in $TESTPOOL/fs $TESTPOOL/fs-rename $TESTPOOL/fs-clone; do - if datasetexists $ds; then - log_must zfs destroy -rRf $ds - fi + datasetexists $ds && destroy_dataset $ds -rRf done } log_onexit cleanup log_assert \ "the userquota and groupquota can't change during zfs actions" cleanup log_must zfs create -o userquota@$QUSER1=$UQUOTA_SIZE \ -o groupquota@$QGROUP=$GQUOTA_SIZE $TESTPOOL/fs log_must zfs snapshot $TESTPOOL/fs@snap log_must eval "zfs list -r -o userquota@$QUSER1,groupquota@$QGROUP \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs@snap "$UQUOTA_SIZE" log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs@snap "$GQUOTA_SIZE" log_note "clone fs gets its parent's userquota/groupquota initially" log_must zfs clone -o userquota@$QUSER1=$UQUOTA_SIZE \ -o groupquota@$QGROUP=$GQUOTA_SIZE \ $TESTPOOL/fs@snap $TESTPOOL/fs-clone log_must eval "zfs list -r -o userquota@$QUSER1,groupquota@$QGROUP \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-clone "$UQUOTA_SIZE" log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-clone "$GQUOTA_SIZE" log_must eval "zfs list -o userquota@$QUSER1,groupquota@$QGROUP \ $TESTPOOL/fs-clone >/dev/null 2>&1" log_note "zfs promote can not change the previously set user|group quota" log_must zfs promote $TESTPOOL/fs-clone log_must eval "zfs list -r -o userquota@$QUSER1,groupquota@$QGROUP \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-clone "$UQUOTA_SIZE" log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-clone "$GQUOTA_SIZE" log_note "zfs send receive can not change the previously set user|group quota" log_must zfs send $TESTPOOL/fs-clone@snap | zfs receive $TESTPOOL/fs-rev log_must eval "zfs list -r -o userquota@$QUSER1,groupquota@$QGROUP \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rev "$UQUOTA_SIZE" log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rev "$GQUOTA_SIZE" log_note "zfs rename can not change the previously set user|group quota" log_must zfs rename $TESTPOOL/fs-rev $TESTPOOL/fs-rename log_must eval "zfs list -r -o userquota@$QUSER1,groupquota@$QGROUP \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rename "$UQUOTA_SIZE" log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rename "$GQUOTA_SIZE" log_note "zfs upgrade can not change the previously set user|group quota" log_must zfs upgrade $TESTPOOL/fs-rename log_must eval "zfs list -r -o userquota@$QUSER1,groupquota@$QGROUP \ $TESTPOOL >/dev/null 2>&1" log_must check_quota "userquota@$QUSER1" $TESTPOOL/fs-rename "$UQUOTA_SIZE" log_must check_quota "groupquota@$QGROUP" $TESTPOOL/fs-rename "$GQUOTA_SIZE" log_pass \ "the userquota and groupquota can't change during zfs actions" diff --git a/tests/zfs-tests/tests/functional/userquota/userquota_012_neg.ksh b/tests/zfs-tests/tests/functional/userquota/userquota_012_neg.ksh index b553f91d40da..12e023134d81 100755 --- a/tests/zfs-tests/tests/functional/userquota/userquota_012_neg.ksh +++ b/tests/zfs-tests/tests/functional/userquota/userquota_012_neg.ksh @@ -1,66 +1,64 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # userquota and groupquota can not be set against snapshot # # # STRATEGY: # 1. Set userquota on snap and check the zfs get # 2. Set groupquota on snap and check the zfs get # function cleanup { cleanup_quota - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs } log_onexit cleanup typeset snap_fs=$QFS@snap log_assert "Check set userquota and groupquota on snapshot" log_note "Check can not set user|group quota on snapshot" log_must zfs snapshot $snap_fs log_mustnot zfs set userquota@$QUSER1=$UQUOTA_SIZE $snap_fs log_mustnot zfs set groupquota@$QGROUP=$GQUOTA_SIZE $snap_fs log_pass "Check set userquota and groupquota on snapshot" diff --git a/tests/zfs-tests/tests/functional/userquota/userspace_001_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userspace_001_pos.ksh index ef05338af41d..9b8919344582 100755 --- a/tests/zfs-tests/tests/functional/userquota/userspace_001_pos.ksh +++ b/tests/zfs-tests/tests/functional/userquota/userspace_001_pos.ksh @@ -1,78 +1,76 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # Check the zfs userspace with all parameters # # # STRATEGY: # 1. set zfs userspace to a fs # 2. write some data to the fs with specified user # 3. use zfs userspace with all possible parameters to check the result # function cleanup { - if datasetexists $snap_fs; then - log_must zfs destroy $snap_fs - fi + datasetexists $snap_fs && destroy_dataset $snap_fs log_must cleanup_quota } log_onexit cleanup log_assert "Check the zfs userspace with all possible parameters" set -A params -- "-n" "-H" "-p" "-o type,name,used,quota" \ "-o name,used,quota" "-o used,quota" "-o used" "-o quota" "-s type" \ "-s name" "-s used" "-s quota" "-S type" "-S name" "-S used" "-S quota" \ "-t posixuser" "-t posixgroup" "-t all" "-i" "-tsmbuser" "-t smbgroup" typeset snap_fs=$QFS@snap log_must zfs set userquota@$QUSER1=100m $QFS mkmount_writable $QFS log_must user_run $QUSER1 mkfile 50m $QFILE sync log_must zfs snapshot $snap_fs for param in "${params[@]}"; do log_must eval "zfs userspace $param $QFS >/dev/null 2>&1" log_must eval "zfs userspace $param $snap_fs >/dev/null 2>&1" done log_pass "zfs userspace with all possible parameters pass as expect" diff --git a/tests/zfs-tests/tests/functional/userquota/userspace_002_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userspace_002_pos.ksh index 8161cc152037..94593ed21ae1 100755 --- a/tests/zfs-tests/tests/functional/userquota/userspace_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/userquota/userspace_002_pos.ksh @@ -1,81 +1,79 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # Check the user used size and quota in zfs userspace # # # STRATEGY: # 1. set zfs userquota to a fs # 2. write some data to the fs with specified user and size # 3. use zfs userspace to check the used size and quota size # function cleanup { - if datasetexists $snapfs; then - log_must zfs destroy $snapfs - fi + datasetexists $snapfs && destroy_dataset $snapfs log_must cleanup_quota } log_onexit cleanup log_assert "Check the zfs userspace used and quota" log_must zfs set userquota@$QUSER1=100m $QFS mkmount_writable $QFS log_must user_run $QUSER1 mkfile 50m $QFILE sync typeset snapfs=$QFS@snap log_must zfs snapshot $snapfs log_must eval "zfs userspace $QFS >/dev/null 2>&1" log_must eval "zfs userspace $snapfs >/dev/null 2>&1" for fs in "$QFS" "$snapfs"; do log_note "check the quota size in zfs userspace $fs" log_must eval "zfs userspace $fs | grep $QUSER1 | grep 100M" log_note "check the user used size in zfs userspace $fs" log_must eval "zfs userspace $fs | grep $QUSER1 | grep 50\\.\*M" done log_pass "Check the zfs userspace used and quota" diff --git a/tests/zfs-tests/tests/functional/userquota/userspace_003_pos.ksh b/tests/zfs-tests/tests/functional/userquota/userspace_003_pos.ksh index 96c3b1930c40..70ef78e7ddbb 100755 --- a/tests/zfs-tests/tests/functional/userquota/userspace_003_pos.ksh +++ b/tests/zfs-tests/tests/functional/userquota/userspace_003_pos.ksh @@ -1,122 +1,120 @@ #!/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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2016 by Jinshan Xiong. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/include/math.shlib . $STF_SUITE/tests/functional/userquota/userquota_common.kshlib # # DESCRIPTION: # Check the user used object accounting in zfs userspace # # # STRATEGY: # 1. create a bunch of files by specific users # 2. use zfs userspace to check the used objects # 3. change the owner of test files and verify object count # 4. delete files and verify object count # function cleanup { - if datasetexists $snapfs; then - log_must zfs destroy $snapfs - fi + datasetexists $snapfs && destroy_dataset $snapfs log_must rm -f ${QFILE}_* log_must cleanup_quota } function user_object_count { typeset fs=$1 typeset user=$2 typeset -i userspacecnt=$(zfs userspace -oname,objused $fs | awk /$user/'{print $2}') typeset -i zfsgetcnt=$(zfs get -H -ovalue userobjused@$user $fs) # 'zfs userspace' and 'zfs get userobjused@' should be equal verify_eq "$userspacecnt" "$zfsgetcnt" "userobjused@$user" echo $userspacecnt } log_onexit cleanup log_assert "Check the zfs userspace object used" mkmount_writable $QFS log_must zfs set xattr=sa $QFS ((user1_cnt = RANDOM % 100 + 1)) ((user2_cnt = RANDOM % 100 + 1)) log_must user_run $QUSER1 mkfiles ${QFILE}_1 $user1_cnt log_must user_run $QUSER2 mkfiles ${QFILE}_2 $user2_cnt sync_pool typeset snapfs=$QFS@snap log_must zfs snapshot $snapfs log_must eval "zfs userspace $QFS >/dev/null 2>&1" log_must eval "zfs userspace $snapfs >/dev/null 2>&1" for fs in "$QFS" "$snapfs"; do log_note "check the user used objects in zfs userspace $fs" [[ $(user_object_count $fs $QUSER1) -eq $user1_cnt ]] || log_fail "expected $user1_cnt" [[ $(user_object_count $fs $QUSER2) -eq $user2_cnt ]] || log_fail "expected $user2_cnt" done log_note "change the owner of files" log_must chown $QUSER2 ${QFILE}_1* sync_pool [[ $(user_object_count $QFS $QUSER1) -eq 0 ]] || log_fail "expected 0 files for $QUSER1" [[ $(user_object_count $snapfs $QUSER1) -eq $user1_cnt ]] || log_fail "expected $user_cnt files for $QUSER1 in snapfs" [[ $(user_object_count $QFS $QUSER2) -eq $((user1_cnt+user2_cnt)) ]] || log_fail "expected $((user1_cnt+user2_cnt)) files for $QUSER2" log_note "file removal" log_must rm ${QFILE}_* sync_pool [[ $(user_object_count $QFS $QUSER2) -eq 0 ]] || log_fail "expected 0 files for $QUSER2" cleanup log_pass "Check the zfs userspace object used" diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_002_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_002_pos.ksh index e5b69239f566..7b8749751b05 100755 --- a/tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/zvol/zvol_cli/zvol_cli_002_pos.ksh @@ -1,62 +1,62 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Creating a volume with a 50 letter name should work. # # STRATEGY: # 1. Using a very long name, create a zvol # 2. Verify volume exists # verify_runnable "global" function cleanup { datasetexists $TESTPOOL/$LONGVOLNAME && \ - zfs destroy $TESTPOOL/$LONGVOLNAME + destroy_dataset $TESTPOOL/$LONGVOLNAME } log_onexit cleanup log_assert "Creating a volume a 50 letter name should work." LONGVOLNAME="volumename50charslong_0123456789012345678901234567" log_must zfs create -V $VOLSIZE $TESTPOOL/$LONGVOLNAME datasetexists $TESTPOOL/$LONGVOLNAME || \ log_fail "Couldn't find long volume name" log_pass "Created a 50-letter zvol volume name" diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_common.shlib b/tests/zfs-tests/tests/functional/zvol/zvol_common.shlib index 342700228764..4f74c9b92613 100644 --- a/tests/zfs-tests/tests/functional/zvol/zvol_common.shlib +++ b/tests/zfs-tests/tests/functional/zvol/zvol_common.shlib @@ -1,134 +1,133 @@ # # 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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/zvol/zvol.cfg # # Create a simple zvol volume # # Where disk_device: is the name of the disk to be used # volume_size: is the size of the volume, e.g. 2G # block_size: is the block size of the volume # function default_zvol_setup # disk_device volume_size block_size { typeset disk=$1 typeset size=$2 typeset blocksize=$3 typeset savedumpdev typeset -i output typeset create_args create_pool $TESTPOOL "$disk" if [ -n "$blocksize" ]; then create_args="-b $blocksize" fi log_must zfs create $create_args -V $size $TESTPOOL/$TESTVOL block_device_wait } # # Destroy the default zvol which was setup using # default_zvol_setup(). # function default_zvol_cleanup { - if datasetexists $TESTPOOL/$TESTVOL ; then - log_must zfs destroy $TESTPOOL/$TESTVOL - fi + datasetexists $TESTPOOL/$TESTVOL && \ + destroy_dataset $TESTPOOL/$TESTVOL destroy_pool $TESTPOOL } function get_dumpdevice { typeset ret=$(dumpadm | grep "Dump device:" | awk '{print $3}') echo $ret } function set_dumpsize { typeset volume=$1 if [[ -z $volume ]] ; then log_note "No volume specified." return 1 fi log_must zfs set volsize=64m $volume output=$(dumpadm -d /dev/zvol/dsk/$volume 2>&1 | \ tail -1 | awk '{print $3}') if [[ -n $output ]]; then (( output = output / 1024 / 1024 )) (( output = output + output / 5 )) log_must zfs set volsize=${output}m $volume fi return 0 } function safe_dumpadm { typeset device=$1 if [[ -z $device || $device == "none" ]] ; then log_note "No dump device volume specified." return 1 fi if [[ $device == "${ZVOL_DEVDIR}/"* ]] ; then typeset volume=${device#${ZVOL_DEVDIR}/} set_dumpsize $volume log_must dumpadm -d $device else log_must swapadd if ! is_swap_inuse $device ; then log_must swap -a $device fi log_must dumpadm -d swap fi } function is_zvol_dumpified { typeset volume=$1 if [[ -z $volume ]] ; then log_note "No volume specified." return 1 fi zdb -dddd $volume 2 | grep "dumpsize" > /dev/null 2>&1 return $? } diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh index 72446ee986fe..2ecb00da92e1 100755 --- a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh +++ b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_002_pos.ksh @@ -1,117 +1,117 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # Copyright 2016 Nexenta Systems, Inc. # . $STF_SUITE/include/libtest.shlib # # DESCRIPTION: # Verify that ZFS volume snapshot could be fscked # # STRATEGY: # 1. Create a ZFS volume # 2. Copy some files and create snapshot # 3. Verify fsck on the snapshot is OK # verify_runnable "global" volsize=$(zfs get -H -o value volsize $TESTPOOL/$TESTVOL) function cleanup { snapexists $TESTPOOL/$TESTVOL@snap && \ - zfs destroy $TESTPOOL/$TESTVOL@snap + destroy_dataset $TESTPOOL/$TESTVOL@snap ismounted $TESTDIR $NEWFS_DEFAULT_FS (( $? == 0 )) && log_must umount $TESTDIR zfs set volsize=$volsize $TESTPOOL/$TESTVOL } log_assert "Verify that ZFS volume snapshot could be fscked" log_onexit cleanup TESTVOL='testvol' BLOCKSZ=$(( 1024 * 1024 )) NUM_WRITES=40 log_must zfs set volsize=128m $TESTPOOL/$TESTVOL log_must new_fs ${ZVOL_RDEVDIR}/$TESTPOOL/$TESTVOL log_must mount ${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL $TESTDIR typeset -i fn=0 typeset -i retval=0 while (( 1 )); do file_write -o create -f $TESTDIR/testfile$$.$fn \ -b $BLOCKSZ -c $NUM_WRITES retval=$? if (( $retval != 0 )); then break fi (( fn = fn + 1 )) done if is_linux || is_freebsd ; then log_must sync else log_must lockfs -f $TESTDIR fi log_must zfs set snapdev=visible $TESTPOOL/$TESTVOL log_must zfs snapshot $TESTPOOL/$TESTVOL@snap block_device_wait fsck -n ${ZVOL_RDEVDIR}/$TESTPOOL/$TESTVOL@snap >/dev/null 2>&1 retval=$? if [ $retval -ne 0 ] ; then if is_linux ; then # Linux's fsck returns a different code for this test depending # on the version: # # e2fsprogs-1.43.3 (Fedora 25 and older): returns 4 # e2fsprogs-1.43.4 (Fedora 26): returns 8 # if [ $retval -ne 4 -a $retval -ne 8 ] ; then log_fail "fsck exited with wrong value $retval" fi else if [ $retval -ne 39 ] ; then log_fail "fsck exited with wrong value $retval" fi fi fi log_pass "Verify that ZFS volume snapshot could be fscked" diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_004_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_004_pos.ksh index 697887368377..e0dce0c2c34a 100755 --- a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_004_pos.ksh @@ -1,117 +1,116 @@ #!/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 2008 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # Copyright 2016 Nexenta Systems, Inc. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/zvol/zvol_common.shlib # # DESCRIPTION: # Verify the ability to take snapshots of zvols used as dump or swap. # # STRATEGY: # 1. Create a ZFS volume # 2. Set the volume as dump or swap # 3. Verify creating a snapshot of the zvol succeeds. # verify_runnable "global" if ! is_physical_device $DISKS; then log_unsupported "This directory cannot be run on raw files." fi volsize=$(zfs get -H -o value volsize $TESTPOOL/$TESTVOL) function cleanup { typeset dumpdev=$(get_dumpdevice) if [[ $dumpdev != $savedumpdev ]] ; then safe_dumpadm $savedumpdev fi swap -l | grep -w $voldev > /dev/null 2>&1 if (( $? == 0 )); then log_must swap -d $voldev fi typeset snap for snap in snap0 snap1 ; do - if datasetexists $TESTPOOL/$TESTVOL@$snap ; then - log_must zfs destroy $TESTPOOL/$TESTVOL@$snap - fi + datasetexists $TESTPOOL/$TESTVOL@$snap && \ + destroy_dataset $TESTPOOL/$TESTVOL@$snap done zfs set volsize=$volsize $TESTPOOL/$TESTVOL } function verify_snapshot { typeset volume=$1 log_must zfs snapshot $volume@snap0 log_must zfs snapshot $volume@snap1 log_must datasetexists $volume@snap0 $volume@snap1 log_must zfs destroy $volume@snap1 log_must zfs snapshot $volume@snap1 log_mustnot zfs rollback -r $volume@snap0 log_must datasetexists $volume@snap0 log_must zfs destroy -r $volume@snap0 } log_assert "Verify the ability to take snapshots of zvols used as dump or swap." log_onexit cleanup voldev=${ZVOL_DEVDIR}/$TESTPOOL/$TESTVOL savedumpdev=$(get_dumpdevice) # create snapshot over dump zvol safe_dumpadm $voldev log_must is_zvol_dumpified $TESTPOOL/$TESTVOL verify_snapshot $TESTPOOL/$TESTVOL safe_dumpadm $savedumpdev log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL # create snapshot over swap zvol log_must swap -a $voldev log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL verify_snapshot $TESTPOOL/$TESTVOL log_must swap -d $voldev log_mustnot is_zvol_dumpified $TESTPOOL/$TESTVOL log_pass "Creating snapshots from dump/swap zvols succeeds." diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_snapdev.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_snapdev.ksh index 8d95bfa39374..1fd87aefdffc 100755 --- a/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_snapdev.ksh +++ b/tests/zfs-tests/tests/functional/zvol/zvol_misc/zvol_misc_snapdev.ksh @@ -1,121 +1,121 @@ #!/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 . All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib . $STF_SUITE/tests/functional/zvol/zvol_common.shlib . $STF_SUITE/tests/functional/zvol/zvol_misc/zvol_misc_common.kshlib # # DESCRIPTION: # Verify that ZFS volume property "snapdev" works as intended. # # STRATEGY: # 1. Verify "snapdev" property does not accept invalid values # 2. Verify "snapdev" adds and removes device nodes when updated # 3. Verify "snapdev" is inherited correctly # verify_runnable "global" function cleanup { - datasetexists $VOLFS && log_must zfs destroy -r $VOLFS - datasetexists $ZVOL && log_must zfs destroy -r $ZVOL + datasetexists $VOLFS && destroy_dataset $VOLFS -r + datasetexists $ZVOL && destroy_dataset $ZVOL -r log_must zfs inherit snapdev $TESTPOOL block_device_wait udev_cleanup } log_assert "Verify that ZFS volume property 'snapdev' works as expected." log_onexit cleanup VOLFS="$TESTPOOL/volfs" ZVOL="$TESTPOOL/vol" SNAP="$ZVOL@snap" SNAPDEV="${ZVOL_DEVDIR}/$SNAP" SUBZVOL="$VOLFS/subvol" SUBSNAP="$SUBZVOL@snap" SUBSNAPDEV="${ZVOL_DEVDIR}/$SUBSNAP" log_must zfs create -o mountpoint=none $VOLFS log_must zfs create -V $VOLSIZE -s $ZVOL log_must zfs create -V $VOLSIZE -s $SUBZVOL # 1. Verify "snapdev" property does not accept invalid values typeset badvals=("off" "on" "1" "nope" "-") for badval in ${badvals[@]} do log_mustnot zfs set snapdev="$badval" $ZVOL done # 2. Verify "snapdev" adds and removes device nodes when updated # 2.1 First create a snapshot then change snapdev property log_must zfs snapshot $SNAP log_must zfs set snapdev=visible $ZVOL blockdev_exists $SNAPDEV log_must zfs set snapdev=hidden $ZVOL blockdev_missing $SNAPDEV log_must zfs destroy $SNAP # 2.2 First set snapdev property then create a snapshot log_must zfs set snapdev=visible $ZVOL log_must zfs snapshot $SNAP blockdev_exists $SNAPDEV log_must zfs destroy $SNAP blockdev_missing $SNAPDEV # 2.3 Verify setting to the same value multiple times does not lead to issues log_must zfs snapshot $SNAP log_must zfs set snapdev=visible $ZVOL blockdev_exists $SNAPDEV log_must zfs set snapdev=visible $ZVOL blockdev_exists $SNAPDEV log_must zfs set snapdev=hidden $ZVOL blockdev_missing $SNAPDEV log_must zfs set snapdev=hidden $ZVOL blockdev_missing $SNAPDEV log_must zfs destroy $SNAP # 3. Verify "snapdev" is inherited correctly # 3.1 Check snapdev=visible case log_must zfs snapshot $SNAP log_must zfs inherit snapdev $ZVOL log_must zfs set snapdev=visible $TESTPOOL verify_inherited 'snapdev' 'visible' $ZVOL $TESTPOOL blockdev_exists $SNAPDEV # 3.2 Check snapdev=hidden case log_must zfs set snapdev=hidden $TESTPOOL verify_inherited 'snapdev' 'hidden' $ZVOL $TESTPOOL blockdev_missing $SNAPDEV # 3.3 Check inheritance on multiple levels log_must zfs snapshot $SUBSNAP log_must zfs inherit snapdev $SUBZVOL log_must zfs set snapdev=hidden $VOLFS log_must zfs set snapdev=visible $TESTPOOL verify_inherited 'snapdev' 'hidden' $SUBZVOL $VOLFS blockdev_missing $SUBSNAPDEV blockdev_exists $SNAPDEV log_pass "ZFS volume property 'snapdev' works as expected" diff --git a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh index cf1e6359bdb6..83bf465b633a 100755 --- a/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh +++ b/tests/zfs-tests/tests/functional/zvol/zvol_swap/zvol_swap_004_pos.ksh @@ -1,76 +1,76 @@ #!/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 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # # Copyright (c) 2013, 2016 by Delphix. All rights reserved. # . $STF_SUITE/include/libtest.shlib . $STF_SUITE/tests/functional/zvol/zvol_common.shlib # # DESCRIPTION: # When a swap zvol is added its volsize does not change. # # STRATEGY: # 1. Determine what 1/4 arc_c_max is. # 2. Create a zvols in a variety of sizes. # 3. Add them as swap, and verify the volsize is not changed. # verify_runnable "global" function cleanup { is_swap_inuse $swapname && log_must swap_cleanup $swapname - datasetexists $vol && log_must zfs destroy $vol + datasetexists $vol && destroy_dataset $vol } log_assert "For an added swap zvol, (2G <= volsize <= 16G)" log_onexit cleanup for vbs in 8192 16384 32768 65536 131072; do for multiplier in 32 16384 131072; do ((volsize = vbs * multiplier)) vol="$TESTPOOL/vol_$volsize" swapname="${ZVOL_DEVDIR}/$vol" # Create a sparse volume to test larger sizes log_must zfs create -s -b $vbs -V $volsize $vol block_device_wait $swapname log_must swap_setup $swapname new_volsize=$(get_prop volsize $vol) [[ $volsize -eq $new_volsize ]] || log_fail "$volsize $new_volsize" log_must swap_cleanup $swapname log_must_busy zfs destroy $vol done done log_pass "For an added swap zvol, (2G <= volsize <= 16G)"