xref: /qemu/tests/qemu-iotests/051 (revision c85c6d9ec1f992a4d9b4b72cabf80235ab652b90)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
247e5df21SKevin Wolf#
347e5df21SKevin Wolf# Test command line configuration of block devices and driver-specific options
447e5df21SKevin Wolf#
547e5df21SKevin Wolf# Copyright (C) 2013 Red Hat, Inc.
647e5df21SKevin Wolf#
747e5df21SKevin Wolf# This program is free software; you can redistribute it and/or modify
847e5df21SKevin Wolf# it under the terms of the GNU General Public License as published by
947e5df21SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
1047e5df21SKevin Wolf# (at your option) any later version.
1147e5df21SKevin Wolf#
1247e5df21SKevin Wolf# This program is distributed in the hope that it will be useful,
1347e5df21SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
1447e5df21SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1547e5df21SKevin Wolf# GNU General Public License for more details.
1647e5df21SKevin Wolf#
1747e5df21SKevin Wolf# You should have received a copy of the GNU General Public License
1847e5df21SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1947e5df21SKevin Wolf#
2047e5df21SKevin Wolf
2147e5df21SKevin Wolf# creator
2247e5df21SKevin Wolfowner=kwolf@redhat.com
2347e5df21SKevin Wolf
2447e5df21SKevin Wolfseq=`basename $0`
2547e5df21SKevin Wolfecho "QA output created by $seq"
2647e5df21SKevin Wolf
2747e5df21SKevin Wolfstatus=1	# failure is the default!
2847e5df21SKevin Wolf
2947e5df21SKevin Wolf_cleanup()
3047e5df21SKevin Wolf{
3147e5df21SKevin Wolf	_cleanup_test_img
3247e5df21SKevin Wolf}
3347e5df21SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
3447e5df21SKevin Wolf
3547e5df21SKevin Wolf# get standard environment, filters and checks
3647e5df21SKevin Wolf. ./common.rc
3747e5df21SKevin Wolf. ./common.filter
3847e5df21SKevin Wolf
3947e5df21SKevin Wolf_supported_fmt qcow2
4047e5df21SKevin Wolf_supported_proto file
415262caa7SMax Reitz# A compat=0.10 image is created in this test which does not support anything
425262caa7SMax Reitz# other than refcount_bits=16
435262caa7SMax Reitz_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)'
44*c85c6d9eSThomas Huth_require_drivers nbd
4547e5df21SKevin Wolf
468cedcffdSEric Blakedo_run_qemu()
4747e5df21SKevin Wolf{
4847e5df21SKevin Wolf    echo Testing: "$@"
494db9c980SFam Zheng    (
504db9c980SFam Zheng        if ! test -t 0; then
514db9c980SFam Zheng            while read cmd; do
524db9c980SFam Zheng                echo $cmd
534db9c980SFam Zheng            done
544db9c980SFam Zheng        fi
554db9c980SFam Zheng        echo quit
564db9c980SFam Zheng    ) | $QEMU -nographic -monitor stdio -serial none "$@"
5747e5df21SKevin Wolf    echo
5847e5df21SKevin Wolf}
5947e5df21SKevin Wolf
608cedcffdSEric Blakerun_qemu()
6147e5df21SKevin Wolf{
6269404d9eSKevin Wolf    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu |
6369404d9eSKevin Wolf        _filter_generated_node_ids | _filter_hmp
6447e5df21SKevin Wolf}
6547e5df21SKevin Wolf
6647e5df21SKevin Wolfsize=128M
67dd87de06SBo Tudevice_id="drive0"
6847e5df21SKevin Wolf
6947e5df21SKevin Wolf_make_test_img $size
701ab39193SJeff Codycp "$TEST_IMG" "$TEST_IMG.orig"
711ab39193SJeff Codymv "$TEST_IMG" "$TEST_IMG.base"
721ab39193SJeff Cody_make_test_img -b "$TEST_IMG.base" $size
7347e5df21SKevin Wolf
7447e5df21SKevin Wolfecho
7547e5df21SKevin Wolfecho === Unknown option ===
7647e5df21SKevin Wolfecho
7747e5df21SKevin Wolf
78dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=,if=none,id=$device_id
79dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=on,if=none,id=$device_id
80dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=1234,if=none,id=$device_id
81dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=foo,if=none,id=$device_id
8247e5df21SKevin Wolf
834db9c980SFam Zhengecho
84eb909c7fSKevin Wolfecho === Unknown protocol option ===
85eb909c7fSKevin Wolfecho
86eb909c7fSKevin Wolf
87eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=
88eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=on
89eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=1234
90eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=foo
91eb909c7fSKevin Wolf
92eb909c7fSKevin Wolfecho
9306d22aa3SKevin Wolfecho === Invalid format ===
9406d22aa3SKevin Wolfecho
9506d22aa3SKevin Wolf
9606d22aa3SKevin Wolfrun_qemu -drive file="$TEST_IMG",format=foo
9706d22aa3SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=foo
9817b005f1SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=raw,format=qcow2
9980495fdfSMax Reitzrun_qemu -drive file="$TEST_IMG",driver=qcow2,format=qcow2
10006d22aa3SKevin Wolf
10106d22aa3SKevin Wolfecho
102824808ddSKevin Wolfecho === Node names ===
103824808ddSKevin Wolfecho
104824808ddSKevin Wolf
105824808ddSKevin Wolf# Maximum length: 31 characters
106824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=x123456789012345678901234567890
107824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=x1234567890123456789012345678901
108824808ddSKevin Wolf
109824808ddSKevin Wolf# First character must be alphabetic
110824808ddSKevin Wolf# Following characters alphanumeric or -._
111824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=All-Types.of_all0wed_chars
112824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=123foo
113824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=_foo
114824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=foo#12
115824808ddSKevin Wolf
116824808ddSKevin Wolfecho
117354483e5SChristian Borntraegerecho === Device without drive ===
118354483e5SChristian Borntraegerecho
119354483e5SChristian Borntraeger
12075f02ed5SCornelia Huckcase "$QEMU_DEFAULT_MACHINE" in
12175f02ed5SCornelia Huck  s390-ccw-virtio)
12275f02ed5SCornelia Huck      virtio_scsi=virtio-scsi-ccw
12375f02ed5SCornelia Huck      ;;
12475f02ed5SCornelia Huck  *)
12575f02ed5SCornelia Huck      virtio_scsi=virtio-scsi-pci
12675f02ed5SCornelia Huck      ;;
12775f02ed5SCornelia Huckesac
12875f02ed5SCornelia Huck
12975f02ed5SCornelia Huckrun_qemu -device $virtio_scsi -device scsi-hd |
13075f02ed5SCornelia Huck    sed -e "s/$virtio_scsi/VIRTIO_SCSI/"
131354483e5SChristian Borntraeger
132354483e5SChristian Borntraegerecho
1334db9c980SFam Zhengecho === Overriding backing file ===
1344db9c980SFam Zhengecho
1354db9c980SFam Zheng
136dd87de06SBo Tuecho "info block" | run_qemu -drive file="$TEST_IMG",driver=qcow2,backing.file.filename="$TEST_IMG.orig",if=none,id=$device_id -nodefaults\
13715489c76SJeff Cody                  | _filter_generated_node_ids
13847e5df21SKevin Wolf
1398ee79e70SKevin Wolf# Drivers that don't support backing files
1408ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=raw,backing.file.filename="$TEST_IMG.orig"
1418ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",file.backing.driver=file,file.backing.filename="$TEST_IMG.orig"
1428ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",file.backing.driver=qcow2,file.backing.file.filename="$TEST_IMG.orig"
1438ee79e70SKevin Wolf
14447e5df21SKevin Wolfecho
14547e5df21SKevin Wolfecho === Enable and disable lazy refcounting on the command line, plus some invalid values ===
14647e5df21SKevin Wolfecho
14747e5df21SKevin Wolf
1487e0db6f4SMax Reitz_make_test_img -o compat=1.1 "$size"
1497e0db6f4SMax Reitz
150fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
151fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
152fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=
153fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=42
154fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=foo
15547e5df21SKevin Wolf
15647e5df21SKevin Wolf
15747e5df21SKevin Wolfecho
15847e5df21SKevin Wolfecho === With version 2 images enabling lazy refcounts must fail ===
15947e5df21SKevin Wolfecho
16047e5df21SKevin Wolf
16147e5df21SKevin Wolf_make_test_img -ocompat=0.10 $size
16247e5df21SKevin Wolf
163fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
164fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
16547e5df21SKevin Wolf
16647e5df21SKevin Wolfecho
16747e5df21SKevin Wolfecho === No medium ===
16847e5df21SKevin Wolfecho
16947e5df21SKevin Wolf
170dd87de06SBo Tucase "$QEMU_DEFAULT_MACHINE" in
171dd87de06SBo Tu    pc)
17247e5df21SKevin Wolf        run_qemu -drive if=floppy
17347e5df21SKevin Wolf        run_qemu -drive if=ide,media=cdrom
17447e5df21SKevin Wolf        run_qemu -drive if=ide
175dd87de06SBo Tu        ;;
176dd87de06SBo Tu     *)
177dd87de06SBo Tu        ;;
178dd87de06SBo Tuesac
179dd87de06SBo Tu
180dd87de06SBo Turun_qemu -drive if=virtio
18147e5df21SKevin Wolf
182289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in
183289f3ebaSBo Tu    pc)
18447e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device ide-cd,drive=disk
18547e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-cd,drive=disk
18647e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device ide-drive,drive=disk
18747e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device ide-hd,drive=disk
18847e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-disk,drive=disk
18947e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-hd,drive=disk
190289f3ebaSBo Tu        ;;
191289f3ebaSBo Tu     *)
192289f3ebaSBo Tu        ;;
193289f3ebaSBo Tuesac
19447e5df21SKevin Wolf
19547e5df21SKevin Wolfecho
1966c870535SKevin Wolfecho === Attach to node in non-default iothread ===
1976c870535SKevin Wolfecho
1986c870535SKevin Wolf
1996c870535SKevin Wolfcase "$QEMU_DEFAULT_MACHINE" in
2006c870535SKevin Wolf    pc)
2016c870535SKevin Wolf        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"
2026c870535SKevin Wolf
2036c870535SKevin Wolf        # Can't add a device in the main thread while virtio-scsi0 uses the node
2046c870535SKevin Wolf        run_qemu $iothread -device ide-hd,drive=disk,share-rw=on
2056c870535SKevin Wolf        run_qemu $iothread -device virtio-blk-pci,drive=disk,share-rw=on
2066c870535SKevin Wolf        run_qemu $iothread -device lsi53c895a,id=lsi0 -device scsi-hd,bus=lsi0.0,drive=disk,share-rw=on
2076c870535SKevin Wolf        run_qemu $iothread -device virtio-scsi,id=virtio-scsi1 -device scsi-hd,bus=virtio-scsi1.0,drive=disk,share-rw=on
2086c870535SKevin Wolf
2096c870535SKevin Wolf        # virtio-blk enables the iothread only when the driver initialises the
2106c870535SKevin Wolf        # device, so a second virtio-blk device can't be added even with the
2116c870535SKevin Wolf        # same iothread. virtio-scsi allows this.
2126c870535SKevin Wolf        run_qemu $iothread -device virtio-blk-pci,drive=disk,iohtread=iothread0,share-rw=on
2136c870535SKevin Wolf        run_qemu $iothread -device virtio-scsi,id=virtio-scsi1,iothread=thread0 -device scsi-hd,bus=virtio-scsi1.0,drive=disk,share-rw=on
2146c870535SKevin Wolf        ;;
2156c870535SKevin Wolf     *)
2166c870535SKevin Wolf        ;;
2176c870535SKevin Wolfesac
2186c870535SKevin Wolf
2196c870535SKevin Wolfecho
22047e5df21SKevin Wolfecho === Read-only ===
22147e5df21SKevin Wolfecho
22247e5df21SKevin Wolf
223289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in
224289f3ebaSBo Tu    pc)
225fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=floppy,readonly=on
226fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=ide,media=cdrom,readonly=on
227fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=ide,readonly=on
228289f3ebaSBo Tu        ;;
229289f3ebaSBo Tu     *)
230289f3ebaSBo Tu        ;;
231289f3ebaSBo Tuesac
232289f3ebaSBo Tu
233fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=virtio,readonly=on
23447e5df21SKevin Wolf
235289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in
236289f3ebaSBo Tu    pc)
237fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-cd,drive=disk
238fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-cd,drive=disk
239fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-drive,drive=disk
240fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-hd,drive=disk
241fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-disk,drive=disk
242fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-hd,drive=disk
243289f3ebaSBo Tu        ;;
244289f3ebaSBo Tu     *)
245289f3ebaSBo Tu        ;;
246289f3ebaSBo Tuesac
24747e5df21SKevin Wolf
24847e5df21SKevin Wolfecho
24947e5df21SKevin Wolfecho === Cache modes ===
25047e5df21SKevin Wolfecho
25147e5df21SKevin Wolf
25247e5df21SKevin Wolf# Cannot use the test image because cache=none might not work on the host FS
25347e5df21SKevin Wolf# Use cdrom so that we won't get errors about missing media
25447e5df21SKevin Wolf
255a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=none
256a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=directsync
257a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=writeback
258a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=writethrough
259a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=unsafe
260fc17c259SKevin Wolfrun_qemu -drive driver=null-co,cache=invalid_value
26147e5df21SKevin Wolf
262768ee459SKevin Wolf# Can't test direct=on here because O_DIRECT might not be supported on this FS
263768ee459SKevin Wolf# Test 142 checks the direct=on cases
264768ee459SKevin Wolf
265768ee459SKevin Wolffor cache in writeback writethrough unsafe invalid_value; do
266b43671f8SEric Blake    printf "info block %s\n" '' file backing backing-file | \
26761de4c68SKevin Wolf    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
268768ee459SKevin Wolfdone
269768ee459SKevin Wolf
2702af5ef70SKevin Wolfecho
2712af5ef70SKevin Wolfecho === Specifying the protocol layer ===
2722af5ef70SKevin Wolfecho
2732af5ef70SKevin Wolf
274fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",file.driver=file
2752af5ef70SKevin Wolf
27698289620SKevin Wolfecho
277765003dbSKevin Wolfecho === Leaving out required options ===
278765003dbSKevin Wolfecho
279765003dbSKevin Wolf
280765003dbSKevin Wolfrun_qemu -drive driver=file
28142dc10f1SMax Reitzrun_qemu -drive driver=file,filename=
282765003dbSKevin Wolfrun_qemu -drive driver=nbd
283765003dbSKevin Wolfrun_qemu -drive driver=raw
284765003dbSKevin Wolfrun_qemu -drive file.driver=file
285765003dbSKevin Wolfrun_qemu -drive file.driver=nbd
286765003dbSKevin Wolfrun_qemu -drive file.driver=raw
287765003dbSKevin Wolfrun_qemu -drive foo=bar
288765003dbSKevin Wolf
289765003dbSKevin Wolfecho
2905abbf0eeSKevin Wolfecho === Specifying both an option and its legacy alias ===
2915abbf0eeSKevin Wolfecho
2925abbf0eeSKevin Wolf
2935abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops=1234,throttling.iops-total=5678
2945abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_rd=1234,throttling.iops-read=5678
2955abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_wr=1234,throttling.iops-write=5678
2965abbf0eeSKevin Wolf
2975abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps=1234,throttling.bps-total=5678
2985abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_rd=1234,throttling.bps-read=5678
2995abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_wr=1234,throttling.bps-write=5678
3005abbf0eeSKevin Wolf
3015abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_max=1234,throttling.iops-total-max=5678
3025abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_rd_max=1234,throttling.iops-read-max=5678
3035abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_wr_max=1234,throttling.iops-write-max=5678
3045abbf0eeSKevin Wolf
3055abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_max=1234,throttling.bps-total-max=5678
3065abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_rd_max=1234,throttling.bps-read-max=5678
3075abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_wr_max=1234,throttling.bps-write-max=5678
3085abbf0eeSKevin Wolf
3095abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_size=1234,throttling.iops-size=5678
3105abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",readonly=on,read-only=off
3115abbf0eeSKevin Wolf
3125abbf0eeSKevin Wolfecho
313e9b15550SFam Zhengecho === Catching negative/large throttling values ===
314e9b15550SFam Zhengecho
315e9b15550SFam Zheng
316e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",iops=-1
317e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=-2
318e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps_rd=-3
319e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps_rd_max=-3
320e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",throttling.iops-total=-4
321e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",throttling.bps-total=-5
322e9b15550SFam Zheng# These are accepted
323e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=0
324e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=1
325e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=1000000000000000
326e9b15550SFam Zheng# While these are not
327e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=1000000000000001
328e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=9999999999999999
329e9b15550SFam Zheng
330e9b15550SFam Zhengecho
33198289620SKevin Wolfecho === Parsing protocol from file name ===
33298289620SKevin Wolfecho
33398289620SKevin Wolf
33498289620SKevin Wolf# Protocol strings are supposed to be parsed from traditional option strings,
33598289620SKevin Wolf# but not when using driver-specific options. We can distinguish them by the
33698289620SKevin Wolf# error message for non-existing files.
33798289620SKevin Wolf
33898289620SKevin Wolfrun_qemu -hda foo:bar
33998289620SKevin Wolfrun_qemu -drive file=foo:bar
34098289620SKevin Wolfrun_qemu -drive file.filename=foo:bar
34198289620SKevin Wolf
342e3fa4bfaSKevin Wolfrun_qemu -hda "file:$TEST_IMG"
343e3fa4bfaSKevin Wolfrun_qemu -drive file="file:$TEST_IMG"
344e3fa4bfaSKevin Wolfrun_qemu -drive file.filename="file:$TEST_IMG"
345e3fa4bfaSKevin Wolf
346f32f988cSKevin Wolfecho
347f32f988cSKevin Wolfecho === Snapshot mode ===
348f32f988cSKevin Wolfecho
349f32f988cSKevin Wolf
350f32f988cSKevin Wolf$QEMU_IO -c "write -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io
351f32f988cSKevin Wolf
352289f3ebaSBo Tu
353289f3ebaSBo Tuecho "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file="$TEST_IMG",if=none,id=$device_id -snapshot | _filter_qemu_io
354289f3ebaSBo Tuecho "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
355289f3ebaSBo Tuecho "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\
356289f3ebaSBo Tu                                                 | _filter_qemu_io
357289f3ebaSBo Tuecho "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file.filename="$TEST_IMG",driver=qcow2,if=none,id=$device_id -snapshot\
358289f3ebaSBo Tu                                                 | _filter_qemu_io
359289f3ebaSBo Tuecho "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
360289f3ebaSBo Tuecho "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
361b998875dSKevin Wolf
362b998875dSKevin Wolf# Opening a read-only file r/w with snapshot=on
363b998875dSKevin Wolfchmod u-w "$TEST_IMG"
364289f3ebaSBo Tuecho "qemu-io $device_id \"write -P 0x22 0 4k\"" | run_qemu -drive file="$TEST_IMG",if=none,id=$device_id -snapshot | _filter_qemu_io
365289f3ebaSBo Tuecho "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
366b998875dSKevin Wolfchmod u+w "$TEST_IMG"
367f32f988cSKevin Wolf
368f32f988cSKevin Wolf$QEMU_IO -c "read -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io
369f32f988cSKevin Wolf
370289f3ebaSBo Tuecho "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
371f32f988cSKevin Wolf
372f32f988cSKevin Wolf$QEMU_IO -c "read -P 0x22 0 4k" "$TEST_IMG" | _filter_qemu_io
373f32f988cSKevin Wolf
374b43671f8SEric Blakeprintf %b "qemu-io $device_id \"write -P 0x33 0 4k\"\ncommit $device_id\n" |
375b43671f8SEric Blake    run_qemu -drive file="$TEST_IMG",snapshot=on,if=none,id=$device_id |
376b43671f8SEric Blake    _filter_qemu_io
377b1e6fc08SKevin Wolf
378b1e6fc08SKevin Wolf$QEMU_IO -c "read -P 0x33 0 4k" "$TEST_IMG" | _filter_qemu_io
379b1e6fc08SKevin Wolf
3806a7014efSAlberto Garcia# Using snapshot=on with a non-existent TMPDIR
381ad20319aSAndrey Shinkevichif [ "${VALGRIND_QEMU_VM}" == "y" ]; then
382ad20319aSAndrey Shinkevich    _casenotrun "Valgrind needs a valid TMPDIR for itself"
383ad20319aSAndrey Shinkevichfi
384ad20319aSAndrey ShinkevichVALGRIND_QEMU_VM= \
3856a7014efSAlberto GarciaTMPDIR=/nonexistent run_qemu -drive driver=null-co,snapshot=on
3866a7014efSAlberto Garcia
38730855137SKevin Wolf# Using snapshot=on together with read-only=on
38830855137SKevin Wolfecho "info block" |
38930855137SKevin Wolf    run_qemu -drive file="$TEST_IMG",snapshot=on,read-only=on,if=none,id=$device_id |
39030855137SKevin Wolf    _filter_qemu_io |
39159fba0aaSLukáš Doktor    sed -e 's#"[^"]*/vl\.[A-Za-z0-9]\{6\}"#SNAPSHOT_PATH#g'
39230855137SKevin Wolf
39330855137SKevin Wolf
39447e5df21SKevin Wolf# success, all done
39547e5df21SKevin Wolfecho "*** done"
39647e5df21SKevin Wolfrm -f $seq.full
39747e5df21SKevin Wolfstatus=0
398