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# 24# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26 27. $STF_SUITE/include/libtest.kshlib 28 29################################################################################# 30# 31# __stc_assertion_start 32# 33# ID: zfs_receive_006_pos 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# TESTABILITY: explicit 49# 50# TEST_AUTOMATION_LEVEL: automated 51# 52# CODING_STATUS: COMPLETED (2006-10-13) 53# 54# __stc_assertion_end 55# 56################################################################################ 57 58verify_runnable "both" 59 60function cleanup 61{ 62 for snap in $snap2 $snap1; do 63 datasetexists $snap && log_must $ZFS destroy -rf $snap 64 done 65 for file in $fbackup1 $fbackup2 $mntpnt/file1 $mntpnt/file2; do 66 [[ -f $file ]] && log_must $RM -f $file 67 done 68 69 if is_global_zone; then 70 datasetexists $TESTPOOL/$TESTFS/$TESTFS1 && \ 71 log_must $ZFS destroy -rf $TESTPOOL/$TESTFS/$TESTFS1 72 else 73 datasetexists $TESTPOOL/${ZONE_CTR}0 && \ 74 log_must $ZFS destroy -rf $TESTPOOL/${ZONE_CTR}0 75 fi 76 77} 78 79log_assert "'zfs recv -d <fs>' should succeed no matter ancestor filesystem \ 80 exists." 81log_onexit cleanup 82 83ancestor_fs=$TESTPOOL/$TESTFS 84fs=$TESTPOOL/$TESTFS/$TESTFS1 85snap1=$fs@snap1 86snap2=$fs@snap2 87fbackup1=$TMPDIR/fbackup1.${TESTCASE_ID} 88fbackup2=$TMPDIR/fbackup2.${TESTCASE_ID} 89 90datasetexists $ancestor_fs || \ 91 log_must $ZFS create $ancestor_fs 92log_must $ZFS create $fs 93 94mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs" 95log_must $MKFILE 10m $mntpnt/file1 96log_must $ZFS snapshot $snap1 97log_must $MKFILE 10m $mntpnt/file2 98log_must $ZFS snapshot $snap2 99 100log_must eval "$ZFS send $snap1 > $fbackup1" 101log_must eval "$ZFS send $snap2 > $fbackup2" 102 103log_note "Verify 'zfs receive -d' succeed and create ancestor filesystem \ 104 if it did not exist. " 105log_must $ZFS destroy -rf $ancestor_fs 106log_must eval "$ZFS receive -d $TESTPOOL < $fbackup1" 107is_global_zone || ancestor_fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS 108datasetexists $ancestor_fs || \ 109 log_fail "ancestor filesystem is not created" 110 111log_note "Verify 'zfs receive -d' still succeed if ancestor filesystem exists" 112is_global_zone || fs=$TESTPOOL/${ZONE_CTR}0/$TESTFS/$TESTFS1 113log_must $ZFS destroy -rf $fs 114log_must eval "$ZFS receive -d $TESTPOOL < $fbackup2" 115 116log_pass "'zfs recv -d <fs>' should succeed no matter ancestor filesystem \ 117 exists." 118