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