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 
  46 verify_runnable "both"
  47 
  48 function 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 
  65 log_assert "Verify 'destroy -r' can correctly destroy a snapshot subtree at any point."
  66 log_onexit cleanup
  67 
  68 ctr=$TESTPOOL/$TESTCTR
  69 ctrfs=$ctr/$TESTFS1
  70 ctrvol=$ctr/$TESTVOL1
  71 snappool=$SNAPPOOL
  72 snapfs=$SNAPFS
  73 snapctr=$ctr@$TESTSNAP
  74 snapvol=$SNAPFS1
  75 snapctrvol=$ctr/$TESTVOL1@$TESTSNAP
  76 snapctrclone=$ctr/$TESTCLONE@$TESTSNAP
  77 snapctrfs=$SNAPCTR
  78 
  79 #preparation for testing
  80 log_must $ZFS snapshot $ctrfs@$TESTSNAP1
  81 if is_global_zone; then
  82         log_must $ZFS create -V $VOLSIZE $ctrvol
  83 else
  84         log_must $ZFS create $ctrvol
  85 fi
  86 
  87 log_must $ZFS snapshot -r $snappool
  88 
  89 #select the $TESTCTR as destroy point, $TESTCTR is a child of $TESTPOOL
  90 log_must $ZFS destroy -r $snapctr
  91 for snap in $snapctr $snapctrvol $snapctrclone $snapctrfs; do
  92         snapexists $snap && \
  93                 log_fail "The snapshot $snap is not destroyed correctly."
  94 done
  95 
  96 for snap in $snappool $snapfs $snapvol $ctrfs@$TESTSNAP1;do
  97         ! snapexists $snap && \
  98                 log_fail "The snapshot $snap should be not destroyed."
  99 done
 100 
 101 log_pass  "'destroy -r' destroys snapshot subtree as expected."