147e5df21SKevin Wolf#!/bin/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 Wolfhere=`pwd` 2847e5df21SKevin Wolftmp=/tmp/$$ 2947e5df21SKevin Wolfstatus=1 # failure is the default! 3047e5df21SKevin Wolf 3147e5df21SKevin Wolf_cleanup() 3247e5df21SKevin Wolf{ 3347e5df21SKevin Wolf _cleanup_test_img 3447e5df21SKevin Wolf} 3547e5df21SKevin Wolftrap "_cleanup; exit \$status" 0 1 2 3 15 3647e5df21SKevin Wolf 3747e5df21SKevin Wolf# get standard environment, filters and checks 3847e5df21SKevin Wolf. ./common.rc 3947e5df21SKevin Wolf. ./common.filter 4047e5df21SKevin Wolf 4147e5df21SKevin Wolf_supported_fmt qcow2 4247e5df21SKevin Wolf_supported_proto file 4347e5df21SKevin Wolf_supported_os Linux 445262caa7SMax Reitz# A compat=0.10 image is created in this test which does not support anything 455262caa7SMax Reitz# other than refcount_bits=16 465262caa7SMax Reitz_unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' 4747e5df21SKevin Wolf 4847e5df21SKevin Wolffunction do_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 6247e5df21SKevin Wolffunction run_qemu() 6347e5df21SKevin Wolf{ 64768ee459SKevin Wolf do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_generated_node_ids 6547e5df21SKevin Wolf} 6647e5df21SKevin Wolf 6747e5df21SKevin Wolfsize=128M 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 78fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt= 79fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=on 80fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=1234 81fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,unknown_opt=foo 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 102354483e5SChristian Borntraegerecho === Device without drive === 103354483e5SChristian Borntraegerecho 104354483e5SChristian Borntraeger 105354483e5SChristian Borntraegerrun_qemu -device virtio-scsi-pci -device scsi-hd 106354483e5SChristian Borntraeger 107354483e5SChristian Borntraegerecho 1084db9c980SFam Zhengecho === Overriding backing file === 1094db9c980SFam Zhengecho 1104db9c980SFam Zheng 11115489c76SJeff Codyecho "info block" | run_qemu -drive file="$TEST_IMG",driver=qcow2,backing.file.filename="$TEST_IMG.orig" -nodefaults\ 11215489c76SJeff Cody | _filter_generated_node_ids 11347e5df21SKevin Wolf 1148ee79e70SKevin Wolf# Drivers that don't support backing files 1158ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",driver=raw,backing.file.filename="$TEST_IMG.orig" 1168ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",file.backing.driver=file,file.backing.filename="$TEST_IMG.orig" 1178ee79e70SKevin Wolfrun_qemu -drive file="$TEST_IMG",file.backing.driver=qcow2,file.backing.file.filename="$TEST_IMG.orig" 1188ee79e70SKevin Wolf 11947e5df21SKevin Wolfecho 12047e5df21SKevin Wolfecho === Enable and disable lazy refcounting on the command line, plus some invalid values === 12147e5df21SKevin Wolfecho 12247e5df21SKevin Wolf 123fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on 124fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off 125fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts= 126fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=42 127fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=foo 12847e5df21SKevin Wolf 12947e5df21SKevin Wolf 13047e5df21SKevin Wolfecho 13147e5df21SKevin Wolfecho === With version 2 images enabling lazy refcounts must fail === 13247e5df21SKevin Wolfecho 13347e5df21SKevin Wolf 13447e5df21SKevin Wolf_make_test_img -ocompat=0.10 $size 13547e5df21SKevin Wolf 136fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=on 137fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",format=qcow2,lazy-refcounts=off 13847e5df21SKevin Wolf 13947e5df21SKevin Wolfecho 14047e5df21SKevin Wolfecho === No medium === 14147e5df21SKevin Wolfecho 14247e5df21SKevin Wolf 14347e5df21SKevin Wolfrun_qemu -drive if=floppy 14447e5df21SKevin Wolfrun_qemu -drive if=ide,media=cdrom 14547e5df21SKevin Wolfrun_qemu -drive if=scsi,media=cdrom 14647e5df21SKevin Wolf 14747e5df21SKevin Wolfrun_qemu -drive if=ide 14847e5df21SKevin Wolfrun_qemu -drive if=virtio 14947e5df21SKevin Wolfrun_qemu -drive if=scsi 15047e5df21SKevin Wolf 151*289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in 152*289f3ebaSBo Tu pc) 15347e5df21SKevin Wolf run_qemu -drive if=none,id=disk -device ide-cd,drive=disk 15447e5df21SKevin Wolf run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-cd,drive=disk 15547e5df21SKevin Wolf run_qemu -drive if=none,id=disk -device ide-drive,drive=disk 15647e5df21SKevin Wolf run_qemu -drive if=none,id=disk -device ide-hd,drive=disk 15747e5df21SKevin Wolf run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-disk,drive=disk 15847e5df21SKevin Wolf run_qemu -drive if=none,id=disk -device lsi53c895a -device scsi-hd,drive=disk 159*289f3ebaSBo Tu ;; 160*289f3ebaSBo Tu *) 161*289f3ebaSBo Tu ;; 162*289f3ebaSBo Tuesac 16347e5df21SKevin Wolf 16447e5df21SKevin Wolfecho 16547e5df21SKevin Wolfecho === Read-only === 16647e5df21SKevin Wolfecho 16747e5df21SKevin Wolf 168*289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in 169*289f3ebaSBo Tu pc) 170fef9c191SJeff Cody run_qemu -drive file="$TEST_IMG",if=floppy,readonly=on 171fef9c191SJeff Cody run_qemu -drive file="$TEST_IMG",if=ide,media=cdrom,readonly=on 172fef9c191SJeff Cody run_qemu -drive file="$TEST_IMG",if=scsi,media=cdrom,readonly=on 173fef9c191SJeff Cody run_qemu -drive file="$TEST_IMG",if=ide,readonly=on 174*289f3ebaSBo Tu ;; 175*289f3ebaSBo Tu *) 176*289f3ebaSBo Tu ;; 177*289f3ebaSBo Tuesac 178*289f3ebaSBo Tu 179fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=virtio,readonly=on 180fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",if=scsi,readonly=on 18147e5df21SKevin Wolf 182*289f3ebaSBo Tucase "$QEMU_DEFAULT_MACHINE" in 183*289f3ebaSBo Tu pc) 184fef9c191SJeff Cody run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-cd,drive=disk 185fef9c191SJeff Cody run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-cd,drive=disk 186fef9c191SJeff Cody run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-drive,drive=disk 187fef9c191SJeff Cody run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device ide-hd,drive=disk 188fef9c191SJeff Cody run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-disk,drive=disk 189fef9c191SJeff Cody run_qemu -drive file="$TEST_IMG",if=none,id=disk,readonly=on -device lsi53c895a -device scsi-hd,drive=disk 190*289f3ebaSBo Tu ;; 191*289f3ebaSBo Tu *) 192*289f3ebaSBo Tu ;; 193*289f3ebaSBo Tuesac 19447e5df21SKevin Wolf 19547e5df21SKevin Wolfecho 19647e5df21SKevin Wolfecho === Cache modes === 19747e5df21SKevin Wolfecho 19847e5df21SKevin Wolf 19947e5df21SKevin Wolf# Cannot use the test image because cache=none might not work on the host FS 20047e5df21SKevin Wolf# Use cdrom so that we won't get errors about missing media 20147e5df21SKevin Wolf 202fc17c259SKevin Wolfrun_qemu -drive driver=null-co,cache=none 203fc17c259SKevin Wolfrun_qemu -drive driver=null-co,cache=directsync 204fc17c259SKevin Wolfrun_qemu -drive driver=null-co,cache=writeback 205fc17c259SKevin Wolfrun_qemu -drive driver=null-co,cache=writethrough 206fc17c259SKevin Wolfrun_qemu -drive driver=null-co,cache=unsafe 207fc17c259SKevin Wolfrun_qemu -drive driver=null-co,cache=invalid_value 20847e5df21SKevin Wolf 209768ee459SKevin Wolf# Can't test direct=on here because O_DIRECT might not be supported on this FS 210768ee459SKevin Wolf# Test 142 checks the direct=on cases 211768ee459SKevin Wolf 212768ee459SKevin Wolffor cache in writeback writethrough unsafe invalid_value; do 213768ee459SKevin Wolf echo -e "info block\ninfo block file\ninfo block backing\ninfo block backing-file" | \ 214768ee459SKevin Wolf run_qemu -drive file="$TEST_IMG",cache=$cache,backing.file.filename="$TEST_IMG.base",backing.cache.no-flush=on,backing.cache.writeback=on,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file -nodefaults 215768ee459SKevin Wolfdone 216768ee459SKevin Wolf 2172af5ef70SKevin Wolfecho 2182af5ef70SKevin Wolfecho === Specifying the protocol layer === 2192af5ef70SKevin Wolfecho 2202af5ef70SKevin Wolf 221fef9c191SJeff Codyrun_qemu -drive file="$TEST_IMG",file.driver=file 2222af5ef70SKevin Wolf 22398289620SKevin Wolfecho 224765003dbSKevin Wolfecho === Leaving out required options === 225765003dbSKevin Wolfecho 226765003dbSKevin Wolf 227765003dbSKevin Wolfrun_qemu -drive driver=file 228765003dbSKevin Wolfrun_qemu -drive driver=nbd 229765003dbSKevin Wolfrun_qemu -drive driver=raw 230765003dbSKevin Wolfrun_qemu -drive file.driver=file 231765003dbSKevin Wolfrun_qemu -drive file.driver=nbd 232765003dbSKevin Wolfrun_qemu -drive file.driver=raw 233765003dbSKevin Wolfrun_qemu -drive foo=bar 234765003dbSKevin Wolf 235765003dbSKevin Wolfecho 2365abbf0eeSKevin Wolfecho === Specifying both an option and its legacy alias === 2375abbf0eeSKevin Wolfecho 2385abbf0eeSKevin Wolf 2395abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops=1234,throttling.iops-total=5678 2405abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_rd=1234,throttling.iops-read=5678 2415abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_wr=1234,throttling.iops-write=5678 2425abbf0eeSKevin Wolf 2435abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps=1234,throttling.bps-total=5678 2445abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_rd=1234,throttling.bps-read=5678 2455abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_wr=1234,throttling.bps-write=5678 2465abbf0eeSKevin Wolf 2475abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_max=1234,throttling.iops-total-max=5678 2485abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_rd_max=1234,throttling.iops-read-max=5678 2495abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_wr_max=1234,throttling.iops-write-max=5678 2505abbf0eeSKevin Wolf 2515abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_max=1234,throttling.bps-total-max=5678 2525abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_rd_max=1234,throttling.bps-read-max=5678 2535abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",bps_wr_max=1234,throttling.bps-write-max=5678 2545abbf0eeSKevin Wolf 2555abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",iops_size=1234,throttling.iops-size=5678 2565abbf0eeSKevin Wolfrun_qemu -drive file="$TEST_IMG",readonly=on,read-only=off 2575abbf0eeSKevin Wolf 2585abbf0eeSKevin Wolfecho 25998289620SKevin Wolfecho === Parsing protocol from file name === 26098289620SKevin Wolfecho 26198289620SKevin Wolf 26298289620SKevin Wolf# Protocol strings are supposed to be parsed from traditional option strings, 26398289620SKevin Wolf# but not when using driver-specific options. We can distinguish them by the 26498289620SKevin Wolf# error message for non-existing files. 26598289620SKevin Wolf 26698289620SKevin Wolfrun_qemu -hda foo:bar 26798289620SKevin Wolfrun_qemu -drive file=foo:bar 26898289620SKevin Wolfrun_qemu -drive file.filename=foo:bar 26998289620SKevin Wolf 270e3fa4bfaSKevin Wolfrun_qemu -hda "file:$TEST_IMG" 271e3fa4bfaSKevin Wolfrun_qemu -drive file="file:$TEST_IMG" 272e3fa4bfaSKevin Wolfrun_qemu -drive file.filename="file:$TEST_IMG" 273e3fa4bfaSKevin Wolf 274f32f988cSKevin Wolfecho 275f32f988cSKevin Wolfecho === Snapshot mode === 276f32f988cSKevin Wolfecho 277f32f988cSKevin Wolf 278f32f988cSKevin Wolf$QEMU_IO -c "write -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io 279f32f988cSKevin Wolf 280*289f3ebaSBo Tudevice_id="drive0" 281*289f3ebaSBo Tu 282*289f3ebaSBo 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 283*289f3ebaSBo 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 284*289f3ebaSBo 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\ 285*289f3ebaSBo Tu | _filter_qemu_io 286*289f3ebaSBo 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\ 287*289f3ebaSBo Tu | _filter_qemu_io 288*289f3ebaSBo 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 289*289f3ebaSBo 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 290b998875dSKevin Wolf 291b998875dSKevin Wolf# Opening a read-only file r/w with snapshot=on 292b998875dSKevin Wolfchmod u-w "$TEST_IMG" 293*289f3ebaSBo 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 294*289f3ebaSBo 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 295b998875dSKevin Wolfchmod u+w "$TEST_IMG" 296f32f988cSKevin Wolf 297f32f988cSKevin Wolf$QEMU_IO -c "read -P 0x11 0 4k" "$TEST_IMG" | _filter_qemu_io 298f32f988cSKevin Wolf 299*289f3ebaSBo 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 300f32f988cSKevin Wolf 301f32f988cSKevin Wolf$QEMU_IO -c "read -P 0x22 0 4k" "$TEST_IMG" | _filter_qemu_io 302f32f988cSKevin Wolf 303*289f3ebaSBo Tuecho -e "qemu-io $device_id \"write -P 0x33 0 4k\"\ncommit $device_id" | run_qemu -drive file="$TEST_IMG",snapshot=on,if=none,id=$device_id\ 304*289f3ebaSBo Tu | _filter_qemu_io 305b1e6fc08SKevin Wolf 306b1e6fc08SKevin Wolf$QEMU_IO -c "read -P 0x33 0 4k" "$TEST_IMG" | _filter_qemu_io 307b1e6fc08SKevin Wolf 30847e5df21SKevin Wolf# success, all done 30947e5df21SKevin Wolfecho "*** done" 31047e5df21SKevin Wolfrm -f $seq.full 31147e5df21SKevin Wolfstatus=0 312