1#!/bin/ksh
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 (c) 2013 by Delphix. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22
23#
24# DESCRIPTION:
25#       refquota limits the amount of space a dataset can consume,
26#       This test verifies that zfs receive does not override
27#       refquota.
28#
29# STRATEGY:
30#       1. Create a sub-filesystem $TESTSUBFS1
31#       2. Create a file in the sub-filesystem $TESTSUBFS1
32#       3. Create a snapshot of the sub-filesystem $TESTSUBFS1
33#       4. Create another sub-filesystem $TESTSUBFS2
34#       5. Apply a refquota value to $TESTSUBFS2,
35#		half the sub-filesystem $TESTSUBFS1 file size
36#       6. Verify that zfs receive of the snapshot of $TESTSUBFS1
37#		fails due to refquota
38#
39
40verify_runnable "both"
41
42oldvalue=$(get_tunable SPA_ASIZE_INFLATION)
43function cleanup
44{
45	set_tunable32 SPA_ASIZE_INFLATION $oldvalue
46        log_must zfs destroy -rf $TESTPOOL/$TESTFS
47        log_must zfs create $TESTPOOL/$TESTFS
48        log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
49}
50
51log_onexit cleanup
52
53set_tunable32 SPA_ASIZE_INFLATION 2
54
55TESTFILE='testfile'
56FS=$TESTPOOL/$TESTFS
57log_must zfs create $FS/$TESTSUBFS1
58log_must zfs create $FS/$TESTSUBFS2
59
60mntpnt1=$(get_prop mountpoint $FS/$TESTSUBFS1)
61mntpnt2=$(get_prop mountpoint $FS/$TESTSUBFS2)
62
63log_must mkfile 200M $mntpnt1/$TESTFILE
64log_must zfs snapshot $FS/$TESTSUBFS1@snap200m
65
66log_must zfs set refquota=10M $FS/$TESTSUBFS2
67log_mustnot eval "zfs send $FS/$TESTSUBFS1@snap200m |" \
68        "zfs receive -F $FS/$TESTSUBFS2"
69
70log_pass "ZFS receive does not override refquota"
71
72