xref: /titanic_51/usr/src/test/zfs-tests/tests/functional/snapshot/snapshot_013_pos.ksh (revision f38cb554a534c6df738be3f4d23327e69888e634)
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
47verify_runnable "both"
48
49function 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
61log_assert "Verify snapshots from 'snapshot -r' can be used for zfs send/recv"
62log_onexit cleanup
63
64ctr=$TESTPOOL/$TESTCTR
65ctrfs=$ctr/$TESTFS
66snappool=$SNAPPOOL
67snapfs=$SNAPFS
68snapctr=$ctr@$TESTSNAP
69snapctrfs=$ctrfs@$TESTSNAP
70fsdir=/$ctrfs
71snapdir=$fsdir/.zfs/snapshot/$TESTSNAP
72
73[[ -n $TESTDIR ]] && \
74    log_must $RM -rf $TESTDIR/* > /dev/null 2>&1
75
76typeset -i COUNT=10
77
78log_note "Populate the $TESTDIR directory (prior to snapshot)"
79typeset -i i=0
80while (( 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 ))
85done
86
87log_must $ZFS snapshot -r $snappool
88
89$ZFS send $snapfs | $ZFS receive $ctrfs >/dev/null 2>&1
90if ! datasetexists $ctrfs || ! snapexists $snapctrfs; then
91	log_fail "zfs send/receive fails with snapshot $snapfs."
92fi
93
94for 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"
97done
98
99log_pass "'zfs send/receive' works as expected with snapshots from 'snapshot -r'"
100