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 'destroy -r' can correctly destroy a snapshot tree at any point. 38# 39# STRATEGY: 40# 1. Use the snapshot -r to create snapshot for top level pool 41# 2. Select a middle point of the snapshot tree, use destroy -r to destroy all 42# snapshots beneath the point. 43# 3. Verify the destroy results. 44# 45 46verify_runnable "both" 47 48function cleanup 49{ 50 typeset snap 51 52 datasetexists $ctrvol && \ 53 log_must $ZFS destroy -f $ctrvol 54 55 for snap in $ctrfs@$TESTSNAP1 \ 56 $snappool $snapvol $snapctr $snapctrvol \ 57 $snapctrclone $snapctrfs 58 do 59 snapexists $snap && \ 60 log_must $ZFS destroy -rf $snap 61 done 62 63} 64 65log_assert "Verify 'destroy -r' can correctly destroy a snapshot subtree at any point." 66log_onexit cleanup 67 68ctr=$TESTPOOL/$TESTCTR 69ctrfs=$ctr/$TESTFS1 70ctrvol=$ctr/$TESTVOL1 71snappool=$SNAPPOOL 72snapfs=$SNAPFS 73snapctr=$ctr@$TESTSNAP 74snapvol=$SNAPFS1 75snapctrvol=$ctr/$TESTVOL1@$TESTSNAP 76snapctrclone=$ctr/$TESTCLONE@$TESTSNAP 77snapctrfs=$SNAPCTR 78 79#preparation for testing 80log_must $ZFS snapshot $ctrfs@$TESTSNAP1 81if is_global_zone; then 82 log_must $ZFS create -V $VOLSIZE $ctrvol 83else 84 log_must $ZFS create $ctrvol 85fi 86 87log_must $ZFS snapshot -r $snappool 88 89#select the $TESTCTR as destroy point, $TESTCTR is a child of $TESTPOOL 90log_must $ZFS destroy -r $snapctr 91for snap in $snapctr $snapctrvol $snapctrclone $snapctrfs; do 92 snapexists $snap && \ 93 log_fail "The snapshot $snap is not destroyed correctly." 94done 95 96for snap in $snappool $snapfs $snapvol $ctrfs@$TESTSNAP1;do 97 ! snapexists $snap && \ 98 log_fail "The snapshot $snap should be not destroyed." 99done 100 101log_pass "'destroy -r' destroys snapshot subtree as expected." 102