1*5602294fSDan Kimmel#!/usr/bin/ksh
2*5602294fSDan Kimmel
3*5602294fSDan Kimmel#
4*5602294fSDan Kimmel# This file and its contents are supplied under the terms of the
5*5602294fSDan Kimmel# Common Development and Distribution License ("CDDL"), version 1.0.
6*5602294fSDan Kimmel# You may only use this file in accordance with the terms of version
7*5602294fSDan Kimmel# 1.0 of the CDDL.
8*5602294fSDan Kimmel#
9*5602294fSDan Kimmel# A full copy of the text of the CDDL should have accompanied this
10*5602294fSDan Kimmel# source.  A copy of the CDDL is also available via the Internet at
11*5602294fSDan Kimmel# http://www.illumos.org/license/CDDL.
12*5602294fSDan Kimmel#
13*5602294fSDan Kimmel
14*5602294fSDan Kimmel#
15*5602294fSDan Kimmel# Copyright (c) 2015 by Delphix. All rights reserved.
16*5602294fSDan Kimmel#
17*5602294fSDan Kimmel
18*5602294fSDan Kimmel. $STF_SUITE/tests/functional/rsend/rsend.kshlib
19*5602294fSDan Kimmel
20*5602294fSDan Kimmel#
21*5602294fSDan Kimmel# Description:
22*5602294fSDan Kimmel# Verify a pool without the lz4 feature gracefully rejects a compressed stream
23*5602294fSDan Kimmel# because on any sending pool that supports it, metadata will be compressed
24*5602294fSDan Kimmel# with lz4 even if user data is not compressed.
25*5602294fSDan Kimmel#
26*5602294fSDan Kimmel# Strategy:
27*5602294fSDan Kimmel# 1. For each of an uncompressed, gzip and lz4 dataset, do the following
28*5602294fSDan Kimmel#    receives into a pool without the lz4 feature:
29*5602294fSDan Kimmel# 2. Attempt to receive the compressed stream (should fail)
30*5602294fSDan Kimmel# 3. Attempt to receive the uncompressed stream (should succeed)
31*5602294fSDan Kimmel#
32*5602294fSDan Kimmel
33*5602294fSDan Kimmelverify_runnable "both"
34*5602294fSDan Kimmel
35*5602294fSDan Kimmellog_assert "Verify compressed streams are rejected if incompatible."
36*5602294fSDan Kimmel
37*5602294fSDan Kimmeltypeset compress_types="off gzip lz4"
38*5602294fSDan Kimmeltypeset send_ds=$POOL2/testds
39*5602294fSDan Kimmeltypeset recv_ds=$POOL3/testds
40*5602294fSDan Kimmel
41*5602294fSDan Kimmelfunction cleanup
42*5602294fSDan Kimmel{
43*5602294fSDan Kimmel	poolexists $POOL2 && destroy_pool $POOL2
44*5602294fSDan Kimmel	poolexists $POOL3 && destroy_pool $POOL3
45*5602294fSDan Kimmel	log_must zpool create $POOL2 $DISK2
46*5602294fSDan Kimmel}
47*5602294fSDan Kimmellog_onexit cleanup
48*5602294fSDan Kimmel
49*5602294fSDan Kimmeldatasetexists $POOL3 && log_must zpool destroy $POOL3
50*5602294fSDan Kimmellog_must zpool create -d $POOL3 $DISK3
51*5602294fSDan Kimmel
52*5602294fSDan Kimmelfor compress in $compress_types; do
53*5602294fSDan Kimmel	datasetexists $send_ds && log_must zfs destroy -r $send_ds
54*5602294fSDan Kimmel	datasetexists $recv_ds && log_must zfs destroy -r $recv_ds
55*5602294fSDan Kimmel
56*5602294fSDan Kimmel	log_must zfs create -o compress=$compress $send_ds
57*5602294fSDan Kimmel	typeset dir=$(get_prop mountpoint $send_ds)
58*5602294fSDan Kimmel	write_compressible $dir 16m
59*5602294fSDan Kimmel	log_must zfs snapshot $send_ds@full
60*5602294fSDan Kimmel
61*5602294fSDan Kimmel	log_must eval "zfs send -c $send_ds@full >$BACKDIR/full-c"
62*5602294fSDan Kimmel	log_mustnot eval "zfs recv $recv_ds <$BACKDIR/full-c"
63*5602294fSDan Kimmel
64*5602294fSDan Kimmel	log_must eval "zfs send $send_ds@full >$BACKDIR/full"
65*5602294fSDan Kimmel	log_must eval "zfs recv $recv_ds <$BACKDIR/full"
66*5602294fSDan Kimmeldone
67*5602294fSDan Kimmel
68*5602294fSDan Kimmellog_pass "Compressed streams are rejected if incompatible."
69