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 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26
27 #
28 # Copyright (c) 2013 by Delphix. All rights reserved.
29 #
30
31 . $STF_SUITE/include/libtest.shlib
32 . $STF_SUITE/tests/functional/inheritance/inherit.kshlib
33
34 #
35 # DESCRIPTION:
36 # Test that properties are correctly inherited using 'zfs set',
37 # 'zfs inherit' and 'zfs inherit -r'.
38 #
39 # STRATEGY:
40 # 1) Read a configX.cfg file and create the specified datasets
41 # 2) Read a stateX.cfg file and execute the commands within it
42 # and verify that the properties have the correct values
43 # 3) Repeat steps 1-2 for each configX and stateX files found.
44 #
45
46 verify_runnable "global"
47
48 log_assert "Test properties are inherited correctly"
49
50 #
51 # Simple function to create specified datasets.
52 #
53 function create_dataset { #name type disks
54 typeset dataset=$1
55 typeset type=$2
56 typeset disks=$3
57
58 if [[ $type == "POOL" ]]; then
59 create_pool "$dataset" "$disks"
60 elif [[ $type == "CTR" ]]; then
61 log_must $ZFS create $dataset
62 log_must $ZFS set canmount=off $dataset
63 elif [[ $type == "FS" ]]; then
64 log_must $ZFS create $dataset
65 else
66 log_fail "Unrecognised type $type"
67 fi
68
69 list="$list $dataset"
70 }
71
72 #
73 # Function to walk through all the properties in a
74 # dataset, setting them to a 'local' value if required.
75 #
76 function init_props { #dataset init_code
77 typeset dataset=$1
78 typeset init_code=$2
79 typeset dir=$3
80
81 typeset -i i=0
82
83 #
84 # Though the effect of '-' and 'default' is the same we
126 typeset init_code=$2
127 typeset idx=0
128 typeset record_val
129
130 #
131 # First need to find where the recordsize property is
132 # located in the arrays
133 #
134 while (( idx < ${#prop[*]} )); do
135 [[ ${prop[idx]} == "recordsize" ]] && break
136
137 ((idx = idx + 2))
138 done
139
140 ((idx = idx / 2))
141 record_val=`get_prop recordsize $dataset`
142 if [[ $init_code == "-" || $init_code == "default" ]]; then
143 def_val[idx]=$record_val
144 def_recordsize=1
145 elif [[ $init_code == "local" ]]; then
146 log_must $ZFS set recordsize=$record_val $dataset
147 local_val[idx]=$record_val
148 fi
149 }
150
151 #
152 # The mountpoint property is slightly different from other properties and
153 # so is handled here. For all other properties if they are set to a specific
154 # value at a higher level in the data hierarchy (i.e. checksum=on) then that
155 # value propogates down the hierarchy unchanged, with the source field being
156 # set to 'inherited from <higher dataset>'.
157 #
158 # The mountpoint property is different in that while the value propogates
159 # down the hierarchy, the value at each level is determined by a combination
160 # of the top-level value and the current level in the hierarchy.
161 #
162 # For example consider the case where we have a pool (called pool1), containing
163 # a dataset (ctr) which in turn contains a filesystem (fs). If we set the
164 # mountpoint of the pool to '/mnt2' then the mountpoints for the dataset and
165 # filesystem are '/mnt2/ctr' and /mnt2/ctr/fs' respectively, with the 'source'
166 # field being set to 'inherited from pool1'.
315 while IFS=: read target op; do
316 #
317 # The user can if they wish specify that no
318 # operation be performed (by specifying '-'
319 # rather than a command). This is not as
320 # useless as it sounds as it allows us to
321 # verify that the dataset hierarchy has been
322 # set up correctly as specified in the
323 # configX.cfg file (which includes 'set'ting
324 # properties at a higher level and checking
325 # that they propogate down to the lower levels.
326 #
327 # Note in a few places here, we use
328 # check_failure, rather than log_must - this
329 # substantially reduces journal output.
330 #
331 if [[ $op == "-" ]]; then
332 log_note "No operation specified"
333 else
334 export __ZFS_POOL_RESTRICT="$TESTPOOL"
335 log_must $ZFS unmount -a
336 unset __ZFS_POOL_RESTRICT
337
338 for p in ${prop[i]} ${prop[((i+1))]}; do
339 $ZFS $op $p $target
340 ret=$?
341 check_failure $ret "$ZFS $op $p \
342 $target"
343 done
344 fi
345 for check_obj in $list; do
346 read init_src final_src
347
348 for p in ${prop[i]} ${prop[((i+1))]}; do
349 # check_failure to keep journal small
350 verify_prop_src $check_obj $p \
351 $final_src
352 ret=$?
353 check_failure $ret "verify" \
354 "_prop_src $check_obj $p" \
355 "$final_src"
356
357 # Again, to keep journal size down.
358 verify_prop_val $p $check_obj \
359 $final_src $j
360 ret=$?
361 check_failure $ret "verify" \
|
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 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26
27 #
28 # Copyright (c) 2013, 2016 by Delphix. All rights reserved.
29 #
30
31 . $STF_SUITE/include/libtest.shlib
32 . $STF_SUITE/tests/functional/inheritance/inherit.kshlib
33
34 #
35 # DESCRIPTION:
36 # Test that properties are correctly inherited using 'zfs set',
37 # 'zfs inherit' and 'zfs inherit -r'.
38 #
39 # STRATEGY:
40 # 1) Read a configX.cfg file and create the specified datasets
41 # 2) Read a stateX.cfg file and execute the commands within it
42 # and verify that the properties have the correct values
43 # 3) Repeat steps 1-2 for each configX and stateX files found.
44 #
45
46 verify_runnable "global"
47
48 log_assert "Test properties are inherited correctly"
49
50 #
51 # Simple function to create specified datasets.
52 #
53 function create_dataset { #name type disks
54 typeset dataset=$1
55 typeset type=$2
56 typeset disks=$3
57
58 if [[ $type == "POOL" ]]; then
59 create_pool "$dataset" "$disks"
60 elif [[ $type == "CTR" ]]; then
61 log_must zfs create $dataset
62 log_must zfs set canmount=off $dataset
63 elif [[ $type == "FS" ]]; then
64 log_must zfs create $dataset
65 else
66 log_fail "Unrecognised type $type"
67 fi
68
69 list="$list $dataset"
70 }
71
72 #
73 # Function to walk through all the properties in a
74 # dataset, setting them to a 'local' value if required.
75 #
76 function init_props { #dataset init_code
77 typeset dataset=$1
78 typeset init_code=$2
79 typeset dir=$3
80
81 typeset -i i=0
82
83 #
84 # Though the effect of '-' and 'default' is the same we
126 typeset init_code=$2
127 typeset idx=0
128 typeset record_val
129
130 #
131 # First need to find where the recordsize property is
132 # located in the arrays
133 #
134 while (( idx < ${#prop[*]} )); do
135 [[ ${prop[idx]} == "recordsize" ]] && break
136
137 ((idx = idx + 2))
138 done
139
140 ((idx = idx / 2))
141 record_val=`get_prop recordsize $dataset`
142 if [[ $init_code == "-" || $init_code == "default" ]]; then
143 def_val[idx]=$record_val
144 def_recordsize=1
145 elif [[ $init_code == "local" ]]; then
146 log_must zfs set recordsize=$record_val $dataset
147 local_val[idx]=$record_val
148 fi
149 }
150
151 #
152 # The mountpoint property is slightly different from other properties and
153 # so is handled here. For all other properties if they are set to a specific
154 # value at a higher level in the data hierarchy (i.e. checksum=on) then that
155 # value propogates down the hierarchy unchanged, with the source field being
156 # set to 'inherited from <higher dataset>'.
157 #
158 # The mountpoint property is different in that while the value propogates
159 # down the hierarchy, the value at each level is determined by a combination
160 # of the top-level value and the current level in the hierarchy.
161 #
162 # For example consider the case where we have a pool (called pool1), containing
163 # a dataset (ctr) which in turn contains a filesystem (fs). If we set the
164 # mountpoint of the pool to '/mnt2' then the mountpoints for the dataset and
165 # filesystem are '/mnt2/ctr' and /mnt2/ctr/fs' respectively, with the 'source'
166 # field being set to 'inherited from pool1'.
315 while IFS=: read target op; do
316 #
317 # The user can if they wish specify that no
318 # operation be performed (by specifying '-'
319 # rather than a command). This is not as
320 # useless as it sounds as it allows us to
321 # verify that the dataset hierarchy has been
322 # set up correctly as specified in the
323 # configX.cfg file (which includes 'set'ting
324 # properties at a higher level and checking
325 # that they propogate down to the lower levels.
326 #
327 # Note in a few places here, we use
328 # check_failure, rather than log_must - this
329 # substantially reduces journal output.
330 #
331 if [[ $op == "-" ]]; then
332 log_note "No operation specified"
333 else
334 export __ZFS_POOL_RESTRICT="$TESTPOOL"
335 log_must zfs unmount -a
336 unset __ZFS_POOL_RESTRICT
337
338 for p in ${prop[i]} ${prop[((i+1))]}; do
339 zfs $op $p $target
340 ret=$?
341 check_failure $ret "zfs $op $p \
342 $target"
343 done
344 fi
345 for check_obj in $list; do
346 read init_src final_src
347
348 for p in ${prop[i]} ${prop[((i+1))]}; do
349 # check_failure to keep journal small
350 verify_prop_src $check_obj $p \
351 $final_src
352 ret=$?
353 check_failure $ret "verify" \
354 "_prop_src $check_obj $p" \
355 "$final_src"
356
357 # Again, to keep journal size down.
358 verify_prop_val $p $check_obj \
359 $final_src $j
360 ret=$?
361 check_failure $ret "verify" \
|