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