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 2008 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28. $STF_SUITE/include/libtest.shlib 29. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib 30 31# 32# DESCRIPTION: 33# 'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any snapshots 34# more recent than the one specified. 35# 36# STRATEGY: 37# 1. Create pool, fs & volume. 38# 2. Separately create three snapshots or clones for fs & volume 39# 3. Roll back to the second snapshot and check the results. 40# 4. Create the third snapshot or clones for fs & volume again. 41# 5. Roll back to the first snapshot and check the results. 42# 6. Separately create two snapshots for fs & volume. 43# 7. Roll back to the first snapshot and check the results. 44# 45 46verify_runnable "both" 47 48log_assert "'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any " \ 49 "snapshots more recent than the one specified." 50log_onexit cleanup_env 51 52# 53# Create suitable test environment and run 'zfs rollback', then compare with 54# expected value to check the system status. 55# 56# $1 option. 57# $2 the number of snapshots or clones. 58# $3 the number of snapshot point which we want to rollback. 59# 60function test_n_check #opt num_snap_clone num_rollback 61{ 62 typeset opt=$1 63 typeset -i cnt=$2 64 typeset -i pointcnt=$3 65 typeset dtst 66 67 (( cnt > 3 || pointcnt > cnt )) && \ 68 log_fail "Unsupported testing condition." 69 70 # Clean up the test environment 71 datasetexists $FS && log_must $ZFS destroy -Rf $FS 72 if datasetexists $VOL; then 73 $DF -lhF ufs "/dev/zvol/dsk/$VOL" > /dev/null 2>&1 74 (( $? == 0 )) && log_must $UMOUNT -f $TESTDIR1 75 76 log_must $ZFS destroy -Rf $VOL 77 fi 78 79 # Create specified test environment 80 case $opt in 81 *r*) setup_snap_env $cnt ;; 82 *R*) setup_clone_env $cnt ;; 83 esac 84 85 all_snap="$TESTSNAP $TESTSNAP1 $TESTSNAP2" 86 all_clone="$TESTCLONE $TESTCLONE1 $TESTCLONE2" 87 typeset snap_point 88 typeset exist_snap 89 typeset exist_clone 90 case $pointcnt in 91 1) snap_point=$TESTSNAP 92 exist_snap=$TESTSNAP 93 [[ $opt == *R* ]] && exist_clone=$TESTCLONE 94 ;; 95 2) snap_point=$TESTSNAP1 96 exist_snap="$TESTSNAP $TESTSNAP1" 97 [[ $opt == *R* ]] && exist_clone="$TESTCLONE $TESTCLONE1" 98 ;; 99 esac 100 101 typeset snap 102 for dtst in $FS $VOL; do 103 # Volume is not available in Local Zone. 104 if [[ $dtst == $VOL ]]; then 105 if ! is_global_zone; then 106 break 107 fi 108 fi 109 if [[ $opt == *f* ]]; then 110 # To write data to the mountpoint directory, 111 write_mountpoint_dir $dtst 112 opt=${opt%f} 113 fi 114 115 if [[ $dtst == $VOL ]]; then 116 log_must $UMOUNT -f $TESTDIR1 117 log_must $ZFS rollback $opt $dtst@$snap_point 118 log_must $MOUNT \ 119 /dev/zvol/dsk/$TESTPOOL/$TESTVOL $TESTDIR1 120 else 121 log_must $ZFS rollback $opt $dtst@$snap_point 122 fi 123 124 for snap in $all_snap; do 125 if [[ " $exist_snap " == *" $snap "* ]]; then 126 log_must datasetexists $dtst@$snap 127 else 128 log_must datasetnonexists $dtst@$snap 129 fi 130 done 131 for clone in $all_clone; do 132 if [[ " $exist_clone " == *" $clone "* ]]; then 133 log_must datasetexists $dtst$clone 134 else 135 log_must datasetnonexists $dtst$clone 136 fi 137 done 138 139 check_files $dtst@$snap_point 140 done 141} 142 143typeset opt 144for opt in "-r" "-rf" "-R" "-Rf"; do 145 # 146 # Currently, the test case was limited to create and rollback 147 # in three snapshots 148 # 149 log_note "Create 3 snapshots, rollback to the 2nd snapshot " \ 150 "using $opt." 151 test_n_check "$opt" 3 2 152 153 log_note "Create 3 snapshots and rollback to the 1st snapshot " \ 154 "using $opt." 155 test_n_check "$opt" 3 1 156 157 log_note "Create 2 snapshots and rollback to the 1st snapshot " \ 158 "using $opt." 159 test_n_check "$opt" 2 1 160done 161 162log_pass "'zfs rollback -r|-rf|-R|-Rf' recursively destroy any snapshots more "\ 163 "recent than the one specified passed." 164