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 embedded blocks and redacted send work correctly together. 23# 24# Strategy: 25# 1. Create recsize sized files with embedded blocks from size 512b to 16k. 26# 2. Receive a redacted send stream with nothing redacted. 27# 3. Verify the received files match the source, contain embedded blocks, and 28# that the stream has the redacted and embedded data features. 29# 4. Receive a redacted send stream with files 512, 2048 and 8192 redacted. 30# 5. Verify that the redacted files no longer match, but the others still 31# contain embedded blocks and the stream has the redacted and embedded 32# data features. 33# 34 35typeset ds_name="embedded" 36typeset sendfs="$POOL/$ds_name" 37typeset recvfs="$POOL2/$ds_name" 38typeset clone="$POOL/${ds_name}_clone" 39typeset tmpdir="$(get_prop mountpoint $POOL)/tmp" 40typeset stream=$(mktemp $tmpdir/stream.XXXX) 41setup_dataset $ds_name '-o compress=lz4' setup_embedded 42typeset clone_mnt="$(get_prop mountpoint $clone)" 43typeset send_mnt="$(get_prop mountpoint $sendfs)" 44typeset recv_mnt="/$POOL2/$ds_name" 45typeset recsize send_obj recv_obj 46 47log_onexit redacted_cleanup $sendfs $recvfs 48 49log_must zfs redact $sendfs@snap book1 $clone@snap 50log_must eval "zfs send -e --redact book1 $sendfs@snap >$stream" 51log_must eval "zfs recv $recvfs <$stream" 52log_must stream_has_features $stream redacted embed_data 53 54log_must mount_redacted -f $recvfs 55for recsize in 512 1024 2048 4096 8192 16384; do 56 send_obj=$(get_objnum $send_mnt/$recsize) 57 recv_obj=$(get_objnum $recv_mnt/$recsize) 58 59 log_must diff $send_mnt/$recsize $recv_mnt/$recsize 60 log_must eval "zdb -ddddd $sendfs $send_obj >$tmpdir/send.zdb" 61 log_must eval "zdb -ddddd $recvfs $recv_obj >$tmpdir/recv.zdb" 62 63 log_must grep -q "EMBEDDED" $tmpdir/send.zdb 64 log_must grep -q "EMBEDDED" $tmpdir/recv.zdb 65 66 log_must eval "zstream dump -v $stream | grep -q \"WRITE_EMBEDDED object = $send_obj offset = 0\"" 67done 68 69log_must zfs destroy -R $recvfs 70for recsize in 512 2048 8192; do 71 log_must dd if=/dev/urandom of=$clone_mnt/$recsize bs=$recsize count=1 72done 73log_must zfs snapshot $clone@snap1 74log_must zfs redact $sendfs@snap book2 $clone@snap1 75log_must eval "zfs send -e --redact book2 $sendfs@snap >$stream" 76log_must eval "zfs recv $recvfs <$stream" 77log_must stream_has_features $stream redacted embed_data 78 79log_must mount_redacted -f $recvfs 80for recsize in 512 2048 8192; do 81 log_mustnot diff $send_mnt/$recsize $recv_mnt/$recsize 82done 83for recsize in 1024 4096 16384; do 84 send_obj=$(get_objnum $send_mnt/$recsize) 85 recv_obj=$(get_objnum $recv_mnt/$recsize) 86 87 log_must diff $send_mnt/$recsize $recv_mnt/$recsize 88 log_must eval "zdb -ddddd $sendfs $send_obj >$tmpdir/send.zdb" 89 log_must eval "zdb -ddddd $recvfs $recv_obj >$tmpdir/recv.zdb" 90 91 log_must grep -q "EMBEDDED" $tmpdir/send.zdb 92 log_must grep -q "EMBEDDED" $tmpdir/recv.zdb 93 94 log_must eval "zstream dump -v $stream | log_must grep -q \"WRITE_EMBEDDED object = $send_obj offset = 0\"" 95done 96 97log_pass "Embedded blocks and redacted send work correctly together." 98