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 https://opensource.org/licenses/CDDL-1.0. 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, 2016 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 destroy_dataset $ctrvol "-rf" 53 54 for snap in $ctrfs@$TESTSNAP1 \ 55 $snappool $snapvol $snapctr $snapctrvol \ 56 $snapctrclone $snapctrfs 57 do 58 snapexists $snap && destroy_dataset $snap "-rf" 59 done 60 61} 62 63log_assert "Verify 'destroy -r' can correctly destroy a snapshot subtree at any point." 64log_onexit cleanup 65 66ctr=$TESTPOOL/$TESTCTR 67ctrfs=$ctr/$TESTFS1 68ctrvol=$ctr/$TESTVOL1 69snappool=$SNAPPOOL 70snapfs=$SNAPFS 71snapctr=$ctr@$TESTSNAP 72snapvol=$SNAPFS1 73snapctrvol=$ctr/$TESTVOL1@$TESTSNAP 74snapctrclone=$ctr/$TESTCLONE@$TESTSNAP 75snapctrfs=$SNAPCTR 76 77#preparation for testing 78log_must zfs snapshot $ctrfs@$TESTSNAP1 79if is_global_zone; then 80 log_must zfs create -V $VOLSIZE $ctrvol 81else 82 log_must zfs create $ctrvol 83fi 84 85log_must zfs snapshot -r $snappool 86block_device_wait 87 88#select the $TESTCTR as destroy point, $TESTCTR is a child of $TESTPOOL 89log_must zfs destroy -r $snapctr 90for snap in $snapctr $snapctrvol $snapctrclone $snapctrfs; do 91 snapexists $snap && \ 92 log_fail "The snapshot $snap is not destroyed correctly." 93done 94 95for snap in $snappool $snapfs $snapvol $ctrfs@$TESTSNAP1; do 96 ! snapexists $snap && \ 97 log_fail "The snapshot $snap should be not destroyed." 98done 99 100log_pass "'destroy -r' destroys snapshot subtree as expected." 101