xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_009_pos.ksh (revision e82490700e19f1b8a2cef6102f4726144d281988)
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) 2013, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
34
35#
36# DESCRIPTION:
37#	Verify 'snapshot -r' and 'destroy -r' can correctly create and destroy
38#	snapshot tree respectively.
39#
40# STRATEGY:
41# 1. Use the snapshot -r to create snapshot for top level pool
42# 2. Verify the children snapshots are created correctly.
43# 3. Use destroy -r to destroy the top level snapshot
44# 4. Verify that all children snapshots are destroyed too.
45#
46
47verify_runnable "both"
48
49function cleanup
50{
51	typeset ds
52	typeset snap
53
54	for ds in $ctr/$TESTVOL1 $ctr/$TESTCLONE; do
55		datasetexists $ds && \
56			log_must zfs destroy -f $ds
57	done
58
59	for snap in $ctr/$TESTFS1@$TESTSNAP1 \
60		$snappool $snapvol $snapctr $snapctrvol \
61		$snapctrclone $snapctrfs
62	do
63		snapexists $snap && \
64			log_must zfs destroy -rf $snap
65	done
66
67}
68
69log_assert "Verify snapshot -r can correctly create a snapshot tree."
70log_onexit cleanup
71
72ctr=$TESTPOOL/$TESTCTR
73ctrfs=$ctr/$TESTFS1
74ctrclone=$ctr/$TESTCLONE
75ctrvol=$ctr/$TESTVOL1
76snappool=$SNAPPOOL
77snapfs=$SNAPFS
78snapctr=$ctr@$TESTSNAP
79snapvol=$SNAPFS1
80snapctrvol=$ctrvol@$TESTSNAP
81snapctrclone=$ctrclone@$TESTSNAP
82snapctrfs=$SNAPCTR
83
84#preparation for testing
85log_must zfs snapshot $ctrfs@$TESTSNAP1
86log_must zfs clone $ctrfs@$TESTSNAP1 $ctrclone
87if is_global_zone; then
88	log_must zfs create -V $VOLSIZE $ctrvol
89else
90	log_must zfs create $ctrvol
91fi
92
93log_must zfs snapshot -r $snappool
94
95#verify the snapshot -r results
96for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \
97		$snapctrclone $snapctrfs
98do
99	! snapexists $snap && \
100		log_fail "The snapshot $snap is not created via -r option."
101done
102
103log_note "Verify that destroy -r can destroy the snapshot tree."
104
105log_must zfs destroy -r $snappool
106for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \
107		$snapctrclone $snapctrfs
108do
109	snapexists $snap && \
110		log_fail "The snapshot $snap is not destroyed correctly."
111done
112
113log_note "Verify that the snapshot with different name should \
114		be not destroyed."
115! snapexists $ctrfs@$TESTSNAP1 && \
116	log_fail "destroy -r incorrectly destroys the snapshot \
117		$ctrfs@$TESTSNAP1."
118
119log_pass  "snapshot|destroy -r with snapshot tree works as expected."
120