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# $FreeBSD$
24
25#
26# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zpool_destroy_002_pos.ksh	1.3	09/06/22 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32
33################################################################################
34#
35# __stc_assertion_start
36#
37# ID: zpool_destroy_002_pos
38#
39# DESCRIPTION:
40#	'zpool destroy -f <pool>' can forcely destroy the specified pool.
41#
42# STRATEGY:
43#	1. Create a storage pool
44#	2. Create some datasets within the pool
45#	3. Change directory to any mountpoint of these datasets,
46#	   Verify 'zpool destroy' without '-f' will fail.
47#	4. 'zpool destroy -f' the pool
48#	5. Verify the pool is destroyed successfully
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2005-07-04)
55#
56# __stc_assertion_end
57#
58###############################################################################
59
60verify_runnable "global"
61
62function cleanup
63{
64	[[ -n $cwd ]] && log_must cd $cwd
65
66	if [[ -d $TESTDIR ]]; then
67		ismounted $TESTDIR
68		((  $? == 0 )) && \
69			log_must $UNMOUNT $TESTDIR
70		log_must $RM -rf $TESTDIR
71	fi
72
73	destroy_pool $TESTPOOL
74}
75
76set -A datasets "$TESTPOOL/$TESTFS" "$TESTPOOL/$TESTCTR/$TESTFS1" \
77	"$TESTPOOL/$TESTCTR" "$TESTPOOL/$TESTVOL" \
78
79log_assert "'zpool destroy -f <pool>' can forcely destroy the specified pool"
80
81log_onexit cleanup
82
83typeset cwd=""
84
85create_pool "$TESTPOOL" "$DISK"
86log_must $ZFS create $TESTPOOL/$TESTFS
87log_must $MKDIR -p $TESTDIR
88log_must $ZFS set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
89log_must $ZFS create $TESTPOOL/$TESTCTR
90log_must $ZFS create $TESTPOOL/$TESTCTR/$TESTFS1
91log_must $ZFS create -V $VOLSIZE $TESTPOOL/$TESTVOL
92
93typeset -i i=0
94while (( $i < ${#datasets[*]} )); do
95	datasetexists "${datasets[i]}" || \
96		log_fail "Create datasets fail."
97	((i = i + 1))
98done
99
100cwd=$PWD
101log_note "'zpool destroy' without '-f' will fail " \
102	"while pool is busy."
103
104for dir in $TESTDIR /$TESTPOOL/$TESTCTR /$TESTPOOL/$TESTCTR/$TESTFS1 ; do
105	log_must cd $dir
106	log_mustnot $ZPOOL destroy $TESTPOOL
107
108	# Need mount here, otherwise some dataset may be unmounted.
109	log_must $ZFS mount -a
110
111	i=0
112	while (( i < ${#datasets[*]} )); do
113		datasetexists "${datasets[i]}" || \
114			log_fail "Dataset ${datasets[i]} removed unexpected."
115		((i = i + 1))
116	done
117done
118
119destroy_pool $TESTPOOL
120log_mustnot poolexists "$TESTPOOL"
121
122log_pass "'zpool destroy -f <pool>' success."
123