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) 2012, 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib
33. $STF_SUITE/tests/functional/cli_root/zfs_send/zfs_send.cfg
34
35#
36# DESCRIPTION:
37#	Verify 'zfs send' can generate valid streams with a property setup.
38#
39# STRATEGY:
40#	1. Setup property for filesystem
41#	2. Fill in some data into filesystem
42#	3. Create a full send streams
43#	4. Receive the send stream
44#	5. Verify the receive result
45#
46
47verify_runnable "both"
48
49function cleanup
50{
51	snapexists $snap && \
52		log_must zfs destroy $snap
53
54	datasetexists $ctr && \
55		log_must zfs destroy -r $ctr
56
57	[[ -e $origfile ]] && \
58		log_must rm -f $origfile
59
60	[[ -e $stream ]] && \
61		log_must rm -f $stream
62}
63
64function do_testing # <prop> <prop_value>
65{
66	typeset property=$1
67	typeset prop_val=$2
68
69	log_must zfs set $property=$prop_val $fs
70	file_write -o create -f $origfile -b $BLOCK_SIZE -c $WRITE_COUNT
71	log_must zfs snapshot $snap
72	zfs send $snap > $stream
73	(( $? != 0 )) && \
74		log_fail "'zfs send' fails to create send streams."
75	zfs receive -d $ctr <$stream
76	(( $? != 0 )) && \
77		log_fail "'zfs receive' fails to receive send streams."
78
79	#verify receive result
80	! datasetexists $rstfs && \
81		log_fail "'zfs receive' fails to restore $rstfs"
82	! snapexists $rstfssnap && \
83		log_fail "'zfs receive' fails to restore $rstfssnap"
84	if [[ ! -e $rstfile ]] || [[ ! -e $rstsnapfile ]]; then
85		log_fail " Data lost after receiving stream"
86	fi
87
88	compare_cksum $origfile $rstfile
89	compare_cksum $origsnapfile $rstsnapfile
90
91	#Destroy datasets and stream for next testing
92	log_must zfs destroy $snap
93	if is_global_zone ; then
94		log_must zfs destroy -r $rstfs
95	else
96		log_must zfs destroy -r $ds_path
97	fi
98	log_must rm -f $stream
99}
100
101log_assert "Verify 'zfs send' generates valid streams with a property setup"
102log_onexit cleanup
103
104fs=$TESTPOOL/$TESTFS
105snap=$fs@$TESTSNAP
106ctr=$TESTPOOL/$TESTCTR
107if is_global_zone; then
108	rstfs=$ctr/$TESTFS
109else
110	ds_path=$ctr/${ZONE_CTR}0
111	rstfs=$ds_path/$TESTFS
112fi
113rstfssnap=$rstfs@$TESTSNAP
114snapdir=".zfs/snapshot/$TESTSNAP"
115origfile=$TESTDIR/$TESTFILE1
116rstfile=/$rstfs/$TESTFILE1
117origsnapfile=$TESTDIR/$snapdir/$TESTFILE1
118rstsnapfile=/$rstfs/$snapdir/$TESTFILE1
119stream=/var/tmp/streamfile.$$
120
121set -A props "compression" "checksum" "recordsize"
122set -A propval "on lzjb" "on fletcher2 fletcher4 sha256" \
123	"512 1k 4k 8k 16k 32k 64k 128k"
124
125#Create a dataset to receive the send stream
126log_must zfs create $ctr
127
128typeset -i i=0
129while (( i < ${#props[*]} ))
130do
131	for value in ${propval[i]}
132	do
133		do_testing ${props[i]} $value
134	done
135
136	(( i = i + 1 ))
137done
138
139log_pass "'zfs send' generates streams with a property setup as expected."
140