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 send size estimates of redacted sends work correctly
23#
24# Strategy:
25# 1. Perform a redacted send with -nv and without, and verify the
26#    size estimate is the same as the size of the actual send.
27# 2. Receive an incremental send from the redaction bookmark with
28#    -nv and without, and verify the size estimate is the same as
29#    the size of the actual send.
30#
31
32ds_name="sizes"
33typeset sendfs="$POOL/$ds_name"
34typeset clone="$POOL/${ds_name}_clone2"
35setup_dataset $ds_name "-o compress=lz4"
36typeset tmpdir="$(get_prop mountpoint $POOL)/tmp"
37typeset size=$(mktemp $tmpdir/size.XXXX)
38typeset size2=$(mktemp $tmpdir/size.XXXX)
39
40log_onexit redacted_cleanup $sendfs $clone
41log_must zfs clone $sendfs@snap $clone
42typeset clone_mnt="$(get_prop mountpoint $clone)"
43log_must rm -rf $clone_mnt/*
44log_must zfs snapshot $clone@snap
45log_must zfs redact $sendfs@snap book $clone@snap
46log_must eval "zfs send -nvP --redact book $sendfs@snap | awk '/^size/ {print \$2}' >$size"
47log_must eval "zfs send --redact book $sendfs@snap | wc -c >$size2"
48read -r bytes1 < $size
49read -r bytes2 < $size2
50[ "$bytes1" -eq "$bytes2" ] || \
51    log_fail "Full sizes differ: estimate $bytes1 and actual $bytes2"
52
53log_must zfs snapshot $sendfs@snap2
54log_must eval "zfs send -nvP -i $sendfs#book $sendfs@snap2 | awk '/^size/ {print \$2}' >$size"
55log_must eval "zfs send -i $sendfs#book $sendfs@snap2 | wc -c >$size2"
56read -r bytes1 < $size
57read -r bytes2 < $size2
58[ "$bytes1" -eq "$bytes2" ] || \
59    log_fail "Incremental sizes differ: estimate $bytes1 and actual $bytes2"
60
61log_pass "Size estimates of redacted sends estimate accurately."
62