1#!/usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23# $FreeBSD$
24
25#
26# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)rsend_009_pos.ksh	1.1	08/02/27 SMI"
30#
31
32. $STF_SUITE/tests/rsend/rsend.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: rsend_009_pos
39#
40# DESCRIPTION:
41#	zfs receive can handle out of space correctly.
42#
43# STRATEGY:
44#	1. Create two pools, one is big and another is small.
45#	2. Fill the big pool with data.
46#	3. Take snapshot and backup the whole pool.
47#	4. Receive this stream in small pool.
48#	5. Verify zfs receive can handle the out of space error correctly.
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2007-10-10)
55#
56# __stc_assertion_end
57#
58################################################################################
59
60verify_runnable "global"
61
62function cleanup
63{
64	if datasetexists bpool ; then
65		log_must $ZPOOL destroy -f bpool
66	fi
67	if datasetexists spool ; then
68		log_must $ZPOOL destroy -f spool
69	fi
70}
71
72log_assert "Verify zfs receive can handle out of space correctly."
73log_onexit cleanup
74
75log_must $TRUNCATE -s 100M $TESTDIR/bfile
76log_must $TRUNCATE -s 64M  $TESTDIR/sfile
77log_must $ZPOOL create bpool $TESTDIR/bfile
78log_must $ZPOOL create spool $TESTDIR/sfile
79
80#
81# Test out of space on sub-filesystem
82#
83log_must $ZFS create bpool/fs
84mntpnt=$(get_prop mountpoint bpool/fs)
85log_must $TRUNCATE -s 30M $mntpnt/file
86
87log_must $ZFS snapshot bpool/fs@snap
88log_must eval "$ZFS send -R bpool/fs@snap > $BACKDIR/fs-R"
89log_mustnot eval "$ZFS receive -d -F spool < $BACKDIR/fs-R"
90
91log_must datasetnonexists spool/fs
92log_must ismounted spool
93
94#
95# Test out of space on top filesystem
96#
97mntpnt2=$(get_prop mountpoint bpool)
98log_must $MV $mntpnt/file $mntpnt2
99log_must $ZFS destroy -rf bpool/fs
100
101log_must $ZFS snapshot bpool@snap
102log_must eval "$ZFS send -R bpool@snap > $BACKDIR/bpool-R"
103log_mustnot eval "$ZFS receive -d -F spool < $BACKDIR/bpool-R"
104
105log_must datasetnonexists spool/fs
106log_must ismounted spool
107
108log_pass "zfs receive can handle out of space correctly."
109