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
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.
18 # Copyright 2016, loli10K. All rights reserved.
21 . $STF_SUITE/include/libtest.shlib
22 . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
26 # Verify ZFS successfully receive and restore properties.
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
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.
39 verify_runnable "both"
41 orig=$TESTPOOL/$TESTFS1
42 dest=$TESTPOOL/$TESTFS2
43 typeset userprop=$(valid_user_property 8)
44 typeset userval=$(user_property_value 8)
45 typeset streamfile_full=/var/tmp/streamfile_full.$$
46 typeset streamfile_incr=/var/tmp/streamfile_incr.$$
47 typeset streamfile_trun=/var/tmp/streamfile_trun.$$
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
59 # Verify property $2 is set from source $4 on dataset $1 and has value $3.
66 function check_prop_source
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" ]]
83 log_assert "ZFS successfully receive and restore properties."
86 # 1. Create a filesystem.
87 log_must eval "$ZFS create $orig"
88 mntpnt=$(get_prop mountpoint $orig)
90 # 2. Create a full stream with properties and receive it.
91 log_must eval "$ZFS set compression='gzip-1' $orig"
92 log_must eval "$ZFS set '$userprop'='$userval' $orig"
93 log_must eval "$ZFS snapshot $orig@snap1"
94 log_must eval "$ZFS send -p $orig@snap1 > $streamfile_full"
95 log_must eval "$ZFS recv $dest < $streamfile_full"
96 log_must eval "check_prop_source $dest compression 'gzip-1' received"
97 log_must eval "check_prop_source $dest '$userprop' '$userval' received"
99 # 3. Create also an incremental stream without some properties and a truncated
101 log_must eval "$ZFS set compression='gzip-2' $orig"
102 log_must eval "$ZFS inherit '$userprop' $orig"
103 log_must eval "$DD if=/dev/urandom of=$mntpnt/file bs=1024k count=10"
104 log_must eval "$ZFS snapshot $orig@snap2"
105 log_must eval "$ZFS send -p -i $orig@snap1 $orig@snap2 > $streamfile_incr"
106 log_must eval "$DD if=$streamfile_incr of=$streamfile_trun bs=1024k count=9"
107 log_must eval "$ZFS snapshot $orig@snap3"
108 log_must eval "$ZFS send -p -i $orig@snap1 $orig@snap3 > $streamfile_incr"
110 # 4. Fail to receive the truncated incremental stream and verify previously
111 # received properties are still present.
112 log_mustnot eval "$ZFS recv -F $dest < $streamfile_trun"
113 log_must eval "check_prop_source $dest compression 'gzip-1' received"
114 log_must eval "check_prop_source $dest '$userprop' '$userval' received"
116 # 5. Receive the complete incremental send stream and verify that sent
117 # properties are successfully received.
118 log_must eval "$ZFS recv -F $dest < $streamfile_incr"
119 log_must eval "check_prop_source $dest compression 'gzip-2' received"
120 log_must eval "check_prop_source $dest '$userprop' '-' '-'"
122 log_pass "ZFS properties are successfully received and restored."