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 that the snapshots created by 'snapshot -r' can be used for 38 # zfs send/recv 39 # 40 # STRATEGY: 41 # 1. create a dataset tree and populate a filesystem 42 # 2. snapshot -r the dataset tree 43 # 3. select one snapshot used for zfs send/recv 44 # 4. verify the data integrity after zfs send/recv 45 # 46 47 verify_runnable "both" 48 49 function cleanup 50 { 51 datasetexists $ctrfs && \ 52 $ZFS destroy -r $ctrfs 53 54 snapexists $snappool && \ 55 log_must $ZFS destroy -r $snappool 56 57 [[ -e $TESTDIR ]] && \ 58 log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 59 } 60 61 log_assert "Verify snapshots from 'snapshot -r' can be used for zfs send/recv" 62 log_onexit cleanup 63 64 ctr=$TESTPOOL/$TESTCTR 65 ctrfs=$ctr/$TESTFS 66 snappool=$SNAPPOOL 67 snapfs=$SNAPFS 68 snapctr=$ctr@$TESTSNAP 69 snapctrfs=$ctrfs@$TESTSNAP 70 fsdir=/$ctrfs 71 snapdir=$fsdir/.zfs/snapshot/$TESTSNAP 72 73 [[ -n $TESTDIR ]] && \ 74 log_must $RM -rf $TESTDIR/* > /dev/null 2>&1 75 76 typeset -i COUNT=10 77 78 log_note "Populate the $TESTDIR directory (prior to snapshot)" 79 typeset -i i=0 80 while (( i < COUNT )); do 81 log_must $FILE_WRITE -o create -f $TESTDIR/file$i \ 82 -b $BLOCKSZ -c $NUM_WRITES -d $i 83 84 (( i = i + 1 )) 85 done 86 87 log_must $ZFS snapshot -r $snappool 88 89 $ZFS send $snapfs | $ZFS receive $ctrfs >/dev/null 2>&1 90 if ! datasetexists $ctrfs || ! snapexists $snapctrfs; then 91 log_fail "zfs send/receive fails with snapshot $snapfs." 92 fi 93 94 for dir in $fsdir $snapdir; do 95 FILE_COUNT=`$LS -Al $dir | $GREP -v "total" | wc -l` 96 (( FILE_COUNT != COUNT )) && log_fail "Got $FILE_COUNT expected $COUNT" 97 done 98 99 log_pass "'zfs send/receive' works as expected with snapshots from 'snapshot -r'"