From 5d884f3d3c3b0639ce06152f3f91d6ac87d13cb6 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Mon, 28 Jan 2019 17:18:55 +0100 Subject: [PATCH] qemu: Forbid cdroms on virtio bus Attempting to create an empty virtio-blk drive results into: -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0xc,drive=drive-virtio-disk1,id=virtio-disk1: Device needs media, but drive is empty Attempting to eject media from virtio-blk based drive results into: error: internal error: unable to execute QEMU command 'eject': Device 'drive-virtio-disk0' is not removable Forbid configurations where users would attempt to use cdroms in virtio bus. Fix few wrong examples which are not really relevant to the tested code. Signed-off-by: Peter Krempa --- src/qemu/qemu_domain.c | 8 ++++++++ tests/qemuxml2argvdata/disk-scsi-disk-vpd-build-error.xml | 2 +- tests/qemuxml2argvdata/pci-autofill-addr.args | 4 ++-- tests/qemuxml2argvdata/pci-autofill-addr.xml | 2 +- tests/qemuxml2xmloutdata/pci-autofill-addr.xml | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index b6c1a0e4e5..fde0f9e19e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5078,6 +5078,14 @@ qemuDomainDeviceDefValidateDisk(const virDomainDiskDef *disk, return -1; } + if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM && + disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk type 'virtio' of '%s' does not support ejectable media"), + disk->dst); + return -1; + } + return 0; } diff --git a/tests/qemuxml2argvdata/disk-scsi-disk-vpd-build-error.xml b/tests/qemuxml2argvdata/disk-scsi-disk-vpd-build-error.xml index e116aff114..6c83715be2 100644 --- a/tests/qemuxml2argvdata/disk-scsi-disk-vpd-build-error.xml +++ b/tests/qemuxml2argvdata/disk-scsi-disk-vpd-build-error.xml @@ -14,7 +14,7 @@ destroy /usr/bin/qemu-system-i686 - + SEAGATE diff --git a/tests/qemuxml2argvdata/pci-autofill-addr.args b/tests/qemuxml2argvdata/pci-autofill-addr.args index b546443db3..1508787f8b 100644 --- a/tests/qemuxml2argvdata/pci-autofill-addr.args +++ b/tests/qemuxml2argvdata/pci-autofill-addr.args @@ -22,8 +22,8 @@ server,nowait \ -no-acpi \ -usb \ -drive file=/var/iso/f18kde.iso,format=raw,if=none,id=drive-virtio-disk0,\ -media=cdrom,readonly=on \ +readonly=on \ -device virtio-blk-pci,bus=pci.0,addr=0x3,drive=drive-virtio-disk0,\ -id=virtio-disk0 \ +id=virtio-disk0,bootindex=1 \ -vga cirrus \ -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x4 diff --git a/tests/qemuxml2argvdata/pci-autofill-addr.xml b/tests/qemuxml2argvdata/pci-autofill-addr.xml index 0d10ec8635..a601c50ab9 100644 --- a/tests/qemuxml2argvdata/pci-autofill-addr.xml +++ b/tests/qemuxml2argvdata/pci-autofill-addr.xml @@ -10,7 +10,7 @@ /usr/bin/qemu-system-x86_64 - + diff --git a/tests/qemuxml2xmloutdata/pci-autofill-addr.xml b/tests/qemuxml2xmloutdata/pci-autofill-addr.xml index 581d42f11e..84cf1043e3 100644 --- a/tests/qemuxml2xmloutdata/pci-autofill-addr.xml +++ b/tests/qemuxml2xmloutdata/pci-autofill-addr.xml @@ -14,7 +14,7 @@ destroy /usr/bin/qemu-system-x86_64 - + -- GitLab