Merge remote-tracking branch 'remotes/nvme/tags/nvme-fixes-20210407-pull-request...
[qemu/ar7.git] / tests / qemu-iotests / 051
blob7bf29343d72a8095a4a43f29ed57627a9d3c4e81
1 #!/usr/bin/env bash
2 # group: rw
4 # Test command line configuration of block devices and driver-specific options
6 # Copyright (C) 2013 Red Hat, Inc.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
22 # creator
23 owner=kwolf@redhat.com
25 seq=`basename $0`
26 echo "QA output created by $seq"
28 status=1 # failure is the default!
30 _cleanup()
32 _cleanup_test_img
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
37 . ./common.rc
38 . ./common.filter
40 _supported_fmt qcow2
41 _supported_proto file
42 # A compat=0.10 image is created in this test which does not support anything
43 # other than refcount_bits=16;
44 # it also will not support an external data file
45 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file
46 _require_drivers nbd
48 do_run_qemu()
50 echo Testing: "$@"
52 if ! test -t 0; then
53 while read cmd; do
54 echo $cmd
55 done
57 echo quit
58 ) | $QEMU -nographic -monitor stdio -serial none "$@"
59 echo
62 run_qemu()
64 do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu |
65 _filter_generated_node_ids | _filter_hmp
68 size=128M
69 device_id="drive0"
71 _make_test_img $size
72 cp "$TEST_IMG" "$TEST_IMG.orig"
73 mv "$TEST_IMG" "$TEST_IMG.base"
74 _make_test_img -b "$TEST_IMG.base" -F $IMGFMT $size
76 echo
77 echo === Unknown option ===
78 echo
80 run_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=,if=none,id=$device_id
81 run_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=on,if=none,id=$device_id
82 run_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=1234,if=none,id=$device_id
83 run_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=foo,if=none,id=$device_id
85 echo
86 echo === Unknown protocol option ===
87 echo
89 run_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=
90 run_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=on
91 run_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=1234
92 run_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=foo
94 echo
95 echo === Invalid format ===
96 echo
98 run_qemu -drive file="$TEST_IMG",format=foo
99 run_qemu -drive file="$TEST_IMG",driver=foo
100 run_qemu -drive file="$TEST_IMG",driver=raw,format=qcow2
101 run_qemu -drive file="$TEST_IMG",driver=qcow2,format=qcow2
103 echo
104 echo === Node names ===
105 echo
107 # Maximum length: 31 characters
108 run_qemu -drive file="$TEST_IMG",node-name=x123456789012345678901234567890
109 run_qemu -drive file="$TEST_IMG",node-name=x1234567890123456789012345678901
111 # First character must be alphabetic
112 # Following characters alphanumeric or -._
113 run_qemu -drive file="$TEST_IMG",node-name=All-Types.of_all0wed_chars
114 run_qemu -drive file="$TEST_IMG",node-name=123foo
115 run_qemu -drive file="$TEST_IMG",node-name=_foo
116 run_qemu -drive file="$TEST_IMG",node-name=foo#12
118 echo
119 echo === Device without drive ===
120 echo
122 run_qemu -device virtio-scsi -device scsi-hd
124 echo
125 echo === Overriding backing file ===
126 echo
128 echo "info block" | run_qemu -drive file="$TEST_IMG",driver=qcow2,backing.file.filename="$TEST_IMG.orig",if=none,id=$device_id -nodefaults\
129 | _filter_generated_node_ids
131 # Drivers that don't support backing files
132 run_qemu -drive file="$TEST_IMG",driver=raw,backing.file.filename="$TEST_IMG.orig"
133 run_qemu -drive file="$TEST_IMG",file.backing.driver=file,file.backing.filename="$TEST_IMG.orig"
134 run_qemu -drive file="$TEST_IMG",file.backing.driver=qcow2,file.backing.file.filename="$TEST_IMG.orig"
136 echo
137 echo === Enable and disable lazy refcounting on the command line, plus some invalid values ===
138 echo
140 _make_test_img -o compat=1.1 "$size"
142 run_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
143 run_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
144 run_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=
145 run_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=42
146 run_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=foo
149 echo
150 echo === With version 2 images enabling lazy refcounts must fail ===
151 echo
153 _make_test_img -o compat=0.10 $size
155 run_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
156 run_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
158 echo
159 echo === No medium ===
160 echo
162 case "$QEMU_DEFAULT_MACHINE" in
164 run_qemu -drive if=floppy
165 run_qemu -drive if=ide,media=cdrom
166 run_qemu -drive if=ide
170 esac
172 run_qemu -drive if=virtio
174 case "$QEMU_DEFAULT_MACHINE" in
176 run_qemu -drive if=none,id=disk -device ide-cd,drive=disk
177 run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-cd,drive=disk
178 run_qemu -drive if=none,id=disk -device ide-hd,drive=disk
179 run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-hd,drive=disk
183 esac
185 echo
186 echo === Attach to node in non-default iothread ===
187 echo
189 case "$QEMU_DEFAULT_MACHINE" in
191 iothread="-drive file=$TEST_IMG,if=none,node-name=disk -object iothread,id=thread0 -device virtio-scsi,iothread=thread0,id=virtio-scsi0 -device scsi-hd,bus=virtio-scsi0.0,drive=disk,share-rw=on"
193 # Can't add a device in the main thread while virtio-scsi0 uses the node
194 run_qemu $iothread -device ide-hd,drive=disk,share-rw=on
195 run_qemu $iothread -device virtio-blk-pci,drive=disk,share-rw=on
196 run_qemu $iothread -device lsi53c895a,id=lsi0 -device scsi-hd,bus=lsi0.0,drive=disk,share-rw=on
197 run_qemu $iothread -device virtio-scsi,id=virtio-scsi1 -device scsi-hd,bus=virtio-scsi1.0,drive=disk,share-rw=on
199 # virtio-blk enables the iothread only when the driver initialises the
200 # device, so a second virtio-blk device can't be added even with the
201 # same iothread. virtio-scsi allows this.
202 run_qemu $iothread -device virtio-blk-pci,drive=disk,iothread=iothread0,share-rw=on
203 run_qemu $iothread -device virtio-scsi,id=virtio-scsi1,iothread=thread0 -device scsi-hd,bus=virtio-scsi1.0,drive=disk,share-rw=on
207 esac
209 echo
210 echo === Read-only ===
211 echo
213 case "$QEMU_DEFAULT_MACHINE" in
215 run_qemu -drive file="$TEST_IMG",if=floppy,readonly=on
216 run_qemu -drive file="$TEST_IMG",if=ide,media=cdrom,readonly=on
217 run_qemu -drive file="$TEST_IMG",if=ide,readonly=on
221 esac
223 run_qemu -drive file="$TEST_IMG",if=virtio,readonly=on
225 case "$QEMU_DEFAULT_MACHINE" in
227 run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-cd,drive=disk
228 run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-cd,drive=disk
229 run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-hd,drive=disk
230 run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-hd,drive=disk
234 esac
236 echo
237 echo === Cache modes ===
238 echo
240 # Cannot use the test image because cache=none might not work on the host FS
241 # Use cdrom so that we won't get errors about missing media
243 run_qemu -drive driver=null-co,read-zeroes=on,cache=none
244 run_qemu -drive driver=null-co,read-zeroes=on,cache=directsync
245 run_qemu -drive driver=null-co,read-zeroes=on,cache=writeback
246 run_qemu -drive driver=null-co,read-zeroes=on,cache=writethrough
247 run_qemu -drive driver=null-co,read-zeroes=on,cache=unsafe
248 run_qemu -drive driver=null-co,cache=invalid_value
250 # Can't test direct=on here because O_DIRECT might not be supported on this FS
251 # Test 142 checks the direct=on cases
253 for cache in writeback writethrough unsafe invalid_value; do
254 printf "info block %s\n" '' file backing backing-file | \
255 run_qemu -drive file="$TEST_IMG",cache=$cache,backing.file.filename="$TEST_IMG.base",backing.cache.no-flush=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,if=none,id=$device_id -nodefaults
256 done
258 echo
259 echo === Specifying the protocol layer ===
260 echo
262 run_qemu -drive file="$TEST_IMG",file.driver=file
264 echo
265 echo === Leaving out required options ===
266 echo
268 run_qemu -drive driver=file
269 run_qemu -drive driver=file,filename=
270 run_qemu -drive driver=nbd
271 run_qemu -drive driver=raw
272 run_qemu -drive file.driver=file
273 run_qemu -drive file.driver=nbd
274 run_qemu -drive file.driver=raw
275 run_qemu -drive foo=bar
277 echo
278 echo === Specifying both an option and its legacy alias ===
279 echo
281 run_qemu -drive file="$TEST_IMG",iops=1234,throttling.iops-total=5678
282 run_qemu -drive file="$TEST_IMG",iops_rd=1234,throttling.iops-read=5678
283 run_qemu -drive file="$TEST_IMG",iops_wr=1234,throttling.iops-write=5678
285 run_qemu -drive file="$TEST_IMG",bps=1234,throttling.bps-total=5678
286 run_qemu -drive file="$TEST_IMG",bps_rd=1234,throttling.bps-read=5678
287 run_qemu -drive file="$TEST_IMG",bps_wr=1234,throttling.bps-write=5678
289 run_qemu -drive file="$TEST_IMG",iops_max=1234,throttling.iops-total-max=5678
290 run_qemu -drive file="$TEST_IMG",iops_rd_max=1234,throttling.iops-read-max=5678
291 run_qemu -drive file="$TEST_IMG",iops_wr_max=1234,throttling.iops-write-max=5678
293 run_qemu -drive file="$TEST_IMG",bps_max=1234,throttling.bps-total-max=5678
294 run_qemu -drive file="$TEST_IMG",bps_rd_max=1234,throttling.bps-read-max=5678
295 run_qemu -drive file="$TEST_IMG",bps_wr_max=1234,throttling.bps-write-max=5678
297 run_qemu -drive file="$TEST_IMG",iops_size=1234,throttling.iops-size=5678
298 run_qemu -drive file="$TEST_IMG",readonly=on,read-only=off
300 echo
301 echo === Catching negative/large throttling values ===
302 echo
304 run_qemu -drive file="$TEST_IMG",iops=-1
305 run_qemu -drive file="$TEST_IMG",bps=-2
306 run_qemu -drive file="$TEST_IMG",bps_rd=-3
307 run_qemu -drive file="$TEST_IMG",bps_rd_max=-3
308 run_qemu -drive file="$TEST_IMG",throttling.iops-total=-4
309 run_qemu -drive file="$TEST_IMG",throttling.bps-total=-5
310 # These are accepted
311 run_qemu -drive file="$TEST_IMG",bps=0
312 run_qemu -drive file="$TEST_IMG",bps=1
313 run_qemu -drive file="$TEST_IMG",bps=1000000000000000
314 # While these are not
315 run_qemu -drive file="$TEST_IMG",bps=1000000000000001
316 run_qemu -drive file="$TEST_IMG",bps=9999999999999999
318 echo
319 echo === Parsing protocol from file name ===
320 echo
322 # Protocol strings are supposed to be parsed from traditional option strings,
323 # but not when using driver-specific options. We can distinguish them by the
324 # error message for non-existing files.
326 run_qemu -hda foo:bar
327 run_qemu -drive file=foo:bar
328 run_qemu -drive file.filename=foo:bar
330 run_qemu -hda "file:$TEST_IMG"
331 run_qemu -drive file="file:$TEST_IMG"
332 run_qemu -drive file.filename="file:$TEST_IMG"
334 echo
335 echo === Snapshot mode ===
336 echo
338 $QEMU_IO -c "write -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io
341 echo "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file="$TEST_IMG",if=none,id=$device_id -snapshot | _filter_qemu_io
342 echo "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file="$TEST_IMG",snapshot=on,if=none,id=$device_id | _filter_qemu_io
343 echo "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file.filename="$TEST_IMG",driver=qcow2,snapshot=on,if=none,id=$device_id\
344 | _filter_qemu_io
345 echo "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file.filename="$TEST_IMG",driver=qcow2,if=none,id=$device_id -snapshot\
346 | _filter_qemu_io
347 echo "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file="file:$TEST_IMG",if=none,id=$device_id -snapshot | _filter_qemu_io
348 echo "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file="file:$TEST_IMG",snapshot=on,if=none,id=$device_id | _filter_qemu_io
350 # Opening a read-only file r/w with snapshot=on
351 chmod u-w "$TEST_IMG"
352 echo "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file="$TEST_IMG",if=none,id=$device_id -snapshot | _filter_qemu_io
353 echo "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file="$TEST_IMG",snapshot=on,if=none,id=$device_id | _filter_qemu_io
354 chmod u+w "$TEST_IMG"
356 $QEMU_IO -c "read -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io
358 echo "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file="$TEST_IMG",snapshot=off,if=none,id=$device_id | _filter_qemu_io
360 $QEMU_IO -c "read -P 0x22 0 4k" "$TEST_IMG" | _filter_qemu_io
362 printf %b "qemu-io $device_id \"write -P 0x33 0 4k\"\ncommit $device_id\n" |
363 run_qemu -drive file="$TEST_IMG",snapshot=on,if=none,id=$device_id |
364 _filter_qemu_io
366 $QEMU_IO -c "read -P 0x33 0 4k" "$TEST_IMG" | _filter_qemu_io
368 # Using snapshot=on with a non-existent TMPDIR
369 if [ "${VALGRIND_QEMU_VM}" == "y" ]; then
370 _casenotrun "Valgrind needs a valid TMPDIR for itself"
372 VALGRIND_QEMU_VM= \
373 TMPDIR=/nonexistent run_qemu -drive driver=null-co,snapshot=on
375 # Using snapshot=on together with read-only=on
376 echo "info block" |
377 run_qemu -drive file="$TEST_IMG",snapshot=on,read-only=on,if=none,id=$device_id |
378 _filter_qemu_io |
379 sed -e 's#"[^"]*/vl\.[A-Za-z0-9]\{6\}"#SNAPSHOT_PATH#g'
382 # success, all done
383 echo "*** done"
384 rm -f $seq.full
385 status=0