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 
  50 verify_runnable "both"
  51 
  52 function 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 
  66 log_assert "Verify rollback is with respect to latest snapshot."
  67 
  68 log_onexit cleanup
  69 
  70 [[ -n $TESTDIR ]] && \
  71     log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
  72 
  73 typeset -i COUNT=10
  74 
  75 log_note "Populate the $TESTDIR directory (prior to first snapshot)"
  76 typeset -i i=1
  77 while [[ $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 ))
  82 done
  83 
  84 log_must $ZFS snapshot $SNAPFS
  85 
  86 FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
  87 if [[ $FILE_COUNT -ne $COUNT ]]; then
  88         $LS -Al $SNAPDIR
  89         log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
  90 fi
  91 
  92 log_note "Populate the $TESTDIR directory (prior to second snapshot)"
  93 typeset -i i=1
  94 while [[ $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 ))
  99 done
 100 
 101 log_must $ZFS snapshot $SNAPFS.1
 102 
 103 log_note "Populate the $TESTDIR directory (Post second snapshot)"
 104 typeset -i i=1
 105 while [[ $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 ))
 110 done
 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 #
 118 log_must $ZFS rollback $SNAPFS.1
 119 
 120 FILE_COUNT=`$LS -Al $TESTDIR/aftersecond* 2> /dev/null \
 121     | $GREP -v "total" | wc -l`
 122 if [[ $FILE_COUNT -ne 0 ]]; then
 123         $LS -Al $TESTDIR
 124         log_fail "$TESTDIR contains $FILE_COUNT aftersecond* files(s)."
 125 fi
 126 
 127 FILE_COUNT=`$LS -Al $TESTDIR/original* $TESTDIR/afterfirst*| $GREP -v "total" | wc -l`
 128 if [[ $FILE_COUNT -ne 20 ]]; then
 129         $LS -Al $TESTDIR
 130         log_fail "$TESTDIR contains $FILE_COUNT original* files(s)."
 131 fi
 132 
 133 log_pass "The rollback to the latest snapshot succeeded."