1#!/usr/local/bin/ksh93 -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# $FreeBSD$
24
25#
26# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_destroy_003_pos.ksh	1.2	07/01/09 SMI"
30#
31. $STF_SUITE/include/libtest.kshlib
32
33################################################################################
34#
35# __stc_assertion__start
36#
37# ID: zfs_destroy_003_pos
38#
39# DESCRIPTION:
40#	Verify 'zfs destroy [-rR]' succeeds as root.
41#
42# STRATEGY:
43#	1. Create two datasets in the storage pool
44#	2. Create fs,vol,ctr,snapshot and clones of snapshot in the two datasets
45#	3. Create clone in the second dataset for the snapshot in the first dataset
46#	4. Verify 'zfs destroy -r' fails to destroy dataset with clone outside it
47#	5. Verify 'zfs destroy -R' succeeds to destroy dataset with clone outside it
48#	6. Verify 'zfs destroy -r' succeeds to destroy dataset without clone outside it.
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2005-08-02)
55#
56# __stc_assertion_end
57#
58###############################################################################
59
60verify_runnable "both"
61
62function cleanup
63{
64	for obj in $ctr2 $ctr1 $ctr; do
65		datasetexists $obj && \
66			log_must $ZFS destroy -Rf $obj
67	done
68
69	for mntp in $TESTDIR1 $TESTDIR2; do
70		[[ -d $mntp ]] && \
71			log_must $RM -rf $mntp
72	done
73}
74
75log_assert "Verify that 'zfs destroy [-rR]' succeeds as root. "
76
77log_onexit cleanup
78
79#
80# Preparations for testing
81#
82for dir in $TESTDIR1 $TESTDIR2; do
83	[[ ! -d $dir ]] && \
84		log_must $MKDIR -p $dir
85done
86
87ctr=$TESTPOOL/$TESTCTR
88ctr1=$TESTPOOL/$TESTCTR1
89ctr2=$ctr/$TESTCTR2
90ctr3=$ctr1/$TESTCTR2
91child_fs=$ctr/$TESTFS1
92child_fs1=$ctr1/$TESTFS2
93child_fs_mntp=$TESTDIR1
94child_fs1_mntp=$TESTDIR2
95child_vol=$ctr/$TESTVOL
96child_vol1=$ctr1/$TESTVOL
97child_fs_snap=$child_fs@snap
98child_fs1_snap=$child_fs1@snap
99child_fs_snap_clone=$ctr/$TESTCLONE
100child_fs_snap_clone1=$ctr1/${TESTCLONE}_across_ctr
101child_fs_snap_clone2=$ctr2/$TESTCLONE2
102child_fs1_snap_clone=$ctr1/$TESTCLONE1
103child_fs1_snap_clone1=$ctr/${TESTCLONE1}_across_ctr
104
105#
106# Create two datasets in the storage pool
107#
108log_must $ZFS create $ctr
109log_must $ZFS create $ctr1
110
111#
112# Create children datasets fs,vol,snapshot in the datasets, and
113# clones across two datasets
114#
115log_must $ZFS create $ctr2
116
117for fs in $child_fs $child_fs1; do
118	log_must $ZFS create $fs
119done
120
121log_must $ZFS set mountpoint=$child_fs_mntp $child_fs
122log_must $ZFS set mountpoint=$child_fs1_mntp $child_fs1
123
124for snap in $child_fs_snap $child_fs1_snap; do
125	log_must $ZFS snapshot $snap
126done
127
128if is_global_zone ; then
129	for vol in $child_vol $child_vol1; do
130		log_must $ZFS create -V $VOLSIZE $vol
131	done
132fi
133
134for clone in $child_fs_snap_clone $child_fs_snap_clone1; do
135	log_must $ZFS clone $child_fs_snap $clone
136done
137
138
139for clone in $child_fs1_snap_clone $child_fs1_snap_clone1; do
140	log_must $ZFS clone $child_fs1_snap $clone
141done
142
143log_note "Verify that 'zfs destroy -r' fails to destroy dataset " \
144	"with clone dependent outside it."
145
146for obj in $child_fs $child_fs1 $ctr $ctr1; do
147	log_mustnot $ZFS destroy -r $obj
148	datasetexists $obj || \
149		log_fail "'zfs destroy -r' fails to keep clone " \
150			"dependent outside the hirearchy."
151done
152
153
154log_note "Verify that 'zfs destroy -R' succeeds to destroy dataset " \
155	"with clone dependent outside it."
156
157log_must $ZFS destroy -R $ctr1
158datasetexists $ctr1 && \
159	log_fail "'zfs destroy -R' fails to destroy dataset with clone outside it."
160
161log_note "Verify that 'zfs destroy -r' succeeds to destroy dataset " \
162	"without clone dependent outside it."
163
164log_must $ZFS destroy -r $ctr
165datasetexists $ctr && \
166	log_fail "'zfs destroy -r' fails to destroy dataset with clone outside it."
167
168log_pass "'zfs destroy [-rR] succeeds as root."
169