xref: /qemu/tests/qemu-iotests/051 (revision 0c83471bd75d329f4945e27dc1aa3a6cc2fda3bf)
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
48*0c83471bSThomas Huthif [ "$QEMU_DEFAULT_MACHINE" = "pc" ]; then
49*0c83471bSThomas Huth    _require_devices lsi53c895a
50*0c83471bSThomas Huthfi
51*0c83471bSThomas Huth
528cedcffdSEric Blakedo_run_qemu()
5347e5df21SKevin Wolf{
5447e5df21SKevin Wolf    echo Testing: "$@"
554db9c980SFam Zheng    (
564db9c980SFam Zheng        if ! test -t 0; then
574db9c980SFam Zheng            while read cmd; do
584db9c980SFam Zheng                echo $cmd
594db9c980SFam Zheng            done
604db9c980SFam Zheng        fi
614db9c980SFam Zheng        echo quit
624db9c980SFam Zheng    ) | $QEMU -nographic -monitor stdio -serial none "$@"
6347e5df21SKevin Wolf    echo
6447e5df21SKevin Wolf}
6547e5df21SKevin Wolf
668cedcffdSEric Blakerun_qemu()
6747e5df21SKevin Wolf{
6869404d9eSKevin Wolf    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu |
6969404d9eSKevin Wolf        _filter_generated_node_ids | _filter_hmp
7047e5df21SKevin Wolf}
7147e5df21SKevin Wolf
7247e5df21SKevin Wolfsize=128M
73dd87de06SBo Tudevice_id="drive0"
7447e5df21SKevin Wolf
7547e5df21SKevin Wolf_make_test_img $size
761ab39193SJeff Codycp "$TEST_IMG" "$TEST_IMG.orig"
771ab39193SJeff Codymv "$TEST_IMG" "$TEST_IMG.base"
78b66ff2c2SEric Blake_make_test_img -b "$TEST_IMG.base" -F $IMGFMT $size
7947e5df21SKevin Wolf
8047e5df21SKevin Wolfecho
8147e5df21SKevin Wolfecho === Unknown option ===
8247e5df21SKevin Wolfecho
8347e5df21SKevin Wolf
84dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=,if=none,id=$device_id
85dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=on,if=none,id=$device_id
86dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=1234,if=none,id=$device_id
87dd87de06SBo Turun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=foo,if=none,id=$device_id
8847e5df21SKevin Wolf
894db9c980SFam Zhengecho
90eb909c7fSKevin Wolfecho === Unknown protocol option ===
91eb909c7fSKevin Wolfecho
92eb909c7fSKevin Wolf
93eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=
94eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=on
95eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=1234
96eb909c7fSKevin Wolfrun_qemu -drive file="$TEST_IMG",format=qcow2,file.unknown_opt=foo
97eb909c7fSKevin Wolf
98eb909c7fSKevin Wolfecho
9906d22aa3SKevin Wolfecho === Invalid format ===
10006d22aa3SKevin Wolfecho
10106d22aa3SKevin Wolf
10206d22aa3SKevin Wolfrun_qemu -drive file="$TEST_IMG",format=foo
10306d22aa3SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=foo
10417b005f1SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=raw,format=qcow2
10580495fdfSMax Reitzrun_qemu -drive file="$TEST_IMG",driver=qcow2,format=qcow2
10606d22aa3SKevin Wolf
10706d22aa3SKevin Wolfecho
108824808ddSKevin Wolfecho === Node names ===
109824808ddSKevin Wolfecho
110824808ddSKevin Wolf
111824808ddSKevin Wolf# Maximum length: 31 characters
112824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=x123456789012345678901234567890
113824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=x1234567890123456789012345678901
114824808ddSKevin Wolf
115824808ddSKevin Wolf# First character must be alphabetic
116824808ddSKevin Wolf# Following characters alphanumeric or -._
117824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=All-Types.of_all0wed_chars
118824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=123foo
119824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=_foo
120824808ddSKevin Wolfrun_qemu -drive file="$TEST_IMG",node-name=foo#12
121824808ddSKevin Wolf
122824808ddSKevin Wolfecho
123354483e5SChristian Borntraegerecho === Device without drive ===
124354483e5SChristian Borntraegerecho
125354483e5SChristian Borntraeger
12622329f0dSLaurent Vivierrun_qemu -device virtio-scsi -device scsi-hd
127354483e5SChristian Borntraeger
128354483e5SChristian Borntraegerecho
1294db9c980SFam Zhengecho === Overriding backing file ===
1304db9c980SFam Zhengecho
1314db9c980SFam Zheng
132dd87de06SBo Tuecho "info block" | run_qemu -drive file="$TEST_IMG",driver=qcow2,backing.file.filename="$TEST_IMG.orig",if=none,id=$device_id -nodefaults\
13315489c76SJeff Cody                  | _filter_generated_node_ids
13447e5df21SKevin Wolf
1358ee79e70SKevin Wolf# Drivers that don't support backing files
1368ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=raw,backing.file.filename="$TEST_IMG.orig"
1378ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",file.backing.driver=file,file.backing.filename="$TEST_IMG.orig"
1388ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",file.backing.driver=qcow2,file.backing.file.filename="$TEST_IMG.orig"
1398ee79e70SKevin Wolf
14047e5df21SKevin Wolfecho
14147e5df21SKevin Wolfecho === Enable and disable lazy refcounting on the command line, plus some invalid values ===
14247e5df21SKevin Wolfecho
14347e5df21SKevin Wolf
1447e0db6f4SMax Reitz_make_test_img -o compat=1.1 "$size"
1457e0db6f4SMax Reitz
146fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
147fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
148fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=
149fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=42
150fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=foo
15147e5df21SKevin Wolf
15247e5df21SKevin Wolf
15347e5df21SKevin Wolfecho
15447e5df21SKevin Wolfecho === With version 2 images enabling lazy refcounts must fail ===
15547e5df21SKevin Wolfecho
15647e5df21SKevin Wolf
15747e5df21SKevin Wolf_make_test_img -o compat=0.10 $size
15847e5df21SKevin Wolf
159fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on
160fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off
16147e5df21SKevin Wolf
16247e5df21SKevin Wolfecho
16347e5df21SKevin Wolfecho === No medium ===
16447e5df21SKevin Wolfecho
16547e5df21SKevin Wolf
166dd87de06SBo Tucase "$QEMU_DEFAULT_MACHINE" in
167dd87de06SBo Tu    pc)
16847e5df21SKevin Wolf        run_qemu -drive if=floppy
16947e5df21SKevin Wolf        run_qemu -drive if=ide,media=cdrom
17047e5df21SKevin Wolf        run_qemu -drive if=ide
171dd87de06SBo Tu        ;;
172dd87de06SBo Tu     *)
173dd87de06SBo Tu        ;;
174dd87de06SBo Tuesac
175dd87de06SBo Tu
176dd87de06SBo Turun_qemu -drive if=virtio
17747e5df21SKevin Wolf
178289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in
179289f3ebaSBo Tu    pc)
18047e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device ide-cd,drive=disk
18147e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-cd,drive=disk
18247e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device ide-hd,drive=disk
18347e5df21SKevin Wolf        run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-hd,drive=disk
184289f3ebaSBo Tu        ;;
185289f3ebaSBo Tu     *)
186289f3ebaSBo Tu        ;;
187289f3ebaSBo Tuesac
18847e5df21SKevin Wolf
18947e5df21SKevin Wolfecho
1906c870535SKevin Wolfecho === Attach to node in non-default iothread ===
1916c870535SKevin Wolfecho
1926c870535SKevin Wolf
1936c870535SKevin Wolfcase "$QEMU_DEFAULT_MACHINE" in
1946c870535SKevin Wolf    pc)
1956c870535SKevin 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"
1966c870535SKevin Wolf
1976c870535SKevin Wolf        # Can't add a device in the main thread while virtio-scsi0 uses the node
1986c870535SKevin Wolf        run_qemu $iothread -device ide-hd,drive=disk,share-rw=on
1996c870535SKevin Wolf        run_qemu $iothread -device virtio-blk-pci,drive=disk,share-rw=on
2006c870535SKevin Wolf        run_qemu $iothread -device lsi53c895a,id=lsi0 -device scsi-hd,bus=lsi0.0,drive=disk,share-rw=on
2016c870535SKevin Wolf        run_qemu $iothread -device virtio-scsi,id=virtio-scsi1 -device scsi-hd,bus=virtio-scsi1.0,drive=disk,share-rw=on
2026c870535SKevin Wolf
2036c870535SKevin Wolf        # virtio-blk enables the iothread only when the driver initialises the
2046c870535SKevin Wolf        # device, so a second virtio-blk device can't be added even with the
2056c870535SKevin Wolf        # same iothread. virtio-scsi allows this.
206af6400afSKevin Wolf        run_qemu $iothread -device virtio-blk-pci,drive=disk,iothread=thread0,share-rw=on
2076c870535SKevin Wolf        run_qemu $iothread -device virtio-scsi,id=virtio-scsi1,iothread=thread0 -device scsi-hd,bus=virtio-scsi1.0,drive=disk,share-rw=on
2086c870535SKevin Wolf        ;;
2096c870535SKevin Wolf     *)
2106c870535SKevin Wolf        ;;
2116c870535SKevin Wolfesac
2126c870535SKevin Wolf
2136c870535SKevin Wolfecho
21447e5df21SKevin Wolfecho === Read-only ===
21547e5df21SKevin Wolfecho
21647e5df21SKevin Wolf
217289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in
218289f3ebaSBo Tu    pc)
219fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=floppy,readonly=on
220fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=ide,media=cdrom,readonly=on
221fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=ide,readonly=on
222289f3ebaSBo Tu        ;;
223289f3ebaSBo Tu     *)
224289f3ebaSBo Tu        ;;
225289f3ebaSBo Tuesac
226289f3ebaSBo Tu
227fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=virtio,readonly=on
22847e5df21SKevin Wolf
229289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in
230289f3ebaSBo Tu    pc)
231fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-cd,drive=disk
232fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-cd,drive=disk
233fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-hd,drive=disk
234fef9c191SJeff Cody        run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-hd,drive=disk
235289f3ebaSBo Tu        ;;
236289f3ebaSBo Tu     *)
237289f3ebaSBo Tu        ;;
238289f3ebaSBo Tuesac
23947e5df21SKevin Wolf
24047e5df21SKevin Wolfecho
24147e5df21SKevin Wolfecho === Cache modes ===
24247e5df21SKevin Wolfecho
24347e5df21SKevin Wolf
24447e5df21SKevin Wolf# Cannot use the test image because cache=none might not work on the host FS
24547e5df21SKevin Wolf# Use cdrom so that we won't get errors about missing media
24647e5df21SKevin Wolf
247a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=none
248a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=directsync
249a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=writeback
250a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=writethrough
251a6862418SAndrey Shinkevichrun_qemu -drive driver=null-co,read-zeroes=on,cache=unsafe
252fc17c259SKevin Wolfrun_qemu -drive driver=null-co,cache=invalid_value
25347e5df21SKevin Wolf
254768ee459SKevin Wolf# Can't test direct=on here because O_DIRECT might not be supported on this FS
255768ee459SKevin Wolf# Test 142 checks the direct=on cases
256768ee459SKevin Wolf
257768ee459SKevin Wolffor cache in writeback writethrough unsafe invalid_value; do
258b43671f8SEric Blake    printf "info block %s\n" '' file backing backing-file | \
25961de4c68SKevin 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
260768ee459SKevin Wolfdone
261768ee459SKevin Wolf
2622af5ef70SKevin Wolfecho
2632af5ef70SKevin Wolfecho === Specifying the protocol layer ===
2642af5ef70SKevin Wolfecho
2652af5ef70SKevin Wolf
266fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",file.driver=file
2672af5ef70SKevin Wolf
26898289620SKevin Wolfecho
269765003dbSKevin Wolfecho === Leaving out required options ===
270765003dbSKevin Wolfecho
271765003dbSKevin Wolf
272765003dbSKevin Wolfrun_qemu -drive driver=file
27342dc10f1SMax Reitzrun_qemu -drive driver=file,filename=
274765003dbSKevin Wolfrun_qemu -drive driver=nbd
275765003dbSKevin Wolfrun_qemu -drive driver=raw
276765003dbSKevin Wolfrun_qemu -drive file.driver=file
277765003dbSKevin Wolfrun_qemu -drive file.driver=nbd
278765003dbSKevin Wolfrun_qemu -drive file.driver=raw
279765003dbSKevin Wolfrun_qemu -drive foo=bar
280765003dbSKevin Wolf
281765003dbSKevin Wolfecho
2825abbf0eeSKevin Wolfecho === Specifying both an option and its legacy alias ===
2835abbf0eeSKevin Wolfecho
2845abbf0eeSKevin Wolf
2855abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops=1234,throttling.iops-total=5678
2865abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_rd=1234,throttling.iops-read=5678
2875abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_wr=1234,throttling.iops-write=5678
2885abbf0eeSKevin Wolf
2895abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps=1234,throttling.bps-total=5678
2905abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_rd=1234,throttling.bps-read=5678
2915abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_wr=1234,throttling.bps-write=5678
2925abbf0eeSKevin Wolf
2935abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_max=1234,throttling.iops-total-max=5678
2945abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_rd_max=1234,throttling.iops-read-max=5678
2955abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_wr_max=1234,throttling.iops-write-max=5678
2965abbf0eeSKevin Wolf
2975abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_max=1234,throttling.bps-total-max=5678
2985abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_rd_max=1234,throttling.bps-read-max=5678
2995abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_wr_max=1234,throttling.bps-write-max=5678
3005abbf0eeSKevin Wolf
3015abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_size=1234,throttling.iops-size=5678
3025abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",readonly=on,read-only=off
3035abbf0eeSKevin Wolf
3045abbf0eeSKevin Wolfecho
305e9b15550SFam Zhengecho === Catching negative/large throttling values ===
306e9b15550SFam Zhengecho
307e9b15550SFam Zheng
308e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",iops=-1
309e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=-2
310e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps_rd=-3
311e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps_rd_max=-3
312e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",throttling.iops-total=-4
313e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",throttling.bps-total=-5
314e9b15550SFam Zheng# These are accepted
315e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=0
316e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=1
317e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=1000000000000000
318e9b15550SFam Zheng# While these are not
319e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=1000000000000001
320e9b15550SFam Zhengrun_qemu -drive file="$TEST_IMG",bps=9999999999999999
321e9b15550SFam Zheng
322e9b15550SFam Zhengecho
32398289620SKevin Wolfecho === Parsing protocol from file name ===
32498289620SKevin Wolfecho
32598289620SKevin Wolf
32698289620SKevin Wolf# Protocol strings are supposed to be parsed from traditional option strings,
32798289620SKevin Wolf# but not when using driver-specific options. We can distinguish them by the
32898289620SKevin Wolf# error message for non-existing files.
32998289620SKevin Wolf
33098289620SKevin Wolfrun_qemu -hda foo:bar
33198289620SKevin Wolfrun_qemu -drive file=foo:bar
33298289620SKevin Wolfrun_qemu -drive file.filename=foo:bar
33398289620SKevin Wolf
334e3fa4bfaSKevin Wolfrun_qemu -hda "file:$TEST_IMG"
335e3fa4bfaSKevin Wolfrun_qemu -drive file="file:$TEST_IMG"
336e3fa4bfaSKevin Wolfrun_qemu -drive file.filename="file:$TEST_IMG"
337e3fa4bfaSKevin Wolf
338f32f988cSKevin Wolfecho
339f32f988cSKevin Wolfecho === Snapshot mode ===
340f32f988cSKevin Wolfecho
341f32f988cSKevin Wolf
342f32f988cSKevin Wolf$QEMU_IO -c "write -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io
343f32f988cSKevin Wolf
344289f3ebaSBo Tu
345289f3ebaSBo 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
346289f3ebaSBo 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
347289f3ebaSBo 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\
348289f3ebaSBo Tu                                                 | _filter_qemu_io
349289f3ebaSBo 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\
350289f3ebaSBo Tu                                                 | _filter_qemu_io
351289f3ebaSBo 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
352289f3ebaSBo 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
353b998875dSKevin Wolf
354b998875dSKevin Wolf# Opening a read-only file r/w with snapshot=on
355b998875dSKevin Wolfchmod u-w "$TEST_IMG"
356289f3ebaSBo 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
357289f3ebaSBo 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
358b998875dSKevin Wolfchmod u+w "$TEST_IMG"
359f32f988cSKevin Wolf
360f32f988cSKevin Wolf$QEMU_IO -c "read -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io
361f32f988cSKevin Wolf
362289f3ebaSBo 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
363f32f988cSKevin Wolf
364f32f988cSKevin Wolf$QEMU_IO -c "read -P 0x22 0 4k" "$TEST_IMG" | _filter_qemu_io
365f32f988cSKevin Wolf
366b43671f8SEric Blakeprintf %b "qemu-io $device_id \"write -P 0x33 0 4k\"\ncommit $device_id\n" |
367b43671f8SEric Blake    run_qemu -drive file="$TEST_IMG",snapshot=on,if=none,id=$device_id |
368b43671f8SEric Blake    _filter_qemu_io
369b1e6fc08SKevin Wolf
370b1e6fc08SKevin Wolf$QEMU_IO -c "read -P 0x33 0 4k" "$TEST_IMG" | _filter_qemu_io
371b1e6fc08SKevin Wolf
3726a7014efSAlberto Garcia# Using snapshot=on with a non-existent TMPDIR
373ad20319aSAndrey Shinkevichif [ "${VALGRIND_QEMU_VM}" == "y" ]; then
374ad20319aSAndrey Shinkevich    _casenotrun "Valgrind needs a valid TMPDIR for itself"
375ad20319aSAndrey Shinkevichfi
376ad20319aSAndrey ShinkevichVALGRIND_QEMU_VM= \
3776a7014efSAlberto GarciaTMPDIR=/nonexistent run_qemu -drive driver=null-co,snapshot=on
3786a7014efSAlberto Garcia
37930855137SKevin Wolf# Using snapshot=on together with read-only=on
38030855137SKevin Wolfecho "info block" |
38130855137SKevin Wolf    run_qemu -drive file="$TEST_IMG",snapshot=on,read-only=on,if=none,id=$device_id |
38230855137SKevin Wolf    _filter_qemu_io |
38359fba0aaSLukáš Doktor    sed -e 's#"[^"]*/vl\.[A-Za-z0-9]\{6\}"#SNAPSHOT_PATH#g'
38430855137SKevin Wolf
38530855137SKevin Wolf
38647e5df21SKevin Wolf# success, all done
38747e5df21SKevin Wolfecho "*** done"
38847e5df21SKevin Wolfrm -f $seq.full
38947e5df21SKevin Wolfstatus=0
390