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.
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.
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]
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
37 # Verify 'zfs destroy -f' succeeds as root.
40 # 1. Create filesystem in the storage pool
41 # 2. Set mountpoint for the filesystem and make it busy
42 # 3. Verify that 'zfs destroy' fails to destroy the filesystem
43 # 4. Verify 'zfs destroy -f' succeeds to destroy the filesystem.
46 verify_runnable "both"
52 datasetexists $clone && \
53 log_must zfs destroy -f $clone
56 log_must zfs destroy -f $snap
58 for fs in $fs1 $fs2; do
59 datasetexists $fs && \
60 log_must zfs destroy -f $fs
63 for dir in $TESTDIR1 $TESTDIR2; do
69 log_assert "Verify that 'zfs destroy -f' succeeds as root. "
74 # Preparations for testing
78 for dir in $TESTDIR1 $TESTDIR2; do
80 log_must mkdir -p $dir
83 fs1=$TESTPOOL/$TESTFS1
85 fs2=$TESTPOOL/$TESTFS2
86 snap=$TESTPOOL/$TESTFS2@snap
87 clone=$TESTPOOL/$TESTCLONE
91 # Create filesystem and clone in the storage pool, mount them and
92 # make the mountpoint busy
94 for fs in $fs1 $fs2; do
95 log_must zfs create $fs
98 log_must zfs snapshot $snap
99 log_must zfs clone $snap $clone
101 log_must zfs set mountpoint=$mntp1 $fs1
102 log_must zfs set mountpoint=$mntp2 $clone
104 for arg in "$fs1 $mntp1" "$clone $mntp2"; do
105 fs=`echo $arg | awk '{print $1}'`
106 mntp=`echo $arg | awk '{print $2}'`
108 log_note "Verify that 'zfs destroy' fails to" \
109 "destroy filesystem when it is busy."
111 log_mustnot zfs destroy $fs
114 log_mustnot zfs destroy -f $fs
115 datasetnonexists $fs && \
116 log_fail "'zfs destroy -f' destroyed busy filesystem."
118 log_must zfs destroy -f $fs
119 datasetexists $fs && \
120 log_fail "'zfs destroy -f' fail to destroy busy filesystem."
126 log_pass "'zfs destroy -f' succeeds as root."