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/>.
23 owner
=kwolf@redhat.com
26 echo "QA output created by $seq"
28 status
=1 # failure is the default!
34 trap "_cleanup; exit \$status" 0 1 2 3 15
36 # get standard environment, filters and checks
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
58 ) |
$QEMU -nographic -monitor stdio
-serial none
"$@"
64 do_run_qemu
"$@" 2>&1 | _filter_testdir | _filter_qemu |
65 _filter_generated_node_ids | _filter_hmp
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
77 echo === Unknown option
===
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
86 echo === Unknown protocol option
===
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
95 echo === Invalid format
===
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
104 echo === Node names
===
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
119 echo === Device without drive
===
122 run_qemu
-device virtio-scsi
-device scsi-hd
125 echo === Overriding backing
file ===
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"
137 echo === Enable and disable lazy refcounting on the
command line
, plus some invalid values
===
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
150 echo === With version
2 images enabling lazy refcounts must fail
===
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
159 echo === No medium
===
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
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
186 echo === Attach to node
in non-default iothread
===
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
210 echo === Read-only
===
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
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
237 echo === Cache modes
===
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
259 echo === Specifying the protocol layer
===
262 run_qemu
-drive file="$TEST_IMG",file.driver
=file
265 echo === Leaving out required options
===
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
278 echo === Specifying both an option and its legacy
alias ===
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
301 echo === Catching negative
/large throttling values
===
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
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
319 echo === Parsing protocol from
file name
===
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"
335 echo === Snapshot mode
===
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\
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\
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 |
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"
373 TMPDIR
=/nonexistent run_qemu
-drive driver
=null-co
,snapshot
=on
375 # Using snapshot=on together with read-only=on
377 run_qemu
-drive file="$TEST_IMG",snapshot
=on
,read-only
=on
,if=none
,id
=$device_id |
379 sed -e 's#"[^"]*/vl\.[A-Za-z0-9]\{6\}"#SNAPSHOT_PATH#g'