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 2007 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28#
29# ident	"@(#)zfs_receive_006_pos.ksh	1.2	07/01/09 SMI"
30#
31
32. $STF_SUITE/include/libtest.kshlib
33
34#################################################################################
35#
36# __stc_assertion_start
37#
38# ID: zfs_receive_006_pos
39#
40# DESCRIPTION:
41#	'zfs recv -d <fs>' should create ancestor filesystem if it does not
42#   exist and it should not fail if it exists
43#
44# STRATEGY:
45#	1. Create pool and fs.
46#	2. Create some files in fs and take snapshots.
47#	3. Keep the stream and restore the stream to the pool
48#	4. Verify receiving the stream succeeds, and the ancestor filesystem
49#	   is created if it did not exist
50#	5. Verify receiving the stream still succeeds when ancestor filesystem
51#	   exists
52#
53# TESTABILITY: explicit
54#
55# TEST_AUTOMATION_LEVEL: automated
56#
57# CODING_STATUS: COMPLETED (2006-10-13)
58#
59# __stc_assertion_end
60#
61################################################################################
62
63verify_runnable "both"
64
65function cleanup
66{
67	for snap in $snap2 $snap1; do
68		datasetexists $snap && log_must $ZFS destroy -rf $snap
69	done
70	for file in $fbackup1 $fbackup2 $mntpnt/file1 $mntpnt/file2; do
71		[[ -f $file ]] && log_must $RM -f $file
72	done
73
74	if is_global_zone; then
75		datasetexists $TESTPOOL/$TESTFS/$TESTFS1 && \
76			log_must $ZFS destroy -rf $TESTPOOL/$TESTFS/$TESTFS1
77	else
78		datasetexists $TESTPOOL/${ZONE_CTR}0 && \
79			log_must $ZFS destroy -rf $TESTPOOL/${ZONE_CTR}0
80	fi
81
82}
83
84log_assert "'zfs recv -d <fs>' should succeed no matter ancestor filesystem \
85	exists."
86log_onexit cleanup
87
88ancestor_fs=$TESTPOOL/$TESTFS
89fs=$TESTPOOL/$TESTFS/$TESTFS1
90snap1=$fs@snap1
91snap2=$fs@snap2
92fbackup1=$TMPDIR/fbackup1.${TESTCASE_ID}
93fbackup2=$TMPDIR/fbackup2.${TESTCASE_ID}
94
95datasetexists $ancestor_fs || \
96	log_must $ZFS create $ancestor_fs
97log_must $ZFS create $fs
98
99mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs"
100log_must $MKFILE 10m $mntpnt/file1
101log_must $ZFS snapshot $snap1
102log_must $MKFILE 10m $mntpnt/file2
103log_must $ZFS snapshot $snap2
104
105log_must eval "$ZFS send $snap1 > $fbackup1"
106log_must eval "$ZFS send $snap2 > $fbackup2"
107
108log_note "Verify 'zfs receive -d' succeed and create ancestor filesystem \
109	 if it did not exist. "
110log_must $ZFS destroy -rf $ancestor_fs
111log_must eval "$ZFS receive -d $TESTPOOL < $fbackup1"
112is_global_zone || ancestor_fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS
113datasetexists $ancestor_fs || \
114	log_fail "ancestor filesystem is not created"
115
116log_note "Verify 'zfs receive -d' still succeed if ancestor filesystem exists"
117is_global_zone || fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS/$TESTFS1
118log_must $ZFS destroy -rf $fs
119log_must eval "$ZFS receive -d $TESTPOOL < $fbackup2"
120
121log_pass "'zfs recv -d <fs>' should succeed no matter ancestor filesystem \
122	exists."
123