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