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) 2017, 2018 by Delphix. All rights reserved.
16#
17
18. $STF_SUITE/tests/functional/redacted_send/redacted.kshlib
19
20#
21# Description:
22# Verify redaction works as expected with respect to deleted files
23#
24# Strategy:
25# 1. A file on the delete queue counts as deleted when using it to calculate
26#    redaction.
27# 2. A file that is removed in the tosnap of an incremental, where the fromsnap
28#    is a redaction bookmark that contains references to that file, does not
29#    result in records for that file.
30#
31
32typeset ds_name="deleted"
33typeset sendfs="$POOL/$ds_name"
34typeset recvfs="$POOL2/$ds_name"
35typeset clone="$POOL/${ds_name}_clone"
36typeset clone2="$POOL/${ds_name}_clone2"
37typeset tmpdir="$(get_prop mountpoint $POOL)/tmp"
38typeset stream=$(mktemp $tmpdir/stream.XXXX)
39setup_dataset $ds_name ''
40typeset clone_mnt="$(get_prop mountpoint $clone)"
41typeset send_mnt="$(get_prop mountpoint $sendfs)"
42typeset recv_mnt="/$POOL2/$ds_name"
43
44log_onexit redacted_cleanup $sendfs $recvfs
45
46#
47# A file on the delete queue counts as deleted when using it to calculate
48# redaction.
49#
50
51#
52# Open file descriptor 5 for appending to $clone_mnt/f1 so that it will go on
53# the delete queue when we rm it.
54#
55exec 5>>$clone_mnt/f1
56log_must dd if=/dev/urandom of=$clone_mnt/f1 bs=512 count=1 conv=notrunc
57log_must rm $clone_mnt/f1
58log_must zfs snapshot $clone@snap1
59# Close file descriptor 5
60exec 5>&-
61log_must zfs redact $sendfs@snap book1 $clone@snap1
62log_must eval "zfs send --redact book1 $sendfs@snap >$stream"
63log_must eval "zfs recv $recvfs <$stream"
64log_must mount_redacted -f $recvfs
65#
66# We have temporarily disabled redaction blkptrs, so this will not
67# fail as was originally intended.  We should uncomment this line
68# when we re-enable redaction blkptrs.
69#
70#log_mustnot dd if=$recv_mnt/f1 of=/dev/null bs=512 count=1
71log_must diff $send_mnt/f2 $recv_mnt/f2
72log_must zfs rollback -R $clone@snap
73log_must zfs destroy -R $recvfs
74
75#
76# A file that is removed in the tosnap of an incremental, where the fromsnap
77# is a redaction bookmark that contains references to that file, does not
78# result in records for that file.
79#
80log_must zfs clone  $sendfs@snap $clone2
81typeset clone2_mnt="$(get_prop mountpoint $clone2)"
82log_must rm -rf $clone2_mnt/*
83log_must zfs snapshot $clone2@snap
84log_must zfs redact $sendfs@snap book2 $clone2@snap
85log_must zfs destroy -R $clone2
86log_must eval "zfs send --redact book2 $sendfs@snap >$stream"
87log_must eval "zfs recv $recvfs <$stream"
88log_must rm $send_mnt/f1
89log_must zfs snapshot $sendfs@snap2
90log_must zfs clone  $sendfs@snap2 $clone2
91typeset clone2_mnt="$(get_prop mountpoint $clone2)"
92log_must rm $clone2_mnt/*
93log_must zfs snapshot $clone2@snap
94log_must zfs redact $sendfs@snap2 book3 $clone2@snap
95log_must zfs destroy -R $clone2
96log_must eval "zfs send -i $sendfs#book2 --redact book3 $sendfs@snap2 >$stream"
97log_must eval "zfs recv $recvfs <$stream"
98log_must mount_redacted -f $recvfs
99log_must diff <(ls $send_mnt) <(ls $recv_mnt)
100log_must zfs destroy -R $recvfs
101log_must zfs rollback -R $sendfs@snap
102
103log_pass "Verify Redaction works as expected with respect to deleted files."
104