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