d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# CDDL HEADER START
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# The contents of this file are subject to the terms of the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Common Development and Distribution License (the "License").
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# You may not use this file except in compliance with the License.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# or http://www.opensolaris.org/os/licensing.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# See the License for the specific language governing permissions
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# and limitations under the License.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# When distributing Covered Code, include this CDDL HEADER in each
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# If applicable, add the following below this CDDL HEADER, with the
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# fields enclosed by brackets "[]" replaced with your own identifying
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# information: Portions Copyright [yyyy] [name of copyright owner]
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# CDDL HEADER END
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Use is subject to license terms.
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy# Copyright (c) 2016 by Delphix. All rights reserved.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy. $STF_SUITE/tests/functional/cli_root/zfs_rollback/zfs_rollback_common.kshlib
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any snapshots
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# more recent than the one specified.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 1. Create pool, fs & volume.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 2. Separately create three snapshots or clones for fs & volume
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 3. Roll back to the second snapshot and check the results.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 4. Create the third snapshot or clones for fs & volume again.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 5. Roll back to the first snapshot and check the results.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 6. Separately create two snapshots for fs & volume.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# 7. Roll back to the first snapshot and check the results.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedylog_assert "'zfs rollback -r|-rf|-R|-Rf' will recursively destroy any " \
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy "snapshots more recent than the one specified."
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# Create suitable test environment and run 'zfs rollback', then compare with
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# expected value to check the system status.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $2 the number of snapshots or clones.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy# $3 the number of snapshot point which we want to rollback.
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedyfunction test_n_check #opt num_snap_clone num_rollback
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy typeset -i cnt=$2
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy datasetexists $FS && log_must zfs destroy -Rf $FS
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy df -lhF ufs "/dev/zvol/dsk/$VOL" > /dev/null 2>&1
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy (( $? == 0 )) && log_must umount -f $TESTDIR1
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy all_snap="$TESTSNAP $TESTSNAP1 $TESTSNAP2"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy all_clone="$TESTCLONE $TESTCLONE1 $TESTCLONE2"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy [[ $opt == *R* ]] && exist_clone=$TESTCLONE
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy [[ $opt == *R* ]] && exist_clone="$TESTCLONE $TESTCLONE1"
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ $dtst == $VOL ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ $opt == *f* ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy # To write data to the mountpoint directory,
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ $dtst == $VOL ]]; then
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs rollback $opt $dtst@$snap_point
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy /dev/zvol/dsk/$TESTPOOL/$TESTVOL $TESTDIR1
1d32ba663e202c24a5a1f2e5aef83fffb447cb7fJohn Wren Kennedy log_must zfs rollback $opt $dtst@$snap_point
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ " $exist_snap " == *" $snap "* ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy if [[ " $exist_clone " == *" $clone "* ]]; then
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy # Currently, the test case was limited to create and rollback
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy # in three snapshots
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy log_note "Create 3 snapshots, rollback to the 2nd snapshot " \
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy log_note "Create 3 snapshots and rollback to the 1st snapshot " \
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy log_note "Create 2 snapshots and rollback to the 1st snapshot " \
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedylog_pass "'zfs rollback -r|-rf|-R|-Rf' recursively destroy any snapshots more "\
d583b39bfb4e2571d3e41097c5c357ffe353ad45John Wren Kennedy "recent than the one specified passed."