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 https://opensource.org/licenses/CDDL-1.0. 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, 2016 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# Populate a file system and take a snapshot. Add some more files to the 38# file system and rollback to the last snapshot. Verify no post snapshot 39# file exist. 40# 41# STRATEGY: 42# 1. Empty a file system 43# 2. Populate the file system 44# 3. Take a snapshot of the file system 45# 4. Add new files to the file system 46# 5. Perform a rollback 47# 6. Verify the snapshot and file system agree 48# 49 50verify_runnable "both" 51 52function cleanup 53{ 54 snapexists $SNAPFS && 55 log_must zfs destroy $SNAPFS 56 57 [ -e $TESTDIR ] && log_must rm -rf $TESTDIR/* 58} 59 60log_assert "Verify that a rollback to a previous snapshot succeeds." 61 62log_onexit cleanup 63 64[ -n $TESTDIR ] && log_must rm -rf $TESTDIR/* 65 66typeset -i COUNT=10 67 68log_note "Populate the $TESTDIR directory (prior to snapshot)" 69typeset -i i=1 70while [[ $i -le $COUNT ]]; do 71 log_must file_write -o create -f $TESTDIR/before_file$i \ 72 -b $BLOCKSZ -c $NUM_WRITES -d $i 73 74 (( i = i + 1 )) 75done 76 77log_must zfs snapshot $SNAPFS 78 79FILE_COUNT=$(ls -A $SNAPDIR | wc -l) 80if [[ $FILE_COUNT -ne $COUNT ]]; then 81 ls -Al $SNAPDIR 82 log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)." 83fi 84 85log_note "Populate the $TESTDIR directory (post snapshot)" 86typeset -i i=1 87while [[ $i -le $COUNT ]]; do 88 log_must file_write -o create -f $TESTDIR/after_file$i \ 89 -b $BLOCKSZ -c $NUM_WRITES -d $i 90 91 (( i = i + 1 )) 92done 93sync_pool $TESTPOOL 94 95# 96# Now rollback to latest snapshot 97# 98log_must zfs rollback $SNAPFS 99 100FILE_COUNT=$(ls -A $TESTDIR/after* 2> /dev/null | wc -l) 101if [[ $FILE_COUNT -ne 0 ]]; then 102 ls -Al $TESTDIR 103 log_fail "$TESTDIR contains $FILE_COUNT after* files(s)." 104fi 105 106FILE_COUNT=$(ls -A $TESTDIR/before* 2> /dev/null | 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