1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2018 by Datto Inc. All rights reserved.
19#
20
21. $STF_SUITE/tests/functional/rsend/rsend.kshlib
22
23#
24# DESCRIPTION:
25# Verify that a raw zfs send and receive can deal with several different
26# types of file layouts.
27#
28# STRATEGY:
29# 1. Create a new encrypted filesystem
30# 2. Add an empty file to the filesystem
31# 3. Add a small 512 byte file to the filesystem
32# 4. Add a larger 32M file to the filesystem
33# 5. Add a large sparse file to the filesystem
34# 6. Add 1000 empty files to the filesystem
35# 7. Add a file with a large xattr value
36# 8. Use xattrtest to create files with random xattrs (with and without xattrs=on)
37# 9. Take a snapshot of the filesystem
38# 10. Remove the 1000 empty files to the filesystem
39# 11. Take another snapshot of the filesystem
40# 12. Send and receive both snapshots
41# 13. Mount the filesystem and check the contents
42#
43
44verify_runnable "both"
45
46function cleanup
47{
48	datasetexists $TESTPOOL/$TESTFS2 && \
49		log_must zfs destroy -r $TESTPOOL/$TESTFS2
50	datasetexists $TESTPOOL/recv && \
51		log_must zfs destroy -r $TESTPOOL/recv
52	[[ -f $keyfile ]] && log_must rm $keyfile
53	[[ -f $sendfile ]] && log_must rm $sendfile
54}
55log_onexit cleanup
56
57log_assert "Verify 'zfs send -w' works with many different file layouts"
58
59typeset keyfile=/$TESTPOOL/pkey
60typeset sendfile=/$TESTPOOL/sendfile
61typeset sendfile2=/$TESTPOOL/sendfile2
62
63# Create an encrypted dataset
64log_must eval "echo 'password' > $keyfile"
65log_must zfs create -o encryption=on -o keyformat=passphrase \
66	-o keylocation=file://$keyfile $TESTPOOL/$TESTFS2
67
68# Create files with varied layouts on disk
69log_must touch /$TESTPOOL/$TESTFS2/empty
70log_must mkfile 512 /$TESTPOOL/$TESTFS2/small
71log_must mkfile 32M /$TESTPOOL/$TESTFS2/full
72log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/sparse \
73	bs=512 count=1 seek=1048576 >/dev/null 2>&1
74
75log_must mkdir -p /$TESTPOOL/$TESTFS2/dir
76for i in {1..1000}; do
77	log_must mkfile 512 /$TESTPOOL/$TESTFS2/dir/file-$i
78done
79
80log_must mkdir -p /$TESTPOOL/$TESTFS2/xattrondir
81log_must zfs set xattr=on $TESTPOOL/$TESTFS2
82
83# XXX - the lines below (through the end of the file) that are commented out
84# are differences from ZoL due to currently unsupported extended attribute code
85# on illumos.
86# log_must xattrtest -f 10 -x 3 -s 32768 -r -k -p /$TESTPOOL/$TESTFS2/xattrondir
87# log_must mkdir -p /$TESTPOOL/$TESTFS2/xattrsadir
88# log_must zfs set xattr=sa $TESTPOOL/$TESTFS2
89# log_must xattrtest -f 10 -x 3 -s 32768 -r -k -p /$TESTPOOL/$TESTFS2/xattrsadir
90
91# ZoL issue #7432
92# log_must zfs set compression=on xattr=sa $TESTPOOL/$TESTFS2
93# log_must touch /$TESTPOOL/$TESTFS2/attrs
94# log_must eval "python -c 'print \"a\" * 4096' | \
95# 	attr -s bigval /$TESTPOOL/$TESTFS2/attrs"
96# log_must zfs set compression=off xattr=on $TESTPOOL/$TESTFS2
97
98log_must zfs snapshot $TESTPOOL/$TESTFS2@snap1
99
100# Remove the empty files created in the first snapshot
101for i in {1..1000}; do
102	log_must rm /$TESTPOOL/$TESTFS2/dir/file-$i
103done
104sync
105
106log_must zfs snapshot $TESTPOOL/$TESTFS2@snap2
107expected_cksum=$(recursive_cksum /$TESTPOOL/$TESTFS2)
108
109log_must eval "zfs send -wp $TESTPOOL/$TESTFS2@snap1 > $sendfile"
110log_must eval "zfs send -wp -i @snap1 $TESTPOOL/$TESTFS2@snap2 > $sendfile2"
111
112log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile"
113log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile2"
114log_must zfs load-key $TESTPOOL/recv
115
116log_must zfs mount -a
117actual_cksum=$(recursive_cksum /$TESTPOOL/recv)
118[[ "$expected_cksum" != "$actual_cksum" ]] && \
119	log_fail "Recursive checksums differ ($expected_cksum != $actual_cksum)"
120
121# log_must xattrtest -f 10 -o3 -y -p /$TESTPOOL/recv/xattrondir
122# log_must xattrtest -f 10 -o3 -y -p /$TESTPOOL/recv/xattrsadir
123
124log_pass "Verified 'zfs send -w' works with many different file layouts"
125