1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright 2015, OmniTI Computer Consulting, Inc. All rights reserved.
19#
20
21#
22# Copyright (c) 2016 by Delphix. All rights reserved.
23#
24
25. $STF_SUITE/include/libtest.shlib
26
27#
28# DESCRIPTION:
29#	refquota should be sent-and-received, but it should not interfere with
30#	the receipt of intermediate snapshots that may have preceded the
31#	final snapshot, where the refquota should hold.
32#
33# STRATEGY:
34#	1. Create a filesystem.
35#	2. Create two equal-sized large files.
36#	3. Snapshot the filesystem.
37#	4. Remove one of the two large files.
38#	5. Create a refquota larger than one file, but smaller than both.
39#	6. Snapshot the filesystem again.
40#	7. Send a replication stream of the second snapshot to a new filesystem.
41#
42#
43
44verify_runnable "both"
45
46typeset streamfile=/var/tmp/streamfile.$$
47
48function cleanup
49{
50	log_must rm $streamfile
51	log_must zfs destroy -rf $TESTPOOL/$TESTFS1
52	log_must zfs destroy -rf $TESTPOOL/$TESTFS2
53}
54
55log_assert "refquota is properly sent-and-received, regardless of any " \
56	"intermediate snapshots sent by a replication stream."
57log_onexit cleanup
58
59orig=$TESTPOOL/$TESTFS1
60dest=$TESTPOOL/$TESTFS2
61#	1. Create a filesystem.
62log_must zfs create $orig
63origdir=$(get_prop mountpoint $orig)
64
65#	2. Create two equal-sized large files.
66log_must mkfile 5M $origdir/file1
67log_must mkfile 5M $origdir/file2
68sync_all_pools
69
70#	3. Snapshot the filesystem.
71log_must zfs snapshot $orig@1
72
73#	4. Remove one of the two large files.
74log_must rm $origdir/file2
75sync_all_pools
76
77#	5. Create a refquota larger than one file, but smaller than both.
78log_must zfs set refquota=8M $orig
79
80#	6. Snapshot the filesystem again.
81log_must zfs snapshot $orig@2
82
83#	7. Send a replication stream of the second snapshot to a new filesystem.
84log_must eval "zfs send -R $orig@2 > $streamfile"
85log_must eval "zfs recv $dest < $streamfile"
86
87log_pass "refquota is properly sent-and-received, regardless of any " \
88	"intermediate snapshots sent by a replication stream."
89