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