]> git.proxmox.com Git - mirror_qemu.git/blob - tests/qemu-iotests/142
Merge remote-tracking branch 'remotes/kraxel/tags/audio-20170717-pull-request' into...
[mirror_qemu.git] / tests / qemu-iotests / 142
1 #!/bin/bash
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 owner=kwolf@redhat.com
23
24 seq=`basename $0`
25 echo "QA output created by $seq"
26
27 here=`pwd`
28 status=1 # failure is the default!
29
30 _cleanup()
31 {
32 _cleanup_test_img
33 rm -f $TEST_IMG.snap
34 }
35 trap "_cleanup; exit \$status" 0 1 2 3 15
36
37 # get standard environment, filters and checks
38 . ./common.rc
39 . ./common.filter
40
41 _supported_fmt qcow2
42 _supported_proto file
43 _supported_os Linux
44
45 # We test all cache modes anyway, but O_DIRECT needs to be supported
46 _default_cache_mode none
47 _supported_cache_modes none directsync
48
49 function do_run_qemu()
50 {
51 echo Testing: "$@"
52 (
53 if ! test -t 0; then
54 while read cmd; do
55 echo $cmd
56 done
57 fi
58 echo quit
59 ) | $QEMU -nographic -monitor stdio -nodefaults "$@"
60 echo
61 }
62
63 function run_qemu()
64 {
65 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_hmp
66 }
67
68 size=128M
69
70 TEST_IMG="$TEST_IMG.base" _make_test_img $size
71 TEST_IMG="$TEST_IMG.snap" _make_test_img $size
72 _make_test_img -b "$TEST_IMG.base" $size
73
74 echo
75 echo === Simple test for all cache modes ===
76 echo
77
78 run_qemu -drive file="$TEST_IMG",cache=none
79 run_qemu -drive file="$TEST_IMG",cache=directsync
80 run_qemu -drive file="$TEST_IMG",cache=writeback
81 run_qemu -drive file="$TEST_IMG",cache=writethrough
82 run_qemu -drive file="$TEST_IMG",cache=unsafe
83 run_qemu -drive file="$TEST_IMG",cache=invalid_value
84
85 echo
86 echo === Check inheritance of cache modes ===
87 echo
88
89 files="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base"
90 ids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file"
91
92 function check_cache_all()
93 {
94 # cache.direct is supposed to be inherited by both bs->file and
95 # bs->backing
96
97 printf "cache.direct=on on none0\n"
98 echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't"
99 printf "\ncache.direct=on on file\n"
100 echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't"
101 printf "\ncache.direct=on on backing\n"
102 echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.direct=on | grep -e "Cache" -e "[Cc]annot|[Cc]ould not|[Cc]an't"
103 printf "\ncache.direct=on on backing-file\n"
104 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"
105
106 # cache.writeback is supposed to be inherited by bs->backing; bs->file
107 # always gets cache.writeback=on
108
109 printf "\n\ncache.writeback=off on none0\n"
110 echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.writeback=off | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
111 printf "\ncache.writeback=off on file\n"
112 echo "$hmp_cmds" | run_qemu -drive "$files","$ids",file.cache.writeback=off | grep -e "doesn't" -e "does not"
113 printf "\ncache.writeback=off on backing\n"
114 echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.cache.writeback=off | grep -e "doesn't" -e "does not"
115 printf "\ncache.writeback=off on backing-file\n"
116 echo "$hmp_cmds" | run_qemu -drive "$files","$ids",backing.file.cache.writeback=off | grep -e "doesn't" -e "does not"
117
118 # cache.no-flush is supposed to be inherited by both bs->file and bs->backing
119
120 printf "\n\ncache.no-flush=on on none0\n"
121 echo "$hmp_cmds" | run_qemu -drive "$files","$ids",cache.no-flush=on | grep -e "Cache" -e "[Cc]annot\|[Cc]ould not\|[Cc]an't"
122 printf "\ncache.no-flush=on on file\n"
123 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"
124 printf "\ncache.no-flush=on on backing\n"
125 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"
126 printf "\ncache.no-flush=on on backing-file\n"
127 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"
128 }
129
130 echo
131 echo "--- Configure cache modes on the command line ---"
132 echo
133
134 # First check the inherited cache mode after opening the image.
135
136 hmp_cmds="info block none0
137 info block image
138 info block file
139 info block backing
140 info block backing-file"
141
142 check_cache_all
143
144 echo
145 echo "--- Cache modes after reopen (live snapshot) ---"
146 echo
147
148 # Then trigger a reopen and check that the cache modes are still the same.
149
150 hmp_cmds="snapshot_blkdev -n none0 $TEST_IMG.snap $IMGFMT
151 info block
152 info block image
153 info block file
154 info block backing
155 info block backing-file"
156
157 check_cache_all
158
159 echo
160 echo "--- Change cache modes with reopen (qemu-io command, flags) ---"
161 echo
162
163 # This one actually changes the cache mode with the reopen. For this test, the
164 # new cache mode is specified in the flags, not as an option.
165
166 hmp_cmds='qemu-io none0 "reopen -c none"
167 info block none0
168 info block image
169 info block file
170 info block backing
171 info block backing-file'
172
173 check_cache_all
174
175 echo
176 echo "--- Change cache modes with reopen (qemu-io command, options) ---"
177 echo
178
179 # This one actually changes the cache mode with the reopen. For this test, the
180 # new cache mode is specified as an option, not in the flags.
181
182 hmp_cmds='qemu-io none0 "reopen -o cache.direct=on"
183 info block none0
184 info block image
185 info block file
186 info block backing
187 info block backing-file'
188
189 check_cache_all
190
191 echo
192 echo "--- Change cache modes after snapshot ---"
193 echo
194
195 # This checks that the original image doesn't inherit from the snapshot
196
197 hmp_cmds="snapshot_blkdev -n none0 $TEST_IMG.snap $IMGFMT
198 qemu-io none0 \"reopen -c none\"
199 info block none0
200 info block image
201 info block file
202 info block backing
203 info block backing-file"
204
205 check_cache_all
206
207 echo
208 echo "--- Change cache mode in parent, child has explicit option in JSON ---"
209 echo
210
211 # This checks that children with options explicitly set by the json:
212 # pseudo-protocol don't inherit these options from their parents.
213 #
214 # Yes, blkdebug::json:... is criminal, but I can't see another way to have a
215 # BDS initialised with the json: pseudo-protocol, but still have it inherit
216 # options from its parent node.
217
218 hmp_cmds="qemu-io none0 \"reopen -o cache.direct=on,cache.no-flush=on\"
219 info block none0
220 info block image
221 info block blkdebug
222 info block file"
223
224 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"
225
226 echo
227 echo "=== Check that referenced BDSes don't inherit ==="
228 echo
229
230 drv_bkfile="if=none,driver=file,filename=$TEST_IMG.base,node-name=backing-file"
231 drv_bk="if=none,file=json:{'driver':'$IMGFMT',,'file':'backing-file',,'node-name':'backing'}"
232 drv_file="if=none,driver=file,filename=$TEST_IMG,node-name=file"
233 drv_img="if=none,id=blk,file=json:{'driver':'$IMGFMT',,'file':'file',,'backing':'backing',,'node-name':'image'}"
234
235 function check_cache_all_separate()
236 {
237 # Check cache.direct
238
239 printf "cache.direct=on on blk\n"
240 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"
241 printf "\ncache.direct=on on file\n"
242 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"
243 printf "\ncache.direct=on on backing\n"
244 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"
245 printf "\ncache.direct=on on backing-file\n"
246 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"
247
248 # Check cache.writeback
249
250 printf "\n\ncache.writeback=off on blk\n"
251 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"
252 printf "\ncache.writeback=off on file\n"
253 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"
254 printf "\ncache.writeback=off on backing\n"
255 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"
256 printf "\ncache.writeback=off on backing-file\n"
257 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"
258
259 # Check cache.no-flush
260
261 printf "\n\ncache.no-flush=on on blk\n"
262 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"
263 printf "\ncache.no-flush=on on file\n"
264 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"
265 printf "\ncache.no-flush=on on backing\n"
266 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"
267 printf "\ncache.no-flush=on on backing-file\n"
268 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"
269 }
270
271 echo
272 echo "--- Configure cache modes on the command line ---"
273 echo
274
275 # First check the inherited cache mode after opening the image.
276
277 hmp_cmds="info block image
278 info block file
279 info block backing
280 info block backing-file"
281
282 check_cache_all_separate
283
284 echo
285 echo "--- Cache modes after reopen (live snapshot) ---"
286 echo
287
288 # Then trigger a reopen and check that the cache modes are still the same.
289
290 hmp_cmds="snapshot_blkdev -n blk $TEST_IMG.snap $IMGFMT
291 info block blk
292 info block image
293 info block file
294 info block backing
295 info block backing-file"
296
297 check_cache_all_separate
298
299 echo
300 echo "--- Change cache modes with reopen (qemu-io command, flags) ---"
301 echo
302
303 # This one actually changes the cache mode with the reopen. For this test, the
304 # new cache mode is specified as flags, not as option.
305
306 hmp_cmds='qemu-io blk "reopen -c none"
307 info block image
308 info block file
309 info block backing
310 info block backing-file'
311
312 check_cache_all_separate
313
314
315 echo
316 echo "=== Reopening children instead of the root ==="
317 echo
318
319 files="if=none,file=$TEST_IMG,backing.file.filename=$TEST_IMG.base"
320 ids="node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file"
321
322 echo
323 echo "--- Basic reopen ---"
324 echo
325
326 hmp_cmds='qemu-io none0 "reopen -o backing.cache.direct=on"
327 info block none0
328 info block image
329 info block file
330 info block backing
331 info block backing-file'
332
333 check_cache_all
334
335 echo
336 echo "--- Change cache mode after reopening child ---"
337 echo
338
339 # This checks that children with options explicitly set with reopen don't
340 # inherit these options from their parents any more
341
342 # TODO Implement node-name support for 'qemu-io' HMP command for -c
343 # Can use only -o to access child node options for now
344
345 hmp_cmds="qemu-io none0 \"reopen -o file.cache.direct=off,file.cache.no-flush=off\"
346 qemu-io none0 \"reopen -o backing.file.cache.direct=off,backing.file.cache.no-flush=on\"
347 qemu-io none0 \"reopen -c none\"
348 info block image
349 info block file
350 info block backing
351 info block backing-file"
352
353 echo "$hmp_cmds" | run_qemu -drive "$files","$ids" | grep "Cache"
354
355 # success, all done
356 echo "*** done"
357 rm -f $seq.full
358 status=0