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# use 'snapshot -r' to create a snapshot tree, add some files to one child 38# filesystem, rollback the child filesystem snapshot, verify that the child 39# filesystem gets back to the status while taking the snapshot. 40# 41# STRATEGY: 42# 1. Add some files to a target child filesystem 43# 2. snapshot -r the parent filesystem 44# 3. Add some other files to the target child filesystem 45# 4. rollback the child filesystem snapshot 46# 5. verify that the child filesystem get back to the status while being 47# snapshot'd 48# 49 50verify_runnable "both" 51 52function cleanup 53{ 54 snapexists $SNAPPOOL && destroy_dataset $SNAPPOOL -r 55 56 [ -e $TESTDIR ] && log_must rm -rf $TESTDIR/* 57} 58 59log_assert "Verify that rollback to a snapshot created by snapshot -r succeeds." 60log_onexit cleanup 61 62[ -n $TESTDIR ] && log_must rm -rf $TESTDIR/* 63 64typeset -i COUNT=10 65 66log_note "Populate the $TESTDIR directory (prior to snapshot)" 67typeset -i i=0 68while (( i < COUNT )); do 69 log_must file_write -o create -f $TESTDIR/before_file$i \ 70 -b $BLOCKSZ -c $NUM_WRITES -d $i 71 72 (( i = i + 1 )) 73done 74 75log_must zfs snapshot -r $SNAPPOOL 76 77FILE_COUNT=$(ls -A $SNAPDIR | wc -l) 78if (( FILE_COUNT != COUNT )); then 79 ls -Al $SNAPDIR 80 log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)." 81fi 82 83log_note "Populate the $TESTDIR directory (post snapshot)" 84typeset -i i=0 85while (( i < COUNT )); do 86 log_must file_write -o create -f $TESTDIR/after_file$i \ 87 -b $BLOCKSZ -c $NUM_WRITES -d $i 88 89 (( i = i + 1 )) 90done 91 92# 93# Now rollback to latest snapshot 94# 95log_must zfs rollback $SNAPFS 96 97FILE_COUNT=$(ls -A $TESTDIR/after* 2> /dev/null | wc -l) 98if (( FILE_COUNT != 0 )); then 99 ls -Al $TESTDIR 100 log_fail "$TESTDIR contains $FILE_COUNT after* files(s)." 101fi 102 103FILE_COUNT=$(ls -A $TESTDIR/before* 2> /dev/null | wc -l) 104if (( FILE_COUNT != $COUNT )); then 105 ls -Al $TESTDIR 106 log_fail "$TESTDIR contains $FILE_COUNT before* files(s)." 107fi 108 109log_pass "Rollback with child snapshot works as expected." 110