xref: /freebsd/tests/sys/cddl/zfs/tests/snapshot/rollback_001_pos.ksh (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
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#
27# ident	"@(#)rollback_001_pos.ksh	1.2	07/01/09 SMI"
28#
29. $STF_SUITE/include/libtest.kshlib
30
31################################################################################
32#
33# __stc_assertion_start
34#
35# ID: rollback_001_pos
36#
37# DESCRIPTION:
38# Populate a file system and take a snapshot. Add some more files to the
39# file system and rollback to the last snapshot. Verify no post snapshot
40# file exist.
41#
42# STRATEGY:
43# 1. Empty a file system
44# 2. Populate the file system
45# 3. Take a snapshot of the file system
46# 4. Add new files to the file system
47# 5. Perform a rollback
48# 6. Verify the snapshot and file system agree
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2005-07-04)
55#
56# __stc_assertion_end
57#
58################################################################################
59
60verify_runnable "both"
61
62function cleanup
63{
64	snapexists $SNAPFS
65	[[ $? -eq 0 ]] && \
66		log_must $ZFS destroy $SNAPFS
67
68	[[ -e $TESTDIR ]] && \
69		log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
70}
71
72log_assert "Verify that a rollback to a previous snapshot succeeds."
73
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
83log_must $ZFS snapshot $SNAPFS
84
85FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
86if [[ $FILE_COUNT -ne $COUNT ]]; then
87        $LS -Al $SNAPDIR
88        log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
89fi
90
91log_note "Populate the $TESTDIR directory (post snapshot)"
92populate_dir $TESTDIR/after_file $COUNT $NUM_WRITES $BLOCKSZ ITER
93
94#
95# Now rollback to latest snapshot
96#
97log_must $ZFS rollback $SNAPFS
98
99FILE_COUNT=`$LS -Al $TESTDIR/after* 2> /dev/null | $GREP -v "total" | wc -l`
100if [[ $FILE_COUNT -ne 0 ]]; then
101        $LS -Al $TESTDIR
102        log_fail "$TESTDIR contains $FILE_COUNT after* files(s)."
103fi
104
105FILE_COUNT=`$LS -Al $TESTDIR/before* 2> /dev/null \
106    | $GREP -v "total" | wc -l`
107if [[ $FILE_COUNT -ne $COUNT ]]; then
108	$LS -Al $TESTDIR
109	log_fail "$TESTDIR contains $FILE_COUNT before* files(s)."
110fi
111
112log_pass "The rollback operation succeeded."
113