1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/include/libtest.kshlib
27
28################################################################################
29#
30# __stc_assertion_start
31#
32# ID: zpool_destroy_002_pos
33#
34# DESCRIPTION:
35#	'zpool destroy -f <pool>' can forcely destroy the specified pool.
36#
37# STRATEGY:
38#	1. Create a storage pool
39#	2. Create some datasets within the pool
40#	3. Change directory to any mountpoint of these datasets,
41#	   Verify 'zpool destroy' without '-f' will fail.
42#	4. 'zpool destroy -f' the pool
43#	5. Verify the pool is destroyed successfully
44#
45# TESTABILITY: explicit
46#
47# TEST_AUTOMATION_LEVEL: automated
48#
49# CODING_STATUS: COMPLETED (2005-07-04)
50#
51# __stc_assertion_end
52#
53###############################################################################
54
55verify_runnable "global"
56
57function cleanup
58{
59	[[ -n $cwd ]] && log_must cd $cwd
60
61	if [[ -d $TESTDIR ]]; then
62		ismounted $TESTDIR
63		((  $? == 0 )) && \
64			log_must $UNMOUNT $TESTDIR
65		log_must $RM -rf $TESTDIR
66	fi
67
68	destroy_pool $TESTPOOL
69}
70
71set -A datasets "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR/$TESTFS1" \
72	"$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" \
73
74log_assert "'zpool destroy -f <pool>' can forcely destroy the specified pool"
75
76log_onexit cleanup
77
78typeset cwd=""
79
80create_pool "$TESTPOOL" "$DISK"
81log_must $ZFS create $TESTPOOL/$TESTFS
82log_must $MKDIR -p $TESTDIR
83log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
84log_must $ZFS create $TESTPOOL/$TESTCTR
85log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTFS1
86log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
87
88typeset -i i=0
89while (( $i < ${#datasets[*]} )); do
90	datasetexists "${datasets[i]}" || \
91		log_fail "Create datasets fail."
92	((i = i + 1))
93done
94
95cwd=$PWD
96log_note "'zpool destroy' without '-f' will fail " \
97	"while pool is busy."
98
99for dir in $TESTDIR /$TESTPOOL/$TESTCTR /$TESTPOOL/$TESTCTR/$TESTFS1 ; do
100	log_must cd $dir
101	log_mustnot $ZPOOL destroy $TESTPOOL
102
103	# Need mount here, otherwise some dataset may be unmounted.
104	log_must $ZFS mount -a
105
106	i=0
107	while (( i < ${#datasets[*]} )); do
108		datasetexists "${datasets[i]}" || \
109			log_fail "Dataset ${datasets[i]} removed unexpected."
110		((i = i + 1))
111	done
112done
113
114destroy_pool $TESTPOOL
115log_mustnot poolexists "$TESTPOOL"
116
117log_pass "'zpool destroy -f <pool>' success."
118