]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/openzfs/tests/zfs-tests/tests/functional/rsend/rsend_012_pos.ksh
Update OpenZFS to 2.0.0-rc3-gfc5966
[FreeBSD/FreeBSD.git] / sys / contrib / openzfs / tests / zfs-tests / tests / functional / rsend / rsend_012_pos.ksh
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 http://www.opensolaris.org/os/licensing.
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 (c) 2009, Sun Microsystems Inc. All rights reserved.
25 # Copyright (c) 2013, 2016, Delphix. All rights reserved.
26 # Use is subject to license terms.
27 #
28
29 . $STF_SUITE/include/properties.shlib
30 . $STF_SUITE/tests/functional/rsend/rsend.kshlib
31
32 #
33 # DESCRIPTION:
34 #       zfs send -R will backup all the filesystem properties correctly.
35 #
36 # STRATEGY:
37 #       1. Setting properties for all the filesystem and volumes randomly
38 #       2. Backup all the data from POOL by send -R
39 #       3. Restore all the data in POOL2
40 #       4. Verify all the properties in the two pools are the same
41 #
42
43 verify_runnable "global"
44
45 function edited_prop
46 {
47         typeset behaviour=$1
48         typeset ds=$2
49         typeset backfile=$TESTDIR/edited_prop_$ds
50
51         case $behaviour in
52                 "get")
53                         typeset props=$(zfs inherit 2>&1 | \
54                                 awk '$2=="YES" {print $1}' | \
55                                 egrep -v "^vol|\.\.\.$")
56                         for item in $props ; do
57                                 if [[ $item == "mlslabel" ]] && \
58                                         ! is_te_enabled ; then
59                                         continue
60                                 fi
61                                 zfs get -H -o property,value $item $ds >> \
62                                         $backfile
63                                 if (($? != 0)); then
64                                         log_fail "zfs get -H -o property,value"\
65                                                 "$item $ds > $backfile"
66                                 fi
67                         done
68                         ;;
69                 "set")
70                         if [[ ! -f $backfile ]] ; then
71                                 log_fail "$ds need backup properties firstly."
72                         fi
73
74                         typeset prop value
75                         while read prop value ; do
76                                 eval zfs set $prop='$value' $ds
77                                 if (($? != 0)); then
78                                         log_fail "zfs set $prop=$value $ds"
79                                 fi
80                         done < $backfile
81                         ;;
82                 *)
83                         log_fail "Unrecognized behaviour: $behaviour"
84         esac
85 }
86
87 function cleanup
88 {
89         log_must cleanup_pool $POOL
90         log_must cleanup_pool $POOL2
91
92         log_must edited_prop "set" $POOL
93         log_must edited_prop "set" $POOL2
94
95         typeset prop
96         for prop in $(fs_inherit_prop) ; do
97                 log_must zfs inherit $prop $POOL
98                 log_must zfs inherit $prop $POOL2
99         done
100
101         log_must setup_test_model $POOL
102
103         if [[ -d $TESTDIR ]]; then
104                 log_must rm -rf $TESTDIR/*
105         fi
106 }
107
108 log_assert "Verify zfs send -R will backup all the filesystem properties " \
109         "correctly."
110 log_onexit cleanup
111
112 log_must edited_prop "get" $POOL
113 log_must edited_prop "get" $POOL2
114
115 for fs in "$POOL" "$POOL/pclone" "$POOL/$FS" "$POOL/$FS/fs1" \
116         "$POOL/$FS/fs1/fs2" "$POOL/$FS/fs1/fclone" ; do
117         rand_set_prop $fs aclinherit "discard" "noallow" "secure" "passthrough"
118         rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256"
119         rand_set_prop $fs acltype "off" "posix" "nfsv4" "noacl" "posixacl"
120         rand_set_prop $fs atime "on" "off"
121         rand_set_prop $fs checksum "on" "off" "fletcher2" "fletcher4" "sha256"
122         rand_set_prop $fs compression "${compress_prop_vals[@]}"
123         rand_set_prop $fs copies "1" "2" "3"
124         rand_set_prop $fs devices "on" "off"
125         rand_set_prop $fs exec "on" "off"
126         rand_set_prop $fs quota "512M" "1024M"
127         rand_set_prop $fs recordsize "512" "2K" "8K" "32K" "128K"
128         rand_set_prop $fs dnodesize "legacy" "auto" "1k" "2k" "4k" "8k" "16k"
129         rand_set_prop $fs setuid "on" "off"
130         rand_set_prop $fs snapdir "hidden" "visible"
131         if ! is_freebsd; then
132                 rand_set_prop $fs xattr "on" "off"
133         fi
134         rand_set_prop $fs user:prop "aaa" "bbb" "23421" "()-+?"
135 done
136
137 for vol in "$POOL/vol" "$POOL/$FS/vol" ; do
138         rand_set_prop $vol checksum "on" "off" "fletcher2" "fletcher4" "sha256"
139         rand_set_prop $vol compression "${compress_prop_vals[@]}"
140         rand_set_prop $vol readonly "on" "off"
141         rand_set_prop $vol copies "1" "2" "3"
142         rand_set_prop $vol user:prop "aaa" "bbb" "23421" "()-+?"
143 done
144
145
146 # Verify inherited property can be received
147 rand_set_prop $POOL redundant_metadata "all" "most"
148 rand_set_prop $POOL sync "standard" "always" "disabled"
149
150 #
151 # Duplicate POOL2 for testing
152 #
153 log_must eval "zfs send -R $POOL@final > $BACKDIR/pool-final-R"
154 log_must eval "zfs receive -d -F $POOL2 < $BACKDIR/pool-final-R"
155
156 #
157 # Define all the POOL/POOL2 datasets pair
158 #
159 set -A pair     "$POOL"                 "$POOL2"                \
160                 "$POOL/$FS"             "$POOL2/$FS"            \
161                 "$POOL/$FS/fs1"         "$POOL2/$FS/fs1"        \
162                 "$POOL/$FS/fs1/fs2"     "$POOL2/$FS/fs1/fs2"    \
163                 "$POOL/pclone"          "$POOL2/pclone"         \
164                 "$POOL/$FS/fs1/fclone"  "$POOL2/$FS/fs1/fclone" \
165                 "$POOL/vol"             "$POOL2/vol"            \
166                 "$POOL/$FS/vol"         "$POOL2/$FS/vol"
167
168 typeset -i i=0
169 while ((i < ${#pair[@]})); do
170         log_must cmp_ds_prop ${pair[$i]} ${pair[((i+1))]}
171
172         ((i += 2))
173 done
174
175
176 zpool upgrade -v | grep "Snapshot properties" > /dev/null 2>&1
177 if (( $? == 0 )) ; then
178         i=0
179         while ((i < ${#pair[@]})); do
180                 log_must cmp_ds_prop ${pair[$i]}@final ${pair[((i+1))]}@final
181                 ((i += 2))
182         done
183 fi
184
185 log_pass "Verify zfs send -R will backup all the filesystem properties " \
186         "correctly."