]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/redacted_send/redacted_volume.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / redacted_send / redacted_volume.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) 2018 by Delphix. All rights reserved.
16 #
17
18 . $STF_SUITE/tests/functional/redacted_send/redacted.kshlib
19
20 #
21 # Description:
22 # Verify that redacted send works on volumes.
23 #
24 # Strategy:
25 # 1. Write to a volume, then make a clone of that volume.
26 # 2. Receive a redacted stream that sends all blocks.
27 # 3. Receive a redacted stream that redacts the first half of the written area.
28 #
29
30 typeset ds_name="volume"
31 typeset sendvol="$POOL/$ds_name"
32 typeset recvvol="$POOL2/$ds_name"
33 typeset clone="$POOL/${ds_name}_clone"
34 typeset tmpdir="$(get_prop mountpoint $POOL)/tmp"
35 typeset stream=$(mktemp $tmpdir/stream.XXXX)
36 typeset send_file="/dev/zvol/$sendvol"
37 typeset recv_file="/dev/zvol/$recvvol"
38 typeset clone_file="/dev/zvol/$clone"
39
40 log_onexit redacted_cleanup $sendvol $recvvol
41
42 log_must zfs create -b 8k -V 1g $sendvol
43 sleep 10
44 log_must zpool export $POOL
45 log_must zpool import $POOL
46 udevadm settle
47 if ! is_disk_device $send_file; then
48         udevadm settle
49         for t in 10 5 3 2 1; do
50                 log_note "Polling $t seconds for device file."
51                 udevadm settle
52                 sleep $t
53                 is_disk_device $send_file && break
54         done
55 fi
56 log_must dd if=/dev/urandom of=$send_file bs=8k count=64
57 log_must zfs snapshot $sendvol@snap
58 log_must zfs clone $sendvol@snap $clone
59 log_must zfs snapshot $clone@snap
60
61 log_must set_tunable32 ALLOW_REDACTED_DATASET_MOUNT 1
62 log_must zfs redact $sendvol@snap book1 $clone@snap
63 log_must eval "zfs send --redact book1 $sendvol@snap >$stream"
64 log_must eval "zfs recv $recvvol <$stream"
65 sleep 10
66 log_must zpool export $POOL2
67 log_must zpool import $POOL2
68 udevadm settle
69 if ! is_disk_device $recv_file; then
70         udevadm settle
71         for t in 10 5 3 2 1; do
72                 log_note "Polling $t seconds for device file."
73                 udevadm settle
74                 sleep $t
75                 is_disk_device $recv_file && break
76         done
77 fi
78 log_must dd if=$send_file of=$tmpdir/send.dd bs=8k count=64
79 log_must dd if=$recv_file of=$tmpdir/recv.dd bs=8k count=64
80 log_must diff $tmpdir/send.dd $tmpdir/recv.dd
81 log_must zfs destroy -R $recvvol
82
83 log_must dd if=/dev/urandom of=$clone_file bs=8k count=32
84 log_must zfs snapshot $clone@snap1
85 log_must zfs redact $sendvol@snap book2 $clone@snap1
86 log_must eval "zfs send --redact book2 $sendvol@snap >$stream"
87 log_must eval "zfs recv $recvvol <$stream"
88 sleep 10
89 log_must zpool export $POOL2
90 log_must zpool import $POOL2
91 udevadm settle
92 if ! is_disk_device $recv_file; then
93         udevadm settle
94         for t in 10 5 3 2 1; do
95                 log_note "Polling $t seconds for device file."
96                 udevadm settle
97                 sleep $t
98                 is_disk_device $recv_file && break
99         done
100 fi
101 log_must dd if=$send_file of=$tmpdir/send.dd bs=8k count=32 skip=32
102 log_must dd if=$recv_file of=$tmpdir/recv.dd bs=8k count=32 skip=32
103 log_must diff $tmpdir/send.dd $tmpdir/recv.dd
104
105 log_pass "Redacted send works correctly with volumes."