xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/rsend/send_encrypted_freeobjects.ksh (revision c3b397890d6e53844f306787c3e343c8ef35293d)
1#!/bin/ksh
2
3#
4# This file and its contents are supplied under the terms of the
5# Common Development and Distribution License ("CDDL"), version 1.0.
6# You may only use this file in accordance with the terms of version
7# 1.0 of the CDDL.
8#
9# A full copy of the text of the CDDL should have accompanied this
10# source.  A copy of the CDDL is also available via the Internet at
11# http://www.illumos.org/license/CDDL.
12#
13
14#
15# Copyright (c) 2017 by Lawrence Livermore National Security, LLC.
16# Copyright (c) 2023 by Findity AB
17#
18
19. $STF_SUITE/tests/functional/rsend/rsend.kshlib
20
21#
22# Description:
23# Verify that receiving a raw encrypted stream, with a FREEOBJECTS
24# removing all existing objects in a block followed by an OBJECT write
25# to the same block, does not result in a panic.
26#
27# Strategy:
28# 1. Create a new encrypted filesystem
29# 2. Create file f1 as the first object in some block (here object 128)
30# 3. Take snapshot A
31# 4. Create file f2 as the second object in the same block (here object 129)
32# 5. Delete f1
33# 6. Take snapshot B
34# 7. Receive a full raw encrypted send of A
35# 8. Receive an incremental raw send of B
36#
37verify_runnable "both"
38
39function create_object_with_num
40{
41	file=$1
42	num=$2
43
44	tries=100
45	for ((i=0; i<$tries; i++)); do
46		touch $file
47		onum=$(ls -li $file | awk '{print $1}')
48
49		if [[ $onum -ne $num ]] ; then
50			rm -f $file
51		else
52			break
53		fi
54	done
55	if [[ $i -eq $tries ]]; then
56		log_fail "Failed to create object with number $num"
57	fi
58}
59
60log_assert "FREEOBJECTS followed by OBJECT in encrypted stream does not crash"
61
62sendds=sendencfods
63recvds=recvencfods
64keyfile=/$POOL/keyencfods
65f1=/$POOL/$sendds/f1
66f2=/$POOL/$sendds/f2
67
68log_must eval "echo 'password' > $keyfile"
69
70#
71# xattr=on and dnodesize=legacy for sequential object numbers, see
72# note in send_freeobjects.ksh.
73#
74log_must zfs create -o xattr=on -o dnodesize=legacy -o encryption=on \
75	-o keyformat=passphrase -o keylocation=file://$keyfile $POOL/$sendds
76
77create_object_with_num $f1 128
78log_must zfs snap $POOL/$sendds@A
79create_object_with_num $f2 129
80log_must rm $f1
81log_must zfs snap $POOL/$sendds@B
82
83log_must eval "zfs send -w $POOL/$sendds@A | zfs recv $POOL/$recvds"
84log_must eval "zfs send -w -i $POOL/$sendds@A $POOL/$sendds@B |" \
85	"zfs recv $POOL/$recvds"
86
87log_pass "FREEOBJECTS followed by OBJECT in encrypted stream did not crash"
88