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