1#! /usr/local/bin/ksh93 -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. $STF_SUITE/include/libtest.kshlib 27 28################################################################################ 29# 30# __stc_assertion_start 31# 32# ID: snapshot_009_pos 33# 34# DESCRIPTION: 35# Verify 'snapshot -r' and 'destroy -r' can correctly create and destroy 36# snapshot tree respectively. 37# 38# STRATEGY: 39# 1. Use the snapshot -r to create snapshot for top level pool 40# 2. Verify the children snapshots are created correctly. 41# 3. Use destroy -r to destroy the top level snapshot 42# 4. Verify that all children snapshots are destroyed too. 43# 44# TESTABILITY: explicit 45# 46# TEST_AUTOMATION_LEVEL: automated 47# 48# CODING_STATUS: COMPLETED (2006-06-20) 49# 50# __stc_assertion_end 51# 52################################################################################ 53 54verify_runnable "both" 55 56function cleanup 57{ 58 typeset ds 59 typeset snap 60 61 for ds in $ctr/$TESTVOL1 $ctr/$TESTCLONE; do 62 datasetexists $ds && \ 63 log_must $ZFS destroy -f $ds 64 done 65 66 for snap in $ctr/$TESTFS1@$TESTSNAP1 \ 67 $snappool $snapvol $snapctr $snapctrvol \ 68 $snapctrclone $snapctrfs 69 do 70 snapexists $snap && \ 71 log_must $ZFS destroy -rf $snap 72 done 73 74} 75 76log_assert "Verify snapshot -r can correctly create a snapshot tree." 77log_onexit cleanup 78 79ctr=$TESTPOOL/$TESTCTR 80ctrfs=$ctr/$TESTFS1 81ctrclone=$ctr/$TESTCLONE 82ctrvol=$ctr/$TESTVOL1 83snappool=$SNAPPOOL 84snapfs=$SNAPFS 85snapctr=$ctr@$TESTSNAP 86snapvol=$SNAPFS1 87snapctrvol=$ctrvol@$TESTSNAP 88snapctrclone=$ctrclone@$TESTSNAP 89snapctrfs=$SNAPCTR 90 91#preparation for testing 92log_must $ZFS snapshot $ctrfs@$TESTSNAP1 93log_must $ZFS clone $ctrfs@$TESTSNAP1 $ctrclone 94if is_global_zone; then 95 log_must $ZFS create -V $VOLSIZE $ctrvol 96else 97 log_must $ZFS create $ctrvol 98fi 99 100log_must $ZFS snapshot -r $snappool 101 102#verify the snapshot -r results 103for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \ 104 $snapctrclone $snapctrfs 105do 106 ! snapexists $snap && \ 107 log_fail "The snapshot $snap is not created via -r option." 108done 109 110log_note "Verify that destroy -r can destroy the snapshot tree." 111 112log_must $ZFS destroy -r $snappool 113for snap in $snappool $snapfs $snapvol $snapctr $snapctrvol \ 114 $snapctrclone $snapctrfs 115do 116 snapexists $snap && \ 117 log_fail "The snapshot $snap is not destroyed correctly." 118done 119 120log_note "Verify that the snapshot with different name should \ 121 be not destroyed." 122! snapexists $ctrfs@$TESTSNAP1 && \ 123 log_fail "destroy -r incorrectly destroys the snapshot \ 124 $ctrfs@$TESTSNAP1." 125 126log_pass "snapshot|destroy -r with snapshot tree works as expected." 127