1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# This file and its contents are supplied under the terms of the 6# Common Development and Distribution License ("CDDL"), version 1.0. 7# You may only use this file in accordance with the terms of version 8# 1.0 of the CDDL. 9# 10# A full copy of the text of the CDDL should have accompanied this 11# source. A copy of the CDDL is also available via the Internet at 12# http://www.illumos.org/license/CDDL. 13# 14# CDDL HEADER END 15# 16 17# 18# Copyright 2017, loli10K. All rights reserved. 19# 20 21. $STF_SUITE/include/libtest.shlib 22. $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib 23 24# 25# DESCRIPTION: 26# Verify ZFS successfully receive and restore properties. 27# 28# STRATEGY: 29# 1. Create a filesystem. 30# 2. Create a full stream with properties and receive it. 31# 3. Create also an incremental stream without some properties and a truncated 32# stream. 33# 4. Fail to receive the truncated incremental stream and verify previously 34# received properties are still present. 35# 5. Receive the complete incremental send stream and verify that sent 36# properties are successfully received. 37# 38 39verify_runnable "both" 40 41orig=$TESTPOOL/$TESTFS1 42dest=$TESTPOOL/$TESTFS2 43typeset userprop=$(valid_user_property 8) 44typeset userval=$(user_property_value 8) 45typeset streamfile_full=$TESTDIR/streamfile_full.$$ 46typeset streamfile_incr=$TESTDIR/streamfile_incr.$$ 47typeset streamfile_trun=$TESTDIR/streamfile_trun.$$ 48 49function cleanup 50{ 51 log_must rm $streamfile_full 52 log_must rm $streamfile_incr 53 log_must rm $streamfile_trun 54 log_must zfs destroy -rf $orig 55 log_must zfs destroy -rf $dest 56} 57 58# 59# Verify property $2 is set from source $4 on dataset $1 and has value $3. 60# 61# $1 checked dataset 62# $2 user property 63# $3 property value 64# $4 source 65# 66function check_prop_source 67{ 68 typeset dataset=$1 69 typeset prop=$2 70 typeset value=$3 71 typeset source=$4 72 typeset chk_value=$(get_prop "$prop" "$dataset") 73 typeset chk_source=$(get_source "$prop" "$dataset") 74 if [[ "$chk_value" != "$value" || \ 75 "$chk_source" != "$4" ]] 76 then 77 return 1 78 else 79 return 0 80 fi 81} 82 83log_assert "ZFS successfully receive and restore properties." 84log_onexit cleanup 85 86# 1. Create a filesystem. 87log_must eval "zfs create $orig" 88mntpnt=$(get_prop mountpoint $orig) 89 90# 2. Create a full stream with properties and receive it. 91log_must eval "zfs set compression='gzip-1' $orig" 92log_must eval "zfs set '$userprop'='$userval' $orig" 93log_must eval "zfs snapshot $orig@snap1" 94log_must eval "zfs send -p $orig@snap1 > $streamfile_full" 95log_must eval "zfs recv $dest < $streamfile_full" 96log_must eval "check_prop_source $dest compression 'gzip-1' received" 97log_must eval "check_prop_source $dest '$userprop' '$userval' received" 98 99# 3. Create also an incremental stream without some properties and a truncated 100# stream. 101log_must eval "zfs set compression='gzip-2' $orig" 102log_must eval "zfs inherit '$userprop' $orig" 103log_must eval "dd if=/dev/urandom of=$mntpnt/file bs=1024k count=10" 104log_must eval "zfs snapshot $orig@snap2" 105log_must eval "zfs send -p -i $orig@snap1 $orig@snap2 > $streamfile_incr" 106log_must eval "dd if=$streamfile_incr of=$streamfile_trun bs=1024k count=9" 107log_must eval "zfs snapshot $orig@snap3" 108log_must eval "zfs send -p -i $orig@snap1 $orig@snap3 > $streamfile_incr" 109 110# 4. Fail to receive the truncated incremental stream and verify previously 111# received properties are still present. 112log_mustnot eval "zfs recv -F $dest < $streamfile_trun" 113log_must eval "check_prop_source $dest compression 'gzip-1' received" 114log_must eval "check_prop_source $dest '$userprop' '$userval' received" 115 116# 5. Receive the complete incremental send stream and verify that sent 117# properties are successfully received. 118log_must eval "zfs recv -F $dest < $streamfile_incr" 119log_must eval "check_prop_source $dest compression 'gzip-2' received" 120log_must eval "check_prop_source $dest '$userprop' '-' '-'" 121 122log_pass "ZFS properties are successfully received and restored." 123