]>
Commit | Line | Data |
---|---|---|
11a82d14 | 1 | #!/usr/bin/env bash |
8f7acbe6 KW |
2 | # |
3 | # Test for configuring cache modes of arbitrary nodes (requires O_DIRECT) | |
4 | # | |
5 | # Copyright (C) 2015 Red Hat, Inc. | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 2 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | # | |
20 | ||
21 | # creator | |
22 | [email protected] | |
23 | ||
24 | seq=`basename $0` | |
25 | echo "QA output created by $seq" | |
26 | ||
8f7acbe6 KW |
27 | status=1 # failure is the default! |
28 | ||
29 | _cleanup() | |
30 | { | |
31 | _cleanup_test_img | |
f91ecbd7 | 32 | _rm_test_img "$TEST_IMG.snap" |
8f7acbe6 KW |
33 | } |
34 | trap "_cleanup; exit \$status" 0 1 2 3 15 | |
35 | ||
36 | # get standard environment, filters and checks | |
37 | . ./common.rc | |
38 | . ./common.filter | |
39 | ||
40 | _supported_fmt qcow2 | |
41 | _supported_proto file | |
8f7acbe6 KW |
42 | |
43 | # We test all cache modes anyway, but O_DIRECT needs to be supported | |
44 | _default_cache_mode none | |
45 | _supported_cache_modes none directsync | |
46 | ||
8cedcffd | 47 | do_run_qemu() |
8f7acbe6 KW |
48 | { |
49 | echo Testing: "$@" | |
50 | ( | |
51 | if ! test -t 0; then | |
52 | while read cmd; do | |
53 | echo $cmd | |
54 | done | |
55 | fi | |
56 | echo quit | |
57 | ) | $QEMU -nographic -monitor stdio -nodefaults "$@" | |
58 | echo | |
59 | } | |
60 | ||
8cedcffd | 61 | run_qemu() |
8f7acbe6 | 62 | { |
69404d9e | 63 | do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp |
8f7acbe6 KW |
64 | } |
65 | ||
66 | size=128M | |
67 | ||
68 | TEST_IMG="$TEST_IMG.base" _make_test_img $size | |
69 | TEST_IMG="$TEST_IMG.snap" _make_test_img $size | |
b66ff2c2 | 70 | _make_test_img -b "$TEST_IMG.base" $size -F $IMGFMT |
8f7acbe6 KW |
71 | |
72 | echo | |
73 | echo === Simple test for all cache modes === | |
74 | echo | |
75 | ||
76 | run_qemu -drive file="$TEST_IMG",cache=none | |
77 | run_qemu -drive file="$TEST_IMG",cache=directsync | |
78 | run_qemu -drive file="$TEST_IMG",cache=writeback | |
79 | run_qemu -drive file="$TEST_IMG",cache=writethrough | |
80 | run_qemu -drive file="$TEST_IMG",cache=unsafe | |
81 | run_qemu -drive file="$TEST_IMG",cache=invalid_value | |
82 | ||
83 | echo | |
84 | echo === Check inheritance of cache modes === | |
85 | echo | |
86 | ||
87 | files="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base" | |
88 | ids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file" | |
89 | ||
8cedcffd | 90 | check_cache_all() |
8f7acbe6 KW |
91 | { |
92 | # cache.direct is supposed to be inherited by both bs->file and | |
93 | # bs->backing | |
94 | ||
b43671f8 | 95 | printf "cache.direct=on on none0\n" |
73ac451f | 96 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't" |
b43671f8 | 97 | printf "\ncache.direct=on on file\n" |
73ac451f | 98 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't" |
b43671f8 | 99 | printf "\ncache.direct=on on backing\n" |
73ac451f | 100 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't" |
b43671f8 | 101 | printf "\ncache.direct=on on backing-file\n" |
73ac451f | 102 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't" |
8f7acbe6 KW |
103 | |
104 | # cache.writeback is supposed to be inherited by bs->backing; bs->file | |
105 | # always gets cache.writeback=on | |
106 | ||
b43671f8 | 107 | printf "\n\ncache.writeback=off on none0\n" |
73ac451f | 108 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 109 | printf "\ncache.writeback=off on file\n" |
61de4c68 | 110 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.writeback=off | grep -e "doesn't" -e "does not" |
b43671f8 | 111 | printf "\ncache.writeback=off on backing\n" |
61de4c68 | 112 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.writeback=off | grep -e "doesn't" -e "does not" |
b43671f8 | 113 | printf "\ncache.writeback=off on backing-file\n" |
61de4c68 | 114 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.writeback=off | grep -e "doesn't" -e "does not" |
8f7acbe6 KW |
115 | |
116 | # cache.no-flush is supposed to be inherited by both bs->file and bs->backing | |
117 | ||
b43671f8 | 118 | printf "\n\ncache.no-flush=on on none0\n" |
73ac451f | 119 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 120 | printf "\ncache.no-flush=on on file\n" |
73ac451f | 121 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 122 | printf "\ncache.no-flush=on on backing\n" |
73ac451f | 123 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 124 | printf "\ncache.no-flush=on on backing-file\n" |
73ac451f | 125 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
8f7acbe6 KW |
126 | } |
127 | ||
128 | echo | |
129 | echo "--- Configure cache modes on the command line ---" | |
130 | echo | |
131 | ||
132 | # First check the inherited cache mode after opening the image. | |
133 | ||
c83f9fba KW |
134 | hmp_cmds="info block none0 |
135 | info block image | |
8f7acbe6 KW |
136 | info block file |
137 | info block backing | |
138 | info block backing-file" | |
139 | ||
140 | check_cache_all | |
141 | ||
142 | echo | |
143 | echo "--- Cache modes after reopen (live snapshot) ---" | |
144 | echo | |
145 | ||
146 | # Then trigger a reopen and check that the cache modes are still the same. | |
147 | ||
148 | hmp_cmds="snapshot_blkdev -n none0 $TEST_IMG.snap $IMGFMT | |
149 | info block | |
150 | info block image | |
151 | info block file | |
152 | info block backing | |
153 | info block backing-file" | |
154 | ||
155 | check_cache_all | |
156 | ||
157 | echo | |
158 | echo "--- Change cache modes with reopen (qemu-io command, flags) ---" | |
159 | echo | |
160 | ||
161 | # This one actually changes the cache mode with the reopen. For this test, the | |
162 | # new cache mode is specified in the flags, not as an option. | |
163 | ||
164 | hmp_cmds='qemu-io none0 "reopen -c none" | |
c83f9fba | 165 | info block none0 |
8f7acbe6 KW |
166 | info block image |
167 | info block file | |
168 | info block backing | |
169 | info block backing-file' | |
170 | ||
171 | check_cache_all | |
172 | ||
173 | echo | |
174 | echo "--- Change cache modes with reopen (qemu-io command, options) ---" | |
175 | echo | |
176 | ||
177 | # This one actually changes the cache mode with the reopen. For this test, the | |
178 | # new cache mode is specified as an option, not in the flags. | |
179 | ||
180 | hmp_cmds='qemu-io none0 "reopen -o cache.direct=on" | |
c83f9fba | 181 | info block none0 |
8f7acbe6 KW |
182 | info block image |
183 | info block file | |
184 | info block backing | |
185 | info block backing-file' | |
186 | ||
187 | check_cache_all | |
188 | ||
189 | echo | |
190 | echo "--- Change cache modes after snapshot ---" | |
191 | echo | |
192 | ||
193 | # This checks that the original image doesn't inherit from the snapshot | |
194 | ||
195 | hmp_cmds="snapshot_blkdev -n none0 $TEST_IMG.snap $IMGFMT | |
196 | qemu-io none0 \"reopen -c none\" | |
197 | info block none0 | |
198 | info block image | |
199 | info block file | |
200 | info block backing | |
201 | info block backing-file" | |
202 | ||
203 | check_cache_all | |
204 | ||
205 | echo | |
206 | echo "--- Change cache mode in parent, child has explicit option in JSON ---" | |
207 | echo | |
208 | ||
209 | # This checks that children with options explicitly set by the json: | |
210 | # pseudo-protocol don't inherit these options from their parents. | |
211 | # | |
212 | # Yes, blkdebug::json:... is criminal, but I can't see another way to have a | |
213 | # BDS initialised with the json: pseudo-protocol, but still have it inherit | |
214 | # options from its parent node. | |
215 | ||
19dbecdc | 216 | hmp_cmds="qemu-io none0 \"reopen -o cache.direct=on,cache.no-flush=on\" |
c83f9fba | 217 | info block none0 |
8f7acbe6 KW |
218 | info block image |
219 | info block blkdebug | |
220 | info block file" | |
221 | ||
73ac451f | 222 | echo "$hmp_cmds" | run_qemu -drive if=none,file="blkdebug::json:{\"filename\":\"$TEST_IMG\",,\"cache\":{\"direct\":false}}",node-name=image,file.node-name=blkdebug,file.image.node-name=file | grep "Cache" |
8f7acbe6 KW |
223 | |
224 | echo | |
225 | echo "=== Check that referenced BDSes don't inherit ===" | |
226 | echo | |
227 | ||
228 | drv_bkfile="if=none,driver=file,filename=$TEST_IMG.base,node-name=backing-file" | |
229 | drv_bk="if=none,file=json:{'driver':'$IMGFMT',,'file':'backing-file',,'node-name':'backing'}" | |
230 | drv_file="if=none,driver=file,filename=$TEST_IMG,node-name=file" | |
231 | drv_img="if=none,id=blk,file=json:{'driver':'$IMGFMT',,'file':'file',,'backing':'backing',,'node-name':'image'}" | |
232 | ||
8cedcffd | 233 | check_cache_all_separate() |
8f7acbe6 KW |
234 | { |
235 | # Check cache.direct | |
236 | ||
b43671f8 | 237 | printf "cache.direct=on on blk\n" |
73ac451f | 238 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img",cache.direct=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 239 | printf "\ncache.direct=on on file\n" |
73ac451f | 240 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file",cache.direct=on -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 241 | printf "\ncache.direct=on on backing\n" |
73ac451f | 242 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk",cache.direct=on -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 243 | printf "\ncache.direct=on on backing-file\n" |
73ac451f | 244 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile",cache.direct=on -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
8f7acbe6 KW |
245 | |
246 | # Check cache.writeback | |
247 | ||
b43671f8 | 248 | printf "\n\ncache.writeback=off on blk\n" |
73ac451f | 249 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img",cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 250 | printf "\ncache.writeback=off on file\n" |
73ac451f | 251 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file",cache.writeback=off -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 252 | printf "\ncache.writeback=off on backing\n" |
73ac451f | 253 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk",cache.writeback=off -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 254 | printf "\ncache.writeback=off on backing-file\n" |
73ac451f | 255 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile",cache.writeback=off -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
8f7acbe6 KW |
256 | |
257 | # Check cache.no-flush | |
258 | ||
b43671f8 | 259 | printf "\n\ncache.no-flush=on on blk\n" |
73ac451f | 260 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img",cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 261 | printf "\ncache.no-flush=on on file\n" |
73ac451f | 262 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk" -drive "$drv_file",cache.no-flush=on -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 263 | printf "\ncache.no-flush=on on backing\n" |
73ac451f | 264 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile" -drive "$drv_bk",cache.no-flush=on -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
b43671f8 | 265 | printf "\ncache.no-flush=on on backing-file\n" |
73ac451f | 266 | echo "$hmp_cmds" | run_qemu -drive "$drv_bkfile",cache.no-flush=on -drive "$drv_bk" -drive "$drv_file" -drive "$drv_img" | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't" |
8f7acbe6 KW |
267 | } |
268 | ||
269 | echo | |
270 | echo "--- Configure cache modes on the command line ---" | |
271 | echo | |
272 | ||
273 | # First check the inherited cache mode after opening the image. | |
274 | ||
275 | hmp_cmds="info block image | |
276 | info block file | |
277 | info block backing | |
278 | info block backing-file" | |
279 | ||
280 | check_cache_all_separate | |
281 | ||
282 | echo | |
283 | echo "--- Cache modes after reopen (live snapshot) ---" | |
284 | echo | |
285 | ||
286 | # Then trigger a reopen and check that the cache modes are still the same. | |
287 | ||
288 | hmp_cmds="snapshot_blkdev -n blk $TEST_IMG.snap $IMGFMT | |
289 | info block blk | |
290 | info block image | |
291 | info block file | |
292 | info block backing | |
293 | info block backing-file" | |
294 | ||
295 | check_cache_all_separate | |
296 | ||
297 | echo | |
298 | echo "--- Change cache modes with reopen (qemu-io command, flags) ---" | |
299 | echo | |
300 | ||
301 | # This one actually changes the cache mode with the reopen. For this test, the | |
302 | # new cache mode is specified as flags, not as option. | |
303 | ||
304 | hmp_cmds='qemu-io blk "reopen -c none" | |
305 | info block image | |
306 | info block file | |
307 | info block backing | |
308 | info block backing-file' | |
309 | ||
310 | check_cache_all_separate | |
311 | ||
312 | ||
313 | echo | |
314 | echo "=== Reopening children instead of the root ===" | |
315 | echo | |
316 | ||
317 | files="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base" | |
318 | ids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file" | |
319 | ||
320 | echo | |
321 | echo "--- Basic reopen ---" | |
322 | echo | |
323 | ||
324 | hmp_cmds='qemu-io none0 "reopen -o backing.cache.direct=on" | |
c83f9fba | 325 | info block none0 |
8f7acbe6 KW |
326 | info block image |
327 | info block file | |
328 | info block backing | |
329 | info block backing-file' | |
330 | ||
331 | check_cache_all | |
332 | ||
333 | echo | |
334 | echo "--- Change cache mode after reopening child ---" | |
335 | echo | |
336 | ||
337 | # This checks that children with options explicitly set with reopen don't | |
338 | # inherit these options from their parents any more | |
339 | ||
340 | # TODO Implement node-name support for 'qemu-io' HMP command for -c | |
341 | # Can use only -o to access child node options for now | |
342 | ||
bfd18d1e KW |
343 | hmp_cmds="qemu-io none0 \"reopen -o file.cache.direct=off,file.cache.no-flush=off\" |
344 | qemu-io none0 \"reopen -o backing.file.cache.direct=off,backing.file.cache.no-flush=on\" | |
8f7acbe6 KW |
345 | qemu-io none0 \"reopen -c none\" |
346 | info block image | |
347 | info block file | |
348 | info block backing | |
349 | info block backing-file" | |
350 | ||
351 | echo "$hmp_cmds" | run_qemu -drive "$files","$ids" | grep "Cache" | |
352 | ||
5dbd0ce1 KW |
353 | echo |
354 | echo "--- Alignment after changing O_DIRECT ---" | |
355 | echo | |
356 | ||
357 | # Directly test the protocol level: Can unaligned requests succeed even if | |
358 | # O_DIRECT was only enabled through a reopen and vice versa? | |
359 | ||
360 | # Ensure image size is a multiple of the sector size (required for O_DIRECT) | |
361 | $QEMU_IMG create -f file "$TEST_IMG" 1M | _filter_img_create | |
362 | ||
363 | # And write some data (not strictly necessary, but it feels better to actually | |
364 | # have something to be read) | |
365 | $QEMU_IO -f file -c 'write 0 4096' "$TEST_IMG" | _filter_qemu_io | |
366 | ||
367 | $QEMU_IO --cache=writeback -f file $TEST_IMG <<EOF | _filter_qemu_io | |
368 | read 42 42 | |
369 | reopen -o cache.direct=on | |
370 | read 42 42 | |
371 | reopen -o cache.direct=off | |
372 | read 42 42 | |
373 | EOF | |
374 | $QEMU_IO --cache=none -f file $TEST_IMG <<EOF | _filter_qemu_io | |
375 | read 42 42 | |
376 | reopen -o cache.direct=off | |
377 | read 42 42 | |
378 | reopen -o cache.direct=on | |
379 | read 42 42 | |
380 | EOF | |
381 | ||
8f7acbe6 KW |
382 | # success, all done |
383 | echo "*** done" | |
384 | rm -f $seq.full | |
385 | status=0 |