summaryrefslogtreecommitdiffstats
path: root/tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_010_pos.ksh
blob: 47e23e6ebca7fb87611dd0460003e719de9498a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright (c) 2015, 2016 by Delphix. All rights reserved.
#

. $STF_SUITE/include/libtest.shlib

#
# DESCRIPTION:
# Test that receiving a full send as a clone works correctly.
#
# STRATEGY:
# 1. Create pool and filesystems.
# 2. Send filesystem, receive as clone of itself.
# 3. Verify that nop-write saves space.
# 4. Send filesystem, receive as clone of other filesystem.
# 5. Verify that contents are correct.
# 6. Repeat steps 4 and 5 with filesystems swapped.
#

verify_runnable "both"

fs=$TESTPOOL/$TESTFS/base/fs
fs2=$TESTPOOL/$TESTFS/base/fs2
rfs=$TESTPOOL/$TESTFS/base/rfs

function make_object
{
	typeset objnum=$1
	typeset mntpnt=$2
	typeset type=$3
	if [[ $type == "file" ]]; then
		dd if=/dev/urandom of=${mntpnt}/f$objnum bs=512 count=16
	elif [[ $type == "hole1" ]]; then
		dd if=/dev/zero of=${mntpnt}/fh$objnum bs=512 count=5 seek=4 conv=notrunc
	elif [[ $type == "hole2" ]]; then
		dd if=/dev/zero of=${mntpnt}/fh$objnum bs=512 count=4 seek=5 conv=notrunc
	elif [[ $type == "directory" ]]; then
		mkdir ${mntpnt}/d$objnum
	elif [[ $type == "missing" ]]; then
		touch ${mntpnt}/h$objnum
	fi
}

function create_pair
{
	typeset objnum=$1
	typeset mntpnt1=$2
	typeset mntpnt2=$3
	typeset type1=$4
	typeset type2=$5
	make_object $objnum $mntpnt1 $type1
	make_object $objnum $mntpnt2 $type2
}

function cleanup
{
	zfs destroy -Rf $TESTPOOL/$TESTFS/base
	rm $TESTDIR/zr010p*
}

log_assert "zfs receive of full send as clone should work"
log_onexit cleanup
log_must zfs create -o checksum=sha256 -o compression=gzip -o recordsize=512 \
	$TESTPOOL/$TESTFS/base

log_must zfs create $fs
log_must zfs create $fs2
mntpnt=$(get_prop mountpoint $fs)
mntpnt2=$(get_prop mountpoint $fs2)

#
# Now, we create the two filesystems.  By creating objects with
# different types and the same object number in each filesystem, we
# create a situation where, when you receive the full send of each as
# a clone of the other, we will test to ensure that the code correctly
# handles receiving all object types onto all other object types.
#

# Receive a file onto a file (and vice versa).
create_pair 8 $mntpnt $mntpnt2 "file" "file"

# Receive a file onto a file with holes (and vice versa).
create_pair 9 $mntpnt $mntpnt2 "file" "hole1"

# Receive a file onto a directory (and vice versa).
create_pair 10 $mntpnt $mntpnt2 "file" "directory"

# Receive a file onto a missing object (and vice versa).
create_pair 11 $mntpnt $mntpnt2 "file" "missing"

# Receive a file with holes onto a file with holes (and vice versa).
create_pair 12 $mntpnt $mntpnt2 "hole1" "hole2"

# Receive a file with holes onto a directory (and vice versa).
create_pair 13 $mntpnt $mntpnt2 "hole1" "directory"

# Receive a file with holes onto a missing object (and vice versa).
create_pair 14 $mntpnt $mntpnt2 "hole1" "missing"

# Receive a directory onto a directory (and vice versa).
create_pair 15 $mntpnt $mntpnt2 "directory" "directory"

# Receive a directory onto a missing object (and vice versa).
create_pair 16 $mntpnt $mntpnt2 "directory" "missing"

# Receive a missing object onto a missing object (and vice versa).
create_pair 17 $mntpnt $mntpnt2 "missing" "missing"

# Receive a file with a different record size onto a file (and vice versa).
log_must zfs set recordsize=128k $fs
dd if=/dev/urandom of=$mntpnt/f18 bs=128k count=64
touch $mntpnt2/f18

# Remove objects that are intended to be missing.
rm $mntpnt/h17
rm $mntpnt2/h*

# Add empty objects to $fs to exercise dmu_traverse code
for i in {1..100}; do
	log_must touch $mntpnt/uf$i
done

log_must zfs snapshot $fs@s1
log_must zfs snapshot $fs2@s1

log_must zfs send $fs@s1 > $TESTDIR/zr010p
log_must zfs send $fs2@s1 > $TESTDIR/zr010p2


#
# Test that, when we receive a full send as a clone of itself,
# nop-write saves us all the space used by data blocks.
#
cat $TESTDIR/zr010p | log_must zfs receive -o origin=$fs@s1 $rfs
size=$(get_prop used $rfs)
size2=$(get_prop used $fs)
if [[ $size -ge $(($size2 / 10)) ]] then
        log_fail "nop-write failure; expected usage less than "\
		"$(($size2 / 10)), but is using $size"
fi
log_must zfs destroy -fr $rfs

# Correctness testing: receive each full send as a clone of the other fiesystem.
cat $TESTDIR/zr010p | log_must zfs receive -o origin=$fs2@s1 $rfs
mntpnt_old=$(get_prop mountpoint $fs)
mntpnt_new=$(get_prop mountpoint $rfs)
log_must directory_diff $mntpnt_old $mntpnt_new
log_must zfs destroy -r $rfs

cat $TESTDIR/zr010p2 | log_must zfs receive -o origin=$fs@s1 $rfs
mntpnt_old=$(get_prop mountpoint $fs2)
mntpnt_new=$(get_prop mountpoint $rfs)
log_must directory_diff $mntpnt_old $mntpnt_new

log_pass "zfs receive of full send as clone works"