xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/send-wR_encrypted_zvol.ksh (revision 7a7741af18d6c8a804cc643cb7ecda9d730c6aa6)
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# Copyright (c) 2020 by Delphix. All rights reserved.
20#
21
22. $STF_SUITE/tests/functional/rsend/rsend.kshlib
23
24#
25# DESCRIPTION:
26# Verify that zvols with encryption=on can be sent and received with a raw
27# send stream.
28#
29# STRATEGY:
30# 1. Create a zvol with encryption on and put a filesystem on it
31# 2. Copy a file into the zvol a few times and take a snapshot
32# 3. Repeat step 2 a few times to create more snapshots
33# 4. Send all snapshots in a recursive, raw send stream
34# 5. Mount the received zvol and verify that all of the data there is correct
35#
36
37verify_runnable "both"
38
39function cleanup
40{
41	ismounted $recvmnt $fstype && log_must umount $recvmnt
42	ismounted $mntpnt $fstype && log_must umount $mntpnt
43	[[ -d $recvmnt ]] && log_must rm -rf $keyfile
44	[[ -d $mntpnt ]] && log_must rm -rf $keyfile
45	destroy_dataset $TESTPOOL/recv "-r"
46	destroy_dataset $TESTPOOL/$TESTVOL "-r"
47	[[ -f $keyfile ]] && log_must rm $keyfile
48	[[ -f $sendfile ]] && log_must rm $sendfile
49}
50log_onexit cleanup
51
52log_assert "Verify zfs can receive raw, recursive send streams"
53
54typeset keyfile=/$TESTPOOL/pkey
55typeset snap_count=5
56typeset zdev=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL
57typeset mntpnt=$TESTDIR/$TESTVOL
58typeset recvdev=$ZVOL_DEVDIR/$TESTPOOL/recv
59typeset recvmnt=$TESTDIR/recvmnt
60typeset sendfile=$TESTDIR/sendfile
61typeset fstype=none
62
63log_must eval "echo 'password' > $keyfile"
64
65log_must zfs create -o dedup=on -o encryption=on -o keyformat=passphrase \
66	-o keylocation=file://$keyfile -V 128M $TESTPOOL/$TESTVOL
67block_device_wait
68
69if is_linux; then
70	# ext4 only supported on Linux
71	log_must new_fs -t ext4 $zdev
72	fstype=ext4
73	typeset remount_ro="-o remount,ro"
74	typeset remount_rw="-o remount,rw"
75else
76	log_must new_fs $zdev
77	fstype=$NEWFS_DEFAULT_FS
78	typeset remount_ro="-ur"
79	typeset remount_rw="-uw"
80fi
81log_must mkdir -p $mntpnt
82log_must mkdir -p $recvmnt
83log_must mount $zdev $mntpnt
84
85for ((i = 1; i <= $snap_count; i++)); do
86	log_must dd if=/dev/urandom of=$mntpnt/file bs=1M count=1
87	for ((j = 0; j < 10; j++)); do
88		log_must cp $mntpnt/file $mntpnt/file$j
89	done
90
91	sync_all_pools
92	log_must mount $remount_ro $zdev $mntpnt
93	log_must zfs snap $TESTPOOL/$TESTVOL@snap$i
94	log_must mount $remount_rw $zdev $mntpnt
95done
96
97log_must eval "zfs send -wR $TESTPOOL/$TESTVOL@snap$snap_count > $sendfile"
98log_must eval "zfs recv $TESTPOOL/recv < $sendfile"
99log_must zfs load-key $TESTPOOL/recv
100block_device_wait
101
102log_must mount $recvdev $recvmnt
103
104hash1=$(cat $mntpnt/* | xxh128digest)
105hash2=$(cat $recvmnt/* | xxh128digest)
106[[ "$hash1" == "$hash2" ]] || log_fail "hash mismatch: $hash1 != $hash2"
107
108log_pass "zfs can receive raw, recursive send streams"
109