]> git.proxmox.com Git - mirror_zfs.git/blob - tests/zfs-tests/tests/functional/rsend/send_realloc_encrypted_files.ksh
Fix send/recv lost spill block
[mirror_zfs.git] / tests / zfs-tests / tests / functional / rsend / send_realloc_encrypted_files.ksh
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) 2019 by Lawrence Livermore National Security, LLC.
16 #
17
18 . $STF_SUITE/include/libtest.shlib
19 . $STF_SUITE/tests/functional/rsend/rsend.kshlib
20
21 #
22 # Description:
23 # Verify encrypted raw incremental receives handle dnode reallocation.
24
25 # Strategy:
26 # 1. Create a pool containing an encrypted filesystem.
27 # 2. Use 'zfs send -wp' to perform a raw send of the initial filesystem.
28 # 3. Repeat the followings steps N times to verify raw incremental receives.
29 # a) Randomly change several key dataset properties.
30 # b) Modify the contents of the filesystem such that dnode reallocation
31 # is likely during the 'zfs receive', and receive_object() exercises
32 # as much of its functionality as possible.
33 # c) Create a new snapshot and generate an raw incremental stream.
34 # d) Receive the raw incremental stream and verify the received contents.
35 # e) Destroy the incremental stream and old snapshot.
36 #
37
38 verify_runnable "both"
39
40 log_assert "Verify encrypted raw incremental receive handles reallocation"
41
42 function cleanup
43 {
44 rm -f $BACKDIR/fs@*
45 rm -f $keyfile
46 destroy_dataset $POOL/fs "-rR"
47 destroy_dataset $POOL/newfs "-rR"
48 }
49
50 log_onexit cleanup
51
52 typeset keyfile=/$TESTPOOL/pkey
53
54 # Create an encrypted dataset
55 log_must eval "echo 'password' > $keyfile"
56 log_must zfs create -o encryption=on -o keyformat=passphrase \
57 -o keylocation=file://$keyfile $POOL/fs
58
59 last_snap=1
60 log_must zfs snapshot $POOL/fs@snap${last_snap}
61 log_must eval "zfs send -wp $POOL/fs@snap${last_snap} \
62 >$BACKDIR/fs@snap${last_snap}"
63 log_must eval "zfs recv $POOL/newfs < $BACKDIR/fs@snap${last_snap}"
64
65 # Set atime=off to prevent the recursive_cksum from modifying newfs.
66 log_must zfs set atime=off $POOL/newfs
67
68 # Due to reduced performance on debug kernels use fewer files by default.
69 if is_kmemleak; then
70 nr_files=100
71 passes=2
72 else
73 nr_files=1000
74 passes=3
75 fi
76
77 for i in {1..$passes}; do
78 # Randomly modify several dataset properties in order to generate
79 # more interesting incremental send streams.
80 rand_set_prop $POOL/fs checksum "off" "fletcher4" "sha256"
81 rand_set_prop $POOL/fs compression "off" "lzjb" "gzip" "lz4"
82 rand_set_prop $POOL/fs recordsize "32K" "128K"
83 rand_set_prop $POOL/fs dnodesize "legacy" "auto" "4k"
84 rand_set_prop $POOL/fs xattr "on" "sa"
85
86 # Churn the filesystem in such a way that we're likely to be both
87 # allocating and reallocating objects in the incremental stream.
88 log_must churn_files $nr_files 524288 $POOL/fs
89 expected_cksum=$(recursive_cksum /$POOL/fs)
90
91 # Create a snapshot and use it to send an incremental stream.
92 this_snap=$((last_snap + 1))
93 log_must zfs snapshot $POOL/fs@snap${this_snap}
94 log_must eval "zfs send -wp -i $POOL/fs@snap${last_snap} \
95 $POOL/fs@snap${this_snap} > $BACKDIR/fs@snap${this_snap}"
96
97 # Receive the incremental stream and verify the received contents.
98 log_must eval "zfs recv -Fu $POOL/newfs < $BACKDIR/fs@snap${this_snap}"
99
100 log_must zfs load-key $POOL/newfs
101 log_must zfs mount $POOL/newfs
102 actual_cksum=$(recursive_cksum /$POOL/newfs)
103 log_must zfs umount $POOL/newfs
104 log_must zfs unload-key $POOL/newfs
105
106 if [[ "$expected_cksum" != "$actual_cksum" ]]; then
107 log_fail "Checksums differ ($expected_cksum != $actual_cksum)"
108 fi
109
110 # Destroy the incremental stream and old snapshot.
111 rm -f $BACKDIR/fs@snap${last_snap}
112 log_must zfs destroy $POOL/fs@snap${last_snap}
113 log_must zfs destroy $POOL/newfs@snap${last_snap}
114 last_snap=$this_snap
115 done
116
117 log_pass "Verify encrypted raw incremental receive handles reallocation"