xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send_raw_ashift.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh
2# SPDX-License-Identifier: CDDL-1.0
3
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
15#
16# Copyright (c) 2019, Lawrence Livermore National Security, LLC.
17# Copyright (c) 2021, George Amanakis. All rights reserved.
18#
19
20. $STF_SUITE/include/libtest.shlib
21. $STF_SUITE/include/properties.shlib
22. $STF_SUITE/tests/functional/rsend/rsend.kshlib
23
24#
25# Description:
26# Verify encrypted raw sending to pools with greater ashift succeeds.
27#
28# Strategy:
29# 1) Create a set of files each containing some file data in an
30#	encrypted filesystem.
31# 2) Snapshot and raw send these files to a pool with greater ashift
32# 3) Verify that all the xattrs (and thus the spill block) were
33#    preserved when receiving the incremental stream.
34# 4) Repeat the test for a non-encrypted filesystem using raw send
35#
36
37verify_runnable "both"
38
39log_assert "Verify raw sending to pools with greater ashift succeeds"
40
41if is_freebsd; then
42	log_unsupported "Runs too long on FreeBSD 14 (Issue #14961)"
43fi
44
45function cleanup
46{
47	rm -f $BACKDIR/fs@*
48	poolexists pool9 && destroy_pool pool9
49	poolexists pool12 && destroy_pool pool12
50	log_must rm -f $TESTDIR/vdev_a $TESTDIR/vdev_b
51}
52
53function xattr_test
54{
55	log_must zfs set xattr=sa pool9/$1
56	log_must zfs set dnodesize=legacy pool9/$1
57	log_must zfs set recordsize=128k pool9/$1
58	rand_set_prop pool9/$1 compression "${compress_prop_vals[@]}"
59
60	# Create 40 files each with a spill block containing xattrs.  Each file
61	# will be modified in a different way to validate the incremental receive.
62	for i in {1..40}; do
63		file="/pool9/$1/file$i"
64
65		log_must mkfile 16384 $file
66		for j in {1..20}; do
67			log_must set_xattr "testattr$j" "$attrvalue" $file
68		done
69	done
70
71	# Snapshot the pool and send it to the new dataset.
72	log_must zfs snapshot pool9/$1@snap1
73	log_must eval "zfs send -w pool9/$1@snap1 >$BACKDIR/$1@snap1"
74	log_must eval "zfs recv pool12/$1 < $BACKDIR/$1@snap1"
75
76	#
77	# Modify file[1-6]'s contents but not the spill blocks.
78	#
79	# file1 - Increase record size; single block
80	# file2 - Increase record size; multiple blocks
81	# file3 - Truncate file to zero size; single block
82	# file4 - Truncate file to smaller size; single block
83	# file5 - Truncate file to much larger size; add holes
84	# file6 - Truncate file to embedded size; embedded data
85	#
86	log_must mkfile 32768 /pool9/$1/file1
87	log_must mkfile 1048576 /pool9/$1/file2
88	log_must truncate -s 0 /pool9/$1/file3
89	log_must truncate -s 8192 /pool9/$1/file4
90	log_must truncate -s 1073741824 /pool9/$1/file5
91	log_must truncate -s 50 /pool9/$1/file6
92
93	#
94	# Modify file[11-16]'s contents and their spill blocks.
95	#
96	# file11 - Increase record size; single block
97	# file12 - Increase record size; multiple blocks
98	# file13 - Truncate file to zero size; single block
99	# file14 - Truncate file to smaller size; single block
100	# file15 - Truncate file to much larger size; add holes
101	# file16 - Truncate file to embedded size; embedded data
102	#
103	log_must mkfile 32768 /pool9/$1/file11
104	log_must mkfile 1048576 /pool9/$1/file12
105	log_must truncate -s 0 /pool9/$1/file13
106	log_must truncate -s 8192 /pool9/$1/file14
107	log_must truncate -s 1073741824 /pool9/$1/file15
108	log_must truncate -s 50 /pool9/$1/file16
109
110	for i in {11..20}; do
111		log_must rm_xattr testattr1 /pool9/$1/file$i
112	done
113
114	#
115	# Modify file[21-26]'s contents and remove their spill blocks.
116	#
117	# file21 - Increase record size; single block
118	# file22 - Increase record size; multiple blocks
119	# file23 - Truncate file to zero size; single block
120	# file24 - Truncate file to smaller size; single block
121	# file25 - Truncate file to much larger size; add holes
122	# file26 - Truncate file to embedded size; embedded data
123	#
124	log_must mkfile 32768 /pool9/$1/file21
125	log_must mkfile 1048576 /pool9/$1/file22
126	log_must truncate -s 0 /pool9/$1/file23
127	log_must truncate -s 8192 /pool9/$1/file24
128	log_must truncate -s 1073741824 /pool9/$1/file25
129	log_must truncate -s 50 /pool9/$1/file26
130
131	for i in {21..30}; do
132		for j in {1..20}; do
133			log_must rm_xattr testattr$j /pool9/$1/file$i
134		done
135	done
136
137	#
138	# Modify file[31-40]'s spill blocks but not the file contents.
139	#
140	for i in {31..40}; do
141		file="/pool9/$1/file$i"
142		log_must rm_xattr testattr$(((RANDOM % 20) + 1)) $file
143		log_must set_xattr testattr$(((RANDOM % 20) + 1)) "$attrvalue" $file
144	done
145
146	# Snapshot the pool and send the incremental snapshot.
147	log_must zfs snapshot pool9/$1@snap2
148	log_must eval "zfs send -w -i pool9/$1@snap1 pool9/$1@snap2 >$BACKDIR/$1@snap2"
149	log_must eval "zfs recv pool12/$1 < $BACKDIR/$1@snap2"
150}
151
152attrvalue="abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"
153
154log_onexit cleanup
155
156# Create pools
157truncate -s $MINVDEVSIZE $TESTDIR/vdev_a
158truncate -s $MINVDEVSIZE $TESTDIR/vdev_b
159log_must zpool create -f -o ashift=9 pool9 $TESTDIR/vdev_a
160log_must zpool create -f -o ashift=12 pool12 $TESTDIR/vdev_b
161
162# Create encrypted fs
163log_must eval "echo 'password' | zfs create -o encryption=on" \
164	"-o keyformat=passphrase -o keylocation=prompt " \
165	"pool9/encfs"
166
167# Run xattr tests for encrypted fs
168xattr_test encfs
169
170# Calculate the expected recursive checksum for source encrypted fs
171expected_cksum=$(recursive_cksum /pool9/encfs)
172
173# Mount target encrypted fs
174log_must eval "echo 'password' | zfs load-key pool12/encfs"
175log_must zfs mount pool12/encfs
176
177# Validate the received copy using the received recursive checksum
178actual_cksum=$(recursive_cksum /pool12/encfs)
179if [[ "$expected_cksum" != "$actual_cksum" ]]; then
180	log_fail "Checksums differ ($expected_cksum != $actual_cksum)"
181fi
182
183# Perform the same test but without encryption (send -w)
184log_must zfs create pool9/fs
185
186# Run xattr tests for non-encrypted fs
187xattr_test fs
188
189# Calculate the expected recursive checksum for source non-encrypted fs
190expected_cksum=$(recursive_cksum /pool9/fs)
191
192# Validate the received copy using the received recursive checksum
193actual_cksum=$(recursive_cksum /pool12/fs)
194if [[ "$expected_cksum" != "$actual_cksum" ]]; then
195	log_fail "Checksums differ ($expected_cksum != $actual_cksum)"
196fi
197
198log_pass "Verify raw sending to pools with greater ashift succeeds"
199