]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zfs_receive/zfs_receive_014_pos.ksh
Fix dsl_props_set_sync_impl to work with nested nvlist
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zfs_receive / zfs_receive_014_pos.ksh
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 2016, 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
39 verify_runnable "both"
40
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.$$
48
49 function 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 #
66 function 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
83 log_assert "ZFS successfully receive and restore properties."
84 log_onexit cleanup
85
86 # 1. Create a filesystem.
87 log_must eval "$ZFS create $orig"
88 mntpnt=$(get_prop mountpoint $orig)
89
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"
98
99 # 3. Create also an incremental stream without some properties and a truncated
100 #    stream.
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"
109
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"
115
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' '-' '-'"
121
122 log_pass "ZFS properties are successfully received and restored."