]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/rsend/send_encrypted_truncated_files.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / rsend / send_encrypted_truncated_files.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 #
26 #
27 # STRATEGY:
28 # 1. Create a new encrypted filesystem
29 # 2. Add a 4 files that are to be truncated later
30 # 3. Take a snapshot of the filesystem
31 # 4. Truncate one of the files from 32M to 128k
32 # 5. Truncate one of the files from 512k to 384k
33 # 6. Truncate one of the files from 512k to 0 to 384k via reallocation
34 # 7. Truncate one of the files from 1k to 0 to 512b via reallocation
35 # 8. Take another snapshot of the filesystem
36 # 9. Send and receive both snapshots
37 # 10. Mount the filesystem and check the contents
38 #
39
40 verify_runnable "both"
41
42 function cleanup
43 {
44         datasetexists $TESTPOOL/$TESTFS2 && \
45                 log_must zfs destroy -r $TESTPOOL/$TESTFS2
46         datasetexists $TESTPOOL/recv && \
47                 log_must zfs destroy -r $TESTPOOL/recv
48         [[ -f $keyfile ]] && log_must rm $keyfile
49         [[ -f $sendfile ]] && log_must rm $sendfile
50 }
51 log_onexit cleanup
52
53 function recursive_cksum
54 {
55         case "$(uname)" in
56         FreeBSD)
57                 find $1 -type f -exec sha256 -q {} \; | \
58                     sort | sha256digest
59                 ;;
60         *)
61                 find $1 -type f -exec sha256sum {} \; | \
62                     sort -k 2 | awk '{ print $1 }' | sha256digest
63                 ;;
64         esac
65 }
66
67 log_assert "Verify 'zfs send -w' works with many different file layouts"
68
69 typeset keyfile=/$TESTPOOL/pkey
70 typeset sendfile=/$TESTPOOL/sendfile
71 typeset sendfile2=/$TESTPOOL/sendfile2
72
73 # Create an encrypted dataset
74 log_must eval "echo 'password' > $keyfile"
75 log_must zfs create -o encryption=on -o keyformat=passphrase \
76         -o keylocation=file://$keyfile $TESTPOOL/$TESTFS2
77
78 # Explicitly set the recordsize since the truncation sizes below depend on
79 # this value being 128k.  This is currently same as the default recordsize.
80 log_must zfs set recordsize=128k $TESTPOOL/$TESTFS2
81
82 # Create files with varied layouts on disk
83 log_must mkfile 32M /$TESTPOOL/$TESTFS2/truncated
84 log_must mkfile 524288 /$TESTPOOL/$TESTFS2/truncated2
85 log_must mkfile 524288 /$TESTPOOL/$TESTFS2/truncated3
86 log_must mkfile 1024 /$TESTPOOL/$TESTFS2/truncated4
87
88 log_must zfs snapshot $TESTPOOL/$TESTFS2@snap1
89
90 #
91 # Truncate files created in the first snapshot. The first tests
92 # truncating a large file to a single block. The second tests
93 # truncating one block off the end of a file without changing
94 # the required nlevels to hold it. The third tests handling
95 # of a maxblkid that is dropped and then raised again. The
96 # fourth tests an object that is truncated from a single block
97 # to a smaller single block.
98 #
99 log_must truncate -s 131072 /$TESTPOOL/$TESTFS2/truncated
100 log_must truncate -s 393216 /$TESTPOOL/$TESTFS2/truncated2
101 log_must rm -f /$TESTPOOL/$TESTFS2/truncated3
102 log_must rm -f /$TESTPOOL/$TESTFS2/truncated4
103 log_must zpool sync $TESTPOOL
104 log_must zfs umount $TESTPOOL/$TESTFS2
105 log_must zfs mount $TESTPOOL/$TESTFS2
106 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/truncated3 \
107         bs=128k count=3 iflag=fullblock
108 log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/truncated4 \
109         bs=512 count=1 iflag=fullblock
110
111 log_must zfs snapshot $TESTPOOL/$TESTFS2@snap2
112 expected_cksum=$(recursive_cksum /$TESTPOOL/$TESTFS2)
113
114 log_must eval "zfs send -wp $TESTPOOL/$TESTFS2@snap1 > $sendfile"
115 log_must eval "zfs send -wp -i @snap1 $TESTPOOL/$TESTFS2@snap2 > $sendfile2"
116
117 log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile"
118 log_must eval "zfs recv -F $TESTPOOL/recv < $sendfile2"
119 log_must zfs load-key $TESTPOOL/recv
120
121 log_must zfs mount -a
122 actual_cksum=$(recursive_cksum /$TESTPOOL/recv)
123 [[ "$expected_cksum" != "$actual_cksum" ]] && \
124         log_fail "Recursive checksums differ ($expected_cksum != $actual_cksum)"
125
126 log_pass "Verified 'zfs send -w' works with many different file layouts"