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
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.
15 # Copyright (c) 2015 by Delphix. All rights reserved.
18 . $STF_SUITE/tests/functional/rsend/rsend.kshlib
19 . $STF_SUITE/include/properties.shlib
23 # Verify that compressed streams can contain embedded blocks.
26 # 1. Create a filesystem with compressible data and embedded blocks.
27 # 2. Verify the created streams can be received correctly.
28 # 3. Verify the presence / absence of embedded blocks in the compressed stream,
29 # as well as the receiving file system.
32 verify_runnable "both"
34 log_assert "Verify that compressed streams can contain embedded blocks."
35 log_onexit cleanup_pool $POOL2
37 typeset objs obj recsize
38 typeset sendfs=$POOL2/sendfs
39 typeset recvfs=$POOL2/recvfs
40 typeset stream=$BACKDIR/stream
41 typeset dump=$BACKDIR/dump
42 typeset recvfs2=$POOL2/recvfs2
43 typeset stream2=$BACKDIR/stream2
44 typeset dump2=$BACKDIR/dump2
45 log_must zfs create -o compress=lz4 $sendfs
46 log_must zfs create -o compress=lz4 $recvfs
47 log_must zfs create -o compress=lz4 $recvfs2
48 typeset dir=$(get_prop mountpoint $sendfs)
50 # Populate the send dataset with compressible data and embedded block files.
51 write_compressible $dir 16m
52 for recsize in "${recsize_prop_vals[@]}"; do
53 # For lz4, this method works for blocks up to 16k, but not larger
54 [[ $recsize -eq $((32 * 1024)) ]] && break
56 if is_linux || is_freebsd; then
57 log_must truncate -s $recsize $dir/$recsize
58 log_must dd if=/dev/urandom of=$dir/$recsize \
59 seek=$((recsize - 8)) bs=1 count=8 conv=notrunc
61 log_must mkholes -h 0:$((recsize - 8)) -d $((recsize - 8)):8 \
66 # Generate the streams and zstreamdump output.
67 log_must zfs snapshot $sendfs@now
68 log_must eval "zfs send -c $sendfs@now >$stream"
69 log_must eval "zstreamdump -v <$stream >$dump"
70 log_must eval "zfs recv -d $recvfs <$stream"
71 cmp_ds_cont $sendfs $recvfs
72 verify_stream_size $stream $sendfs
73 log_mustnot stream_has_features $stream embed_data
75 log_must eval "zfs send -c -e $sendfs@now >$stream2"
76 log_must eval "zstreamdump -v <$stream2 >$dump2"
77 log_must eval "zfs recv -d $recvfs2 <$stream2"
78 cmp_ds_cont $sendfs $recvfs2
79 verify_stream_size $stream2 $sendfs
80 log_must stream_has_features $stream2 embed_data
82 # Verify embedded blocks are present only when expected.
83 for recsize in "${recsize_prop_vals[@]}"; do
84 [[ $recsize -eq $((32 * 1024)) ]] && break
86 typeset send_obj=$(get_objnum $(get_prop mountpoint $sendfs)/$recsize)
87 typeset recv_obj=$(get_objnum \
88 $(get_prop mountpoint $recvfs/sendfs)/$recsize)
89 typeset recv2_obj=$(get_objnum \
90 $(get_prop mountpoint $recvfs2/sendfs)/$recsize)
92 log_must eval "zdb -ddddd $sendfs $send_obj >$BACKDIR/sendfs.zdb"
93 log_must eval "zdb -ddddd $recvfs/sendfs $recv_obj >$BACKDIR/recvfs.zdb"
94 log_must eval "zdb -ddddd $recvfs2/sendfs $recv2_obj >$BACKDIR/recvfs2.zdb"
96 grep -q "EMBEDDED" $BACKDIR/sendfs.zdb || \
97 log_fail "Obj $send_obj not embedded in $sendfs"
98 grep -q "EMBEDDED" $BACKDIR/recvfs.zdb || \
99 log_fail "Obj $recv_obj not embedded in $recvfs"
100 grep -q "EMBEDDED" $BACKDIR/recvfs2.zdb || \
101 log_fail "Obj $recv2_obj not embedded in $recvfs2"
103 grep -q "WRITE_EMBEDDED object = $send_obj offset = 0" $dump && \
104 log_fail "Obj $obj embedded in zstreamdump output"
105 grep -q "WRITE_EMBEDDED object = $send_obj offset = 0" $dump2 || \
106 log_fail "Obj $obj not embedded in zstreamdump output"
109 log_pass "Compressed streams can contain embedded blocks."