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_011_pos
33#
34# DESCRIPTION:
35#	use 'snapshot -r' to create a snapshot tree, add some files to one child
36#	filesystem, rollback the child filesystem snapshot, verify that the child
37# 	filesystem gets back to the status while taking the snapshot.
38#
39# STRATEGY:
40#	1. Add some files to a target child filesystem
41#	2. snapshot -r the parent filesystem
42#	3. Add some other files to the target child filesystem
43#	4. rollback the child filesystem snapshot
44#	5. verify that the child filesystem get back to the status while being
45#	   snapshot'd
46#
47# TESTABILITY: explicit
48#
49# TEST_AUTOMATION_LEVEL: automated
50#
51# CODING_STATUS: COMPLETED (2006-06-20)
52#
53# __stc_assertion_end
54#
55################################################################################
56
57verify_runnable "both"
58
59function cleanup
60{
61	snapexists $SNAPPOOL && \
62		log_must $ZFS destroy -r $SNAPPOOL
63
64	[[ -e $TESTDIR ]] && \
65		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
66}
67
68log_assert "Verify that rollback to a snapshot created by snapshot -r succeeds."
69log_onexit cleanup
70
71[[ -n $TESTDIR ]] && \
72    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
73
74typeset -i COUNT=10
75
76log_note "Populate the $TESTDIR directory (prior to snapshot)"
77populate_dir $TESTDIR/before_file $COUNT $NUM_WRITES $BLOCKSZ ITER
78
79log_must $ZFS snapshot -r $SNAPPOOL
80
81FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
82if (( FILE_COUNT != COUNT )); then
83        $LS -Al $SNAPDIR
84        log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
85fi
86
87log_note "Populate the $TESTDIR directory (post snapshot)"
88typeset -i i=0
89populate_dir $TESTDIR/after_file $COUNT $NUM_WRITES $BLOCKSZ ITER
90
91#
92# Now rollback to latest snapshot
93#
94log_must $ZFS rollback $SNAPFS
95
96FILE_COUNT=`$LS -Al $TESTDIR/after* 2> /dev/null | $GREP -v "total" | wc -l`
97if (( FILE_COUNT != 0 )); then
98        $LS -Al $TESTDIR
99        log_fail "$TESTDIR contains $FILE_COUNT after* files(s)."
100fi
101
102FILE_COUNT=`$LS -Al $TESTDIR/before* 2> /dev/null \
103    | $GREP -v "total" | wc -l`
104if (( FILE_COUNT != $COUNT )); then
105	$LS -Al $TESTDIR
106	log_fail "$TESTDIR contains $FILE_COUNT before* files(s)."
107fi
108
109log_pass "Rollback with child snapshot works as expected."
110