7290 ZFS test suite needs to control what utilities it can run
[unleashed.git] / usr / src / test / zfs-tests / tests / functional / cli_root / zfs_destroy / zfs_destroy_004_pos.ksh
blob04e666964a0bfde47d6107344c5208982879c8db
1 #!/bin/ksh -p
3 # CDDL HEADER START
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]
20 # CDDL HEADER END
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
36 # DESCRIPTION:
37 # Verify 'zfs destroy -f' succeeds as root.
39 # STRATEGY:
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"
48 function cleanup
50 cd $olddir
52 datasetexists $clone && \
53 log_must zfs destroy -f $clone
55 snapexists $snap && \
56 log_must zfs destroy -f $snap
58 for fs in $fs1 $fs2; do
59 datasetexists $fs && \
60 log_must zfs destroy -f $fs
61 done
63 for dir in $TESTDIR1 $TESTDIR2; do
64 [[ -d $dir ]] && \
65 log_must rm -rf $dir
66 done
69 log_assert "Verify that 'zfs destroy -f' succeeds as root. "
71 log_onexit cleanup
74 # Preparations for testing
76 olddir=$PWD
78 for dir in $TESTDIR1 $TESTDIR2; do
79 [[ ! -d $dir ]] && \
80 log_must mkdir -p $dir
81 done
83 fs1=$TESTPOOL/$TESTFS1
84 mntp1=$TESTDIR1
85 fs2=$TESTPOOL/$TESTFS2
86 snap=$TESTPOOL/$TESTFS2@snap
87 clone=$TESTPOOL/$TESTCLONE
88 mntp2=$TESTDIR2
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
96 done
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."
110 cd $mntp
111 log_mustnot zfs destroy $fs
113 log_must zfs destroy -f $fs
114 datasetexists $fs && \
115 log_fail "'zfs destroy -f' fails to destroy busy filesystem."
117 cd $olddir
118 done
120 log_pass "'zfs destroy -f' succeeds as root."