xref: /openbmc/qemu/tests/qemu-iotests/051 (revision 22329f0d2963515e031584d21a03d3585b19cbf9)
111a82d14SPhilippe Mathieu-Daudé#!/usr/bin/env bash
29dd003a9SVladimir Sementsov-Ogievskiy# group: rw
347e5df21SKevin Wolf#
447e5df21SKevin Wolf# Test command line configuration of block devices and driver-specific options
547e5df21SKevin Wolf#
647e5df21SKevin Wolf# Copyright (C) 2013 Red Hat, Inc.
747e5df21SKevin Wolf#
847e5df21SKevin Wolf# This program is free software; you can redistribute it and/or modify
947e5df21SKevin Wolf# it under the terms of the GNU General Public License as published by
1047e5df21SKevin Wolf# the Free Software Foundation; either version 2 of the License, or
1147e5df21SKevin Wolf# (at your option) any later version.
1247e5df21SKevin Wolf#
1347e5df21SKevin Wolf# This program is distributed in the hope that it will be useful,
1447e5df21SKevin Wolf# but WITHOUT ANY WARRANTY; without even the implied warranty of
1547e5df21SKevin Wolf# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1647e5df21SKevin Wolf# GNU General Public License for more details.
1747e5df21SKevin Wolf#
1847e5df21SKevin Wolf# You should have received a copy of the GNU General Public License
1947e5df21SKevin Wolf# along with this program.  If not, see <http://www.gnu.org/licenses/>.
2047e5df21SKevin Wolf#
2147e5df21SKevin Wolf
2247e5df21SKevin Wolf# creator
2347e5df21SKevin Wolfowner=kwolf@redhat.com
2447e5df21SKevin Wolf
2547e5df21SKevin Wolfseq=`basename $0`
2647e5df21SKevin Wolfecho "QA output created by $seq"
2747e5df21SKevin Wolf
2847e5df21SKevin Wolfstatus=1	# failure is the default!
2947e5df21SKevin Wolf
3047e5df21SKevin Wolf_cleanup()
3147e5df21SKevin Wolf{
3247e5df21SKevin Wolf	_cleanup_test_img
3347e5df21SKevin Wolf}
3447e5df21SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15
3547e5df21SKevin Wolf
3647e5df21SKevin Wolf# get standard environment, filters and checks
3747e5df21SKevin Wolf. ./common.rc
3847e5df21SKevin Wolf. ./common.filter
3947e5df21SKevin Wolf
4047e5df21SKevin Wolf_supported_fmt qcow2
4147e5df21SKevin Wolf_supported_proto file
425262caa7SMax Reitz# A compat=0.10 image is created in this test which does not support anything
433be2024aSMax Reitz# other than refcount_bits=16;
443be2024aSMax Reitz# it also will not support an external data file
453be2024aSMax Reitz_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file
46c85c6d9eSThomas Huth_require_drivers nbd
4747e5df21SKevin Wolf
488cedcffdSEric Blakedo_run_qemu()
4947e5df21SKevin Wolf{
5047e5df21SKevin Wolf    echo Testing: "$@"
514db9c980SFam Zheng    (
524db9c980SFam Zheng        if ! test -t 0; then
534db9c980SFam Zheng            while read cmd; do
544db9c980SFam Zheng                echo $cmd
554db9c980SFam Zheng            done
564db9c980SFam Zheng        fi
574db9c980SFam Zheng        echo quit
584db9c980SFam Zheng    ) | $QEMU -nographic -monitor stdio -serial none "$@"
5947e5df21SKevin Wolf    echo
6047e5df21SKevin Wolf}
6147e5df21SKevin Wolf
628cedcffdSEric Blakerun_qemu()
6347e5df21SKevin Wolf{
6469404d9eSKevin Wolf    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu |
6569404d9eSKevin Wolf        _filter_generated_node_ids | _filter_hmp
6647e5df21SKevin Wolf}
6747e5df21SKevin Wolf
6847e5df21SKevin Wolfsize=128M
69dd87de06SBo Tudevice_id="drive0"
7047e5df21SKevin Wolf
7147e5df21SKevin Wolf_make_test_img $size
721ab39193SJeff Codycp "$TEST_IMG" "$TEST_IMG.orig"
731ab39193SJeff Codymv "$TEST_IMG" "$TEST_IMG.base"
74b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $size
7547e5df21SKevin Wolf
7647e5df21SKevin Wolfecho
7747e5df21SKevin Wolfecho === Unknown option ===
7847e5df21SKevin Wolfecho
7947e5df21SKevin Wolf
80dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=,if=none,id=$device_id
81dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=on,if=none,id=$device_id
82dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=1234,if=none,id=$device_id
83dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=foo,if=none,id=$device_id
8447e5df21SKevin Wolf
854db9c980SFam Zhengecho
86eb909c7fSKevin Wolfecho === Unknown protocol option ===
87eb909c7fSKevin Wolfecho
88eb909c7fSKevin Wolf
89eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=
90eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=on
91eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=1234
92eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=foo
93eb909c7fSKevin Wolf
94eb909c7fSKevin Wolfecho
9506d22aa3SKevin Wolfecho === Invalid format ===
9606d22aa3SKevin Wolfecho
9706d22aa3SKevin Wolf
9806d22aa3SKevin Wolfrun_qemu -drive file="$TEST_IMG",format=foo
9906d22aa3SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=foo
10017b005f1SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=raw,format=qcow2
10180495fdfSMax Reitzrun_qemu -drive file="$TEST_IMG",driver=qcow2,format=qcow2
10206d22aa3SKevin Wolf
10306d22aa3SKevin Wolfecho
104824808ddSKevin Wolfecho === Node names ===
105824808ddSKevin Wolfecho
106824808ddSKevin Wolf
107824808ddSKevin Wolf# Maximum length: 31 characters
108824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=x123456789012345678901234567890
109824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=x1234567890123456789012345678901
110824808ddSKevin Wolf
111824808ddSKevin Wolf# First character must be alphabetic
112824808ddSKevin Wolf# Following characters alphanumeric or -._
113824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=All-Types.of_all0wed_chars
114824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=123foo
115824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=_foo
116824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=foo#12
117824808ddSKevin Wolf
118824808ddSKevin Wolfecho
119354483e5SChristian Borntraegerecho === Device without drive ===
120354483e5SChristian Borntraegerecho
121354483e5SChristian Borntraeger
122*22329f0dSLaurent Vivierrun_qemu -device virtio-scsi -device scsi-hd
123354483e5SChristian Borntraeger
124354483e5SChristian Borntraegerecho
1254db9c980SFam Zhengecho === Overriding backing file ===
1264db9c980SFam Zhengecho
1274db9c980SFam Zheng
128dd87de06SBo Tuecho "info block" | run_qemu -drive file="$TEST_IMG",driver=qcow2,backing.file.filename="$TEST_IMG.orig",if=none,id=$device_id -nodefaults\
12915489c76SJeff Cody                  | _filter_generated_node_ids
13047e5df21SKevin Wolf
1318ee79e70SKevin Wolf# Drivers that don't support backing files
1328ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=raw,backing.file.filename="$TEST_IMG.orig"
1338ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",file.backing.driver=file,file.backing.filename="$TEST_IMG.orig"
1348ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",file.backing.driver=qcow2,file.backing.file.filename="$TEST_IMG.orig"
1358ee79e70SKevin Wolf
13647e5df21SKevin Wolfecho
13747e5df21SKevin Wolfecho === Enable and disable lazy refcounting on the command line, plus some invalid values ===
13847e5df21SKevin Wolfecho
13947e5df21SKevin Wolf
1407e0db6f4SMax Reitz_make_test_img -o compat=1.1 "$size"
1417e0db6f4SMax Reitz
142fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
143fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
144fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=
145fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=42
146fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=foo
14747e5df21SKevin Wolf
14847e5df21SKevin Wolf
14947e5df21SKevin Wolfecho
15047e5df21SKevin Wolfecho === With version 2 images enabling lazy refcounts must fail ===
15147e5df21SKevin Wolfecho
15247e5df21SKevin Wolf
15347e5df21SKevin Wolf_make_test_img -o compat=0.10 $size
15447e5df21SKevin Wolf
155fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
156fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
15747e5df21SKevin Wolf
15847e5df21SKevin Wolfecho
15947e5df21SKevin Wolfecho === No medium ===
16047e5df21SKevin Wolfecho
16147e5df21SKevin Wolf
162dd87de06SBo Tucase "$QEMU_DEFAULT_MACHINE" in
163dd87de06SBo Tu    pc)
16447e5df21SKevin Wolf        run_qemu -drive if=floppy
16547e5df21SKevin Wolf        run_qemu -drive if=ide,media=cdrom
16647e5df21SKevin Wolf        run_qemu -drive if=ide
167dd87de06SBo Tu        ;;
168dd87de06SBo Tu     *)
169dd87de06SBo Tu        ;;
170dd87de06SBo Tuesac
171dd87de06SBo Tu
172dd87de06SBo Turun_qemu -drive if=virtio
17347e5df21SKevin Wolf
174289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in
175289f3ebaSBo Tu    pc)
17647e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device ide-cd,drive=disk
17747e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-cd,drive=disk
17847e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device ide-hd,drive=disk
17947e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-hd,drive=disk
180289f3ebaSBo Tu        ;;
181289f3ebaSBo Tu     *)
182289f3ebaSBo Tu        ;;
183289f3ebaSBo Tuesac
18447e5df21SKevin Wolf
18547e5df21SKevin Wolfecho
1866c870535SKevin Wolfecho === Attach to node in non-default iothread ===
1876c870535SKevin Wolfecho
1886c870535SKevin Wolf
1896c870535SKevin Wolfcase "$QEMU_DEFAULT_MACHINE" in
1906c870535SKevin Wolf    pc)
1916c870535SKevin 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"
1926c870535SKevin Wolf
1936c870535SKevin Wolf        # Can't add a device in the main thread while virtio-scsi0 uses the node
1946c870535SKevin Wolf        run_qemu $iothread -device ide-hd,drive=disk,share-rw=on
1956c870535SKevin Wolf        run_qemu $iothread -device virtio-blk-pci,drive=disk,share-rw=on
1966c870535SKevin Wolf        run_qemu $iothread -device lsi53c895a,id=lsi0 -device scsi-hd,bus=lsi0.0,drive=disk,share-rw=on
1976c870535SKevin Wolf        run_qemu $iothread -device virtio-scsi,id=virtio-scsi1 -device scsi-hd,bus=virtio-scsi1.0,drive=disk,share-rw=on
1986c870535SKevin Wolf
1996c870535SKevin Wolf        # virtio-blk enables the iothread only when the driver initialises the
2006c870535SKevin Wolf        # device, so a second virtio-blk device can't be added even with the
2016c870535SKevin Wolf        # same iothread. virtio-scsi allows this.
2026c870535SKevin Wolf        run_qemu $iothread -device virtio-blk-pci,drive=disk,iohtread=iothread0,share-rw=on
2036c870535SKevin Wolf        run_qemu $iothread -device virtio-scsi,id=virtio-scsi1,iothread=thread0 -device scsi-hd,bus=virtio-scsi1.0,drive=disk,share-rw=on
2046c870535SKevin Wolf        ;;
2056c870535SKevin Wolf     *)
2066c870535SKevin Wolf        ;;
2076c870535SKevin Wolfesac
2086c870535SKevin Wolf
2096c870535SKevin Wolfecho
21047e5df21SKevin Wolfecho === Read-only ===
21147e5df21SKevin Wolfecho
21247e5df21SKevin Wolf
213289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in
214289f3ebaSBo Tu    pc)
215fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=floppy,readonly=on
216fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=ide,media=cdrom,readonly=on
217fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=ide,readonly=on
218289f3ebaSBo Tu        ;;
219289f3ebaSBo Tu     *)
220289f3ebaSBo Tu        ;;
221289f3ebaSBo Tuesac
222289f3ebaSBo Tu
223fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=virtio,readonly=on
22447e5df21SKevin Wolf
225289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in
226289f3ebaSBo Tu    pc)
227fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-cd,drive=disk
228fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-cd,drive=disk
229fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-hd,drive=disk
230fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-hd,drive=disk
231289f3ebaSBo Tu        ;;
232289f3ebaSBo Tu     *)
233289f3ebaSBo Tu        ;;
234289f3ebaSBo Tuesac
23547e5df21SKevin Wolf
23647e5df21SKevin Wolfecho
23747e5df21SKevin Wolfecho === Cache modes ===
23847e5df21SKevin Wolfecho
23947e5df21SKevin Wolf
24047e5df21SKevin Wolf# Cannot use the test image because cache=none might not work on the host FS
24147e5df21SKevin Wolf# Use cdrom so that we won't get errors about missing media
24247e5df21SKevin Wolf
243a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=none
244a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=directsync
245a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=writeback
246a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=writethrough
247a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=unsafe
248fc17c259SKevin Wolfrun_qemu -drive driver=null-co,cache=invalid_value
24947e5df21SKevin Wolf
250768ee459SKevin Wolf# Can't test direct=on here because O_DIRECT might not be supported on this FS
251768ee459SKevin Wolf# Test 142 checks the direct=on cases
252768ee459SKevin Wolf
253768ee459SKevin Wolffor cache in writeback writethrough unsafe invalid_value; do
254b43671f8SEric Blake    printf "info block %s\n" '' file backing backing-file | \
25561de4c68SKevin 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
256768ee459SKevin Wolfdone
257768ee459SKevin Wolf
2582af5ef70SKevin Wolfecho
2592af5ef70SKevin Wolfecho === Specifying the protocol layer ===
2602af5ef70SKevin Wolfecho
2612af5ef70SKevin Wolf
262fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",file.driver=file
2632af5ef70SKevin Wolf
26498289620SKevin Wolfecho
265765003dbSKevin Wolfecho === Leaving out required options ===
266765003dbSKevin Wolfecho
267765003dbSKevin Wolf
268765003dbSKevin Wolfrun_qemu -drive driver=file
26942dc10f1SMax Reitzrun_qemu -drive driver=file,filename=
270765003dbSKevin Wolfrun_qemu -drive driver=nbd
271765003dbSKevin Wolfrun_qemu -drive driver=raw
272765003dbSKevin Wolfrun_qemu -drive file.driver=file
273765003dbSKevin Wolfrun_qemu -drive file.driver=nbd
274765003dbSKevin Wolfrun_qemu -drive file.driver=raw
275765003dbSKevin Wolfrun_qemu -drive foo=bar
276765003dbSKevin Wolf
277765003dbSKevin Wolfecho
2785abbf0eeSKevin Wolfecho === Specifying both an option and its legacy alias ===
2795abbf0eeSKevin Wolfecho
2805abbf0eeSKevin Wolf
2815abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops=1234,throttling.iops-total=5678
2825abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_rd=1234,throttling.iops-read=5678
2835abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_wr=1234,throttling.iops-write=5678
2845abbf0eeSKevin Wolf
2855abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps=1234,throttling.bps-total=5678
2865abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_rd=1234,throttling.bps-read=5678
2875abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_wr=1234,throttling.bps-write=5678
2885abbf0eeSKevin Wolf
2895abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_max=1234,throttling.iops-total-max=5678
2905abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_rd_max=1234,throttling.iops-read-max=5678
2915abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_wr_max=1234,throttling.iops-write-max=5678
2925abbf0eeSKevin Wolf
2935abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_max=1234,throttling.bps-total-max=5678
2945abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_rd_max=1234,throttling.bps-read-max=5678
2955abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_wr_max=1234,throttling.bps-write-max=5678
2965abbf0eeSKevin Wolf
2975abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_size=1234,throttling.iops-size=5678
2985abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",readonly=on,read-only=off
2995abbf0eeSKevin Wolf
3005abbf0eeSKevin Wolfecho
301e9b15550SFam Zhengecho === Catching negative/large throttling values ===
302e9b15550SFam Zhengecho
303e9b15550SFam Zheng
304e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",iops=-1
305e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=-2
306e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps_rd=-3
307e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps_rd_max=-3
308e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",throttling.iops-total=-4
309e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",throttling.bps-total=-5
310e9b15550SFam Zheng# These are accepted
311e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=0
312e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=1
313e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=1000000000000000
314e9b15550SFam Zheng# While these are not
315e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=1000000000000001
316e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=9999999999999999
317e9b15550SFam Zheng
318e9b15550SFam Zhengecho
31998289620SKevin Wolfecho === Parsing protocol from file name ===
32098289620SKevin Wolfecho
32198289620SKevin Wolf
32298289620SKevin Wolf# Protocol strings are supposed to be parsed from traditional option strings,
32398289620SKevin Wolf# but not when using driver-specific options. We can distinguish them by the
32498289620SKevin Wolf# error message for non-existing files.
32598289620SKevin Wolf
32698289620SKevin Wolfrun_qemu -hda foo:bar
32798289620SKevin Wolfrun_qemu -drive file=foo:bar
32898289620SKevin Wolfrun_qemu -drive file.filename=foo:bar
32998289620SKevin Wolf
330e3fa4bfaSKevin Wolfrun_qemu -hda "file:$TEST_IMG"
331e3fa4bfaSKevin Wolfrun_qemu -drive file="file:$TEST_IMG"
332e3fa4bfaSKevin Wolfrun_qemu -drive file.filename="file:$TEST_IMG"
333e3fa4bfaSKevin Wolf
334f32f988cSKevin Wolfecho
335f32f988cSKevin Wolfecho === Snapshot mode ===
336f32f988cSKevin Wolfecho
337f32f988cSKevin Wolf
338f32f988cSKevin Wolf$QEMU_IO -c "write -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io
339f32f988cSKevin Wolf
340289f3ebaSBo Tu
341289f3ebaSBo 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
342289f3ebaSBo 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
343289f3ebaSBo 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\
344289f3ebaSBo Tu                                                 | _filter_qemu_io
345289f3ebaSBo 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\
346289f3ebaSBo Tu                                                 | _filter_qemu_io
347289f3ebaSBo 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
348289f3ebaSBo 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
349b998875dSKevin Wolf
350b998875dSKevin Wolf# Opening a read-only file r/w with snapshot=on
351b998875dSKevin Wolfchmod u-w "$TEST_IMG"
352289f3ebaSBo 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
353289f3ebaSBo 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
354b998875dSKevin Wolfchmod u+w "$TEST_IMG"
355f32f988cSKevin Wolf
356f32f988cSKevin Wolf$QEMU_IO -c "read -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io
357f32f988cSKevin Wolf
358289f3ebaSBo 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
359f32f988cSKevin Wolf
360f32f988cSKevin Wolf$QEMU_IO -c "read -P 0x22 0 4k" "$TEST_IMG" | _filter_qemu_io
361f32f988cSKevin Wolf
362b43671f8SEric Blakeprintf %b "qemu-io $device_id \"write -P 0x33 0 4k\"\ncommit $device_id\n" |
363b43671f8SEric Blake    run_qemu -drive file="$TEST_IMG",snapshot=on,if=none,id=$device_id |
364b43671f8SEric Blake    _filter_qemu_io
365b1e6fc08SKevin Wolf
366b1e6fc08SKevin Wolf$QEMU_IO -c "read -P 0x33 0 4k" "$TEST_IMG" | _filter_qemu_io
367b1e6fc08SKevin Wolf
3686a7014efSAlberto Garcia# Using snapshot=on with a non-existent TMPDIR
369ad20319aSAndrey Shinkevichif [ "${VALGRIND_QEMU_VM}" == "y" ]; then
370ad20319aSAndrey Shinkevich    _casenotrun "Valgrind needs a valid TMPDIR for itself"
371ad20319aSAndrey Shinkevichfi
372ad20319aSAndrey ShinkevichVALGRIND_QEMU_VM= \
3736a7014efSAlberto GarciaTMPDIR=/nonexistent run_qemu -drive driver=null-co,snapshot=on
3746a7014efSAlberto Garcia
37530855137SKevin Wolf# Using snapshot=on together with read-only=on
37630855137SKevin Wolfecho "info block" |
37730855137SKevin Wolf    run_qemu -drive file="$TEST_IMG",snapshot=on,read-only=on,if=none,id=$device_id |
37830855137SKevin Wolf    _filter_qemu_io |
37959fba0aaSLukáš Doktor    sed -e 's#"[^"]*/vl\.[A-Za-z0-9]\{6\}"#SNAPSHOT_PATH#g'
38030855137SKevin Wolf
38130855137SKevin Wolf
38247e5df21SKevin Wolf# success, all done
38347e5df21SKevin Wolfecho "*** done"
38447e5df21SKevin Wolfrm -f $seq.full
38547e5df21SKevin Wolfstatus=0
386