1#! /bin/ksh -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 28# 29# Copyright (c) 2013 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/snapshot/snapshot.cfg 34 35# 36# DESCRIPTION: 37# Verify that rollbacks are with respect to the latest snapshot. 38# 39# STRATEGY: 40# 1. Empty a file system 41# 2. Populate the file system 42# 3. Take a snapshot of the file system 43# 4. Add new files to the file system 44# 5. Take a snapshot 45# 6. Remove the original files 46# 7. Perform a rollback 47# 8. Verify the latest snapshot and file system agree 48# 49 50verify_runnable "both" 51 52function cleanup 53{ 54 snapexists $SNAPFS.1 55 [[ $? -eq 0 ]] && \ 56 log_must $ZFS destroy $SNAPFS.1 57 58 snapexists $SNAPFS 59 [[ $? -eq 0 ]] && \ 60 log_must $ZFS destroy $SNAPFS 61 62 [[ -e $TESTDIR ]] && \ 63 log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 64} 65 66log_assert "Verify rollback is with respect to latest snapshot." 67 68log_onexit cleanup 69 70[[ -n $TESTDIR ]] && \ 71 log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 72 73typeset -i COUNT=10 74 75log_note "Populate the $TESTDIR directory (prior to first snapshot)" 76typeset -i i=1 77while [[ $i -le $COUNT ]]; do 78 log_must $FILE_WRITE -o create -f $TESTDIR/original_file$i \ 79 -b $BLOCKSZ -c $NUM_WRITES -d $i 80 81 (( i = i + 1 )) 82done 83 84log_must $ZFS snapshot $SNAPFS 85 86FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l` 87if [[ $FILE_COUNT -ne $COUNT ]]; then 88 $LS -Al $SNAPDIR 89 log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)." 90fi 91 92log_note "Populate the $TESTDIR directory (prior to second snapshot)" 93typeset -i i=1 94while [[ $i -le $COUNT ]]; do 95 log_must $FILE_WRITE -o create -f $TESTDIR/afterfirst_file$i \ 96 -b $BLOCKSZ -c $NUM_WRITES -d $i 97 98 (( i = i + 1 )) 99done 100 101log_must $ZFS snapshot $SNAPFS.1 102 103log_note "Populate the $TESTDIR directory (Post second snapshot)" 104typeset -i i=1 105while [[ $i -le $COUNT ]]; do 106 log_must $FILE_WRITE -o create -f $TESTDIR/aftersecond_file$i \ 107 -b $BLOCKSZ -c $NUM_WRITES -d $i 108 109 (( i = i + 1 )) 110done 111 112[[ -n $TESTDIR ]] && \ 113 log_must $RM -rf $TESTDIR/original_file* > /dev/null 2>&1 114 115# 116# Now rollback to latest snapshot 117# 118log_must $ZFS rollback $SNAPFS.1 119 120FILE_COUNT=`$LS -Al $TESTDIR/aftersecond* 2> /dev/null \ 121 | $GREP -v "total" | wc -l` 122if [[ $FILE_COUNT -ne 0 ]]; then 123 $LS -Al $TESTDIR 124 log_fail "$TESTDIR contains $FILE_COUNT aftersecond* files(s)." 125fi 126 127FILE_COUNT=`$LS -Al $TESTDIR/original* $TESTDIR/afterfirst*| $GREP -v "total" | wc -l` 128if [[ $FILE_COUNT -ne 20 ]]; then 129 $LS -Al $TESTDIR 130 log_fail "$TESTDIR contains $FILE_COUNT original* files(s)." 131fi 132 133log_pass "The rollback to the latest snapshot succeeded." 134