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: rollback_002_pos
33#
34# DESCRIPTION:
35# Verify that rollbacks are with respect to the latest snapshot.
36#
37# STRATEGY:
38# 1. Empty a file system
39# 2. Populate the file system
40# 3. Take a snapshot of the file system
41# 4. Add new files to the file system
42# 5. Take a snapshot
43# 6. Remove the original files
44# 7. Perform a rollback
45# 8. Verify the latest snapshot and file system agree
46#
47# TESTABILITY: explicit
48#
49# TEST_AUTOMATION_LEVEL: automated
50#
51# CODING_STATUS: COMPLETED (2005-07-04)
52#
53# __stc_assertion_end
54#
55################################################################################
56
57verify_runnable "both"
58
59function cleanup
60{
61	snapexists $SNAPFS.1
62	[[ $? -eq 0 ]] && \
63		log_must $ZFS destroy $SNAPFS.1
64
65	snapexists $SNAPFS
66	[[ $? -eq 0 ]] && \
67		log_must $ZFS destroy $SNAPFS
68
69	[[ -e $TESTDIR ]] && \
70		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
71}
72
73log_assert "Verify rollback is with respect to latest snapshot."
74
75log_onexit cleanup
76
77[[ -n $TESTDIR ]] && \
78    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
79
80typeset -i COUNT=10
81
82log_note "Populate the $TESTDIR directory (prior to first snapshot)"
83populate_dir $TESTDIR/original_file $COUNT $NUM_WRITES $BLOCKSZ ITER
84
85log_must $ZFS snapshot $SNAPFS
86
87FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
88if [[ $FILE_COUNT -ne $COUNT ]]; then
89        $LS -Al $SNAPDIR
90        log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
91fi
92
93log_note "Populate the $TESTDIR directory (prior to second snapshot)"
94populate_dir $TESTDIR/afterfirst_file $COUNT $NUM_WRITES $BLOCKSZ ITER
95log_must $ZFS snapshot $SNAPFS.1
96
97log_note "Populate the $TESTDIR directory (Post second snapshot)"
98populate_dir $TESTDIR/aftersecond_file $COUNT $NUM_WRITES $BLOCKSZ ITER
99
100[[ -n $TESTDIR ]] && \
101    log_must $RM -rf $TESTDIR/original_file* > /dev/null 2>&1
102
103#
104# Now rollback to latest snapshot
105#
106log_must $ZFS rollback $SNAPFS.1
107
108FILE_COUNT=`$LS -Al $TESTDIR/aftersecond* 2> /dev/null \
109    | $GREP -v "total" | wc -l`
110if [[ $FILE_COUNT -ne 0 ]]; then
111        $LS -Al $TESTDIR
112        log_fail "$TESTDIR contains $FILE_COUNT aftersecond* files(s)."
113fi
114
115FILE_COUNT=`$LS -Al $TESTDIR/original* $TESTDIR/afterfirst*| $GREP -v "total" | wc -l`
116if [[ $FILE_COUNT -ne 20 ]]; then
117        $LS -Al $TESTDIR
118        log_fail "$TESTDIR contains $FILE_COUNT original* files(s)."
119fi
120
121log_pass "The rollback to the latest snapshot succeeded."
122