1a60ca23dSTom Caputi#!/bin/ksh -p
2a60ca23dSTom Caputi#
3a60ca23dSTom Caputi# CDDL HEADER START
4a60ca23dSTom Caputi#
5a60ca23dSTom Caputi# This file and its contents are supplied under the terms of the
6a60ca23dSTom Caputi# Common Development and Distribution License ("CDDL"), version 1.0.
7a60ca23dSTom Caputi# You may only use this file in accordance with the terms of version
8a60ca23dSTom Caputi# 1.0 of the CDDL.
9a60ca23dSTom Caputi#
10a60ca23dSTom Caputi# A full copy of the text of the CDDL should have accompanied this
11a60ca23dSTom Caputi# source.  A copy of the CDDL is also available via the Internet at
12a60ca23dSTom Caputi# http://www.illumos.org/license/CDDL.
13a60ca23dSTom Caputi#
14a60ca23dSTom Caputi# CDDL HEADER END
15a60ca23dSTom Caputi#
16a60ca23dSTom Caputi
17a60ca23dSTom Caputi#
18a60ca23dSTom Caputi# Copyright (c) 2018 by Datto Inc. All rights reserved.
19*e3bf7d5aSKody Kantor# Copyright 2020 Joyent, Inc.
20a60ca23dSTom Caputi#
21a60ca23dSTom Caputi
22a60ca23dSTom Caputi. $STF_SUITE/tests/functional/rsend/rsend.kshlib
23a60ca23dSTom Caputi
24a60ca23dSTom Caputi#
25a60ca23dSTom Caputi# DESCRIPTION:
26a60ca23dSTom Caputi# Verify that zvols with dedup=on and encryption=on can be sent and received
27a60ca23dSTom Caputi# with a deduplicated raw send stream.
28a60ca23dSTom Caputi#
29a60ca23dSTom Caputi# STRATEGY:
30a60ca23dSTom Caputi# 1. Create a zvol with dedup and encryption on and put a filesystem on it
31a60ca23dSTom Caputi# 2. Copy a file into the zvol a few times and take a snapshot
32a60ca23dSTom Caputi# 3. Repeat step 2 a few times to create more snapshots
33a60ca23dSTom Caputi# 4. Send all snapshots in a recursive, raw, deduplicated send stream
34a60ca23dSTom Caputi# 5. Mount the received zvol and verify that all of the data there is correct
35a60ca23dSTom Caputi#
36a60ca23dSTom Caputi
37a60ca23dSTom Caputiverify_runnable "both"
38a60ca23dSTom Caputi
39a60ca23dSTom Caputifunction cleanup
40a60ca23dSTom Caputi{
41a60ca23dSTom Caputi	if is_linux; then
42a60ca23dSTom Caputi		ismounted $recvmnt ext4 && log_must umount $recvmnt
43a60ca23dSTom Caputi		ismounted $mntpnt ext4 && log_must umount $mntpnt
44a60ca23dSTom Caputi	else
45a60ca23dSTom Caputi		ismounted $recvmnt ufs && log_must umount $recvmnt
46a60ca23dSTom Caputi		ismounted $mntpnt ufs && log_must umount $mntpnt
47a60ca23dSTom Caputi	fi
48a60ca23dSTom Caputi	[[ -d $recvmnt ]] && log_must rm -rf $keyfile
49a60ca23dSTom Caputi	[[ -d $mntpnt ]] && log_must rm -rf $keyfile
50a60ca23dSTom Caputi	destroy_dataset $TESTPOOL/recv "-r"
51a60ca23dSTom Caputi	destroy_dataset $TESTPOOL/$TESTVOL "-r"
52a60ca23dSTom Caputi	[[ -f $keyfile ]] && log_must rm $keyfile
53a60ca23dSTom Caputi	[[ -f $sendfile ]] && log_must rm $sendfile
54a60ca23dSTom Caputi}
55a60ca23dSTom Caputilog_onexit cleanup
56a60ca23dSTom Caputi
57a60ca23dSTom Caputilog_assert "Verify zfs can receive raw, recursive, and deduplicated send streams"
58a60ca23dSTom Caputi
59a60ca23dSTom Caputitypeset keyfile=/$TESTPOOL/pkey
60a60ca23dSTom Caputitypeset snap_count=5
61a60ca23dSTom Caputitypeset zdev=$ZVOL_DEVDIR/$TESTPOOL/$TESTVOL
62a60ca23dSTom Caputitypeset mntpnt=$TESTDIR/$TESTVOL
63a60ca23dSTom Caputitypeset recvdev=$ZVOL_DEVDIR/$TESTPOOL/recv
64a60ca23dSTom Caputitypeset recvmnt=$TESTDIR/recvmnt
65a60ca23dSTom Caputitypeset sendfile=$TESTDIR/sendfile
66a60ca23dSTom Caputi
67a60ca23dSTom Caputilog_must eval "echo 'password' > $keyfile"
68a60ca23dSTom Caputi
69a60ca23dSTom Caputilog_must zfs create -o dedup=on -o encryption=on -o keyformat=passphrase \
70a60ca23dSTom Caputi	-o keylocation=file://$keyfile -V 128M $TESTPOOL/$TESTVOL
71a60ca23dSTom Caputilog_must block_device_wait
72a60ca23dSTom Caputi
73a60ca23dSTom Caputiif is_linux; then
74a60ca23dSTom Caputi	log_must eval "echo 'y' | newfs -t ext4 -v $zdev"
75a60ca23dSTom Caputielse
76a60ca23dSTom Caputi	log_must eval "echo 'y' | newfs $zdev"
77a60ca23dSTom Caputifi
78a60ca23dSTom Caputilog_must mkdir -p $mntpnt
79a60ca23dSTom Caputilog_must mkdir -p $recvmnt
80a60ca23dSTom Caputilog_must mount $zdev $mntpnt
81a60ca23dSTom Caputi
82a60ca23dSTom Caputifor ((i = 1; i <= $snap_count; i++)); do
83a60ca23dSTom Caputi	log_must dd if=/dev/urandom of=$mntpnt/file bs=1M count=1
84a60ca23dSTom Caputi	for ((j = 0; j < 10; j++)); do
85a60ca23dSTom Caputi		log_must cp $mntpnt/file $mntpnt/file$j
86a60ca23dSTom Caputi	done
87a60ca23dSTom Caputi
88a60ca23dSTom Caputi	log_must sync
89a60ca23dSTom Caputi	log_must zfs snap $TESTPOOL/$TESTVOL@snap$i
90a60ca23dSTom Caputidone
91a60ca23dSTom Caputi
92a60ca23dSTom Caputilog_must eval "zfs send -wDR $TESTPOOL/$TESTVOL@snap$snap_count > $sendfile"
93a60ca23dSTom Caputilog_must eval "zfs recv $TESTPOOL/recv < $sendfile"
94a60ca23dSTom Caputilog_must zfs load-key $TESTPOOL/recv
95a60ca23dSTom Caputilog_must block_device_wait
96a60ca23dSTom Caputi
97a60ca23dSTom Caputilog_must mount $recvdev $recvmnt
98a60ca23dSTom Caputi
99*e3bf7d5aSKody Kantormd5_1=$(cat $mntpnt/* | digest -a md5)
100*e3bf7d5aSKody Kantormd5_2=$(cat $recvmnt/* | digest -a md5)
101a60ca23dSTom Caputi[[ "$md5_1" == "$md5_2" ]] || log_fail "md5 mismatch: $md5_1 != $md5_2"
102a60ca23dSTom Caputi
103a60ca23dSTom Caputilog_pass "zfs can receive raw, recursive, and deduplicated send streams"
104