xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_destroy/zfs_destroy_003_pos.ksh (revision d3b5f56344d8bfcdd6cfb82446af0e5e55ad9ebe)
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 [-rR]' succeeds as root.
38#
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.
46#
47
48verify_runnable "both"
49
50function cleanup
51{
52	for obj in $ctr2 $ctr1 $ctr; do
53		datasetexists $obj && \
54			log_must zfs destroy -Rf $obj
55	done
56
57	for mntp in $TESTDIR1 $TESTDIR2; do
58		[[ -d $mntp ]] && \
59			log_must rm -rf $mntp
60	done
61}
62
63log_assert "Verify that 'zfs destroy [-rR]' succeeds as root. "
64
65log_onexit cleanup
66
67#
68# Preparations for testing
69#
70for dir in $TESTDIR1 $TESTDIR2; do
71	[[ ! -d $dir ]] && \
72		log_must mkdir -p $dir
73done
74
75ctr=$TESTPOOL/$TESTCTR
76ctr1=$TESTPOOL/$TESTCTR1
77ctr2=$ctr/$TESTCTR2
78ctr3=$ctr1/$TESTCTR2
79child_fs=$ctr/$TESTFS1
80child_fs1=$ctr1/$TESTFS2
81child_fs_mntp=$TESTDIR1
82child_fs1_mntp=$TESTDIR2
83child_vol=$ctr/$TESTVOL
84child_vol1=$ctr1/$TESTVOL
85child_fs_snap=$child_fs@snap
86child_fs1_snap=$child_fs1@snap
87child_fs_snap_clone=$ctr/$TESTCLONE
88child_fs_snap_clone1=$ctr1/${TESTCLONE}_across_ctr
89child_fs_snap_clone2=$ctr2/$TESTCLONE2
90child_fs1_snap_clone=$ctr1/$TESTCLONE1
91child_fs1_snap_clone1=$ctr/${TESTCLONE1}_across_ctr
92
93#
94# Create two datasets in the storage pool
95#
96log_must zfs create $ctr
97log_must zfs create $ctr1
98
99#
100# Create children datasets fs,vol,snapshot in the datasets, and
101# clones across two datasets
102#
103log_must zfs create $ctr2
104
105for fs in $child_fs $child_fs1; do
106	log_must zfs create $fs
107done
108
109log_must zfs set mountpoint=$child_fs_mntp $child_fs
110log_must zfs set mountpoint=$child_fs1_mntp $child_fs1
111
112for snap in $child_fs_snap $child_fs1_snap; do
113	log_must zfs snapshot $snap
114done
115
116if is_global_zone ; then
117	for vol in $child_vol $child_vol1; do
118		log_must zfs create -V $VOLSIZE $vol
119	done
120fi
121
122for clone in $child_fs_snap_clone $child_fs_snap_clone1; do
123	log_must zfs clone $child_fs_snap $clone
124done
125
126
127for clone in $child_fs1_snap_clone $child_fs1_snap_clone1; do
128	log_must zfs clone $child_fs1_snap $clone
129done
130
131log_note "Verify that 'zfs destroy -r' fails to destroy dataset " \
132	"with clone dependant outside it."
133
134for 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 dependent " \
138			"clone outside the hierarchy."
139done
140
141
142log_note "Verify that 'zfs destroy -R' succeeds to destroy dataset " \
143	"with clone dependant outside it."
144
145log_must zfs destroy -R $ctr1
146datasetexists $ctr1 && \
147	log_fail "'zfs destroy -R' fails to destroy dataset with clone outside it."
148
149log_note "Verify that 'zfs destroy -r' succeeds to destroy dataset " \
150	"without clone dependant outside it."
151
152log_must zfs destroy -r $ctr
153datasetexists $ctr && \
154	log_fail "'zfs destroy -r' fails to destroy dataset with clone outside it."
155
156log_pass "'zfs destroy [-rR] succeeds as root."
157