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 2009 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
34 .
$STF_SUITE/tests
/functional
/cli_root
/zfs_destroy
/zfs_destroy_common.kshlib
38 # Separately verify 'zfs destroy -f|-r|-rf|-R|-rR <dataset>' will fail in
39 # different conditions.
42 # 1. Create pool, fs & vol.
43 # 2. Create snapshot for fs & vol.
44 # 3. Invoke 'zfs destroy ''|-f <dataset>', it should fail.
45 # 4. Create clone for fs & vol.
46 # 5. Invoke 'zfs destroy -r|-rf <dataset>', it should fail.
47 # 6. Write file to filesystem or enter snapshot mountpoint.
48 # 7. Invoke 'zfs destroy -R|-rR <dataset>', it should fail.
51 verify_runnable
"both"
53 log_assert
"Separately verify 'zfs destroy -f|-r|-rf|-R|-rR <dataset>' will " \
54 "fail in different conditions."
55 log_onexit cleanup_testenv
58 # Run 'zfs destroy [-rRf] <dataset>', make sure it fail.
60 # $1 the collection of options
61 # $2 the collection of datasets
63 function negative_test
68 for dtst
in $datasets; do
69 if ! is_global_zone
; then
70 if [[ $dtst == $VOL ||
$dtst == $VOLSNAP || \
73 log_note
"UNSUPPORTED: " \
74 "Volume is unavailable in LZ."
78 for opt
in $options; do
79 log_mustnot zfs destroy
$opt $dtst
85 # Create snapshots for filesystem and volume,
86 # and verify 'zfs destroy' fails without '-r' or '-R'.
89 negative_test
"-f" "$CTR $FS $VOL"
92 # Create clones for filesystem and volume,
93 # and verify 'zfs destroy' fails without '-R'.
96 negative_test
"-r -rf" "$CTR $FS $VOL"
99 # Get $FS mountpoint and make it busy, and verify 'zfs destroy $CTR' fails
100 # without '-f'. Then verify the remaining datasets are correct. See below for
101 # an explanation of what 'correct' means for this test.
103 mntpt
=$
(get_prop mountpoint
$FS)
104 pidlist
=$
(mkbusy
$mntpt/$TESTFILE0)
105 log_note
"mkbusy $mntpt/$TESTFILE0 (pidlist: $pidlist)"
106 [[ -z $pidlist ]] && log_fail
"Failure from mkbusy"
107 negative_test
"-R -rR" $CTR
110 # Checking the outcome of the test above is tricky, because the order in
111 # which datasets are destroyed is not deterministic. Both $FS and $VOL are
112 # busy, and the remaining datasets will be different depending on whether we
113 # tried (and failed) to delete $FS or $VOL first.
115 # The following datasets will exist independent of the order
116 check_dataset datasetexists
$CTR $FS $VOL
118 if datasetexists
$VOLSNAP && datasetnonexists
$FSSNAP; then
119 # The recursive destroy failed on $FS
120 check_dataset datasetnonexists
$FSSNAP $FSCLONE
121 check_dataset datasetexists
$VOLSNAP $VOLCLONE
122 elif datasetexists
$FSSNAP && datasetnonexists
$VOLSNAP; then
123 # The recursive destroy failed on $VOL
124 check_dataset datasetnonexists
$VOLSNAP $VOLCLONE
125 check_dataset datasetexists
$FSSNAP $FSCLONE
127 log_must zfs list
-rtall
128 log_fail
"Unexpected datasets remaining"
132 # Create the clones for test environment, and verify 'zfs destroy $FS' fails
133 # without '-f'. Then verify the FS snap and clone are the only datasets
137 negative_test
"-R -rR" $FS
138 check_dataset datasetexists
$CTR $FS $VOL $VOLSNAP $VOLCLONE
139 check_dataset datasetnonexists
$FSSNAP $FSCLONE
141 log_must
kill $pidlist
142 log_mustnot pgrep
-fl mkbusy
146 # Create the clones for test environment and make the volume busy.
147 # Then verify 'zfs destroy $CTR' fails without '-f'.
149 # Then verify the expected datasets exist (see below).
151 if is_global_zone
; then
153 pidlist
=$
(mkbusy
$TESTDIR1/$TESTFILE0)
154 log_note
"mkbusy $TESTDIR1/$TESTFILE0 (pidlist: $pidlist)"
155 [[ -z $pidlist ]] && log_fail
"Failure from mkbusy"
156 negative_test
"-R -rR" $CTR
157 check_dataset datasetexists
$CTR $VOL
158 check_dataset datasetnonexists
$VOLSNAP $VOLCLONE
160 # Here again, the non-determinism of destroy order is a factor. $FS,
161 # $FSSNAP and $FSCLONE will still exist here iff we attempted to destroy
162 # $VOL (and failed) first. So check that either all of the datasets are
163 # present, or they're all gone.
164 if datasetexists
$FS; then
165 check_dataset datasetexists
$FS $FSSNAP $FSCLONE
167 check_dataset datasetnonexists
$FS $FSSNAP $FSCLONE
172 # Create the clones for test environment and make the volume busy.
173 # Then verify 'zfs destroy $VOL' fails without '-f'.
175 # Then verify the snapshot and clone are destroyed, but nothing else is.
177 if is_global_zone
; then
179 negative_test
"-R -rR" $VOL
180 check_dataset datasetexists
$CTR $VOL $FS $FSSNAP $FSCLONE
181 check_dataset datasetnonexists
$VOLSNAP $VOLCLONE
184 log_must
kill $pidlist
185 log_mustnot pgrep
-fl mkbusy
189 # Create the clones for test environment and make the snapshot busy.
191 # For Linux verify 'zfs destroy $snap' fails due to the busy mount point. Then
192 # verify the snapshot remains and the clone was destroyed, but nothing else is.
194 # Under illumos verify 'zfs destroy $snap' succeeds without '-f'. Then verify
195 # the snapshot and clone are destroyed, but nothing else is.
198 mntpt
=$
(snapshot_mountpoint
$FSSNAP)
199 pidlist
=$
(mkbusy
$mntpt)
200 log_note
"mkbusy $mntpt (pidlist: $pidlist)"
201 [[ -z $pidlist ]] && log_fail
"Failure from mkbusy"
203 for option
in -R -rR ; do
207 log_mustnot zfs destroy
$option $FSSNAP
208 check_dataset datasetexists
$CTR $FS $VOL $FSSNAP
209 check_dataset datasetnonexists
$FSCLONE
211 log_must zfs destroy
$option $FSSNAP
212 check_dataset datasetexists
$CTR $FS $VOL
213 check_dataset datasetnonexists
$FSSNAP $FSCLONE
217 log_must
kill $pidlist
218 log_mustnot pgrep
-fl mkbusy
221 log_pass
"zfs destroy -f|-r|-rf|-R|-rR <dataset>' failed in different " \