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#
24# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26. $STF_SUITE/include/libtest.kshlib
27
28################################################################################
29#
30# __stc_assertion_start
31#
32# ID: snapshot_010_pos
33#
34# DESCRIPTION:
35#	Verify 'destroy -r' can correctly destroy a snapshot tree at any point.
36#
37# STRATEGY:
38# 1. Use the snapshot -r to create snapshot for top level pool
39# 2. Select a middle point of the snapshot tree, use destroy -r to destroy all
40#	snapshots beneath the point.
41# 3. Verify the destroy results.
42#
43# TESTABILITY: explicit
44#
45# TEST_AUTOMATION_LEVEL: automated
46#
47# CODING_STATUS: COMPLETED (2006-06-20)
48#
49# __stc_assertion_end
50#
51################################################################################
52
53verify_runnable "both"
54
55function cleanup
56{
57	typeset snap
58
59	datasetexists $ctrvol && \
60		log_must $ZFS destroy -f $ctrvol
61
62	for snap in $ctrfs@$TESTSNAP1 \
63		$snappool $snapvol $snapctr $snapctrvol \
64		$snapctrclone $snapctrfs
65	do
66		snapexists $snap && \
67			log_must $ZFS destroy -rf $snap
68	done
69
70}
71
72log_assert "Verify 'destroy -r' can correctly destroy a snapshot subtree at any point."
73log_onexit cleanup
74
75ctr=$TESTPOOL/$TESTCTR
76ctrfs=$ctr/$TESTFS1
77ctrvol=$ctr/$TESTVOL1
78snappool=$SNAPPOOL
79snapfs=$SNAPFS
80snapctr=$ctr@$TESTSNAP
81snapvol=$SNAPFS1
82snapctrvol=$ctr/$TESTVOL1@$TESTSNAP
83snapctrclone=$ctr/$TESTCLONE@$TESTSNAP
84snapctrfs=$SNAPCTR
85
86#preparation for testing
87log_must $ZFS snapshot $ctrfs@$TESTSNAP1
88if is_global_zone; then
89	log_must $ZFS create -V $VOLSIZE $ctrvol
90else
91	log_must $ZFS create $ctrvol
92fi
93
94log_must $ZFS snapshot -r $snappool
95
96#select the $TESTCTR as destroy point, $TESTCTR is a child of $TESTPOOL
97log_must $ZFS destroy -r $snapctr
98for snap in $snapctr $snapctrvol $snapctrclone $snapctrfs; do
99	snapexists $snap && \
100		log_fail "The snapshot $snap is not destroyed correctly."
101done
102
103for snap in $snappool $snapfs $snapvol $ctrfs@$TESTSNAP1;do
104	! snapexists $snap && \
105		log_fail "The snapshot $snap should be not destroyed."
106done
107
108log_pass  "'destroy -r' destroys snapshot subtree as expected."
109