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 2007 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: zfs_destroy_004_pos
33#
34# DESCRIPTION:
35#	Verify 'zfs destroy -f' succeeds as root.
36#
37# STRATEGY:
38#	1. Create filesystem in the storage pool
39#	2. Set mountpoint for the filesystem and make it busy
40#	3. Verify that 'zfs destroy' fails to destroy the filesystem
41#	4. Verify 'zfs destroy -f' succeeds to destroy the filesystem.
42#
43# TESTABILITY: explicit
44#
45# TEST_AUTOMATION_LEVEL: automated
46#
47# CODING_STATUS: COMPLETED (2005-08-02)
48#
49# __stc_assertion_end
50#
51###############################################################################
52
53verify_runnable "both"
54
55function cleanup
56{
57	cd $olddir
58
59	datasetexists $clone && \
60		log_must $ZFS destroy -f $clone
61
62	snapexists $snap && \
63		log_must $ZFS destroy -f $snap
64
65	for fs in $fs1 $fs2; do
66		datasetexists $fs && \
67			log_must $ZFS destroy -f $fs
68	done
69
70	for dir in $TESTDIR1 $TESTDIR2; do
71		[[ -d $dir ]] && \
72			log_must $RM -rf $dir
73	done
74}
75
76log_assert "Verify that 'zfs destroy -f' succeeds as root. "
77
78log_onexit cleanup
79
80#
81# Preparations for testing
82#
83olddir=$PWD
84
85for dir in $TESTDIR1 $TESTDIR2; do
86	[[ ! -d $dir ]] && \
87		log_must $MKDIR -p $dir
88done
89
90fs1=$TESTPOOL/$TESTFS1
91mntp1=$TESTDIR1
92fs2=$TESTPOOL/$TESTFS2
93snap=$TESTPOOL/$TESTFS2@snap
94clone=$TESTPOOL/$TESTCLONE
95mntp2=$TESTDIR2
96
97#
98# Create filesystem and clone in the storage pool,  mount them and
99# make the mountpoint busy
100#
101for fs in $fs1 $fs2; do
102	log_must $ZFS create $fs
103done
104
105log_must $ZFS snapshot $snap
106log_must $ZFS clone $snap $clone
107
108log_must $ZFS set mountpoint=$mntp1 $fs1
109log_must $ZFS set mountpoint=$mntp2 $clone
110
111for arg in "$fs1 $mntp1" "$clone $mntp2"; do
112	fs=`$ECHO $arg | $AWK '{print $1}'`
113	mntp=`$ECHO $arg | $AWK '{print $2}'`
114
115	log_note "Verify that 'zfs destroy' fails to" \
116			"destroy filesystem when it is busy."
117	cd $mntp
118	log_mustnot $ZFS destroy $fs
119
120	log_must $ZFS destroy -f $fs
121	datasetexists $fs && \
122		log_fail "'zfs destroy -f' fails to destroy busy filesystem."
123
124	cd $olddir
125done
126
127log_pass "'zfs destroy -f' succeeds as root."
128