1#!/usr/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) 2015 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/tests/functional/rsend/rsend.kshlib
19. $STF_SUITE/include/properties.shlib
20
21#
22# Description:
23# Verify that compressed streams can contain embedded blocks.
24#
25# Strategy:
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.
30#
31
32verify_runnable "both"
33
34log_assert "Verify that compressed streams can contain embedded blocks."
35log_onexit cleanup_pool $POOL2
36
37typeset objs obj recsize
38typeset sendfs=$POOL2/sendfs
39typeset recvfs=$POOL2/recvfs
40typeset stream=$BACKDIR/stream
41typeset dump=$BACKDIR/dump
42typeset recvfs2=$POOL2/recvfs2
43typeset stream2=$BACKDIR/stream2
44typeset dump2=$BACKDIR/dump2
45log_must zfs create -o compress=lz4 $sendfs
46log_must zfs create -o compress=lz4 $recvfs
47log_must zfs create -o compress=lz4 $recvfs2
48typeset dir=$(get_prop mountpoint $sendfs)
49
50# Populate the send dataset with compressible data and embedded block files.
51write_compressible $dir 16m
52for 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
55
56	log_must mkholes -h 0:$((recsize - 8)) -d $((recsize - 8)):8 \
57	    $dir/$recsize
58done
59
60# Generate the streams and zstreamdump output.
61log_must zfs snapshot $sendfs@now
62log_must eval "zfs send -c $sendfs@now >$stream"
63log_must eval "zstreamdump -v <$stream >$dump"
64log_must eval "zfs recv -d $recvfs <$stream"
65cmp_ds_cont $sendfs $recvfs
66verify_stream_size $stream $sendfs
67log_mustnot stream_has_features $stream embed_data
68
69log_must eval "zfs send -c -e $sendfs@now >$stream2"
70log_must eval "zstreamdump -v <$stream2 >$dump2"
71log_must eval "zfs recv -d $recvfs2 <$stream2"
72cmp_ds_cont $sendfs $recvfs2
73verify_stream_size $stream2 $sendfs
74log_must stream_has_features $stream2 embed_data
75
76# Verify embedded blocks are present only when expected.
77for recsize in "${recsize_prop_vals[@]}"; do
78	[[ $recsize -eq $((32 * 1024)) ]] && break
79
80	typeset send_obj=$(get_objnum $(get_prop mountpoint $sendfs)/$recsize)
81	typeset recv_obj=$(get_objnum \
82	    $(get_prop mountpoint $recvfs/sendfs)/$recsize)
83	typeset recv2_obj=$(get_objnum \
84	    $(get_prop mountpoint $recvfs2/sendfs)/$recsize)
85
86	log_must eval "zdb -ddddd $sendfs $send_obj >$BACKDIR/sendfs.zdb"
87	log_must eval "zdb -ddddd $recvfs/sendfs $recv_obj >$BACKDIR/recvfs.zdb"
88	log_must eval "zdb -ddddd $recvfs2/sendfs $recv2_obj >$BACKDIR/recvfs2.zdb"
89
90	grep -q "EMBEDDED" $BACKDIR/sendfs.zdb || \
91	    log_fail "Obj $send_obj not embedded in $sendfs"
92	grep -q "EMBEDDED" $BACKDIR/recvfs.zdb || \
93	    log_fail "Obj $recv_obj not embedded in $recvfs"
94	grep -q "EMBEDDED" $BACKDIR/recvfs2.zdb || \
95	    log_fail "Obj $recv2_obj not embedded in $recvfs2"
96
97	grep -q "WRITE_EMBEDDED object = $send_obj offset = 0" $dump && \
98	    log_fail "Obj $obj embedded in zstreamdump output"
99	grep -q "WRITE_EMBEDDED object = $send_obj offset = 0" $dump2 || \
100	    log_fail "Obj $obj not embedded in zstreamdump output"
101done
102
103log_pass "Compressed streams can contain embedded blocks."
104