xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_006_pos.ksh (revision 5f82aa32fbc5dc2c59bca6ff315f44a4c4c9ea86)
1#!/bin/ksh -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#
24# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
25# Use is subject to license terms.
26#
27
28#
29# Copyright (c) 2016 by Delphix. All rights reserved.
30#
31
32. $STF_SUITE/include/libtest.shlib
33
34#
35# DESCRIPTION:
36#	'zfs recv -d <fs>' should create ancestor filesystem if it does not
37#   exist and it should not fail if it exists
38#
39# STRATEGY:
40#	1. Create pool and fs.
41#	2. Create some files in fs and take snapshots.
42#	3. Keep the stream and restore the stream to the pool
43#	4. Verify receiving the stream succeeds, and the ancestor filesystem
44#	   is created if it did not exist
45#	5. Verify receiving the stream still succeeds when ancestor filesystem
46#	   exists
47#
48
49verify_runnable "both"
50
51function cleanup
52{
53	for snap in $snap2 $snap1; do
54		datasetexists $snap && log_must zfs destroy -rf $snap
55	done
56	for file in $fbackup1 $fbackup2 $mntpnt/file1 $mntpnt/file2; do
57		[[ -f $file ]] && log_must rm -f $file
58	done
59
60	if is_global_zone; then
61		datasetexists $TESTPOOL/$TESTFS/$TESTFS1 && \
62			log_must zfs destroy -rf $TESTPOOL/$TESTFS/$TESTFS1
63	else
64		datasetexists $TESTPOOL/${ZONE_CTR}0 && \
65			log_must zfs destroy -rf $TESTPOOL/${ZONE_CTR}0
66	fi
67
68}
69
70log_assert "'zfs recv -d <fs>' should succeed no matter ancestor filesystem \
71	exists."
72log_onexit cleanup
73
74ancestor_fs=$TESTPOOL/$TESTFS
75fs=$TESTPOOL/$TESTFS/$TESTFS1
76snap1=$fs@snap1
77snap2=$fs@snap2
78fbackup1=/var/tmp/fbackup1.$$
79fbackup2=/var/tmp/fbackup2.$$
80
81datasetexists $ancestor_fs || \
82	log_must zfs create $ancestor_fs
83log_must zfs create $fs
84
85mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs"
86log_must mkfile 10m $mntpnt/file1
87log_must zfs snapshot $snap1
88log_must mkfile 10m $mntpnt/file2
89log_must zfs snapshot $snap2
90
91log_must eval "zfs send $snap1 > $fbackup1"
92log_must eval "zfs send $snap2 > $fbackup2"
93
94log_note "Verify 'zfs receive -d' succeed and create ancestor filesystem \
95	 if it did not exist. "
96log_must zfs destroy -rf $ancestor_fs
97log_must eval "zfs receive -d $TESTPOOL < $fbackup1"
98is_global_zone || ancestor_fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS
99datasetexists $ancestor_fs || \
100	log_fail "ancestor filesystem is not created"
101
102log_note "Verify 'zfs receive -d' still succeed if ancestor filesystem exists"
103is_global_zone || fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS/$TESTFS1
104log_must zfs destroy -rf $fs
105log_must eval "zfs receive -d $TESTPOOL < $fbackup2"
106
107log_pass "'zfs recv -d <fs>' should succeed no matter ancestor filesystem \
108	exists."
109