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) 2012, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/tests/functional/cli_root/cli_common.kshlib 33. $STF_SUITE/tests/functional/cli_root/zfs_send/zfs_send.cfg 34 35# 36# DESCRIPTION: 37# Verify 'zfs send' can generate valid streams with a property setup. 38# 39# STRATEGY: 40# 1. Setup property for filesystem 41# 2. Fill in some data into filesystem 42# 3. Create a full send streams 43# 4. Receive the send stream 44# 5. Verify the receive result 45# 46 47verify_runnable "both" 48 49function cleanup 50{ 51 snapexists $snap && destroy_dataset $snap 52 datasetexists $ctr && destroy_dataset $ctr -r 53 54 [[ -e $origfile ]] && \ 55 log_must rm -f $origfile 56 57 [[ -e $stream ]] && \ 58 log_must rm -f $stream 59} 60 61function do_testing # <prop> <prop_value> 62{ 63 typeset property=$1 64 typeset prop_val=$2 65 66 log_must zfs set $property=$prop_val $fs 67 file_write -o create -f $origfile -b $BLOCK_SIZE -c $WRITE_COUNT 68 log_must zfs snapshot $snap 69 log_must eval "zfs send $snap > $stream" 70 log_must eval "zfs receive -d $ctr <$stream" 71 72 #verify receive result 73 ! datasetexists $rstfs && \ 74 log_fail "'zfs receive' fails to restore $rstfs" 75 ! snapexists $rstfssnap && \ 76 log_fail "'zfs receive' fails to restore $rstfssnap" 77 if [[ ! -e $rstfile ]] || [[ ! -e $rstsnapfile ]]; then 78 log_fail " Data lost after receiving stream" 79 fi 80 81 compare_cksum $origfile $rstfile 82 compare_cksum $origsnapfile $rstsnapfile 83 84 #Destroy datasets and stream for next testing 85 log_must zfs destroy $snap 86 if is_global_zone ; then 87 log_must zfs destroy -r $rstfs 88 else 89 log_must zfs destroy -r $ds_path 90 fi 91 log_must rm -f $stream 92} 93 94log_assert "Verify 'zfs send' generates valid streams with a property setup" 95log_onexit cleanup 96 97fs=$TESTPOOL/$TESTFS 98snap=$fs@$TESTSNAP 99ctr=$TESTPOOL/$TESTCTR 100if is_global_zone; then 101 rstfs=$ctr/$TESTFS 102else 103 ds_path=$ctr/${ZONE_CTR}0 104 rstfs=$ds_path/$TESTFS 105fi 106rstfssnap=$rstfs@$TESTSNAP 107snapdir=".zfs/snapshot/$TESTSNAP" 108origfile=$TESTDIR/$TESTFILE1 109rstfile=/$rstfs/$TESTFILE1 110origsnapfile=$TESTDIR/$snapdir/$TESTFILE1 111rstsnapfile=/$rstfs/$snapdir/$TESTFILE1 112stream=$TEST_BASE_DIR/streamfile.$$ 113 114set -A props "compression" "checksum" "recordsize" 115set -A propval "on lzjb" "on fletcher2 fletcher4 sha256" \ 116 "512 1k 4k 8k 16k 32k 64k 128k" 117 118#Create a dataset to receive the send stream 119log_must zfs create $ctr 120 121typeset -i i=0 122while (( i < ${#props[*]} )) 123do 124 for value in ${propval[i]} 125 do 126 do_testing ${props[i]} $value 127 done 128 129 (( i = i + 1 )) 130done 131 132log_pass "'zfs send' generates streams with a property setup as expected." 133