Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/Makefile =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/Makefile (revision 292296) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/Makefile (revision 292297) @@ -1,17 +1,18 @@ # $FreeBSD$ .include TESTSDIR=${TESTSBASE}/sys/cddl/zfs/tests/cli_root/zpool_destroy FILESDIR=${TESTSDIR} ATF_TESTS_KSH93+= zpool_destroy_test FILES+= cleanup.ksh FILES+= zpool_destroy.cfg FILES+= zpool_destroy_001_pos.ksh FILES+= zpool_destroy_002_pos.ksh FILES+= zpool_destroy_003_neg.ksh +FILES+= zpool_destroy_004_pos.ksh .include Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_004_pos.ksh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_004_pos.ksh (nonexistent) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_004_pos.ksh (revision 292297) @@ -0,0 +1,119 @@ +#!/usr/local/bin/ksh93 -p +# +# Copyright 2015 Spectra Logic Corporation. +# + +. $STF_SUITE/include/libtest.kshlib + +################################################################################ +# +# __stc_assertion_start +# +# ID: zpool_destroy_004_pos +# +# DESCRIPTION: +# 'zpool destroy -f ' can forcibly destroy the specified pool, +# even if that pool has running zfs send or receive activity. +# +# STRATEGY: +# 1. Create a storage pool +# 2. For each sleep time in a set: +# 2a. For each destroy type (same pool, sender only, receiver only): +# - Create a dataset with some amount of data +# - Run zfs send | zfs receive in the background. +# - Sleep the amount of time specified for this run. +# - 'zpool destroy -f' the pool. +# - Wait for the send|receive to exit. It must not be killed in +# order to ensure that the destroy takes care of doing so. +# - Verify the pool destroyed successfully +# +# __stc_assertion_end +# +############################################################################### + +verify_runnable "global" + +function cleanup +{ + poolexists $TESTPOOL && destroy_pool $TESTPOOL + poolexists $TESTPOOL1 && destroy_pool $TESTPOOL1 +} + +function create_sender +{ + 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 dd if=/dev/zero of=$TESTDIR/f0 bs=1024k count=$datasz + log_must $ZFS snapshot $TESTPOOL/$TESTFS@snap1 +} + +function create_sender_and_receiver +{ + create_sender + create_pool "$TESTPOOL1" "$DISK1" +} + +function send_recv_destroy +{ + sleeptime=$1 + recv=$2 + to_destroy=$3 + + ( $ZFS send -RP $TESTPOOL/$TESTFS@s0 | $ZFS receive -Fu $recv/d1 ) & + sendrecvpid=$! + + log_must sleep $sleeptime + destroy_start=$(date '+%s') + log_must $ZPOOL destroy -f $to_destroy + destroy_end=$(date '+%s') + dtime=$(expr ${destroy_end} - ${destroy_start}) + log_note "Destroy took ${dtime} seconds." + + log_note "If this wait returns 0, it means send or receive succeeded." + log_mustnot wait $sendrecvpid + wait_end=$(date '+%s') + wtime=$(expr ${wait_end} - ${destroy_end}) + log_note "send|receive took ${wtime} seconds to finish." + + log_mustnot $ZPOOL list $to_destroy +} + +function run_tests +{ + log_note "TEST: send|receive to the same pool" + create_sender + send_recv_destroy $sleeptime $TESTPOOL $TESTPOOL + + log_note "TEST: send|receive to different pools, destroy sender" + create_sender_and_receiver + send_recv_destroy $sleeptime $TESTPOOL1 $TESTPOOL + + log_note "TEST: send|receive to different pools, destroy receiver" + create_sender_and_receiver + send_recv_destroy $sleeptime $TESTPOOL1 $TESTPOOL1 +} + +log_assert "'zpool destroy -f ' can force destroy active pool" +log_onexit cleanup +set_disks + +# Faster tests using 1GB data size +datasz=1000 +log_note "Running fast tests with 1000MB of data" +for sleeptime in 0.1 0.3 0.5 0.75 1 2 3; do + run_tests +done + +# A longer test that simulates a more realistic send|receive that exceeds +# the size of physical memory by 1/3 and gets interrupted a decent amount of +# time after the start of the run. +physmem=$(sysctl -n hw.physmem) +datasz=$(expr ${physmem} / 1048576 \* 4 / 3) +log_note "Running longer test with ${datasz}MB of data" +sleeptime=15 +run_tests + +log_pass "'zpool destroy -f ' successful with active pools." Index: projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_test.sh =================================================================== --- projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_test.sh (revision 292296) +++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cli_root/zpool_destroy/zpool_destroy_test.sh (revision 292297) @@ -1,107 +1,134 @@ # 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 2012 Spectra Logic. All rights reserved. # Use is subject to license terms. # atf_test_case zpool_destroy_001_pos cleanup zpool_destroy_001_pos_head() { atf_set "descr" "'zpool destroy ' can destroy a specified pool." atf_set "require.config" disks_are_physical atf_set "require.progs" zfs zpool } zpool_destroy_001_pos_body() { atf_expect_fail 'BUG26166 cannot create pools on zvols' export TESTCASE_ID=$(echo $(atf_get ident) | cksum -o 2 | cut -f 1 -d " ") . $(atf_get_srcdir)/../../../include/default.cfg . $(atf_get_srcdir)/zpool_destroy.cfg ksh93 $(atf_get_srcdir)/zpool_destroy_001_pos.ksh || atf_fail "Testcase failed" } zpool_destroy_001_pos_cleanup() { export TESTCASE_ID=$(echo $(atf_get ident) | cksum -o 2 | cut -f 1 -d " ") . $(atf_get_srcdir)/../../../include/default.cfg . $(atf_get_srcdir)/zpool_destroy.cfg ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" } atf_test_case zpool_destroy_002_pos cleanup zpool_destroy_002_pos_head() { atf_set "descr" "'zpool destroy -f ' can forcely destroy the specified pool" atf_set "require.progs" zfs zpool } zpool_destroy_002_pos_body() { export TESTCASE_ID=$(echo $(atf_get ident) | cksum -o 2 | cut -f 1 -d " ") . $(atf_get_srcdir)/../../../include/default.cfg . $(atf_get_srcdir)/zpool_destroy.cfg ksh93 $(atf_get_srcdir)/zpool_destroy_002_pos.ksh || atf_fail "Testcase failed" } zpool_destroy_002_pos_cleanup() { export TESTCASE_ID=$(echo $(atf_get ident) | cksum -o 2 | cut -f 1 -d " ") . $(atf_get_srcdir)/../../../include/default.cfg . $(atf_get_srcdir)/zpool_destroy.cfg ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" } atf_test_case zpool_destroy_003_neg cleanup zpool_destroy_003_neg_head() { atf_set "descr" "'zpool destroy' should return an error with badly-formed parameters." atf_set "require.progs" zpool } zpool_destroy_003_neg_body() { export TESTCASE_ID=$(echo $(atf_get ident) | cksum -o 2 | cut -f 1 -d " ") . $(atf_get_srcdir)/../../../include/default.cfg . $(atf_get_srcdir)/zpool_destroy.cfg ksh93 $(atf_get_srcdir)/zpool_destroy_003_neg.ksh || atf_fail "Testcase failed" } zpool_destroy_003_neg_cleanup() { export TESTCASE_ID=$(echo $(atf_get ident) | cksum -o 2 | cut -f 1 -d " ") . $(atf_get_srcdir)/../../../include/default.cfg . $(atf_get_srcdir)/zpool_destroy.cfg ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" } +atf_test_case zpool_destroy_004_pos cleanup +zpool_destroy_004_pos_head() +{ + atf_set "descr" "'zpool destroy -f' should work on active pools." + atf_set "require.progs" zfs zpool + atf_set "require.config" at_least_2_disks + atf_set "timeout" 2000 +} +zpool_destroy_004_pos_body() +{ + export TESTCASE_ID=$(echo $(atf_get ident) | cksum -o 2 | cut -f 1 -d " ") + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_destroy.cfg + + ksh93 $(atf_get_srcdir)/zpool_destroy_004_pos.ksh || atf_fail "Testcase failed" +} +zpool_destroy_004_pos_cleanup() +{ + export TESTCASE_ID=$(echo $(atf_get ident) | cksum -o 2 | cut -f 1 -d " ") + . $(atf_get_srcdir)/../../../include/default.cfg + . $(atf_get_srcdir)/zpool_destroy.cfg + + ksh93 $(atf_get_srcdir)/cleanup.ksh || atf_fail "Cleanup failed" +} + + atf_init_test_cases() { atf_add_test_case zpool_destroy_001_pos atf_add_test_case zpool_destroy_002_pos atf_add_test_case zpool_destroy_003_neg + atf_add_test_case zpool_destroy_004_pos }