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 # 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 
  50 verify_runnable "both"
  51 
  52 function cleanup
  53 {
  54         snapexists $SNAPFS
  55         [[ $? -eq 0 ]] && \
  56                 log_must $ZFS destroy $SNAPFS
  57 
  58         [[ -e $TESTDIR ]] && \
  59                 log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
  60 }
  61 
  62 log_assert "Verify that a rollback to a previous snapshot succeeds."
  63 
  64 log_onexit cleanup
  65 
  66 [[ -n $TESTDIR ]] && \
  67     log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
  68 
  69 typeset -i COUNT=10
  70 
  71 log_note "Populate the $TESTDIR directory (prior to snapshot)"
  72 typeset -i i=1
  73 while [[ $i -le $COUNT ]]; do
  74         log_must $FILE_WRITE -o create -f $TESTDIR/before_file$i \
  75            -b $BLOCKSZ -c $NUM_WRITES -d $i
  76 
  77         (( i = i + 1 ))
  78 done
  79 
  80 log_must $ZFS snapshot $SNAPFS
  81 
  82 FILE_COUNT=`$LS -Al $SNAPDIR | $GREP -v "total" | wc -l`
  83 if [[ $FILE_COUNT -ne $COUNT ]]; then
  84         $LS -Al $SNAPDIR
  85         log_fail "AFTER: $SNAPFS contains $FILE_COUNT files(s)."
  86 fi
  87 
  88 log_note "Populate the $TESTDIR directory (post snapshot)"
  89 typeset -i i=1
  90 while [[ $i -le $COUNT ]]; do
  91         log_must $FILE_WRITE -o create -f $TESTDIR/after_file$i \
  92            -b $BLOCKSZ -c $NUM_WRITES -d $i
  93 
  94         (( i = i + 1 ))
  95 done
  96 
  97 #
  98 # Now rollback to latest snapshot
  99 #
 100 log_must $ZFS rollback $SNAPFS
 101 
 102 FILE_COUNT=`$LS -Al $TESTDIR/after* 2> /dev/null | $GREP -v "total" | wc -l`
 103 if [[ $FILE_COUNT -ne 0 ]]; then
 104         $LS -Al $TESTDIR
 105         log_fail "$TESTDIR contains $FILE_COUNT after* files(s)."
 106 fi
 107 
 108 FILE_COUNT=`$LS -Al $TESTDIR/before* 2> /dev/null \
 109     | $GREP -v "total" | wc -l`
 110 if [[ $FILE_COUNT -ne $COUNT ]]; then
 111         $LS -Al $TESTDIR
 112         log_fail "$TESTDIR contains $FILE_COUNT before* files(s)."
 113 fi
 114 
 115 log_pass "The rollback operation succeeded."