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 https://opensource.org/licenses/CDDL-1.0. 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/tests/functional/cli_root/cli_common.kshlib 33 34# 35# DESCRIPTION: 36# Verify 'zfs receive' fails with unsupported scenarios. 37# including: 38# (1) Invalid send streams; 39# (2) The received incremental send doesn't match the filesystem 40# latest status. 41# 42# STRATEGY: 43# 1. Preparation for unsupported scenarios 44# 2. Execute 'zfs receive' 45# 3. Verify the results are failed 46# 47 48verify_runnable "both" 49 50function cleanup 51{ 52 typeset snap 53 typeset bkup 54 55 for snap in $init_snap $inc_snap; do 56 snapexists $snap && destroy_dataset $snap -f 57 done 58 59 datasetexists $rst_root && destroy_dataset $rst_root -Rf 60 61 for bkup in $full_bkup $inc_bkup; do 62 [[ -e $bkup ]] && \ 63 log_must rm -f $bkup 64 done 65} 66 67log_assert "Verify 'zfs receive' fails with unsupported scenarios." 68log_onexit cleanup 69 70init_snap=$TESTPOOL/$TESTFS@initsnap 71inc_snap=$TESTPOOL/$TESTFS@incsnap 72rst_root=$TESTPOOL/rst_ctr 73rst_init_snap=$rst_root/$TESTFS@init_snap 74rst_inc_snap=$rst_root/$TESTFS@inc_snap 75full_bkup=$TEST_BASE_DIR/full_bkup.$$ 76inc_bkup=$TEST_BASE_DIR/inc_bkup.$$ 77 78log_must zfs create $rst_root 79log_must zfs snapshot $init_snap 80log_must eval "zfs send $init_snap > $full_bkup" 81 82log_note "'zfs receive' fails with invalid send streams." 83log_mustnot eval "cat /dev/zero | zfs receive $rst_init_snap" 84log_mustnot eval "cat /dev/zero | zfs receive -d $rst_root" 85 86log_must eval "zfs receive $rst_init_snap < $full_bkup" 87 88log_note "Unmatched send stream with restoring filesystem" \ 89 " cannot be received." 90log_must zfs snapshot $inc_snap 91log_must eval "zfs send -i $init_snap $inc_snap > $inc_bkup" 92#make changes on the restoring filesystem 93log_must touch $ZFSROOT/$rst_root/$TESTFS/tmpfile 94log_mustnot eval "zfs receive $rst_inc_snap < $inc_bkup" 95log_mustnot eval "zfs receive -d $rst_root < $inc_bkup" 96 97log_pass "Unsupported scenarios to 'zfs receive' fail as expected." 98