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