xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_destroy/zpool_destroy_002_pos.ksh (revision b6805bf78d2bbbeeaea8909a05623587b42d58b3)
1#!/bin/ksh -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#
27
28#
29# Copyright (c) 2012 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/cli_root/zpool_destroy/zpool_destroy.cfg
34
35#
36# DESCRIPTION:
37#	'zpool destroy -f <pool>' can forcely destroy the specified pool.
38#
39# STRATEGY:
40#	1. Create a storage pool
41#	2. Create some datasets within the pool
42#	3. Change directory to any mountpoint of these datasets,
43#	   Verify 'zpool destroy' without '-f' will fail.
44#	4. 'zpool destroy -f' the pool
45#	5. Verify the pool is destroyed successfully
46#
47
48verify_runnable "global"
49
50function cleanup
51{
52	[[ -n $cwd ]] && log_must cd $cwd
53
54	if [[ -d $TESTDIR ]]; then
55		ismounted $TESTDIR
56		((  $? == 0 )) && \
57			log_must $UNMOUNT $TESTDIR
58		log_must $RM -rf $TESTDIR
59	fi
60
61	typeset -i i=0
62	while (( $i < ${#datasets[*]} )); do
63		datasetexists ${datasets[i]} && \
64			log_must $ZFS destroy ${datasets[i]}
65		(( i = i + 1 ))
66	done
67
68	poolexists $TESTPOOL && 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