Skip to content

Commit

Permalink
ZTS: Standardize use of destroy_dataset in cleanup
Browse files Browse the repository at this point in the history
When cleaning up a test case standardize on using the convention:

    datasetexists $ds && destroy_dataset $ds <flags>

By using 'destroy_dataset' instead of 'log_must zfs destroy' we ensure
that the destroy is retried in the event that a ZFS volume is busy.
This helps ensures ensure tests are fully cleaned up and prevents false
positive test failures on Linux.

Note that all of the tests which used 'zfs destroy' in cleanup have
been updated even if they don't use volumes.  This was done to
clearly establish the expected convention.

Reviewed-by: Rich Ercolani <rincebrain@gmail.com>
Reviewed-by: George Melikov <mail@gmelikov.ru>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes openzfs#12663
  • Loading branch information
behlendorf authored and Ryan Moeller committed Nov 3, 2021
1 parent b7e25aa commit 297ebf9
Show file tree
Hide file tree
Showing 242 changed files with 422 additions and 654 deletions.
11 changes: 3 additions & 8 deletions tests/zfs-tests/tests/functional/bootfs/bootfs_002_neg.ksh
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@
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
Expand Down
2 changes: 1 addition & 1 deletion tests/zfs-tests/tests/functional/casenorm/casenorm.kshlib
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function create_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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fs=$TESTPOOL/$TESTFS/testchild

function cleanup
{
datasetexists $fs && log_must zfs destroy -R $fs
datasetexists $fs && destroy_dataset $fs -R
}

log_onexit cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ limit=50000000

function cleanup
{
datasetexists $rootfs && log_must zfs destroy -R $rootfs
datasetexists $rootfs && destroy_dataset $rootfs -R
}

log_onexit cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ function cleanup
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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ 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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ verify_runnable "both"
function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
log_must zfs destroy -f $TESTPOOL/$TESTFS1
destroy_dataset $TESTPOOL/$TESTFS1 -f
}
log_onexit cleanup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ verify_runnable "both"
function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
log_must zfs destroy -r $TESTPOOL/$TESTFS1
destroy_dataset $TESTPOOL/$TESTFS1 -r
}

log_onexit cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ verify_runnable "both"
function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
log_must zfs destroy -Rf $TESTPOOL/$TESTFS1
destroy_dataset $TESTPOOL/$TESTFS1 -Rf
}

log_onexit cleanup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ verify_runnable "both"
function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
log_must zfs destroy -f $TESTPOOL/$TESTFS1
destroy_dataset $TESTPOOL/$TESTFS1 -f
}
log_onexit cleanup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ verify_runnable "both"
function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
log_must zfs destroy -r $TESTPOOL/$TESTFS1
destroy_dataset $TESTPOOL/$TESTFS1 -r
}
log_onexit cleanup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ verify_runnable "both"
function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
log_must zfs destroy -f $TESTPOOL/$TESTFS1
destroy_dataset $TESTPOOL/$TESTFS1 -f
}
log_onexit cleanup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ verify_runnable "both"
function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
log_must zfs destroy -f $TESTPOOL/$TESTFS1
destroy_dataset $TESTPOOL/$TESTFS1 -f
}
log_onexit cleanup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function verify_pbkdf2iters
function cleanup
{
datasetexists $TESTPOOL/$TESTFS1 && \
log_must zfs destroy -f $TESTPOOL/$TESTFS1
destroy_dataset $TESTPOOL/$TESTFS1 -f
}
log_onexit cleanup

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ function setup_all
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,10 @@ function setup_all
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ 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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ 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
}

Expand Down Expand Up @@ -94,13 +92,13 @@ for val in 1 2 3; do
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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ 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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ function cleanup
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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ function cleanup
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ 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."
Expand Down
Loading

0 comments on commit 297ebf9

Please sign in to comment.