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_003_pos.ksh
blob5ffe51ebef969032f9e1c33d6d36d6cb89b9c519
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 [-rR]' succeeds as root.
39 # STRATEGY:
40 # 1. Create two datasets in the storage pool
41 # 2. Create fs,vol,ctr,snapshot and clones of snapshot in the two datasets
42 # 3. Create clone in the second dataset for the snapshot in the first dataset
43 # 4. Verify 'zfs destroy -r' fails to destroy dataset with clone outside it
44 # 5. Verify 'zfs destroy -R' succeeds to destroy dataset with clone outside it
45 # 6. Verify 'zfs destroy -r' succeeds to destroy dataset without clone outside it.
48 verify_runnable "both"
50 function cleanup
52 for obj in $ctr2 $ctr1 $ctr; do
53 datasetexists $obj && \
54 log_must zfs destroy -Rf $obj
55 done
57 for mntp in $TESTDIR1 $TESTDIR2; do
58 [[ -d $mntp ]] && \
59 log_must rm -rf $mntp
60 done
63 log_assert "Verify that 'zfs destroy [-rR]' succeeds as root. "
65 log_onexit cleanup
68 # Preparations for testing
70 for dir in $TESTDIR1 $TESTDIR2; do
71 [[ ! -d $dir ]] && \
72 log_must mkdir -p $dir
73 done
75 ctr=$TESTPOOL/$TESTCTR
76 ctr1=$TESTPOOL/$TESTCTR1
77 ctr2=$ctr/$TESTCTR2
78 ctr3=$ctr1/$TESTCTR2
79 child_fs=$ctr/$TESTFS1
80 child_fs1=$ctr1/$TESTFS2
81 child_fs_mntp=$TESTDIR1
82 child_fs1_mntp=$TESTDIR2
83 child_vol=$ctr/$TESTVOL
84 child_vol1=$ctr1/$TESTVOL
85 child_fs_snap=$child_fs@snap
86 child_fs1_snap=$child_fs1@snap
87 child_fs_snap_clone=$ctr/$TESTCLONE
88 child_fs_snap_clone1=$ctr1/${TESTCLONE}_across_ctr
89 child_fs_snap_clone2=$ctr2/$TESTCLONE2
90 child_fs1_snap_clone=$ctr1/$TESTCLONE1
91 child_fs1_snap_clone1=$ctr/${TESTCLONE1}_across_ctr
94 # Create two datasets in the storage pool
96 log_must zfs create $ctr
97 log_must zfs create $ctr1
100 # Create children datasets fs,vol,snapshot in the datasets, and
101 # clones across two datasets
103 log_must zfs create $ctr2
105 for fs in $child_fs $child_fs1; do
106 log_must zfs create $fs
107 done
109 log_must zfs set mountpoint=$child_fs_mntp $child_fs
110 log_must zfs set mountpoint=$child_fs1_mntp $child_fs1
112 for snap in $child_fs_snap $child_fs1_snap; do
113 log_must zfs snapshot $snap
114 done
116 if is_global_zone ; then
117 for vol in $child_vol $child_vol1; do
118 log_must zfs create -V $VOLSIZE $vol
119 done
122 for clone in $child_fs_snap_clone $child_fs_snap_clone1; do
123 log_must zfs clone $child_fs_snap $clone
124 done
127 for clone in $child_fs1_snap_clone $child_fs1_snap_clone1; do
128 log_must zfs clone $child_fs1_snap $clone
129 done
131 log_note "Verify that 'zfs destroy -r' fails to destroy dataset " \
132 "with clone dependant outside it."
134 for obj in $child_fs $child_fs1 $ctr $ctr1; do
135 log_mustnot zfs destroy -r $obj
136 datasetexists $obj || \
137 log_fail "'zfs destroy -r' fails to keep clone " \
138 "dependant outside the hirearchy."
139 done
142 log_note "Verify that 'zfs destroy -R' succeeds to destroy dataset " \
143 "with clone dependant outside it."
145 log_must zfs destroy -R $ctr1
146 datasetexists $ctr1 && \
147 log_fail "'zfs destroy -R' fails to destroy dataset with clone outside it."
149 log_note "Verify that 'zfs destroy -r' succeeds to destroy dataset " \
150 "without clone dependant outside it."
152 log_must zfs destroy -r $ctr
153 datasetexists $ctr && \
154 log_fail "'zfs destroy -r' fails to destroy dataset with clone outside it."
156 log_pass "'zfs destroy [-rR] succeeds as root."