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, 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 && \ 55 log_must zfs destroy -r $SNAPPOOL 56 57 [[ -e $TESTDIR ]] && \ 58 log_must rm -rf $TESTDIR/* > /dev/null 2>&1 59} 60 61log_assert "Verify that rollback to a snapshot created by snapshot -r succeeds." 62log_onexit cleanup 63 64[[ -n $TESTDIR ]] && \ 65 log_must rm -rf $TESTDIR/* > /dev/null 2>&1 66 67typeset -i COUNT=10 68 69log_note "Populate the $TESTDIR directory (prior to snapshot)" 70typeset -i i=0 71while (( i < COUNT )); do 72 log_must file_write -o create -f $TESTDIR/before_file$i \ 73 -b $BLOCKSZ -c $NUM_WRITES -d $i 74 75 (( i = i + 1 )) 76done 77 78log_must zfs snapshot -r $SNAPPOOL 79 80FILE_COUNT=`ls -Al $SNAPDIR | grep -v "total" | wc -l` 81if (( FILE_COUNT != COUNT )); then 82 ls -Al $SNAPDIR 83 log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)." 84fi 85 86log_note "Populate the $TESTDIR directory (post snapshot)" 87typeset -i i=0 88while (( i < COUNT )); do 89 log_must file_write -o create -f $TESTDIR/after_file$i \ 90 -b $BLOCKSZ -c $NUM_WRITES -d $i 91 92 (( i = i + 1 )) 93done 94 95# 96# Now rollback to latest snapshot 97# 98log_must zfs rollback $SNAPFS 99 100FILE_COUNT=`ls -Al $TESTDIR/after* 2> /dev/null | grep -v "total" | wc -l` 101if (( FILE_COUNT != 0 )); then 102 ls -Al $TESTDIR 103 log_fail "$TESTDIR contains $FILE_COUNT after* files(s)." 104fi 105 106FILE_COUNT=`ls -Al $TESTDIR/before* 2> /dev/null \ 107 | grep -v "total" | wc -l` 108if (( FILE_COUNT != $COUNT )); then 109 ls -Al $TESTDIR 110 log_fail "$TESTDIR contains $FILE_COUNT before* files(s)." 111fi 112 113log_pass "Rollback with child snapshot works as expected." 114