[PATCH 00/20] qemu: Remove one of last two instances of -drive if=none usage

QEMU want's to deprecate -drive if=none. Stop clearing QEMU_CAPS_BLOCKDEV when SD cards are used. Please see 17/20 and 20/20 for more explanation. Obviously few cleanups snuck in as well. Peter Krempa (20): qemuxml2(argv|xml): Modernize 'blkdeviotune' tests qemuxml2(argv|xml): Modernize 'discard'/'detect-zero' tests qemuValidateDomainDeviceDefDisk: Separate disk frontend config validation qemu: validate: Validate blkdeviotune settings in the validator qemu: Move disk config validation to qemuValidateDomainDeviceDefDiskFrontend qemuCheckDiskConfig: Remove and untangle callers qemu: Rename qemuDiskBusNeedsDriveArg to qemuDiskBusIsSD qemuBuildDiskCommandLine: Clarify logic around building -device for disks qemuBuildDriveStr: Refactor formatting of command line for 'sd' cards qemuBuildDiskDeviceStr: Use XML disk bus type names in error message qemu: command: Remove 'virDomainDiskQEMUBus' enum converters qemuDomainSetBlockThreshold: Call qemuBlockNodeNamesDetect only without blockdev qemuDomainValidateStorageSource: Extract check for BLOCKDEV capability qemuDomainValidateStorageSource: Allow masking out blockdev support tests: Add tests for a virtio and sd disk in a single machine qemu: Forbid 'cdrom' on 'sd' bus qemu: Refuse blockjobs on disk bus='sd' with -blockdev qemu: Handle cases when 'qomName' isn't present qemu: Prepare for 'sd' card use together with blockdev qemu: process: Don't clear QEMU_CAPS_BLOCKDEV when SD card is present src/qemu/qemu_backup.c | 3 + src/qemu/qemu_checkpoint.c | 3 + src/qemu/qemu_command.c | 404 ++---------------- src/qemu/qemu_command.h | 7 +- src/qemu/qemu_domain.c | 65 ++- src/qemu/qemu_domain.h | 7 +- src/qemu/qemu_driver.c | 46 +- src/qemu/qemu_hotplug.c | 7 +- src/qemu/qemu_process.c | 17 +- src/qemu/qemu_validate.c | 383 +++++++++++++++-- src/qemu/qemu_validate.h | 1 + tests/qemublocktest.c | 7 +- ... blkdeviotune-group-num.x86_64-4.1.0.args} | 26 +- .../blkdeviotune-group-num.x86_64-latest.args | 50 +++ .../blkdeviotune-group-num.xml | 5 +- ...blkdeviotune-max-length.x86_64-4.1.0.args} | 26 +- ...blkdeviotune-max-length.x86_64-latest.args | 50 +++ .../blkdeviotune-max-length.xml | 5 +- ...rgs => blkdeviotune-max.x86_64-4.1.0.args} | 26 +- .../blkdeviotune-max.x86_64-latest.args | 50 +++ tests/qemuxml2argvdata/blkdeviotune-max.xml | 5 +- .../disk-arm-virtio-sd.aarch64-4.0.0.args | 39 ++ .../disk-arm-virtio-sd.aarch64-latest.args | 43 ++ tests/qemuxml2argvdata/disk-arm-virtio-sd.xml | 36 ++ .../disk-cdrom-bus-other.x86_64-latest.args | 13 +- .../qemuxml2argvdata/disk-cdrom-bus-other.xml | 11 - .../disk-detect-zeroes.x86_64-2.12.0.args | 1 + tests/qemuxml2argvdata/disk-detect-zeroes.xml | 5 +- ...rd.args => disk-discard.x86_64-4.1.0.args} | 22 +- .../disk-discard.x86_64-latest.args | 46 ++ tests/qemuxml2argvtest.c | 26 +- ... blkdeviotune-group-num.x86_64-latest.xml} | 0 ...blkdeviotune-max-length.x86_64-latest.xml} | 0 ...xml => blkdeviotune-max.x86_64-latest.xml} | 0 ...une.xml => blkdeviotune.x86_64-latest.xml} | 7 +- .../disk-arm-virtio-sd.aarch64-latest.xml | 41 ++ .../disk-cdrom-bus-other.xml | 11 - ...l => disk-detect-zeroes.x86_64-latest.xml} | 0 ...ard.xml => disk-discard.x86_64-latest.xml} | 7 +- tests/qemuxml2xmltest.c | 14 +- 40 files changed, 958 insertions(+), 557 deletions(-) rename tests/qemuxml2argvdata/{blkdeviotune-group-num.args => blkdeviotune-group-num.x86_64-4.1.0.args} (69%) create mode 100644 tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-latest.args rename tests/qemuxml2argvdata/{blkdeviotune-max-length.args => blkdeviotune-max-length.x86_64-4.1.0.args} (71%) create mode 100644 tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-latest.args rename tests/qemuxml2argvdata/{blkdeviotune-max.args => blkdeviotune-max.x86_64-4.1.0.args} (67%) create mode 100644 tests/qemuxml2argvdata/blkdeviotune-max.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.xml rename tests/qemuxml2argvdata/{disk-discard.args => disk-discard.x86_64-4.1.0.args} (59%) create mode 100644 tests/qemuxml2argvdata/disk-discard.x86_64-latest.args rename tests/qemuxml2xmloutdata/{blkdeviotune-group-num.xml => blkdeviotune-group-num.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{blkdeviotune-max-length.xml => blkdeviotune-max-length.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{blkdeviotune-max.xml => blkdeviotune-max.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{blkdeviotune.xml => blkdeviotune.x86_64-latest.xml} (88%) create mode 100644 tests/qemuxml2xmloutdata/disk-arm-virtio-sd.aarch64-latest.xml rename tests/qemuxml2xmloutdata/{disk-detect-zeroes.xml => disk-detect-zeroes.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{disk-discard.xml => disk-discard.x86_64-latest.xml} (87%) -- 2.26.2

Move the tests to DO_TEST_CAPS_LATEST. Since switch to blockdev stopped us formatting the tunning parameters on the command line let's also add version cases for qemu-4.1 data which doesn't enable blockdev. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- ... blkdeviotune-group-num.x86_64-4.1.0.args} | 26 ++++++---- .../blkdeviotune-group-num.x86_64-latest.args | 50 +++++++++++++++++++ .../blkdeviotune-group-num.xml | 5 +- ...blkdeviotune-max-length.x86_64-4.1.0.args} | 26 ++++++---- ...blkdeviotune-max-length.x86_64-latest.args | 50 +++++++++++++++++++ .../blkdeviotune-max-length.xml | 5 +- ...rgs => blkdeviotune-max.x86_64-4.1.0.args} | 26 ++++++---- .../blkdeviotune-max.x86_64-latest.args | 50 +++++++++++++++++++ tests/qemuxml2argvdata/blkdeviotune-max.xml | 5 +- tests/qemuxml2argvtest.c | 14 +++--- ... blkdeviotune-group-num.x86_64-latest.xml} | 0 ...blkdeviotune-max-length.x86_64-latest.xml} | 0 ...xml => blkdeviotune-max.x86_64-latest.xml} | 0 ...une.xml => blkdeviotune.x86_64-latest.xml} | 7 ++- tests/qemuxml2xmltest.c | 8 +-- 15 files changed, 228 insertions(+), 44 deletions(-) rename tests/qemuxml2argvdata/{blkdeviotune-group-num.args => blkdeviotune-group-num.x86_64-4.1.0.args} (69%) create mode 100644 tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-latest.args rename tests/qemuxml2argvdata/{blkdeviotune-max-length.args => blkdeviotune-max-length.x86_64-4.1.0.args} (71%) create mode 100644 tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-latest.args rename tests/qemuxml2argvdata/{blkdeviotune-max.args => blkdeviotune-max.x86_64-4.1.0.args} (67%) create mode 100644 tests/qemuxml2argvdata/blkdeviotune-max.x86_64-latest.args rename tests/qemuxml2xmloutdata/{blkdeviotune-group-num.xml => blkdeviotune-group-num.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{blkdeviotune-max-length.xml => blkdeviotune-max-length.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{blkdeviotune-max.xml => blkdeviotune-max.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{blkdeviotune.xml => blkdeviotune.x86_64-latest.xml} (88%) diff --git a/tests/qemuxml2argvdata/blkdeviotune-group-num.args b/tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-4.1.0.args similarity index 69% rename from tests/qemuxml2argvdata/blkdeviotune-group-num.args rename to tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-4.1.0.args index dfa7155b1e..8aa4c2be7d 100644 --- a/tests/qemuxml2argvdata/blkdeviotune-group-num.args +++ b/tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-4.1.0.args @@ -8,33 +8,41 @@ XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ QEMU_AUDIO_DRV=none \ /usr/bin/qemu-system-i386 \ --name QEMUGuest1 \ +-name guest=QEMUGuest1,debug-threads=on \ -S \ --machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc-i440fx-4.1,accel=tcg,usb=off,dump-guest-core=off \ +-cpu qemu64 \ -m 214 \ --realtime mlock=off \ +-overcommit mem-lock=off \ -smp 1,sockets=1,cores=1,threads=1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ -display none \ -no-user-config \ -nodefaults \ --chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\ -server,nowait \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ -mon chardev=charmonitor,id=monitor,mode=control \ -rtc base=utc \ -no-shutdown \ -no-acpi \ --usb \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ -drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\ cache=none,throttling.bps-total=5000,throttling.iops-total=6000,\ throttling.bps-total-max=10000,throttling.iops-total-max=11000,\ throttling.group=libvirt_iotune_group1 \ --device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ +-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1,\ +write-cache=on \ -drive file=/dev/HostVG/QEMUGuest2,format=qcow2,if=none,id=drive-ide0-0-1,\ cache=none,throttling.bps-read=5000,throttling.bps-write=5500,\ throttling.iops-read=3500,throttling.iops-write=4000,\ throttling.bps-read-max=6000,throttling.bps-write-max=6500,\ throttling.iops-read-max=7000,throttling.iops-write-max=7500,\ throttling.iops-size=2000,throttling.group=libvirt_iotune_group2 \ --device ide-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 \ --device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 +-device ide-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1,\ +write-cache=on \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-latest.args b/tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-latest.args new file mode 100644 index 0000000000..fe8a845aae --- /dev/null +++ b/tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-latest.args @@ -0,0 +1,50 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-cpu qemu64 \ +-m 214 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\ +"node-name":"libvirt-2-storage","cache":{"direct":true,"no-flush":false},\ +"auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":false,\ +"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\ +"file":"libvirt-2-storage"}' \ +-device ide-hd,bus=ide.0,unit=0,drive=libvirt-2-format,id=ide0-0-0,bootindex=1,\ +write-cache=on \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest2",\ +"node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},\ +"auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,\ +"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\ +"file":"libvirt-1-storage"}' \ +-device ide-hd,bus=ide.0,unit=1,drive=libvirt-1-format,id=ide0-0-1,\ +write-cache=on \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/blkdeviotune-group-num.xml b/tests/qemuxml2argvdata/blkdeviotune-group-num.xml index c82430a1e9..7b43bfea87 100644 --- a/tests/qemuxml2argvdata/blkdeviotune-group-num.xml +++ b/tests/qemuxml2argvdata/blkdeviotune-group-num.xml @@ -8,6 +8,9 @@ <type arch='i686' machine='pc'>hvm</type> <boot dev='hd'/> </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> @@ -45,7 +48,7 @@ </iotune> <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> - <controller type='usb' index='0'> + <controller type='usb' index='0' model='piix3-uhci'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> diff --git a/tests/qemuxml2argvdata/blkdeviotune-max-length.args b/tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-4.1.0.args similarity index 71% rename from tests/qemuxml2argvdata/blkdeviotune-max-length.args rename to tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-4.1.0.args index 5d301a465d..b8416ef3b0 100644 --- a/tests/qemuxml2argvdata/blkdeviotune-max-length.args +++ b/tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-4.1.0.args @@ -8,28 +8,32 @@ XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ QEMU_AUDIO_DRV=none \ /usr/bin/qemu-system-i386 \ --name QEMUGuest1 \ +-name guest=QEMUGuest1,debug-threads=on \ -S \ --machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc-i440fx-4.1,accel=tcg,usb=off,dump-guest-core=off \ +-cpu qemu64 \ -m 214 \ --realtime mlock=off \ +-overcommit mem-lock=off \ -smp 1,sockets=1,cores=1,threads=1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ -display none \ -no-user-config \ -nodefaults \ --chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\ -server,nowait \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ -mon chardev=charmonitor,id=monitor,mode=control \ -rtc base=utc \ -no-shutdown \ -no-acpi \ --usb \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ -drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\ cache=none,throttling.bps-total=5000,throttling.iops-total=6000,\ throttling.bps-total-max=10000,throttling.iops-total-max=11000,\ throttling.bps-total-max-length=3,throttling.iops-total-max-length=5 \ --device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ +-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1,\ +write-cache=on \ -drive file=/dev/HostVG/QEMUGuest2,format=qcow2,if=none,id=drive-ide0-0-1,\ cache=none,throttling.bps-read=5000,throttling.bps-write=5500,\ throttling.iops-read=3500,throttling.iops-write=4000,\ @@ -38,5 +42,9 @@ throttling.iops-read-max=7000,throttling.iops-write-max=7500,\ throttling.iops-size=2000,throttling.bps-read-max-length=3,\ throttling.bps-write-max-length=5,throttling.iops-read-max-length=7,\ throttling.iops-write-max-length=9 \ --device ide-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 \ --device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 +-device ide-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1,\ +write-cache=on \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-latest.args b/tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-latest.args new file mode 100644 index 0000000000..fe8a845aae --- /dev/null +++ b/tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-latest.args @@ -0,0 +1,50 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-cpu qemu64 \ +-m 214 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\ +"node-name":"libvirt-2-storage","cache":{"direct":true,"no-flush":false},\ +"auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":false,\ +"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\ +"file":"libvirt-2-storage"}' \ +-device ide-hd,bus=ide.0,unit=0,drive=libvirt-2-format,id=ide0-0-0,bootindex=1,\ +write-cache=on \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest2",\ +"node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},\ +"auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,\ +"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\ +"file":"libvirt-1-storage"}' \ +-device ide-hd,bus=ide.0,unit=1,drive=libvirt-1-format,id=ide0-0-1,\ +write-cache=on \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/blkdeviotune-max-length.xml b/tests/qemuxml2argvdata/blkdeviotune-max-length.xml index 83fea5c567..f891d15a81 100644 --- a/tests/qemuxml2argvdata/blkdeviotune-max-length.xml +++ b/tests/qemuxml2argvdata/blkdeviotune-max-length.xml @@ -8,6 +8,9 @@ <type arch='i686' machine='pc'>hvm</type> <boot dev='hd'/> </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> @@ -49,7 +52,7 @@ </iotune> <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> - <controller type='usb' index='0'> + <controller type='usb' index='0' model='piix3-uhci'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> diff --git a/tests/qemuxml2argvdata/blkdeviotune-max.args b/tests/qemuxml2argvdata/blkdeviotune-max.x86_64-4.1.0.args similarity index 67% rename from tests/qemuxml2argvdata/blkdeviotune-max.args rename to tests/qemuxml2argvdata/blkdeviotune-max.x86_64-4.1.0.args index 4548443377..b03fe20d30 100644 --- a/tests/qemuxml2argvdata/blkdeviotune-max.args +++ b/tests/qemuxml2argvdata/blkdeviotune-max.x86_64-4.1.0.args @@ -8,32 +8,40 @@ XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ QEMU_AUDIO_DRV=none \ /usr/bin/qemu-system-i386 \ --name QEMUGuest1 \ +-name guest=QEMUGuest1,debug-threads=on \ -S \ --machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc-i440fx-4.1,accel=tcg,usb=off,dump-guest-core=off \ +-cpu qemu64 \ -m 214 \ --realtime mlock=off \ +-overcommit mem-lock=off \ -smp 1,sockets=1,cores=1,threads=1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ -display none \ -no-user-config \ -nodefaults \ --chardev socket,id=charmonitor,path=/tmp/lib/domain--1-QEMUGuest1/monitor.sock,\ -server,nowait \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ -mon chardev=charmonitor,id=monitor,mode=control \ -rtc base=utc \ -no-shutdown \ -no-acpi \ --usb \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ -drive file=/dev/HostVG/QEMUGuest1,format=qcow2,if=none,id=drive-ide0-0-0,\ cache=none,throttling.bps-total=5000,throttling.iops-total=6000,\ throttling.bps-total-max=10000,throttling.iops-total-max=11000 \ --device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \ +-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1,\ +write-cache=on \ -drive file=/dev/HostVG/QEMUGuest2,format=qcow2,if=none,id=drive-ide0-0-1,\ cache=none,throttling.bps-read=5000,throttling.bps-write=5500,\ throttling.iops-read=3500,throttling.iops-write=4000,\ throttling.bps-read-max=6000,throttling.bps-write-max=6500,\ throttling.iops-read-max=7000,throttling.iops-write-max=7500,\ throttling.iops-size=2000 \ --device ide-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 \ --device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 +-device ide-hd,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1,\ +write-cache=on \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/blkdeviotune-max.x86_64-latest.args b/tests/qemuxml2argvdata/blkdeviotune-max.x86_64-latest.args new file mode 100644 index 0000000000..fe8a845aae --- /dev/null +++ b/tests/qemuxml2argvdata/blkdeviotune-max.x86_64-latest.args @@ -0,0 +1,50 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-i386 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-cpu qemu64 \ +-m 214 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest1",\ +"node-name":"libvirt-2-storage","cache":{"direct":true,"no-flush":false},\ +"auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":false,\ +"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\ +"file":"libvirt-2-storage"}' \ +-device ide-hd,bus=ide.0,unit=0,drive=libvirt-2-format,id=ide0-0-0,bootindex=1,\ +write-cache=on \ +-blockdev '{"driver":"host_device","filename":"/dev/HostVG/QEMUGuest2",\ +"node-name":"libvirt-1-storage","cache":{"direct":true,"no-flush":false},\ +"auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,\ +"cache":{"direct":true,"no-flush":false},"driver":"qcow2",\ +"file":"libvirt-1-storage"}' \ +-device ide-hd,bus=ide.0,unit=1,drive=libvirt-1-format,id=ide0-0-1,\ +write-cache=on \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/blkdeviotune-max.xml b/tests/qemuxml2argvdata/blkdeviotune-max.xml index 3c604c2837..912f22e6cb 100644 --- a/tests/qemuxml2argvdata/blkdeviotune-max.xml +++ b/tests/qemuxml2argvdata/blkdeviotune-max.xml @@ -8,6 +8,9 @@ <type arch='i686' machine='pc'>hvm</type> <boot dev='hd'/> </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> @@ -43,7 +46,7 @@ </iotune> <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> - <controller type='usb' index='0'> + <controller type='usb' index='0' model='piix3-uhci'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 04febd1b0c..ff33870581 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1826,14 +1826,12 @@ mymain(void) DO_TEST("numad-auto-memory-vcpu-cpuset", NONE); DO_TEST("numad-auto-memory-vcpu-no-cpuset-and-placement", NONE); DO_TEST("numad-static-memory-auto-vcpu", NONE); - DO_TEST("blkdeviotune-max", - QEMU_CAPS_DRIVE_IOTUNE_MAX); - DO_TEST("blkdeviotune-group-num", - QEMU_CAPS_DRIVE_IOTUNE_MAX, - QEMU_CAPS_DRIVE_IOTUNE_GROUP); - DO_TEST("blkdeviotune-max-length", - QEMU_CAPS_DRIVE_IOTUNE_MAX, - QEMU_CAPS_DRIVE_IOTUNE_MAX_LENGTH); + DO_TEST_CAPS_VER("blkdeviotune-max", "4.1.0"); + DO_TEST_CAPS_LATEST("blkdeviotune-max"); + DO_TEST_CAPS_VER("blkdeviotune-group-num", "4.1.0"); + DO_TEST_CAPS_LATEST("blkdeviotune-group-num"); + DO_TEST_CAPS_VER("blkdeviotune-max-length", "4.1.0"); + DO_TEST_CAPS_LATEST("blkdeviotune-max-length"); DO_TEST("multifunction-pci-device", QEMU_CAPS_SCSI_LSI); diff --git a/tests/qemuxml2xmloutdata/blkdeviotune-group-num.xml b/tests/qemuxml2xmloutdata/blkdeviotune-group-num.x86_64-latest.xml similarity index 100% rename from tests/qemuxml2xmloutdata/blkdeviotune-group-num.xml rename to tests/qemuxml2xmloutdata/blkdeviotune-group-num.x86_64-latest.xml diff --git a/tests/qemuxml2xmloutdata/blkdeviotune-max-length.xml b/tests/qemuxml2xmloutdata/blkdeviotune-max-length.x86_64-latest.xml similarity index 100% rename from tests/qemuxml2xmloutdata/blkdeviotune-max-length.xml rename to tests/qemuxml2xmloutdata/blkdeviotune-max-length.x86_64-latest.xml diff --git a/tests/qemuxml2xmloutdata/blkdeviotune-max.xml b/tests/qemuxml2xmloutdata/blkdeviotune-max.x86_64-latest.xml similarity index 100% rename from tests/qemuxml2xmloutdata/blkdeviotune-max.xml rename to tests/qemuxml2xmloutdata/blkdeviotune-max.x86_64-latest.xml diff --git a/tests/qemuxml2xmloutdata/blkdeviotune.xml b/tests/qemuxml2xmloutdata/blkdeviotune.x86_64-latest.xml similarity index 88% rename from tests/qemuxml2xmloutdata/blkdeviotune.xml rename to tests/qemuxml2xmloutdata/blkdeviotune.x86_64-latest.xml index ed8c8809db..e27f61f2fd 100644 --- a/tests/qemuxml2xmloutdata/blkdeviotune.xml +++ b/tests/qemuxml2xmloutdata/blkdeviotune.x86_64-latest.xml @@ -8,6 +8,9 @@ <type arch='i686' machine='pc'>hvm</type> <boot dev='hd'/> </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> @@ -35,7 +38,7 @@ </iotune> <address type='drive' controller='0' bus='0' target='0' unit='1'/> </disk> - <controller type='usb' index='0'> + <controller type='usb' index='0' model='piix3-uhci'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> @@ -45,7 +48,7 @@ <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </memballoon> </devices> </domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 86f3d2c1f3..8bfa23cddf 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -603,10 +603,10 @@ mymain(void) DO_TEST("usb-redir", NONE); DO_TEST("usb-redir-filter", NONE); DO_TEST("usb-redir-filter-version", NONE); - DO_TEST("blkdeviotune", NONE); - DO_TEST("blkdeviotune-max", NONE); - DO_TEST("blkdeviotune-group-num", NONE); - DO_TEST("blkdeviotune-max-length", NONE); + DO_TEST_CAPS_LATEST("blkdeviotune"); + DO_TEST_CAPS_LATEST("blkdeviotune-max"); + DO_TEST_CAPS_LATEST("blkdeviotune-group-num"); + DO_TEST_CAPS_LATEST("blkdeviotune-max-length"); DO_TEST("controller-usb-order", QEMU_CAPS_PIIX_DISABLE_S3, QEMU_CAPS_PIIX_DISABLE_S4); -- 2.26.2

Switch to DO_TEST_CAPS_LATEST for all of them and also add pre-blockdev case for 'disk-discard' as we had it before. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- .../disk-detect-zeroes.x86_64-2.12.0.args | 1 + tests/qemuxml2argvdata/disk-detect-zeroes.xml | 5 +- ...rd.args => disk-discard.x86_64-4.1.0.args} | 22 +++++---- .../disk-discard.x86_64-latest.args | 46 +++++++++++++++++++ tests/qemuxml2argvtest.c | 7 +-- ...l => disk-detect-zeroes.x86_64-latest.xml} | 0 ...ard.xml => disk-discard.x86_64-latest.xml} | 7 ++- tests/qemuxml2xmltest.c | 4 +- 8 files changed, 73 insertions(+), 19 deletions(-) rename tests/qemuxml2argvdata/{disk-discard.args => disk-discard.x86_64-4.1.0.args} (59%) create mode 100644 tests/qemuxml2argvdata/disk-discard.x86_64-latest.args rename tests/qemuxml2xmloutdata/{disk-detect-zeroes.xml => disk-detect-zeroes.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{disk-discard.xml => disk-discard.x86_64-latest.xml} (87%) diff --git a/tests/qemuxml2argvdata/disk-detect-zeroes.x86_64-2.12.0.args b/tests/qemuxml2argvdata/disk-detect-zeroes.x86_64-2.12.0.args index 1da46d8987..090cccdb5c 100644 --- a/tests/qemuxml2argvdata/disk-detect-zeroes.x86_64-2.12.0.args +++ b/tests/qemuxml2argvdata/disk-detect-zeroes.x86_64-2.12.0.args @@ -13,6 +13,7 @@ QEMU_AUDIO_DRV=none \ -object secret,id=masterKey0,format=raw,\ file=/tmp/lib/domain--1-test/master-key.aes \ -machine pc-i440fx-2.12,accel=tcg,usb=off,dump-guest-core=off \ +-cpu qemu64 \ -m 1024 \ -realtime mlock=off \ -smp 1,sockets=1,cores=1,threads=1 \ diff --git a/tests/qemuxml2argvdata/disk-detect-zeroes.xml b/tests/qemuxml2argvdata/disk-detect-zeroes.xml index d1ae37b81b..851077545e 100644 --- a/tests/qemuxml2argvdata/disk-detect-zeroes.xml +++ b/tests/qemuxml2argvdata/disk-detect-zeroes.xml @@ -10,6 +10,9 @@ <boot dev='hd'/> <bootmenu enable='yes'/> </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> @@ -29,7 +32,7 @@ <readonly/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> - <controller type='usb' index='0'> + <controller type='usb' index='0' model='piix3-uhci'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> diff --git a/tests/qemuxml2argvdata/disk-discard.args b/tests/qemuxml2argvdata/disk-discard.x86_64-4.1.0.args similarity index 59% rename from tests/qemuxml2argvdata/disk-discard.args rename to tests/qemuxml2argvdata/disk-discard.x86_64-4.1.0.args index 163b1b0df2..4437922eee 100644 --- a/tests/qemuxml2argvdata/disk-discard.args +++ b/tests/qemuxml2argvdata/disk-discard.x86_64-4.1.0.args @@ -8,29 +8,33 @@ XDG_CACHE_HOME=/tmp/lib/domain--1-test/.cache \ XDG_CONFIG_HOME=/tmp/lib/domain--1-test/.config \ QEMU_AUDIO_DRV=none \ /usr/bin/qemu-system-x86_64 \ --name test \ +-name guest=test,debug-threads=on \ -S \ --machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-test/master-key.aes \ +-machine pc-i440fx-4.1,accel=tcg,usb=off,dump-guest-core=off \ -m 1024 \ --realtime mlock=off \ +-overcommit mem-lock=off \ -smp 1,sockets=1,cores=1,threads=1 \ -uuid 92d7a226-cfae-425b-a6d3-00bbf9ec5c9e \ -display none \ -no-user-config \ -nodefaults \ --chardev socket,id=charmonitor,path=/tmp/lib/domain--1-test/monitor.sock,\ -server,nowait \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ -mon chardev=charmonitor,id=monitor,mode=control \ -rtc base=utc \ -no-shutdown \ -no-acpi \ --boot menu=on \ --usb \ +-boot menu=on,strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ -drive file=/var/lib/libvirt/images/f14.img,format=qcow2,if=none,\ id=drive-virtio-disk0,discard=unmap \ --device virtio-blk-pci,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,\ +-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,\ id=virtio-disk0,bootindex=2 \ -drive file=/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso,format=raw,if=none,\ id=drive-ide0-1-0,readonly=on,discard=ignore \ -device ide-cd,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0,bootindex=1 \ --device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/disk-discard.x86_64-latest.args b/tests/qemuxml2argvdata/disk-discard.x86_64-latest.args new file mode 100644 index 0000000000..a7cbf567c8 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-discard.x86_64-latest.args @@ -0,0 +1,46 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-test \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-test/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-test/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-test/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-x86_64 \ +-name guest=test,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-test/master-key.aes \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-cpu qemu64 \ +-m 1024 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid 92d7a226-cfae-425b-a6d3-00bbf9ec5c9e \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot menu=on,strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ +-blockdev '{"driver":"file","filename":"/var/lib/libvirt/images/f14.img",\ +"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":false,"discard":"unmap",\ +"driver":"qcow2","file":"libvirt-2-storage"}' \ +-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=libvirt-2-format,\ +id=virtio-disk0,bootindex=2 \ +-blockdev '{"driver":"file",\ +"filename":"/var/lib/libvirt/Fedora-14-x86_64-Live-KDE.iso",\ +"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":true,"discard":"ignore",\ +"driver":"raw","file":"libvirt-1-storage"}' \ +-device ide-cd,bus=ide.1,unit=0,drive=libvirt-1-format,id=ide0-1-0,bootindex=1 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index ff33870581..f45f04548f 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1135,11 +1135,8 @@ mymain(void) QEMU_CAPS_VIRTIO_BLK_SCSI); DO_TEST_CAPS_VER("disk-copy_on_read", "2.12.0"); DO_TEST_CAPS_LATEST("disk-copy_on_read"); - DO_TEST("disk-discard", - QEMU_CAPS_DRIVE_DISCARD); - DO_TEST("disk-detect-zeroes", - QEMU_CAPS_DRIVE_DISCARD, - QEMU_CAPS_DRIVE_DETECT_ZEROES); + DO_TEST_CAPS_VER("disk-discard", "4.1.0"); + DO_TEST_CAPS_LATEST("disk-discard"); DO_TEST_CAPS_VER("disk-detect-zeroes", "2.12.0"); DO_TEST_CAPS_LATEST("disk-detect-zeroes"); DO_TEST("disk-snapshot", NONE); diff --git a/tests/qemuxml2xmloutdata/disk-detect-zeroes.xml b/tests/qemuxml2xmloutdata/disk-detect-zeroes.x86_64-latest.xml similarity index 100% rename from tests/qemuxml2xmloutdata/disk-detect-zeroes.xml rename to tests/qemuxml2xmloutdata/disk-detect-zeroes.x86_64-latest.xml diff --git a/tests/qemuxml2xmloutdata/disk-discard.xml b/tests/qemuxml2xmloutdata/disk-discard.x86_64-latest.xml similarity index 87% rename from tests/qemuxml2xmloutdata/disk-discard.xml rename to tests/qemuxml2xmloutdata/disk-discard.x86_64-latest.xml index 563a24ae04..e55c5bf6d3 100644 --- a/tests/qemuxml2xmloutdata/disk-discard.xml +++ b/tests/qemuxml2xmloutdata/disk-discard.x86_64-latest.xml @@ -10,6 +10,9 @@ <boot dev='hd'/> <bootmenu enable='yes'/> </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> @@ -29,7 +32,7 @@ <readonly/> <address type='drive' controller='0' bus='1' target='0' unit='0'/> </disk> - <controller type='usb' index='0'> + <controller type='usb' index='0' model='piix3-uhci'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> <controller type='ide' index='0'> @@ -39,7 +42,7 @@ <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> </memballoon> </devices> </domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 8bfa23cddf..34a9f2803a 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -638,8 +638,8 @@ mymain(void) DO_TEST("disk-source-pool", NONE); DO_TEST("disk-source-pool-mode", NONE); - DO_TEST("disk-discard", NONE); - DO_TEST("disk-detect-zeroes", NONE); + DO_TEST_CAPS_LATEST("disk-discard"); + DO_TEST_CAPS_LATEST("disk-detect-zeroes"); DO_TEST("disk-serial", NONE); -- 2.26.2

Agregate validation of frontend properties in a new function called qemuValidateDomainDeviceDefDiskFrontend. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_validate.c | 90 ++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 40 deletions(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 9debac6b30..6f13a1df1b 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1897,40 +1897,9 @@ qemuValidateDomainDeviceDefVideo(const virDomainVideoDef *video, } -int -qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, - virQEMUCapsPtr qemuCaps) +static int +qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk) { - const char *driverName = virDomainDiskGetDriver(disk); - virStorageSourcePtr n; - int idx; - int partition; - - if (disk->src->shared && !disk->src->readonly && - !qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("shared access for disk '%s' requires use of " - "supported storage format"), disk->dst); - return -1; - } - - if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON) { - if (disk->src->readonly) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("copy_on_read is not compatible with read-only disk '%s'"), - disk->dst); - return -1; - } - - if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM || - disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("copy_on_read is not supported with removable disk '%s'"), - disk->dst); - return -1; - } - } - if (disk->geometry.cylinders > 0 && disk->geometry.heads > 0 && disk->geometry.sectors > 0) { @@ -1958,13 +1927,6 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, return -1; } - if (driverName && STRNEQ(driverName, "qemu")) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unsupported driver name '%s' for disk '%s'"), - driverName, disk->dst); - return -1; - } - if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM && disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -1973,6 +1935,54 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, return -1; } + if (disk->copy_on_read == VIR_TRISTATE_SWITCH_ON) { + if (disk->src->readonly) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("copy_on_read is not compatible with read-only disk '%s'"), + disk->dst); + return -1; + } + + if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM || + disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("copy_on_read is not supported with removable disk '%s'"), + disk->dst); + return -1; + } + } + + return 0; +} + + +int +qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, + virQEMUCapsPtr qemuCaps) +{ + const char *driverName = virDomainDiskGetDriver(disk); + virStorageSourcePtr n; + int idx; + int partition; + + if (qemuValidateDomainDeviceDefDiskFrontend(disk) < 0) + return -1; + + if (disk->src->shared && !disk->src->readonly && + !qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("shared access for disk '%s' requires use of " + "supported storage format"), disk->dst); + return -1; + } + + if (driverName && STRNEQ(driverName, "qemu")) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unsupported driver name '%s' for disk '%s'"), + driverName, disk->dst); + return -1; + } + if (virDiskNameParse(disk->dst, &idx, &partition) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("invalid disk target '%s'"), disk->dst); -- 2.26.2

Move the code from qemuCheckDiskConfigBlkdeviotune in src/qemu/qemu_commandline.c to qemuValidateDomainDeviceDefDiskBlkdeviotune. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 101 +------------------------------------- src/qemu/qemu_validate.c | 102 ++++++++++++++++++++++++++++++++++++++- src/qemu/qemu_validate.h | 1 + tests/qemublocktest.c | 2 +- 4 files changed, 104 insertions(+), 102 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 269bdbaf56..87cb78e350 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1131,102 +1131,6 @@ qemuDiskConfigBlkdeviotuneEnabled(virDomainDiskDefPtr disk) } -/** - * qemuCheckDiskConfigBlkdeviotune: - * @disk: disk configuration - * @qemuCaps: qemu capabilities, NULL if checking cold-configuration - * - * Checks whether block io tuning settings make sense. Returns -1 on error and - * reports a proper libvirt error. - */ -static int -qemuCheckDiskConfigBlkdeviotune(virDomainDiskDefPtr disk, - const virDomainDef *def, - virQEMUCapsPtr qemuCaps) -{ - /* group_name by itself is ignored by qemu */ - if (disk->blkdeviotune.group_name && - !virDomainBlockIoTuneInfoHasAny(&disk->blkdeviotune)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("group_name can be configured only together with " - "settings")); - return -1; - } - - /* checking def here is only for calling from tests */ - if (disk->blkdeviotune.group_name) { - size_t i; - - for (i = 0; i < def->ndisks; i++) { - virDomainDiskDefPtr d = def->disks[i]; - - if (STREQ(d->dst, disk->dst) || - STRNEQ_NULLABLE(d->blkdeviotune.group_name, - disk->blkdeviotune.group_name)) - continue; - - if (!virDomainBlockIoTuneInfoEqual(&d->blkdeviotune, - &disk->blkdeviotune)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("different iotunes for disks %s and %s"), - disk->dst, d->dst); - return -1; - } - } - } - - if (disk->blkdeviotune.total_bytes_sec > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.read_bytes_sec > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.write_bytes_sec > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.total_iops_sec > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.read_iops_sec > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.write_iops_sec > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.total_bytes_sec_max > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.read_bytes_sec_max > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.write_bytes_sec_max > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.total_iops_sec_max > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.read_iops_sec_max > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.write_iops_sec_max > QEMU_BLOCK_IOTUNE_MAX || - disk->blkdeviotune.size_iops_sec > QEMU_BLOCK_IOTUNE_MAX) { - virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, - _("block I/O throttle limit must " - "be no more than %llu using QEMU"), QEMU_BLOCK_IOTUNE_MAX); - return -1; - } - - if (qemuCaps) { - /* block I/O throttling 1.7 */ - if (virDomainBlockIoTuneInfoHasMax(&disk->blkdeviotune) && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("there are some block I/O throttling parameters " - "that are not supported with this QEMU binary")); - return -1; - } - - /* block I/O group 2.4 */ - if (disk->blkdeviotune.group_name && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_GROUP)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("the block I/O throttling group parameter is " - "not supported with this QEMU binary")); - return -1; - } - - /* block I/O throttling length 2.6 */ - if (virDomainBlockIoTuneInfoHasMaxLength(&disk->blkdeviotune) && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX_LENGTH)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("there are some block I/O throttling length parameters " - "that are not supported with this QEMU binary")); - return -1; - } - } - - return 0; -} - - /** * qemuCheckDiskConfig: * @disk: disk definition @@ -1237,12 +1141,9 @@ qemuCheckDiskConfigBlkdeviotune(virDomainDiskDefPtr disk, */ int qemuCheckDiskConfig(virDomainDiskDefPtr disk, - const virDomainDef *def, + const virDomainDef *def G_GNUC_UNUSED, virQEMUCapsPtr qemuCaps) { - if (qemuCheckDiskConfigBlkdeviotune(disk, def, qemuCaps) < 0) - return -1; - if (disk->wwn) { if ((disk->bus != VIR_DOMAIN_DISK_BUS_IDE) && (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI)) { diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 6f13a1df1b..17cfcddd30 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1956,8 +1956,105 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk) } +/** + * qemuValidateDomainDeviceDefDiskBlkdeviotune: + * @disk: disk configuration + * @qemuCaps: qemu capabilities, NULL if checking cold-configuration + * + * Checks whether block io tuning settings make sense. Returns -1 on error and + * reports a proper libvirt error. + */ +static int +qemuValidateDomainDeviceDefDiskBlkdeviotune(const virDomainDiskDef *disk, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + /* group_name by itself is ignored by qemu */ + if (disk->blkdeviotune.group_name && + !virDomainBlockIoTuneInfoHasAny(&disk->blkdeviotune)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("group_name can be configured only together with " + "settings")); + return -1; + } + + /* checking def here is only for calling from tests */ + if (disk->blkdeviotune.group_name) { + size_t i; + + for (i = 0; i < def->ndisks; i++) { + virDomainDiskDefPtr d = def->disks[i]; + + if (STREQ(d->dst, disk->dst) || + STRNEQ_NULLABLE(d->blkdeviotune.group_name, + disk->blkdeviotune.group_name)) + continue; + + if (!virDomainBlockIoTuneInfoEqual(&d->blkdeviotune, + &disk->blkdeviotune)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("different iotunes for disks %s and %s"), + disk->dst, d->dst); + return -1; + } + } + } + + if (disk->blkdeviotune.total_bytes_sec > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.read_bytes_sec > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.write_bytes_sec > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.total_iops_sec > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.read_iops_sec > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.write_iops_sec > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.total_bytes_sec_max > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.read_bytes_sec_max > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.write_bytes_sec_max > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.total_iops_sec_max > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.read_iops_sec_max > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.write_iops_sec_max > QEMU_BLOCK_IOTUNE_MAX || + disk->blkdeviotune.size_iops_sec > QEMU_BLOCK_IOTUNE_MAX) { + virReportError(VIR_ERR_ARGUMENT_UNSUPPORTED, + _("block I/O throttle limit must " + "be no more than %llu using QEMU"), QEMU_BLOCK_IOTUNE_MAX); + return -1; + } + + if (qemuCaps) { + /* block I/O throttling 1.7 */ + if (virDomainBlockIoTuneInfoHasMax(&disk->blkdeviotune) && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("there are some block I/O throttling parameters " + "that are not supported with this QEMU binary")); + return -1; + } + + /* block I/O group 2.4 */ + if (disk->blkdeviotune.group_name && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_GROUP)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("the block I/O throttling group parameter is " + "not supported with this QEMU binary")); + return -1; + } + + /* block I/O throttling length 2.6 */ + if (virDomainBlockIoTuneInfoHasMaxLength(&disk->blkdeviotune) && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_IOTUNE_MAX_LENGTH)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("there are some block I/O throttling length parameters " + "that are not supported with this QEMU binary")); + return -1; + } + } + + return 0; +} + + int qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, + const virDomainDef *def, virQEMUCapsPtr qemuCaps) { const char *driverName = virDomainDiskGetDriver(disk); @@ -1968,6 +2065,9 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, if (qemuValidateDomainDeviceDefDiskFrontend(disk) < 0) return -1; + if (qemuValidateDomainDeviceDefDiskBlkdeviotune(disk, def, qemuCaps) < 0) + return -1; + if (disk->src->shared && !disk->src->readonly && !qemuBlockStorageSourceSupportsConcurrentAccess(disk->src)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -3679,7 +3779,7 @@ qemuValidateDomainDeviceDef(const virDomainDeviceDef *dev, break; case VIR_DOMAIN_DEVICE_DISK: - ret = qemuValidateDomainDeviceDefDisk(dev->data.disk, qemuCaps); + ret = qemuValidateDomainDeviceDefDisk(dev->data.disk, def, qemuCaps); break; case VIR_DOMAIN_DEVICE_CONTROLLER: diff --git a/src/qemu/qemu_validate.h b/src/qemu/qemu_validate.h index f667a57195..acf7d26ce0 100644 --- a/src/qemu/qemu_validate.h +++ b/src/qemu/qemu_validate.h @@ -28,6 +28,7 @@ int qemuValidateDomainDef(const virDomainDef *def, void *opaque); int qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, + const virDomainDef *def, virQEMUCapsPtr qemuCaps); int qemuValidateDomainDeviceDef(const virDomainDeviceDef *dev, const virDomainDef *def, diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 8001807552..fbe4972981 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -284,7 +284,7 @@ testQemuDiskXMLToProps(const void *opaque) return -1; if (qemuCheckDiskConfig(disk, vmdef, data->qemuCaps) < 0 || - qemuValidateDomainDeviceDefDisk(disk, data->qemuCaps) < 0) { + qemuValidateDomainDeviceDefDisk(disk, vmdef, data->qemuCaps) < 0) { VIR_TEST_VERBOSE("invalid configuration for disk"); return -1; } -- 2.26.2

Previously we've validated it in qemuCheckDiskConfig which was directly called from the command line generator. Move the checks to the validator where they belong. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 202 +------------------------------------- src/qemu/qemu_validate.c | 204 ++++++++++++++++++++++++++++++++++++++- tests/qemuxml2argvtest.c | 2 +- 3 files changed, 205 insertions(+), 203 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 87cb78e350..2dfd17ad40 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -651,23 +651,6 @@ qemuBuildIoEventFdStr(virBufferPtr buf, return 0; } -#define QEMU_SERIAL_PARAM_ACCEPTED_CHARS \ - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_ .+" - -static int -qemuSafeSerialParamValue(const char *value) -{ - if (strspn(value, QEMU_SERIAL_PARAM_ACCEPTED_CHARS) != strlen(value)) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("driver serial '%s' contains unsafe characters"), - value); - return -1; - } - - return 0; -} - - /** * qemuBuildSecretInfoProps: * @secinfo: pointer to the secret info object @@ -1140,191 +1123,10 @@ qemuDiskConfigBlkdeviotuneEnabled(virDomainDiskDefPtr disk) * error reported. */ int -qemuCheckDiskConfig(virDomainDiskDefPtr disk, +qemuCheckDiskConfig(virDomainDiskDefPtr disk G_GNUC_UNUSED, const virDomainDef *def G_GNUC_UNUSED, - virQEMUCapsPtr qemuCaps) + virQEMUCapsPtr qemuCaps G_GNUC_UNUSED) { - if (disk->wwn) { - if ((disk->bus != VIR_DOMAIN_DISK_BUS_IDE) && - (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Only ide and scsi disk support wwn")); - return -1; - } - } - - if ((disk->vendor || disk->product) && - disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Only scsi disk supports vendor and product")); - return -1; - } - - if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { - /* make sure that both the bus supports type='lun' (SG_IO). */ - if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO && - disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("disk device='lun' is not supported for bus='%s'"), - virDomainDiskBusTypeToString(disk->bus)); - return -1; - } - - if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI && - disk->src->format != VIR_STORAGE_FILE_RAW) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("disk device 'lun' using target 'scsi' must use " - "'raw' format")); - return -1; - } - - if (qemuDomainDefValidateDiskLunSource(disk->src) < 0) - return -1; - - if (disk->wwn) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Setting wwn is not supported for lun device")); - return -1; - } - if (disk->vendor || disk->product) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Setting vendor or product is not supported " - "for lun device")); - return -1; - } - } - - switch (disk->bus) { - case VIR_DOMAIN_DISK_BUS_SCSI: - if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("unexpected address type for scsi disk")); - return -1; - } - - /* Setting bus= attr for SCSI drives, causes a controller - * to be created. Yes this is slightly odd. It is not possible - * to have > 1 bus on a SCSI controller (yet). */ - if (disk->info.addr.drive.bus != 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("SCSI controller only supports 1 bus")); - return -1; - } - break; - - case VIR_DOMAIN_DISK_BUS_IDE: - if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("unexpected address type for ide disk")); - return -1; - } - /* We can only have 1 IDE controller (currently) */ - if (disk->info.addr.drive.controller != 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Only 1 IDE controller is supported")); - return -1; - } - break; - - case VIR_DOMAIN_DISK_BUS_FDC: - if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("unexpected address type for fdc disk")); - return -1; - } - /* We can only have 1 FDC controller (currently) */ - if (disk->info.addr.drive.controller != 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Only 1 fdc controller is supported")); - return -1; - } - /* We can only have 1 FDC bus (currently) */ - if (disk->info.addr.drive.bus != 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Only 1 fdc bus is supported")); - return -1; - } - if (disk->info.addr.drive.target != 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("target must be 0 for controller fdc")); - return -1; - } - break; - - case VIR_DOMAIN_DISK_BUS_VIRTIO: - case VIR_DOMAIN_DISK_BUS_XEN: - case VIR_DOMAIN_DISK_BUS_SD: - break; - } - - if (disk->src->readonly && - disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) { - if (disk->bus == VIR_DOMAIN_DISK_BUS_IDE) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("readonly ide disks are not supported")); - return -1; - } - - if (disk->bus == VIR_DOMAIN_DISK_BUS_SATA) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("readonly sata disks are not supported")); - return -1; - } - } - - if (disk->transient) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("transient disks not supported yet")); - return -1; - } - - if (disk->iomode == VIR_DOMAIN_DISK_IO_NATIVE && - disk->cachemode != VIR_DOMAIN_DISK_CACHE_DIRECTSYNC && - disk->cachemode != VIR_DOMAIN_DISK_CACHE_DISABLE) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("native I/O needs either no disk cache " - "or directsync cache mode, QEMU will fallback " - "to aio=threads")); - return -1; - } - - if (qemuCaps) { - if (disk->serial && - disk->bus == VIR_DOMAIN_DISK_BUS_SCSI && - disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("scsi-block 'lun' devices do not support the " - "serial property")); - return -1; - } - - if (disk->discard && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_DISCARD)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("discard is not supported by this QEMU binary")); - return -1; - } - - if (disk->detect_zeroes && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_DETECT_ZEROES)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("detect_zeroes is not supported by this QEMU binary")); - return -1; - } - - if (disk->iomode == VIR_DOMAIN_DISK_IO_URING) { - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_AIO_IO_URING)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("io uring is not supported by this QEMU binary")); - return -1; - } - } - } - - if (disk->serial && - qemuSafeSerialParamValue(disk->serial) < 0) - return -1; - return 0; } diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 17cfcddd30..63cde01762 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1897,8 +1897,26 @@ qemuValidateDomainDeviceDefVideo(const virDomainVideoDef *video, } +#define QEMU_SERIAL_PARAM_ACCEPTED_CHARS \ + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_ .+" + +static int +qemuValidateDomainDeviceDefDiskSerial(const char *value) +{ + if (strspn(value, QEMU_SERIAL_PARAM_ACCEPTED_CHARS) != strlen(value)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("driver serial '%s' contains unsafe characters"), + value); + return -1; + } + + return 0; +} + + static int -qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk) +qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk, + virQEMUCapsPtr qemuCaps) { if (disk->geometry.cylinders > 0 && disk->geometry.heads > 0 && @@ -1952,6 +1970,188 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk) } } + if (disk->wwn) { + if ((disk->bus != VIR_DOMAIN_DISK_BUS_IDE) && + (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Only ide and scsi disk support wwn")); + return -1; + } + } + + if ((disk->vendor || disk->product) && + disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Only scsi disk supports vendor and product")); + return -1; + } + + if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { + /* make sure that both the bus supports type='lun' (SG_IO). */ + if (disk->bus != VIR_DOMAIN_DISK_BUS_VIRTIO && + disk->bus != VIR_DOMAIN_DISK_BUS_SCSI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk device='lun' is not supported for bus='%s'"), + virDomainDiskBusTypeToString(disk->bus)); + return -1; + } + + if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI && + disk->src->format != VIR_STORAGE_FILE_RAW) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("disk device 'lun' using target 'scsi' must use " + "'raw' format")); + return -1; + } + + if (qemuDomainDefValidateDiskLunSource(disk->src) < 0) + return -1; + + if (disk->wwn) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Setting wwn is not supported for lun device")); + return -1; + } + if (disk->vendor || disk->product) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Setting vendor or product is not supported " + "for lun device")); + return -1; + } + } + + switch (disk->bus) { + case VIR_DOMAIN_DISK_BUS_SCSI: + if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("unexpected address type for scsi disk")); + return -1; + } + + /* Setting bus= attr for SCSI drives, causes a controller + * to be created. Yes this is slightly odd. It is not possible + * to have > 1 bus on a SCSI controller (yet). */ + if (disk->info.addr.drive.bus != 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("SCSI controller only supports 1 bus")); + return -1; + } + break; + + case VIR_DOMAIN_DISK_BUS_IDE: + if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("unexpected address type for ide disk")); + return -1; + } + /* We can only have 1 IDE controller (currently) */ + if (disk->info.addr.drive.controller != 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Only 1 IDE controller is supported")); + return -1; + } + break; + + case VIR_DOMAIN_DISK_BUS_FDC: + if (disk->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("unexpected address type for fdc disk")); + return -1; + } + /* We can only have 1 FDC controller (currently) */ + if (disk->info.addr.drive.controller != 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Only 1 fdc controller is supported")); + return -1; + } + /* We can only have 1 FDC bus (currently) */ + if (disk->info.addr.drive.bus != 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Only 1 fdc bus is supported")); + return -1; + } + if (disk->info.addr.drive.target != 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("target must be 0 for controller fdc")); + return -1; + } + break; + + case VIR_DOMAIN_DISK_BUS_VIRTIO: + case VIR_DOMAIN_DISK_BUS_XEN: + case VIR_DOMAIN_DISK_BUS_SD: + break; + } + + if (disk->src->readonly && + disk->device == VIR_DOMAIN_DISK_DEVICE_DISK) { + if (disk->bus == VIR_DOMAIN_DISK_BUS_IDE) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("readonly ide disks are not supported")); + return -1; + } + + if (disk->bus == VIR_DOMAIN_DISK_BUS_SATA) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("readonly sata disks are not supported")); + return -1; + } + } + + if (disk->transient) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("transient disks not supported yet")); + return -1; + } + + if (disk->iomode == VIR_DOMAIN_DISK_IO_NATIVE && + disk->cachemode != VIR_DOMAIN_DISK_CACHE_DIRECTSYNC && + disk->cachemode != VIR_DOMAIN_DISK_CACHE_DISABLE) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("native I/O needs either no disk cache " + "or directsync cache mode, QEMU will fallback " + "to aio=threads")); + return -1; + } + + if (qemuCaps) { + if (disk->serial && + disk->bus == VIR_DOMAIN_DISK_BUS_SCSI && + disk->device == VIR_DOMAIN_DISK_DEVICE_LUN) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("scsi-block 'lun' devices do not support the " + "serial property")); + return -1; + } + + if (disk->discard && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_DISCARD)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("discard is not supported by this QEMU binary")); + return -1; + } + + if (disk->detect_zeroes && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DRIVE_DETECT_ZEROES)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("detect_zeroes is not supported by this QEMU binary")); + return -1; + } + + if (disk->iomode == VIR_DOMAIN_DISK_IO_URING) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_AIO_IO_URING)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("io uring is not supported by this QEMU binary")); + return -1; + } + } + } + + if (disk->serial && + qemuValidateDomainDeviceDefDiskSerial(disk->serial) < 0) + return -1; + + return 0; } @@ -2062,7 +2262,7 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, int idx; int partition; - if (qemuValidateDomainDeviceDefDiskFrontend(disk) < 0) + if (qemuValidateDomainDeviceDefDiskFrontend(disk, qemuCaps) < 0) return -1; if (qemuValidateDomainDeviceDefDiskBlkdeviotune(disk, def, qemuCaps) < 0) diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index f45f04548f..ad89353910 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1115,7 +1115,7 @@ mymain(void) QEMU_CAPS_SCSI_LSI, QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_SCSI_DISK_WWN); DO_TEST("disk-scsi-disk-vpd", QEMU_CAPS_SCSI_LSI, QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_SCSI_DISK_WWN); - DO_TEST_FAILURE("disk-scsi-disk-vpd-build-error", + DO_TEST_PARSE_ERROR("disk-scsi-disk-vpd-build-error", QEMU_CAPS_SCSI_LSI, QEMU_CAPS_VIRTIO_SCSI, QEMU_CAPS_SCSI_DISK_WWN); DO_TEST_CAPS_LATEST("controller-virtio-scsi"); DO_TEST("disk-sata-device", -- 2.26.2

Remove the function and passing of 'def' through the callers. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 36 ++++-------------------------------- src/qemu/qemu_command.h | 5 ----- src/qemu/qemu_driver.c | 2 -- src/qemu/qemu_hotplug.c | 2 +- tests/qemublocktest.c | 3 +-- 5 files changed, 6 insertions(+), 42 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 2dfd17ad40..d9c3a7a52e 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1114,23 +1114,6 @@ qemuDiskConfigBlkdeviotuneEnabled(virDomainDiskDefPtr disk) } -/** - * qemuCheckDiskConfig: - * @disk: disk definition - * @qemuCaps: qemu capabilities, may be NULL for cold-plug check - * - * Perform disk definition config validity checks. Returns -1 on error with - * error reported. - */ -int -qemuCheckDiskConfig(virDomainDiskDefPtr disk G_GNUC_UNUSED, - const virDomainDef *def G_GNUC_UNUSED, - virQEMUCapsPtr qemuCaps G_GNUC_UNUSED) -{ - return 0; -} - - /* QEMU 1.2 and later have a binary flag -enable-fips that must be * used for VNC auth to obey FIPS settings; but the flag only * exists on Linux, and with no way to probe for it via QMP. Our @@ -1449,7 +1432,6 @@ qemuBuildDiskFrontendAttributes(virDomainDiskDefPtr disk, static char * qemuBuildDriveStr(virDomainDiskDefPtr disk, - const virDomainDef *def, virQEMUCapsPtr qemuCaps) { g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER; @@ -1475,10 +1457,6 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk, return NULL; } - /* if we are using -device this will be checked elsewhere */ - if (qemuCheckDiskConfig(disk, def, qemuCaps) < 0) - return NULL; - virBufferAsprintf(&opt, "if=%s", virDomainDiskQEMUBusTypeToString(disk->bus)); virBufferAsprintf(&opt, ",index=%d", idx); @@ -1618,9 +1596,6 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, g_autofree char *scsiVPDDeviceId = NULL; int controllerModel; - if (qemuCheckDiskConfig(disk, def, qemuCaps) < 0) - return NULL; - if (!qemuDomainCheckCCWS390AddressSupport(def, &disk->info, qemuCaps, disk->dst)) return NULL; @@ -2131,7 +2106,6 @@ qemuBuildBlockStorageSourceAttachDataCommandline(virCommandPtr cmd, static int qemuBuildDiskSourceCommandLine(virCommandPtr cmd, virDomainDiskDefPtr disk, - const virDomainDef *def, virQEMUCapsPtr qemuCaps) { g_autoptr(qemuBlockStorageSourceChainData) data = NULL; @@ -2151,7 +2125,7 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd, !(copyOnReadProps = qemuBlockStorageGetCopyOnReadProps(disk))) return -1; } else { - if (!(data = qemuBuildStorageSourceChainAttachPrepareDrive(disk, def, qemuCaps))) + if (!(data = qemuBuildStorageSourceChainAttachPrepareDrive(disk, qemuCaps))) return -1; } @@ -2181,7 +2155,7 @@ qemuBuildDiskCommandLine(virCommandPtr cmd, { g_autofree char *optstr = NULL; - if (qemuBuildDiskSourceCommandLine(cmd, disk, def, qemuCaps) < 0) + if (qemuBuildDiskSourceCommandLine(cmd, disk, qemuCaps) < 0) return -1; if (!qemuDiskBusNeedsDriveArg(disk->bus)) { @@ -9979,7 +9953,6 @@ qemuBuildHotpluggableCPUProps(const virDomainVcpuDef *vcpu) */ qemuBlockStorageSourceAttachDataPtr qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk, - const virDomainDef *def, virQEMUCapsPtr qemuCaps) { g_autoptr(qemuBlockStorageSourceAttachData) data = NULL; @@ -9987,7 +9960,7 @@ qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk, if (VIR_ALLOC(data) < 0) return NULL; - if (!(data->driveCmd = qemuBuildDriveStr(disk, def, qemuCaps)) || + if (!(data->driveCmd = qemuBuildDriveStr(disk, qemuCaps)) || !(data->driveAlias = qemuAliasDiskDriveFromDisk(disk))) return NULL; @@ -10049,7 +10022,6 @@ qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src, */ qemuBlockStorageSourceChainDataPtr qemuBuildStorageSourceChainAttachPrepareDrive(virDomainDiskDefPtr disk, - const virDomainDef *def, virQEMUCapsPtr qemuCaps) { g_autoptr(qemuBlockStorageSourceAttachData) elem = NULL; @@ -10058,7 +10030,7 @@ qemuBuildStorageSourceChainAttachPrepareDrive(virDomainDiskDefPtr disk, if (VIR_ALLOC(data) < 0) return NULL; - if (!(elem = qemuBuildStorageSourceAttachPrepareDrive(disk, def, qemuCaps))) + if (!(elem = qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps))) return NULL; if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, elem, qemuCaps) < 0) diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index bc3ba44fb3..0bb66c3f0b 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -105,7 +105,6 @@ bool qemuDiskBusNeedsDriveArg(int bus); qemuBlockStorageSourceAttachDataPtr qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk, - const virDomainDef *def, virQEMUCapsPtr qemuCaps); int qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src, @@ -115,7 +114,6 @@ qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src, qemuBlockStorageSourceChainDataPtr qemuBuildStorageSourceChainAttachPrepareDrive(virDomainDiskDefPtr disk, - const virDomainDef *def, virQEMUCapsPtr qemuCaps); @@ -200,9 +198,6 @@ int qemuGetDriveSourceString(virStorageSourcePtr src, bool qemuDiskConfigBlkdeviotuneEnabled(virDomainDiskDefPtr disk); -int qemuCheckDiskConfig(virDomainDiskDefPtr disk, - const virDomainDef *def, - virQEMUCapsPtr qemuCaps); bool qemuCheckFips(void); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1c7c87128d..c5e6cab817 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -8143,8 +8143,6 @@ qemuDomainAttachDeviceConfig(virDomainDefPtr vmdef, } if (virDomainDiskTranslateSourcePool(disk) < 0) return -1; - if (qemuCheckDiskConfig(disk, vmdef, NULL) < 0) - return -1; if (qemuCheckDiskConfigAgainstDomain(vmdef, disk) < 0) return -1; if (virDomainDiskInsert(vmdef, disk) < 0) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 60d0729f1e..641b6f1fe1 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -713,7 +713,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, priv->qemuCaps))) goto cleanup; } else { - if (!(data = qemuBuildStorageSourceChainAttachPrepareDrive(disk, vm->def, + if (!(data = qemuBuildStorageSourceChainAttachPrepareDrive(disk, priv->qemuCaps))) goto cleanup; } diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index fbe4972981..b80ee2ae6c 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -283,8 +283,7 @@ testQemuDiskXMLToProps(const void *opaque) virDomainDiskInsert(vmdef, disk) < 0) return -1; - if (qemuCheckDiskConfig(disk, vmdef, data->qemuCaps) < 0 || - qemuValidateDomainDeviceDefDisk(disk, vmdef, data->qemuCaps) < 0) { + if (qemuValidateDomainDeviceDefDisk(disk, vmdef, data->qemuCaps) < 0) { VIR_TEST_VERBOSE("invalid configuration for disk"); return -1; } -- 2.26.2

The function effectively boils down to whether the disk is 'SD'. Since we'll need to make more decisions based on the fact whether the disk is on the SD bus, rename the function. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 8 ++++---- src/qemu/qemu_command.h | 2 +- src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_process.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index d9c3a7a52e..1b3651a758 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1141,7 +1141,7 @@ qemuCheckFips(void) /** - * qemuDiskBusNeedsDriveArg: + * qemuDiskBusIsSD: * @bus: disk bus * * Unfortunately it is not possible to use -device for SD devices. @@ -1149,7 +1149,7 @@ qemuCheckFips(void) * without -device. */ bool -qemuDiskBusNeedsDriveArg(int bus) +qemuDiskBusIsSD(int bus) { return bus == VIR_DOMAIN_DISK_BUS_SD; } @@ -1441,7 +1441,7 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk, if (qemuBuildDriveSourceStr(disk, qemuCaps, &opt) < 0) return NULL; - if (!qemuDiskBusNeedsDriveArg(disk->bus)) { + if (!qemuDiskBusIsSD(disk->bus)) { g_autofree char *drivealias = qemuAliasDiskDriveFromDisk(disk); if (!drivealias) return NULL; @@ -2158,7 +2158,7 @@ qemuBuildDiskCommandLine(virCommandPtr cmd, if (qemuBuildDiskSourceCommandLine(cmd, disk, qemuCaps) < 0) return -1; - if (!qemuDiskBusNeedsDriveArg(disk->bus)) { + if (!qemuDiskBusIsSD(disk->bus)) { if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC || virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { if (qemuCommandAddExtDevice(cmd, &disk->info) < 0) diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 0bb66c3f0b..53e05777e7 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -101,7 +101,7 @@ char *qemuBuildNicDevStr(virDomainDefPtr def, virQEMUCapsPtr qemuCaps); char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk); -bool qemuDiskBusNeedsDriveArg(int bus); +bool qemuDiskBusIsSD(int bus); qemuBlockStorageSourceAttachDataPtr qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 641b6f1fe1..f1b2fbb1a8 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1072,7 +1072,7 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriverPtr driver, case VIR_DOMAIN_DISK_BUS_SD: /* Note that SD card hotplug support should be added only once * they support '-device' (don't require -drive only). - * See also: qemuDiskBusNeedsDriveArg */ + * See also: qemuDiskBusIsSD */ case VIR_DOMAIN_DISK_BUS_LAST: virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("disk bus '%s' cannot be hotplugged."), diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 8ea470f75f..488ca91435 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5499,7 +5499,7 @@ qemuProcessPrepareQEMUCaps(virDomainObjPtr vm, /* clear the 'blockdev' capability for VMs which have disks that need -drive */ for (i = 0; i < vm->def->ndisks; i++) { - if (qemuDiskBusNeedsDriveArg(vm->def->disks[i]->bus)) { + if (qemuDiskBusIsSD(vm->def->disks[i]->bus)) { virQEMUCapsClear(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); break; } -- 2.26.2

For 'SD' disks and floppies in the pre-blockdev era we don't format -device. Extract the logic so that it's more clear and add comments. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 1b3651a758..3f3e3b69a8 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2158,20 +2158,26 @@ qemuBuildDiskCommandLine(virCommandPtr cmd, if (qemuBuildDiskSourceCommandLine(cmd, disk, qemuCaps) < 0) return -1; - if (!qemuDiskBusIsSD(disk->bus)) { - if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC || - virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { - if (qemuCommandAddExtDevice(cmd, &disk->info) < 0) - return -1; + /* SD cards are currently instantiated via -drive if=sd, so the -device + * part must be skipped */ + if (qemuDiskBusIsSD(disk->bus)) + return 0; - virCommandAddArg(cmd, "-device"); + /* floppy devices are instantiated via -drive ...,if=none and bound to the + * controller via -global isa-fdc.driveA/B options in the pre-blockdev era */ + if (disk->bus == VIR_DOMAIN_DISK_BUS_FDC && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) + return 0; - if (!(optstr = qemuBuildDiskDeviceStr(def, disk, bootindex, - qemuCaps))) - return -1; - virCommandAddArg(cmd, optstr); - } - } + if (qemuCommandAddExtDevice(cmd, &disk->info) < 0) + return -1; + + virCommandAddArg(cmd, "-device"); + + if (!(optstr = qemuBuildDiskDeviceStr(def, disk, bootindex, + qemuCaps))) + return -1; + virCommandAddArg(cmd, optstr); return 0; } -- 2.26.2

Remove all the universal code since the 'else' part formats commandline only for the SD card based disk. Note that we can use virDiskNameToIndex without the check as we already validate that 'disk->dst' contains a properly formatted string in the validation code. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3f3e3b69a8..9836972234 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1449,17 +1449,8 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk, virBufferAddLit(&opt, "if=none"); virBufferAsprintf(&opt, ",id=%s", drivealias); } else { - int idx = virDiskNameToIndex(disk->dst); - - if (idx < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unsupported disk type '%s'"), disk->dst); - return NULL; - } - - virBufferAsprintf(&opt, "if=%s", - virDomainDiskQEMUBusTypeToString(disk->bus)); - virBufferAsprintf(&opt, ",index=%d", idx); + virBufferAsprintf(&opt, "if=sd,index=%d", + virDiskNameToIndex(disk->dst)); } /* werror/rerror are really frontend attributes, but older -- 2.26.2

There's no point using the qemu-specific disk bus names in the error message. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 9836972234..77f0d83054 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1581,7 +1581,6 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, virQEMUCapsPtr qemuCaps) { g_auto(virBuffer) opt = VIR_BUFFER_INITIALIZER; - const char *bus = virDomainDiskQEMUBusTypeToString(disk->bus); const char *contAlias; g_autofree char *backendAlias = NULL; g_autofree char *scsiVPDDeviceId = NULL; @@ -1838,7 +1837,8 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, case VIR_DOMAIN_DISK_BUS_LAST: default: virReportError(VIR_ERR_INTERNAL_ERROR, - _("unsupported disk bus '%s' with device setup"), bus); + _("unsupported disk bus '%s' with device setup"), + NULLSTR(virDomainDiskBusTypeToString(disk->bus))); return NULL; } -- 2.26.2

There are no users for the qemu-specific enum values. Remove it. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 77f0d83054..07669ded44 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -73,21 +73,6 @@ VIR_LOG_INIT("qemu.qemu_command"); -VIR_ENUM_DECL(virDomainDiskQEMUBus); -VIR_ENUM_IMPL(virDomainDiskQEMUBus, - VIR_DOMAIN_DISK_BUS_LAST, - "ide", - "floppy", - "scsi", - "virtio", - "xen", - "usb", - "uml", - "sata", - "sd", -); - - VIR_ENUM_DECL(qemuDiskCacheV2); VIR_ENUM_IMPL(qemuDiskCacheV2, -- 2.26.2

Make sure that we don't try to reload node names with -blockdev. If something doesn't have a node name the update will not make the situation better. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c5e6cab817..cb0373bf76 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -22597,7 +22597,8 @@ qemuDomainSetBlockThreshold(virDomainPtr dom, if (!(src = qemuDomainGetStorageSourceByDevstr(dev, vm->def))) goto endjob; - if (!src->nodestorage && + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) && + !src->nodestorage && qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) goto endjob; -- 2.26.2

Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_domain.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9c629c31a3..e76a76021e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5140,6 +5140,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src, virQEMUCapsPtr qemuCaps) { int actualType = virStorageSourceGetActualType(src); + bool blockdev = virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV); if (src->format == VIR_STORAGE_FILE_COW) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -5224,8 +5225,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src, /* In pre-blockdev era we can't configure the slice so we can allow them * only for detected backing store entries as they are populated * from a place that qemu would be able to read */ - if (!src->detected && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (!src->detected && !blockdev) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("storage slice is not supported by this QEMU binary")); return -1; @@ -5241,8 +5241,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src, return -1; } - if (!src->detected && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (!src->detected && !blockdev) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("ssl verification setting is not supported by this QEMU binary")); return -1; @@ -5258,8 +5257,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src, return -1; } - if (!src->detected && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (!src->detected && !blockdev) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("http cookies are not supported by this QEMU binary")); return -1; @@ -5280,8 +5278,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src, return -1; } - if (!src->detected && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (!src->detected && !blockdev) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("readahead setting is not supported with this QEMU binary")); return -1; @@ -5299,8 +5296,7 @@ qemuDomainValidateStorageSource(virStorageSourcePtr src, return -1; } - if (!src->detected && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (!src->detected && !blockdev) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("timeout setting is not supported with this QEMU binary")); return -1; -- 2.26.2

In case of 'sd' cards we'll use pre-blockdev code also if qemu supports blockdev. In that specific case we'll need to mask out blockdev support for 'sd' disks. Plumb in a boolean to allow it. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_domain.c | 12 ++++++++---- src/qemu/qemu_domain.h | 3 ++- src/qemu/qemu_validate.c | 2 +- tests/qemublocktest.c | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e76a76021e..01f2792401 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5137,11 +5137,15 @@ qemuDomainValidateActualNetDef(const virDomainNetDef *net, int qemuDomainValidateStorageSource(virStorageSourcePtr src, - virQEMUCapsPtr qemuCaps) + virQEMUCapsPtr qemuCaps, + bool maskBlockdev) { int actualType = virStorageSourceGetActualType(src); bool blockdev = virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV); + if (maskBlockdev) + blockdev = false; + if (src->format == VIR_STORAGE_FILE_COW) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("'cow' storage format is not supported")); @@ -8294,7 +8298,7 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, if (n->format == VIR_STORAGE_FILE_ISO) n->format = VIR_STORAGE_FILE_RAW; - if (qemuDomainValidateStorageSource(n, priv->qemuCaps) < 0) + if (qemuDomainValidateStorageSource(n, priv->qemuCaps, false) < 0) return -1; qemuDomainPrepareStorageSourceConfig(n, cfg, priv->qemuCaps); @@ -13137,7 +13141,7 @@ qemuDomainPrepareDiskSourceLegacy(virDomainDiskDefPtr disk, qemuDomainObjPrivatePtr priv, virQEMUDriverConfigPtr cfg) { - if (qemuDomainValidateStorageSource(disk->src, priv->qemuCaps) < 0) + if (qemuDomainValidateStorageSource(disk->src, priv->qemuCaps, true) < 0) return -1; qemuDomainPrepareStorageSourceConfig(disk->src, cfg, priv->qemuCaps); @@ -13173,7 +13177,7 @@ qemuDomainPrepareStorageSourceBlockdev(virDomainDiskDefPtr disk, if (qemuBlockStorageSourceNeedsStorageSliceLayer(src)) src->sliceStorage->nodename = g_strdup_printf("libvirt-%u-slice-sto", src->id); - if (qemuDomainValidateStorageSource(src, priv->qemuCaps) < 0) + if (qemuDomainValidateStorageSource(src, priv->qemuCaps, false) < 0) return -1; qemuDomainPrepareStorageSourceConfig(src, cfg, priv->qemuCaps); diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 639d27d8a5..ea0fce64a8 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1237,7 +1237,8 @@ qemuDomainPrepareDiskSourceData(virDomainDiskDefPtr disk, int qemuDomainValidateStorageSource(virStorageSourcePtr src, - virQEMUCapsPtr qemuCaps); + virQEMUCapsPtr qemuCaps, + bool maskBlockdev); int diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 63cde01762..a7c918e5fd 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2297,7 +2297,7 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, } for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) { - if (qemuDomainValidateStorageSource(n, qemuCaps) < 0) + if (qemuDomainValidateStorageSource(n, qemuCaps, false) < 0) return -1; } diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index b80ee2ae6c..82c11311e2 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -294,7 +294,7 @@ testQemuDiskXMLToProps(const void *opaque) if (testQemuDiskXMLToJSONFakeSecrets(n) < 0) return -1; - if (qemuDomainValidateStorageSource(n, data->qemuCaps) < 0) + if (qemuDomainValidateStorageSource(n, data->qemuCaps, false) < 0) return -1; qemuDomainPrepareDiskSourceData(disk, n); @@ -529,7 +529,7 @@ testQemuImageCreate(const void *opaque) src->capacity = UINT_MAX * 2ULL; src->physical = UINT_MAX + 1ULL; - if (qemuDomainValidateStorageSource(src, data->qemuCaps) < 0) + if (qemuDomainValidateStorageSource(src, data->qemuCaps, false) < 0) return -1; if (qemuBlockStorageSourceCreateGetStorageProps(src, &protocolprops) < 0) -- 2.26.2

The 'vexpress-a9' ARM board supports the native 'sd' bus as well as virtio. Add a test case for proving that upcoming changes to handling of 'sd' work. This config was also tested with real qemu and the qemu process starts correctly. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- .../disk-arm-virtio-sd.aarch64-4.0.0.args | 39 ++++++++++++++++++ .../disk-arm-virtio-sd.aarch64-latest.args | 40 ++++++++++++++++++ tests/qemuxml2argvdata/disk-arm-virtio-sd.xml | 36 ++++++++++++++++ tests/qemuxml2argvtest.c | 3 ++ .../disk-arm-virtio-sd.aarch64-latest.xml | 41 +++++++++++++++++++ tests/qemuxml2xmltest.c | 2 + 6 files changed, 161 insertions(+) create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.xml create mode 100644 tests/qemuxml2xmloutdata/disk-arm-virtio-sd.aarch64-latest.xml diff --git a/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args new file mode 100644 index 0000000000..3c2a7cf240 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args @@ -0,0 +1,39 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-armtest \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-armtest/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-armtest/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-armtest/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-arm \ +-name guest=armtest,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-armtest/master-key.aes \ +-machine vexpress-a9,accel=tcg,usb=off,dump-guest-core=off \ +-m 1024 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid 496d7ea8-9739-544b-4ebd-ef08be936e6a \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-boot strict=on \ +-kernel /arm.kernel \ +-initrd /arm.initrd \ +-append 'console=ttyAMA0,\ +115200n8 rw root=/dev/vda3 rootwait physmap.enabled=0' \ +-dtb /arm.dtb \ +-usb \ +-drive file=/arm-sd.qcow2,format=qcow2,if=sd,index=0 \ +-drive file=/arm-virtio.qcow2,format=qcow2,if=none,id=drive-virtio-disk0 \ +-device virtio-blk-device,scsi=off,drive=drive-virtio-disk0,id=virtio-disk0 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args new file mode 100644 index 0000000000..7147dfee76 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args @@ -0,0 +1,40 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-armtest \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-armtest/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-armtest/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-armtest/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-arm \ +-name guest=armtest,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-armtest/master-key.aes \ +-machine vexpress-a9,accel=tcg,usb=off,dump-guest-core=off \ +-cpu cortex-a9 \ +-m 1024 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid 496d7ea8-9739-544b-4ebd-ef08be936e6a \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-boot strict=on \ +-kernel /arm.kernel \ +-initrd /arm.initrd \ +-append 'console=ttyAMA0,\ +115200n8 rw root=/dev/vda3 rootwait physmap.enabled=0' \ +-dtb /arm.dtb \ +-usb \ +-drive file=/arm-sd.qcow2,format=qcow2,if=sd,index=0 \ +-drive file=/arm-virtio.qcow2,format=qcow2,if=none,id=drive-virtio-disk0 \ +-device virtio-blk-device,scsi=off,drive=drive-virtio-disk0,id=virtio-disk0 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/disk-arm-virtio-sd.xml b/tests/qemuxml2argvdata/disk-arm-virtio-sd.xml new file mode 100644 index 0000000000..0a6482fd4a --- /dev/null +++ b/tests/qemuxml2argvdata/disk-arm-virtio-sd.xml @@ -0,0 +1,36 @@ +<domain type="qemu"> + <name>armtest</name> + <uuid>496d7ea8-9739-544b-4ebd-ef08be936e6a</uuid> + <memory>1048576</memory> + <currentMemory>1048576</currentMemory> + <vcpu>1</vcpu> + <os> + <type arch="armv7l" machine="vexpress-a9">hvm</type> + <kernel>/arm.kernel</kernel> + <initrd>/arm.initrd</initrd> + <dtb>/arm.dtb</dtb> + <cmdline>console=ttyAMA0,115200n8 rw root=/dev/vda3 rootwait physmap.enabled=0</cmdline> + </os> + <features> + <acpi/> + <apic/> + <pae/> + </features> + <clock offset="utc"/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>restart</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-arm</emulator> + <disk type='file' device='disk'> + <driver name='qemu' type='qcow2'/> + <source file='/arm-sd.qcow2'/> + <target dev='sda' bus='sd'/> + </disk> + <disk type='file' device='disk'> + <driver name='qemu' type='qcow2'/> + <source file='/arm-virtio.qcow2'/> + <target dev='vda' bus='virtio'/> + </disk> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index ad89353910..4ab664a846 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1175,6 +1175,9 @@ mymain(void) DO_TEST_CAPS_LATEST("disk-slices"); + DO_TEST_CAPS_ARCH_VER("disk-arm-virtio-sd", "aarch64", "4.0.0"); + DO_TEST_CAPS_ARCH_LATEST("disk-arm-virtio-sd", "aarch64"); + DO_TEST("graphics-egl-headless", QEMU_CAPS_EGL_HEADLESS, QEMU_CAPS_DEVICE_CIRRUS_VGA); diff --git a/tests/qemuxml2xmloutdata/disk-arm-virtio-sd.aarch64-latest.xml b/tests/qemuxml2xmloutdata/disk-arm-virtio-sd.aarch64-latest.xml new file mode 100644 index 0000000000..024db53ffb --- /dev/null +++ b/tests/qemuxml2xmloutdata/disk-arm-virtio-sd.aarch64-latest.xml @@ -0,0 +1,41 @@ +<domain type='qemu'> + <name>armtest</name> + <uuid>496d7ea8-9739-544b-4ebd-ef08be936e6a</uuid> + <memory unit='KiB'>1048576</memory> + <currentMemory unit='KiB'>1048576</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='armv7l' machine='vexpress-a9'>hvm</type> + <kernel>/arm.kernel</kernel> + <initrd>/arm.initrd</initrd> + <cmdline>console=ttyAMA0,115200n8 rw root=/dev/vda3 rootwait physmap.enabled=0</cmdline> + <dtb>/arm.dtb</dtb> + <boot dev='hd'/> + </os> + <features> + <acpi/> + <apic/> + <pae/> + </features> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>cortex-a9</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>restart</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-arm</emulator> + <disk type='file' device='disk'> + <driver name='qemu' type='qcow2'/> + <source file='/arm-sd.qcow2'/> + <target dev='sda' bus='sd'/> + </disk> + <disk type='file' device='disk'> + <driver name='qemu' type='qcow2'/> + <source file='/arm-virtio.qcow2'/> + <target dev='vda' bus='virtio'/> + <address type='virtio-mmio'/> + </disk> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 34a9f2803a..e7480fcf9d 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -643,6 +643,8 @@ mymain(void) DO_TEST("disk-serial", NONE); + DO_TEST_CAPS_ARCH_LATEST("disk-arm-virtio-sd", "aarch64"); + DO_TEST("virtio-rng-random", QEMU_CAPS_DEVICE_VIRTIO_RNG); DO_TEST("virtio-rng-egd", -- 2.26.2

We can't set the type of the device on the 'sd' bus and realistically a cdrom doesn't even make sense there. Forbid it. Note that the output of in disk-cdrom-bus-other.x86_64-latest.args switched to blockdev as it's no longer locked out due to use of a disk on 'sd' bus. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_validate.c | 5 +++-- .../disk-cdrom-bus-other.x86_64-latest.args | 13 ++++++------- tests/qemuxml2argvdata/disk-cdrom-bus-other.xml | 11 ----------- tests/qemuxml2xmloutdata/disk-cdrom-bus-other.xml | 11 ----------- 4 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index a7c918e5fd..f49181b639 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1946,9 +1946,10 @@ qemuValidateDomainDeviceDefDiskFrontend(const virDomainDiskDef *disk, } if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM && - disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) { + (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO || + disk->bus == VIR_DOMAIN_DISK_BUS_SD)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("disk type 'virtio' of '%s' does not support ejectable media"), + _("disk type of '%s' does not support ejectable media"), disk->dst); return -1; } diff --git a/tests/qemuxml2argvdata/disk-cdrom-bus-other.x86_64-latest.args b/tests/qemuxml2argvdata/disk-cdrom-bus-other.x86_64-latest.args index b1c30dd4d8..be091f150f 100644 --- a/tests/qemuxml2argvdata/disk-cdrom-bus-other.x86_64-latest.args +++ b/tests/qemuxml2argvdata/disk-cdrom-bus-other.x86_64-latest.args @@ -28,14 +28,13 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ -no-acpi \ -boot strict=on \ -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ --drive file=/root/boot.iso,format=raw,if=none,id=drive-usb-disk0,readonly=on \ --device usb-storage,bus=usb.0,port=1,drive=drive-usb-disk0,id=usb-disk0,\ +-blockdev '{"driver":"file","filename":"/root/boot.iso",\ +"node-name":"libvirt-2-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-2-format","read-only":true,"driver":"raw",\ +"file":"libvirt-2-storage"}' \ +-device usb-storage,bus=usb.0,port=1,drive=libvirt-2-format,id=usb-disk0,\ removable=off \ --drive if=none,id=drive-usb-disk1,readonly=on \ --device usb-storage,bus=usb.0,port=2,drive=drive-usb-disk1,id=usb-disk1,\ -removable=off \ --drive file=/root/boot2.iso,format=raw,if=sd,index=2,readonly=on \ --drive if=sd,index=3,readonly=on \ +-device usb-storage,bus=usb.0,port=2,id=usb-disk1,removable=off \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/disk-cdrom-bus-other.xml b/tests/qemuxml2argvdata/disk-cdrom-bus-other.xml index e73db8c6ab..e6bf1ea797 100644 --- a/tests/qemuxml2argvdata/disk-cdrom-bus-other.xml +++ b/tests/qemuxml2argvdata/disk-cdrom-bus-other.xml @@ -26,17 +26,6 @@ <target dev='sdb' bus='usb'/> <readonly/> </disk> - <disk type='file' device='cdrom'> - <driver name='qemu' type='raw'/> - <source file='/root/boot2.iso'/> - <target dev='sdc' bus='sd'/> - <readonly/> - </disk> - <disk type='file' device='cdrom'> - <driver name='qemu' type='raw'/> - <target dev='sdd' bus='sd'/> - <readonly/> - </disk> <controller type='usb' index='0'/> <controller type='ide' index='0'/> <controller type='pci' index='0' model='pci-root'/> diff --git a/tests/qemuxml2xmloutdata/disk-cdrom-bus-other.xml b/tests/qemuxml2xmloutdata/disk-cdrom-bus-other.xml index 10262e40d7..ec86d19f1d 100644 --- a/tests/qemuxml2xmloutdata/disk-cdrom-bus-other.xml +++ b/tests/qemuxml2xmloutdata/disk-cdrom-bus-other.xml @@ -26,17 +26,6 @@ <target dev='sdb' bus='usb'/> <readonly/> </disk> - <disk type='file' device='cdrom'> - <driver name='qemu' type='raw'/> - <source file='/root/boot2.iso'/> - <target dev='sdc' bus='sd'/> - <readonly/> - </disk> - <disk type='file' device='cdrom'> - <driver name='qemu' type='raw'/> - <target dev='sdd' bus='sd'/> - <readonly/> - </disk> <controller type='usb' index='0'> <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> </controller> -- 2.26.2

We still have to use -drive to instantiate sd disks. Combining that with the new logic for blockjobs would be very complicated and not worth it given that 'sd' cards work only on few rarely used machine types of non-common architectures and libvirt didn't implement support for 'sd' bus controllers. This will allow us to use -blockdev for other kinds on such machines while sacrificing block jobs. Note: this is currently no-op as we mask-out the QEMU_CAPS_BLOCKDEV capability if any of the disks has bus='sd'. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_backup.c | 3 +++ src/qemu/qemu_checkpoint.c | 3 +++ src/qemu/qemu_domain.c | 26 ++++++++++++++++++++++++++ src/qemu/qemu_domain.h | 4 ++++ src/qemu/qemu_driver.c | 22 ++++++++++++++++++---- 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c index 80fc5d77f8..b317b841cd 100644 --- a/src/qemu/qemu_backup.c +++ b/src/qemu/qemu_backup.c @@ -315,6 +315,9 @@ qemuBackupDiskPrepareDataOne(virDomainObjPtr vm, return -1; } + if (!qemuDomainDiskBlockJobIsSupported(vm, dd->domdisk)) + return -1; + if (!dd->store->format) dd->store->format = VIR_STORAGE_FILE_QCOW2; diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c index 3f6aa36ef3..b71b4a7d14 100644 --- a/src/qemu/qemu_checkpoint.c +++ b/src/qemu/qemu_checkpoint.c @@ -445,6 +445,9 @@ qemuCheckpointPrepare(virQEMUDriverPtr driver, vm->def->disks[i]->src->format)); return -1; } + + if (!qemuDomainDiskBlockJobIsSupported(vm, vm->def->disks[i])) + return -1; } return 0; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 01f2792401..395cc3daee 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -13620,3 +13620,29 @@ qemuDomainInitializePflashStorageSource(virDomainObjPtr vm) return 0; } + + +/** + * qemuDomainDiskBlockJobIsSupported: + * + * Returns true if block jobs are supported on @disk by @vm or false and reports + * an error otherwise. + * + * Note that this does not verify whether other block jobs are running etc. + */ +bool +qemuDomainDiskBlockJobIsSupported(virDomainObjPtr vm, + virDomainDiskDefPtr disk) +{ + qemuDomainObjPrivatePtr priv = vm->privateData; + + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) && + qemuDiskBusIsSD(disk->bus)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("block jobs are not supported on disk '%s' using bus 'sd'"), + disk->dst); + return false; + } + + return true; +} diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index ea0fce64a8..41d3f1561d 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1293,3 +1293,7 @@ qemuDomainMakeCPUMigratable(virCPUDefPtr cpu); int qemuDomainInitializePflashStorageSource(virDomainObjPtr vm); + +bool +qemuDomainDiskBlockJobIsSupported(virDomainObjPtr vm, + virDomainDiskDefPtr disk); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index cb0373bf76..c7eb62f10d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -14603,7 +14603,8 @@ qemuDomainSnapshotPrepareDiskExternalInactive(virDomainSnapshotDiskDefPtr snapdi static int -qemuDomainSnapshotPrepareDiskExternalActive(virDomainSnapshotDiskDefPtr snapdisk, +qemuDomainSnapshotPrepareDiskExternalActive(virDomainObjPtr vm, + virDomainSnapshotDiskDefPtr snapdisk, virDomainDiskDefPtr domdisk, bool blockdev) { @@ -14616,6 +14617,9 @@ qemuDomainSnapshotPrepareDiskExternalActive(virDomainSnapshotDiskDefPtr snapdisk return -1; } + if (!qemuDomainDiskBlockJobIsSupported(vm, domdisk)) + return -1; + switch ((virStorageType)actualType) { case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_FILE: @@ -14671,7 +14675,8 @@ qemuDomainSnapshotPrepareDiskExternalActive(virDomainSnapshotDiskDefPtr snapdisk static int -qemuDomainSnapshotPrepareDiskExternal(virDomainDiskDefPtr disk, +qemuDomainSnapshotPrepareDiskExternal(virDomainObjPtr vm, + virDomainDiskDefPtr disk, virDomainSnapshotDiskDefPtr snapdisk, bool active, bool reuse, @@ -14698,7 +14703,7 @@ qemuDomainSnapshotPrepareDiskExternal(virDomainDiskDefPtr disk, if (qemuDomainSnapshotPrepareDiskExternalInactive(snapdisk, disk) < 0) return -1; } else { - if (qemuDomainSnapshotPrepareDiskExternalActive(snapdisk, disk, blockdev) < 0) + if (qemuDomainSnapshotPrepareDiskExternalActive(vm, snapdisk, disk, blockdev) < 0) return -1; } @@ -14857,7 +14862,7 @@ qemuDomainSnapshotPrepare(virDomainObjPtr vm, return -1; } - if (qemuDomainSnapshotPrepareDiskExternal(dom_disk, disk, + if (qemuDomainSnapshotPrepareDiskExternal(vm, dom_disk, disk, active, reuse, blockdev) < 0) return -1; @@ -17444,6 +17449,9 @@ qemuDomainBlockPullCommon(virDomainObjPtr vm, if (qemuDomainDiskBlockJobIsActive(disk)) goto endjob; + if (!qemuDomainDiskBlockJobIsSupported(vm, disk)) + goto endjob; + if (base && (virStorageFileParseChainIndex(disk->dst, base, &baseIndex) < 0 || !(baseSource = virStorageFileChainLookup(disk->src, disk->src, @@ -18002,6 +18010,9 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm, if (qemuDomainDiskBlockJobIsActive(disk)) goto endjob; + if (!qemuDomainDiskBlockJobIsSupported(vm, disk)) + goto endjob; + if (disk->device == VIR_DOMAIN_DISK_DEVICE_LUN && qemuDomainDefValidateDiskLunSource(mirror) < 0) goto endjob; @@ -18483,6 +18494,9 @@ qemuDomainBlockCommit(virDomainPtr dom, if (virDomainObjCheckActive(vm) < 0) goto endjob; + if (!qemuDomainDiskBlockJobIsSupported(vm, disk)) + goto endjob; + blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); /* Convert bandwidth MiB to bytes, if necessary */ -- 2.26.2

Use the drive alias for all cases when we can't generate qomName. This is meant to handle disks on 'sd' bus which are instantiated via -drive if=sd as there isn't any specific QOM name for them. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_driver.c | 16 ++++++++++------ src/qemu/qemu_process.c | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c7eb62f10d..1617f79d34 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10892,7 +10892,7 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver, goto cleanup; } - if (blockdev) { + if (blockdev && QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName) { entryname = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName; } else { if (!disk->info.alias) { @@ -10948,7 +10948,7 @@ qemuDomainBlocksStatsGather(virQEMUDriverPtr driver, disk = vm->def->disks[i]; entryname = disk->info.alias; - if (blockdev) + if (blockdev && QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName) entryname = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName; if (!entryname) @@ -19283,7 +19283,8 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, if (!(disk = qemuDomainDiskByName(def, path))) goto endjob; - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) && + QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName) { qdevid = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName; } else { if (!(drivealias = qemuAliasDiskDriveFromDisk(disk))) @@ -19473,7 +19474,8 @@ qemuDomainGetBlockIoTune(virDomainPtr dom, if (!(disk = qemuDomainDiskByName(def, path))) goto endjob; - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) && + QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName) { qdevid = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName; } else { if (!(drivealias = qemuAliasDiskDriveFromDisk(disk))) @@ -19608,7 +19610,7 @@ qemuDomainGetDiskErrors(virDomainPtr dom, qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); const char *entryname = disk->info.alias; - if (blockdev) + if (blockdev && diskPriv->qomName) entryname = diskPriv->qomName; if ((info = virHashLookup(table, entryname)) && @@ -21426,7 +21428,9 @@ qemuDomainGetStatsBlockExportDisk(virDomainDiskDefPtr disk, for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) { g_autofree char *alias = NULL; - if (blockdev) { + /* for 'sd' disks we won't be displaying stats for the backing chain + * as we don't update the stats correctly */ + if (blockdev && QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName) { frontendalias = QEMU_DOMAIN_DISK_PRIVATE(disk)->qomName; backendalias = n->nodeformat; backendstoragealias = n->nodestorage; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 488ca91435..fe2ac2dcfe 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7729,7 +7729,7 @@ qemuProcessRefreshDisks(virQEMUDriverPtr driver, struct qemuDomainDiskInfo *info; const char *entryname = disk->info.alias; - if (blockdev) + if (blockdev && diskpriv->qomName) entryname = diskpriv->qomName; if (!(info = virHashLookup(table, entryname))) -- 2.26.2

SD cards need to be instantiated via -drive if=sd. This means that all cases where we use the blockdev path need to be special-cased for SD cards. Note that at this point QEMU_CAPS_BLOCKDEV is still cleared if the VM config has a SD card. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_command.c | 3 ++- src/qemu/qemu_domain.c | 13 +++++++++---- src/qemu/qemu_driver.c | 3 ++- src/qemu/qemu_hotplug.c | 3 ++- src/qemu/qemu_process.c | 6 +++++- src/qemu/qemu_validate.c | 4 +++- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 07669ded44..5b803f106b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -2089,7 +2089,8 @@ qemuBuildDiskSourceCommandLine(virCommandPtr cmd, g_autofree char *copyOnReadPropsStr = NULL; size_t i; - if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV) && + !qemuDiskBusIsSD(disk->bus)) { if (virStorageSourceIsEmpty(disk->src)) return 0; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 395cc3daee..0c122f300d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8216,6 +8216,8 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, virStorageSourcePtr src; /* iterator for the backing chain declared in XML */ virStorageSourcePtr n; /* iterator for the backing chain detected from disk */ qemuDomainObjPrivatePtr priv = vm->privateData; + bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); + bool isSD = qemuDiskBusIsSD(disk->bus); uid_t uid; gid_t gid; @@ -8298,13 +8300,14 @@ qemuDomainDetermineDiskChain(virQEMUDriverPtr driver, if (n->format == VIR_STORAGE_FILE_ISO) n->format = VIR_STORAGE_FILE_RAW; - if (qemuDomainValidateStorageSource(n, priv->qemuCaps, false) < 0) + /* mask-out blockdev for 'sd' disks */ + if (qemuDomainValidateStorageSource(n, priv->qemuCaps, isSD) < 0) return -1; qemuDomainPrepareStorageSourceConfig(n, cfg, priv->qemuCaps); qemuDomainPrepareDiskSourceData(disk, n); - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) && + if (blockdev && !isSD && qemuDomainPrepareStorageSourceBlockdev(disk, n, priv, cfg) < 0) return -1; } @@ -8362,7 +8365,8 @@ qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk, { *backendAlias = NULL; - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV) || + qemuDiskBusIsSD(disk->bus)) { if (!(*backendAlias = qemuAliasDiskDriveFromDisk(disk))) return -1; @@ -13238,7 +13242,8 @@ qemuDomainPrepareDiskSource(virDomainDiskDefPtr disk, disk->src->format = VIR_STORAGE_FILE_RAW; } - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) && + !qemuDiskBusIsSD(disk->bus)) { if (qemuDomainPrepareDiskSourceBlockdev(disk, priv, cfg) < 0) return -1; } else { diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 1617f79d34..63b4a49c3c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -10808,7 +10808,8 @@ qemuDomainBlockResize(virDomainPtr dom, disk->src->format == VIR_STORAGE_FILE_QED) size = VIR_ROUND_UP(size, 512); - if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) { + if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) && + !qemuDiskBusIsSD(disk->bus)) { if (virStorageSourceIsEmpty(disk->src) || disk->src->readonly) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("can't resize empty or readonly disk '%s'"), diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f1b2fbb1a8..ab5a7aef84 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4270,7 +4270,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, disk->info.alias, vm, vm->def->name); - if (blockdev) { + if (blockdev && + !qemuDiskBusIsSD(disk->bus)) { corAlias = g_strdup(diskPriv->nodeCopyOnRead); if (diskPriv->blockjob) { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index fe2ac2dcfe..b1751d4b52 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6405,7 +6405,7 @@ qemuProcessPrepareHostStorage(virQEMUDriverPtr driver, continue; /* backing chain needs to be redetected if we aren't using blockdev */ - if (!blockdev) + if (!blockdev || qemuDiskBusIsSD(disk->bus)) virStorageSourceBackingStoreClear(disk->src); /* @@ -6634,6 +6634,10 @@ qemuProcessSetupDiskThrottlingBlockdev(virQEMUDriverPtr driver, virDomainDiskDefPtr disk = vm->def->disks[i]; qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); + /* sd-cards are instantiated via -drive */ + if (qemuDiskBusIsSD(disk->bus)) + continue; + if (!qemuDiskConfigBlkdeviotuneEnabled(disk)) continue; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index f49181b639..2cde678ca0 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2259,6 +2259,7 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, virQEMUCapsPtr qemuCaps) { const char *driverName = virDomainDiskGetDriver(disk); + bool isSD = qemuDiskBusIsSD(disk->bus); virStorageSourcePtr n; int idx; int partition; @@ -2298,7 +2299,8 @@ qemuValidateDomainDeviceDefDisk(const virDomainDiskDef *disk, } for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) { - if (qemuDomainValidateStorageSource(n, qemuCaps, false) < 0) + /* blockdev support is masked out for 'sd' disks */ + if (qemuDomainValidateStorageSource(n, qemuCaps, isSD) < 0) return -1; } -- 2.26.2

Help QEMU in deprecation of -drive if=none without the need to refactor all old boards. Stop masking out -blockdev support when -drive if=sd needs to be used. We achieve this by forbidding blockjobs and special-casing all other code paths. Blockjobs are sacrificed in this case as SD cards are a corner case for some ARM boards and are thus not used commonly. https://bugzilla.redhat.com/show_bug.cgi?id=1821692 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_process.c | 9 --------- .../disk-arm-virtio-sd.aarch64-latest.args | 7 +++++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b1751d4b52..dee3f3fb63 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5488,7 +5488,6 @@ qemuProcessPrepareQEMUCaps(virDomainObjPtr vm, unsigned int processStartFlags) { qemuDomainObjPrivatePtr priv = vm->privateData; - size_t i; virObjectUnref(priv->qemuCaps); if (!(priv->qemuCaps = virQEMUCapsCacheLookupCopy(qemuCapsCache, @@ -5497,14 +5496,6 @@ qemuProcessPrepareQEMUCaps(virDomainObjPtr vm, vm->def->os.machine))) return -1; - /* clear the 'blockdev' capability for VMs which have disks that need -drive */ - for (i = 0; i < vm->def->ndisks; i++) { - if (qemuDiskBusIsSD(vm->def->disks[i]->bus)) { - virQEMUCapsClear(priv->qemuCaps, QEMU_CAPS_BLOCKDEV); - break; - } - } - if (processStartFlags & VIR_QEMU_PROCESS_START_STANDALONE) virQEMUCapsClear(priv->qemuCaps, QEMU_CAPS_CHARDEV_FD_PASS); diff --git a/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args index 7147dfee76..f17dd2157a 100644 --- a/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args +++ b/tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args @@ -33,8 +33,11 @@ file=/tmp/lib/domain--1-armtest/master-key.aes \ -dtb /arm.dtb \ -usb \ -drive file=/arm-sd.qcow2,format=qcow2,if=sd,index=0 \ --drive file=/arm-virtio.qcow2,format=qcow2,if=none,id=drive-virtio-disk0 \ --device virtio-blk-device,scsi=off,drive=drive-virtio-disk0,id=virtio-disk0 \ +-blockdev '{"driver":"file","filename":"/arm-virtio.qcow2",\ +"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"qcow2",\ +"file":"libvirt-1-storage"}' \ +-device virtio-blk-device,scsi=off,drive=libvirt-1-format,id=virtio-disk0 \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ resourcecontrol=deny \ -msg timestamp=on -- 2.26.2

On 5/6/20 2:08 PM, Peter Krempa wrote:
QEMU want's to deprecate -drive if=none. Stop clearing QEMU_CAPS_BLOCKDEV when SD cards are used. Please see 17/20 and 20/20 for more explanation.
Obviously few cleanups snuck in as well.
Peter Krempa (20): qemuxml2(argv|xml): Modernize 'blkdeviotune' tests qemuxml2(argv|xml): Modernize 'discard'/'detect-zero' tests qemuValidateDomainDeviceDefDisk: Separate disk frontend config validation qemu: validate: Validate blkdeviotune settings in the validator qemu: Move disk config validation to qemuValidateDomainDeviceDefDiskFrontend qemuCheckDiskConfig: Remove and untangle callers qemu: Rename qemuDiskBusNeedsDriveArg to qemuDiskBusIsSD qemuBuildDiskCommandLine: Clarify logic around building -device for disks qemuBuildDriveStr: Refactor formatting of command line for 'sd' cards qemuBuildDiskDeviceStr: Use XML disk bus type names in error message qemu: command: Remove 'virDomainDiskQEMUBus' enum converters qemuDomainSetBlockThreshold: Call qemuBlockNodeNamesDetect only without blockdev qemuDomainValidateStorageSource: Extract check for BLOCKDEV capability qemuDomainValidateStorageSource: Allow masking out blockdev support tests: Add tests for a virtio and sd disk in a single machine qemu: Forbid 'cdrom' on 'sd' bus qemu: Refuse blockjobs on disk bus='sd' with -blockdev qemu: Handle cases when 'qomName' isn't present qemu: Prepare for 'sd' card use together with blockdev qemu: process: Don't clear QEMU_CAPS_BLOCKDEV when SD card is present
src/qemu/qemu_backup.c | 3 + src/qemu/qemu_checkpoint.c | 3 + src/qemu/qemu_command.c | 404 ++---------------- src/qemu/qemu_command.h | 7 +- src/qemu/qemu_domain.c | 65 ++- src/qemu/qemu_domain.h | 7 +- src/qemu/qemu_driver.c | 46 +- src/qemu/qemu_hotplug.c | 7 +- src/qemu/qemu_process.c | 17 +- src/qemu/qemu_validate.c | 383 +++++++++++++++-- src/qemu/qemu_validate.h | 1 + tests/qemublocktest.c | 7 +- ... blkdeviotune-group-num.x86_64-4.1.0.args} | 26 +- .../blkdeviotune-group-num.x86_64-latest.args | 50 +++ .../blkdeviotune-group-num.xml | 5 +- ...blkdeviotune-max-length.x86_64-4.1.0.args} | 26 +- ...blkdeviotune-max-length.x86_64-latest.args | 50 +++ .../blkdeviotune-max-length.xml | 5 +- ...rgs => blkdeviotune-max.x86_64-4.1.0.args} | 26 +- .../blkdeviotune-max.x86_64-latest.args | 50 +++ tests/qemuxml2argvdata/blkdeviotune-max.xml | 5 +- .../disk-arm-virtio-sd.aarch64-4.0.0.args | 39 ++ .../disk-arm-virtio-sd.aarch64-latest.args | 43 ++ tests/qemuxml2argvdata/disk-arm-virtio-sd.xml | 36 ++ .../disk-cdrom-bus-other.x86_64-latest.args | 13 +- .../qemuxml2argvdata/disk-cdrom-bus-other.xml | 11 - .../disk-detect-zeroes.x86_64-2.12.0.args | 1 + tests/qemuxml2argvdata/disk-detect-zeroes.xml | 5 +- ...rd.args => disk-discard.x86_64-4.1.0.args} | 22 +- .../disk-discard.x86_64-latest.args | 46 ++ tests/qemuxml2argvtest.c | 26 +- ... blkdeviotune-group-num.x86_64-latest.xml} | 0 ...blkdeviotune-max-length.x86_64-latest.xml} | 0 ...xml => blkdeviotune-max.x86_64-latest.xml} | 0 ...une.xml => blkdeviotune.x86_64-latest.xml} | 7 +- .../disk-arm-virtio-sd.aarch64-latest.xml | 41 ++ .../disk-cdrom-bus-other.xml | 11 - ...l => disk-detect-zeroes.x86_64-latest.xml} | 0 ...ard.xml => disk-discard.x86_64-latest.xml} | 7 +- tests/qemuxml2xmltest.c | 14 +- 40 files changed, 958 insertions(+), 557 deletions(-) rename tests/qemuxml2argvdata/{blkdeviotune-group-num.args => blkdeviotune-group-num.x86_64-4.1.0.args} (69%) create mode 100644 tests/qemuxml2argvdata/blkdeviotune-group-num.x86_64-latest.args rename tests/qemuxml2argvdata/{blkdeviotune-max-length.args => blkdeviotune-max-length.x86_64-4.1.0.args} (71%) create mode 100644 tests/qemuxml2argvdata/blkdeviotune-max-length.x86_64-latest.args rename tests/qemuxml2argvdata/{blkdeviotune-max.args => blkdeviotune-max.x86_64-4.1.0.args} (67%) create mode 100644 tests/qemuxml2argvdata/blkdeviotune-max.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-4.0.0.args create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.aarch64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-arm-virtio-sd.xml rename tests/qemuxml2argvdata/{disk-discard.args => disk-discard.x86_64-4.1.0.args} (59%) create mode 100644 tests/qemuxml2argvdata/disk-discard.x86_64-latest.args rename tests/qemuxml2xmloutdata/{blkdeviotune-group-num.xml => blkdeviotune-group-num.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{blkdeviotune-max-length.xml => blkdeviotune-max-length.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{blkdeviotune-max.xml => blkdeviotune-max.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{blkdeviotune.xml => blkdeviotune.x86_64-latest.xml} (88%) create mode 100644 tests/qemuxml2xmloutdata/disk-arm-virtio-sd.aarch64-latest.xml rename tests/qemuxml2xmloutdata/{disk-detect-zeroes.xml => disk-detect-zeroes.x86_64-latest.xml} (100%) rename tests/qemuxml2xmloutdata/{disk-discard.xml => disk-discard.x86_64-latest.xml} (87%)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Michal Privoznik
-
Peter Krempa