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.
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.
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]
24 # Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved.
27 . $STF_SUITE/include/libtest.shlib
28 . $STF_SUITE/tests/functional/cli_root/zfs_set/zfs_set_common.kshlib
29 . $STF_SUITE/tests/functional/zvol/zvol_common.shlib
30 . $STF_SUITE/tests/functional/zvol/zvol_misc/zvol_misc_common.kshlib
34 # Verify that ZFS volume property "volmode" works as intended.
37 # 1. Verify "volmode" property does not accept invalid values
38 # 2. Verify "volmode=none" hides ZVOL device nodes
39 # 3. Verify "volmode=full" exposes a fully functional device
40 # 4. Verify "volmode=dev" hides partition info on the device
41 # 5. Verify "volmode=default" behaves accordingly to "volmode" module parameter
42 # 6. Verify "volmode" property is inherited correctly
43 # 7. Verify "volmode" behaves correctly at import time
44 # 8. Verify "volmode" behaves accordingly to zvol_inhibit_dev (Linux only)
46 # NOTE: changing volmode may need to remove minors, which could be open, so call
47 # udev_wait() before we "zfs set volmode=<value>".
49 verify_runnable "global"
53 datasetexists $VOLFS && log_must_busy zfs destroy -r $VOLFS
54 datasetexists $ZVOL && log_must_busy zfs destroy -r $ZVOL
55 log_must zfs inherit volmode $TESTPOOL
63 # Set zvol_inhibit_dev tunable to $value
65 function sysctl_inhibit_dev # value
70 log_note "Setting zvol_inhibit_dev tunable to $value"
71 log_must set_tunable32 VOL_INHIBIT_DEV $value
76 # Set volmode tunable to $value
78 function sysctl_volmode # value
82 log_note "Setting volmode tunable to $value"
83 log_must set_tunable32 VOL_MODE $value
87 # Exercise open and close, read and write operations
89 function test_io # dev
93 log_must dd if=/dev/zero of=$dev count=1
94 log_must dd if=$dev of=/dev/null count=1
97 log_assert "Verify that ZFS volume property 'volmode' works as intended"
100 VOLFS="$TESTPOOL/volfs"
102 ZDEV="${ZVOL_DEVDIR}/$ZVOL"
103 SUBZVOL="$VOLFS/subvol"
104 SUBZDEV="${ZVOL_DEVDIR}/$SUBZVOL"
106 log_must zfs create -o mountpoint=none $VOLFS
107 log_must zfs create -V $VOLSIZE -s $SUBZVOL
108 log_must zfs create -V $VOLSIZE -s $ZVOL
113 # 1. Verify "volmode" property does not accept invalid values
114 typeset badvals=("off" "on" "1" "nope" "-")
115 for badval in ${badvals[@]}
117 log_mustnot zfs set volmode="$badval" $ZVOL
120 # 2. Verify "volmode=none" hides ZVOL device nodes
121 log_must zfs set volmode=none $ZVOL
122 blockdev_missing $ZDEV
123 log_must_busy zfs destroy $ZVOL
125 # 3. Verify "volmode=full" exposes a fully functional device
126 log_must zfs create -V $VOLSIZE -s $ZVOL
128 log_must zfs set volmode=full $ZVOL
129 blockdev_exists $ZDEV
131 log_must verify_partition $ZDEV
133 # 3.1 Verify "volmode=geom" is an alias for "volmode=full"
134 log_must zfs set volmode=geom $ZVOL
135 blockdev_exists $ZDEV
136 if [[ "$(get_prop 'volmode' $ZVOL)" != "full" ]]; then
137 log_fail " Volmode value 'geom' is not an alias for 'full'"
140 log_must_busy zfs destroy $ZVOL
142 # 4. Verify "volmode=dev" hides partition info on the device
143 log_must zfs create -V $VOLSIZE -s $ZVOL
145 log_must zfs set volmode=dev $ZVOL
146 blockdev_exists $ZDEV
148 log_mustnot verify_partition $ZDEV
150 log_must_busy zfs destroy $ZVOL
152 # 5. Verify "volmode=default" behaves accordingly to "volmode" module parameter
153 # 5.1 Verify sysctl "volmode=full"
155 log_must zfs create -V $VOLSIZE -s $ZVOL
157 log_must zfs set volmode=default $ZVOL
158 blockdev_exists $ZDEV
159 log_must verify_partition $ZDEV
161 log_must_busy zfs destroy $ZVOL
162 # 5.2 Verify sysctl "volmode=dev"
164 log_must zfs create -V $VOLSIZE -s $ZVOL
166 log_must zfs set volmode=default $ZVOL
167 blockdev_exists $ZDEV
168 log_mustnot verify_partition $ZDEV
170 log_must_busy zfs destroy $ZVOL
171 # 5.2 Verify sysctl "volmode=none"
173 log_must zfs create -V $VOLSIZE -s $ZVOL
175 log_must zfs set volmode=default $ZVOL
176 blockdev_missing $ZDEV
178 # 6. Verify "volmode" property is inherited correctly
179 log_must zfs inherit volmode $ZVOL
180 # 6.1 Check volmode=full case
181 log_must zfs set volmode=full $TESTPOOL
182 verify_inherited 'volmode' 'full' $ZVOL $TESTPOOL
183 blockdev_exists $ZDEV
184 # 6.2 Check volmode=none case
185 log_must zfs set volmode=none $TESTPOOL
186 verify_inherited 'volmode' 'none' $ZVOL $TESTPOOL
187 blockdev_missing $ZDEV
188 # 6.3 Check volmode=dev case
189 log_must zfs set volmode=dev $TESTPOOL
190 verify_inherited 'volmode' 'dev' $ZVOL $TESTPOOL
191 blockdev_exists $ZDEV
192 # 6.4 Check volmode=default case
194 log_must zfs set volmode=default $TESTPOOL
195 verify_inherited 'volmode' 'default' $ZVOL $TESTPOOL
196 blockdev_exists $ZDEV
197 # 6.5 Check inheritance on multiple levels
198 log_must zfs inherit volmode $SUBZVOL
200 log_must zfs set volmode=none $VOLFS
202 log_must zfs set volmode=full $TESTPOOL
203 verify_inherited 'volmode' 'none' $SUBZVOL $VOLFS
204 blockdev_missing $SUBZDEV
205 blockdev_exists $ZDEV
207 # 7. Verify "volmode" behaves correctly at import time
208 log_must zpool export $TESTPOOL
209 blockdev_missing $ZDEV
210 blockdev_missing $SUBZDEV
211 log_must zpool import $TESTPOOL
212 blockdev_exists $ZDEV
213 blockdev_missing $SUBZDEV
214 log_must_busy zfs destroy $ZVOL
215 log_must_busy zfs destroy $SUBZVOL
217 # 8. Verify "volmode" behaves accordingly to zvol_inhibit_dev (Linux only)
220 # 7.1 Verify device nodes not are not created with "volmode=full"
222 log_must zfs create -V $VOLSIZE -s $ZVOL
223 blockdev_missing $ZDEV
224 log_must zfs set volmode=full $ZVOL
225 blockdev_missing $ZDEV
226 log_must_busy zfs destroy $ZVOL
227 # 7.1 Verify device nodes not are not created with "volmode=dev"
229 log_must zfs create -V $VOLSIZE -s $ZVOL
230 blockdev_missing $ZDEV
231 log_must zfs set volmode=dev $ZVOL
232 blockdev_missing $ZDEV
233 log_must_busy zfs destroy $ZVOL
234 # 7.1 Verify device nodes not are not created with "volmode=none"
236 log_must zfs create -V $VOLSIZE -s $ZVOL
237 blockdev_missing $ZDEV
238 log_must zfs set volmode=none $ZVOL
239 blockdev_missing $ZDEV
242 log_pass "Verify that ZFS volume property 'volmode' works as intended"