]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_004_pos.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_destroy / zfs_destroy_004_pos.ksh
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 2007 Sun Microsystems, Inc.  All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 #
29 # Copyright (c) 2012, 2016 by Delphix. All rights reserved.
30 #
31
32 . $STF_SUITE/include/libtest.shlib
33 . $STF_SUITE/tests/functional/cli_root/zfs_destroy/zfs_destroy.cfg
34
35 #
36 # DESCRIPTION:
37 #       Verify 'zfs destroy -f' succeeds as root.
38 #
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.
44 #
45
46 verify_runnable "both"
47
48 function cleanup
49 {
50         cd $olddir
51
52         datasetexists $clone && \
53                 log_must zfs destroy -f $clone
54
55         snapexists $snap && \
56                 log_must zfs destroy -f $snap
57
58         for fs in $fs1 $fs2; do
59                 datasetexists $fs && \
60                         log_must zfs destroy -f $fs
61         done
62
63         for dir in $TESTDIR1 $TESTDIR2; do
64                 [[ -d $dir ]] && \
65                         log_must rm -rf $dir
66         done
67 }
68
69 log_assert "Verify that 'zfs destroy -f' succeeds as root. "
70
71 log_onexit cleanup
72
73 #
74 # Preparations for testing
75 #
76 olddir=$PWD
77
78 for dir in $TESTDIR1 $TESTDIR2; do
79         [[ ! -d $dir ]] && \
80                 log_must mkdir -p $dir
81 done
82
83 fs1=$TESTPOOL/$TESTFS1
84 mntp1=$TESTDIR1
85 fs2=$TESTPOOL/$TESTFS2
86 snap=$TESTPOOL/$TESTFS2@snap
87 clone=$TESTPOOL/$TESTCLONE
88 mntp2=$TESTDIR2
89
90 #
91 # Create filesystem and clone in the storage pool,  mount them and
92 # make the mountpoint busy
93 #
94 for fs in $fs1 $fs2; do
95         log_must zfs create $fs
96 done
97
98 log_must zfs snapshot $snap
99 log_must zfs clone $snap $clone
100
101 log_must zfs set mountpoint=$mntp1 $fs1
102 log_must zfs set mountpoint=$mntp2 $clone
103
104 for arg in "$fs1 $mntp1" "$clone $mntp2"; do
105         fs=`echo $arg | awk '{print $1}'`
106         mntp=`echo $arg | awk '{print $2}'`
107
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
112
113         if is_linux; then
114                 log_mustnot zfs destroy -f $fs
115                 datasetnonexists $fs && \
116                     log_fail "'zfs destroy -f' destroyed busy filesystem."
117         else
118                 log_must zfs destroy -f $fs
119                 datasetexists $fs && \
120                     log_fail "'zfs destroy -f' fail to destroy busy filesystem."
121         fi
122
123         cd $olddir
124 done
125
126 log_pass "'zfs destroy -f' succeeds as root."