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 <pkrempa@redhat.com>
This commit is contained in:
Peter Krempa 2019-01-28 17:18:55 +01:00
parent 6b67eeef8c
commit 5d884f3d3c
5 changed files with 13 additions and 5 deletions

View File

@ -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;
}

View File

@ -14,7 +14,7 @@
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-i686</emulator>
<disk type='block' device='cdrom'>
<disk type='block' device='disk'>
<source dev='/dev/HostVG/QEMUGuest1'/>
<target dev='sda' bus='virtio'/>
<vendor>SEAGATE</vendor>

View File

@ -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

View File

@ -10,7 +10,7 @@
</os>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='cdrom'>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/iso/f18kde.iso'/>
<target dev='vda' bus='virtio'/>

View File

@ -14,7 +14,7 @@
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-system-x86_64</emulator>
<disk type='file' device='cdrom'>
<disk type='file' device='disk'>
<driver name='qemu' type='raw'/>
<source file='/var/iso/f18kde.iso'/>
<target dev='vda' bus='virtio'/>