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 incrementals (redacted and normal) work with redacted datasets. 23# 24# Strategy: 25# 1. Test normal incrementals from the original snap to a subset of the 26# redaction list. 27# 2. Test receipt of intermediate clones, and their children. 28# 3. Test receipt with origin snap specified by '-o origin='. 29# 4. Test incrementals from redaction bookmarks. 30# 31 32typeset ds_name="incrementals" 33typeset sendfs="$POOL/$ds_name" 34typeset recvfs="$POOL2/$ds_name" 35typeset clone="$POOL/${ds_name}_clone" 36typeset tmpdir="$(get_prop mountpoint $POOL)/tmp" 37typeset stream=$(mktemp $tmpdir/stream.XXXX) 38setup_dataset $ds_name '' setup_incrementals 39typeset clone_mnt="$(get_prop mountpoint $clone)" 40typeset send_mnt="$(get_prop mountpoint $sendfs)" 41typeset recv_mnt="/$POOL2/$ds_name" 42 43log_onexit redacted_cleanup $sendfs $recvfs $POOL2/rfs 44 45# Setup a redacted send using a redaction list at varying depth. 46log_must zfs redact $sendfs@snap0 book1 $POOL/rm@snap $POOL/stride3@snap \ 47 $POOL/stride5@snap 48log_must eval "zfs send --redact book1 $sendfs@snap0 >$stream" 49log_must eval "zfs receive $POOL2/rfs <$stream" 50 51# Verify receipt of normal incrementals to redaction list members. 52log_must eval "zfs send -i $sendfs@snap0 $POOL/stride3@snap >$stream" 53log_must eval "zfs recv $POOL2/rstride3 <$stream" 54log_must directory_diff /$POOL/stride3 /$POOL2/rstride3 55log_must eval "zfs send -i $sendfs@snap0 $POOL/stride5@snap >$stream" 56log_must eval "zfs recv $POOL2/rstride5 <$stream" 57log_must directory_diff /$POOL/stride5 /$POOL2/rstride5 58 59# But not a normal child that we weren't redacted with respect to. 60log_must eval "zfs send -i $sendfs@snap0 $POOL/hole@snap >$stream" 61log_mustnot eval "zfs recv $POOL2/rhole@snap <$stream" 62 63# Verify we can receive an intermediate clone redacted with respect to a 64# subset of the original redaction list. 65log_must zfs redact $POOL/int@snap book2 $POOL/rm@snap 66log_must eval "zfs send -i $sendfs@snap0 --redact book2 $POOL/int@snap >$stream" 67log_must eval "zfs recv $POOL2/rint <$stream" 68compare_files $POOL/int $POOL2/rint "f1" "$RANGE0" 69compare_files $POOL/int $POOL2/rint "f2" "$RANGE15" 70compare_files $POOL/int $POOL2/rint "d1/f1" "$RANGE16" 71log_must mount_redacted -f $POOL2/rint 72 73# Verify we can receive grandchildren on the child. 74log_must eval "zfs send -i $POOL/int@snap $POOL/rm@snap >$stream" 75log_must eval "zfs receive $POOL2/rrm <$stream" 76log_must directory_diff /$POOL/rm /$POOL2/rrm 77 78# But not a grandchild that the received child wasn't redacted with respect to. 79log_must eval "zfs send -i $POOL/int@snap $POOL/write@snap >$stream" 80log_mustnot eval "zfs recv $POOL2/rwrite<$stream" 81 82# Verify we cannot receive an intermediate clone that isn't redacted with 83# respect to a subset of the original redaction list. 84log_must zfs redact $POOL/int@snap book4 $POOL/rm@snap $POOL/write@snap 85log_must eval "zfs send -i $sendfs@snap0 --redact book4 $POOL/int@snap >$stream" 86log_mustnot eval "zfs recv $POOL2/rint <$stream" 87log_must zfs redact $POOL/int@snap book5 $POOL/write@snap 88log_must eval "zfs send -i $sendfs@snap0 --redact book5 $POOL/int@snap >$stream" 89log_mustnot eval "zfs recv $POOL2/rint <$stream" 90log_mustnot zfs redact $POOL/int@snap book6 $POOL/hole@snap 91 92# Verify we can receive a full clone of the grandchild on the child. 93log_must eval "zfs send $POOL/write@snap >$stream" 94log_must eval "zfs recv -o origin=$POOL2/rint@snap $POOL2/rwrite <$stream" 95log_must directory_diff /$POOL/write /$POOL2/rwrite 96 97# Along with other origins. 98log_must eval "zfs recv -o origin=$POOL2/rfs@snap0 $POOL2/rwrite1 <$stream" 99log_must directory_diff /$POOL/write /$POOL2/rwrite1 100log_must eval "zfs recv -o origin=$POOL2@init $POOL2/rwrite2 <$stream" 101log_must directory_diff /$POOL/write /$POOL2/rwrite2 102log_must zfs destroy -R $POOL2/rwrite2 103 104log_must zfs destroy -R $POOL2/rfs 105 106# Write some data for tests of incremental sends from bookmarks 107log_must zfs snapshot $sendfs@snap1 108log_must zfs clone $sendfs@snap1 $POOL/hole1 109typeset mntpnt=$(get_prop mountpoint $POOL/hole1) 110log_must dd if=/dev/zero of=$mntpnt/f2 bs=128k count=16 conv=notrunc 111log_must zfs snapshot $POOL/hole1@snap 112log_must zfs clone $sendfs@snap1 $POOL/write1 113mntpnt=$(get_prop mountpoint $POOL/write1) 114log_must dd if=/dev/urandom of=$mntpnt/f2 bs=128k count=16 conv=notrunc 115log_must zfs snapshot $POOL/write1@snap 116log_must zfs clone $POOL/int@snap $POOL/write2 117mntpnt=$(get_prop mountpoint $POOL/write2) 118log_must dd if=/dev/urandom of=$mntpnt/f2 bs=128k count=16 conv=notrunc 119log_must zfs snapshot $POOL/write2@snap 120 121# Setup a redacted send using a redaction list at varying depth. 122log_must zfs redact $sendfs@snap0 book7 $POOL/rm@snap $POOL/stride3@snap \ 123 $POOL/stride5@snap 124log_must eval "zfs send --redact book7 $sendfs@snap0 >$stream" 125log_must eval "zfs receive $POOL2/rfs <$stream" 126 127# Verify we can receive a redacted incremental sending from the bookmark. 128log_must zfs redact $sendfs@snap1 book8 $POOL/write1@snap 129log_must eval "zfs send -i $sendfs#book7 --redact book8 $sendfs@snap1 >$stream" 130log_must eval "zfs receive $POOL2/rfs <$stream" 131# The stride3 and stride5 snaps redact 3 128k blocks at block offsets 0 15 and 132# 30 of f2. The write1 snap only covers the first two of those three blocks. 133compare_files $sendfs $POOL2/rfs "f2" "$RANGE12" 134log_must mount_redacted -f $POOL2/rfs 135log_must diff $send_mnt/f1 /$POOL2/rfs/f1 136log_must diff $send_mnt/d1/f1 /$POOL2/rfs/d1/f1 137unmount_redacted $POOL2/rfs 138 139# Verify we can receive a normal child we weren't redacted with respect to by 140# sending from the bookmark. 141log_must eval "zfs send -i $sendfs#book7 $POOL/hole1@snap >$stream" 142log_must eval "zfs recv $POOL2/rhole1 <$stream" 143log_must directory_diff /$POOL/hole1 /$POOL2/rhole1 144 145# Verify we can receive an intermediate clone redacted with respect to a 146# non-subset if we send from the bookmark. 147log_must zfs redact $POOL/int@snap book9 $POOL/write2@snap 148log_must eval "zfs send -i $sendfs#book7 --redact book9 $POOL/int@snap >$stream" 149log_must eval "zfs receive $POOL2/rint <$stream" 150compare_files $sendfs $POOL2/rint "f2" "$RANGE12" 151 152log_pass "Incrementals (redacted and normal) work with redacted datasets." 153