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	"@(#)snapshot_009_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: snapshot_009_pos
38#
39# DESCRIPTION:
40#	Verify 'snapshot -r' and 'destroy -r' can correctly create and destroy
41#	snapshot tree respectively.
42#
43# STRATEGY:
44# 1. Use the snapshot -r to create snapshot for top level pool
45# 2. Verify the children snapshots are created correctly.
46# 3. Use destroy -r to destroy the top level snapshot
47# 4. Verify that all children snapshots are destroyed too.
48#
49# TESTABILITY: explicit
50#
51# TEST_AUTOMATION_LEVEL: automated
52#
53# CODING_STATUS: COMPLETED (2006-06-20)
54#
55# __stc_assertion_end
56#
57################################################################################
58
59verify_runnable "both"
60
61function cleanup
62{
63	typeset ds
64	typeset snap
65
66	for ds in $ctr/$TESTVOL1 $ctr/$TESTCLONE; do
67		datasetexists $ds && \
68			log_must $ZFS destroy -f $ds
69	done
70
71	for snap in $ctr/$TESTFS1@$TESTSNAP1 \
72		$snappool $snapvol $snapctr $snapctrvol \
73		$snapctrclone $snapctrfs
74	do
75		snapexists $snap && \
76			log_must $ZFS destroy -rf $snap
77	done
78
79}
80
81log_assert "Verify snapshot -r can correctly create a snapshot tree."
82log_onexit cleanup
83
84ctr=$TESTPOOL/$TESTCTR
85ctrfs=$ctr/$TESTFS1
86ctrclone=$ctr/$TESTCLONE
87ctrvol=$ctr/$TESTVOL1
88snappool=$SNAPPOOL
89snapfs=$SNAPFS
90snapctr=$ctr@$TESTSNAP
91snapvol=$SNAPFS1
92snapctrvol=$ctrvol@$TESTSNAP
93snapctrclone=$ctrclone@$TESTSNAP
94snapctrfs=$SNAPCTR
95
96#preparation for testing
97log_must $ZFS snapshot $ctrfs@$TESTSNAP1
98log_must $ZFS clone $ctrfs@$TESTSNAP1 $ctrclone
99if is_global_zone; then
100	log_must $ZFS create -V $VOLSIZE $ctrvol
101else
102	log_must $ZFS create $ctrvol
103fi
104
105log_must $ZFS snapshot -r $snappool
106
107#verify the snapshot -r results
108for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \
109		$snapctrclone $snapctrfs
110do
111	! snapexists $snap && \
112		log_fail "The snapshot $snap is not created via -r option."
113done
114
115log_note "Verify that destroy -r can destroy the snapshot tree."
116
117log_must $ZFS destroy -r $snappool
118for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \
119		$snapctrclone $snapctrfs
120do
121	snapexists $snap && \
122		log_fail "The snapshot $snap is not destroyed correctly."
123done
124
125log_note "Verify that the snapshot with different name should \
126		be not destroyed."
127! snapexists $ctrfs@$TESTSNAP1 && \
128	log_fail "destroy -r incorrectly destroys the snapshot \
129		$ctrfs@$TESTSNAP1."
130
131log_pass  "snapshot|destroy -r with snapshot tree works as expected."
132