]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/rsend/send_mixed_raw.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / rsend / send_mixed_raw.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 # Copyright (c) 2019 Datto, Inc. All rights reserved.
18 #
19
20 . $STF_SUITE/include/libtest.shlib
21
22 #
23 # DESCRIPTION:
24 #       Verify that 'zfs receive' produces an error when mixing
25 #       raw and non-raw sends in a way that would break IV set
26 #       consistency.
27 #
28 # STRATEGY:
29 #       1. Create an initial dataset with 3 snapshots.
30 #       2. Perform a raw send of the first snapshot to 2 other datasets.
31 #       3. Perform a non-raw send of the second snapshot to one of
32 #          the other datasets. Perform a raw send from this dataset to
33 #          the last one.
34 #       4. Attempt to raw send the final snapshot of the first dataset
35 #          to the other 2 datasets, which should fail.
36 #       5. Repeat steps 1-4, but using bookmarks for incremental sends.
37 #
38 #
39 # A                 B             C     notes
40 # ------------------------------------------------------------------------------
41 # snap1 ---raw---> snap1 --raw--> snap1 # all snaps initialized via raw send
42 # snap2 -non-raw-> snap2 --raw--> snap2 # A sends non-raw to B, B sends raw to C
43 # snap3 ------------raw---------> snap3 # attempt send to C (should fail)
44 #
45
46
47 verify_runnable "both"
48
49 function cleanup
50 {
51     datasetexists $TESTPOOL/$TESTFS3 && \
52         log_must zfs destroy -r $TESTPOOL/$TESTFS3
53     datasetexists $TESTPOOL/$TESTFS2 && \
54         log_must zfs destroy -r $TESTPOOL/$TESTFS2
55     datasetexists $TESTPOOL/$TESTFS1 && \
56         log_must zfs destroy -r $TESTPOOL/$TESTFS1
57 }
58 log_onexit cleanup
59
60 log_assert "Mixing raw and non-raw receives should fail"
61
62 typeset passphrase="password"
63
64 log_must eval "echo $passphrase | zfs create -o encryption=on" \
65     "-o keyformat=passphrase  $TESTPOOL/$TESTFS1"
66
67 log_must zfs snapshot $TESTPOOL/$TESTFS1@1
68 log_must touch /$TESTPOOL/$TESTFS1/a
69 log_must zfs snapshot $TESTPOOL/$TESTFS1@2
70 log_must touch /$TESTPOOL/$TESTFS1/b
71 log_must zfs snapshot $TESTPOOL/$TESTFS1@3
72
73 # Testing with snapshots
74 log_must eval "zfs send -w $TESTPOOL/$TESTFS1@1 |" \
75     "zfs receive $TESTPOOL/$TESTFS2"
76 log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS2"
77 log_must eval "zfs send -w $TESTPOOL/$TESTFS2@1 |" \
78     "zfs receive $TESTPOOL/$TESTFS3"
79 log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS3"
80
81 log_must eval "zfs send -i $TESTPOOL/$TESTFS1@1 $TESTPOOL/$TESTFS1@2 |" \
82     "zfs receive $TESTPOOL/$TESTFS2"
83 log_must eval "zfs send -w -i $TESTPOOL/$TESTFS2@1 $TESTPOOL/$TESTFS2@2 |" \
84     "zfs receive $TESTPOOL/$TESTFS3"
85
86 log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS1@2 $TESTPOOL/$TESTFS1@3 |" \
87     "zfs receive $TESTPOOL/$TESTFS2"
88 log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS2@2 $TESTPOOL/$TESTFS2@3 |" \
89     "zfs receive $TESTPOOL/$TESTFS3"
90
91 log_must zfs destroy -r $TESTPOOL/$TESTFS3
92 log_must zfs destroy -r $TESTPOOL/$TESTFS2
93
94 # Testing with bookmarks
95 log_must zfs bookmark $TESTPOOL/$TESTFS1@1 $TESTPOOL/$TESTFS1#b1
96 log_must zfs bookmark $TESTPOOL/$TESTFS1@2 $TESTPOOL/$TESTFS1#b2
97
98 log_must eval "zfs send -w $TESTPOOL/$TESTFS1@1 |" \
99     "zfs receive $TESTPOOL/$TESTFS2"
100 log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS2"
101
102 log_must zfs bookmark $TESTPOOL/$TESTFS2@1 $TESTPOOL/$TESTFS2#b1
103
104 log_must eval "zfs send -w $TESTPOOL/$TESTFS2@1 |" \
105     "zfs receive $TESTPOOL/$TESTFS3"
106 log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS3"
107
108 log_must eval "zfs send -i $TESTPOOL/$TESTFS1#b1 $TESTPOOL/$TESTFS1@2 |" \
109     "zfs receive $TESTPOOL/$TESTFS2"
110 log_must eval "zfs send -w -i $TESTPOOL/$TESTFS2#b1 $TESTPOOL/$TESTFS2@2 |" \
111     "zfs receive $TESTPOOL/$TESTFS3"
112
113 log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS1#b2" \
114     "$TESTPOOL/$TESTFS1@3 | zfs receive $TESTPOOL/$TESTFS2"
115 log_mustnot eval "zfs send -w -i $TESTPOOL/$TESTFS2#b2" \
116     "$TESTPOOL/$TESTFS2@3 | zfs receive $TESTPOOL/$TESTFS3"
117
118 log_pass "Mixing raw and non-raw receives fail as expected"