qemu: support CDROM hotplug cdrom with USB/SCSI bus

QEMU supports hotplug of a cdrom device with USB or SCSI bus. Just
unblock these devices in qemuDomainAttachDeviceDiskLiveInternal() and
qemuDomainDetachPrepDisk().

Fixes: https://gitlab.com/libvirt/libvirt/-/issues/261

Signed-off-by: minglei.liu <minglei.liu@smartx.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
minglei.liu 2022-07-06 02:57:10 -07:00 committed by Michal Privoznik
parent 7b28561c85
commit 3078799fef
6 changed files with 162 additions and 3 deletions

View File

@ -992,10 +992,9 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *driver,
bool releaseSeclabel = false;
int ret = -1;
if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM ||
disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("cdrom/floppy device hotplug isn't supported"));
_("floppy device hotplug isn't supported"));
return -1;
}
@ -1025,6 +1024,10 @@ qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriver *driver,
break;
case VIR_DOMAIN_DISK_BUS_VIRTIO:
if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("cdrom device with virtio bus isn't supported"));
}
if (qemuDomainEnsureVirtioAddress(&releaseVirtio, vm, dev) < 0)
goto cleanup;
break;
@ -5413,6 +5416,12 @@ qemuDomainDetachPrepDisk(virDomainObj *vm,
break;
case VIR_DOMAIN_DISK_DEVICE_CDROM:
if (disk->bus == VIR_DOMAIN_DISK_BUS_USB ||
disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
break;
}
G_GNUC_FALLTHROUGH;
case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("disk device type '%s' cannot be detached"),

View File

@ -860,6 +860,24 @@ mymain(void)
DO_TEST_DETACH("base-live", "guestfwd", false, false,
"netdev_del", QMP_OK);
DO_TEST_ATTACH("base-live", "cdrom-usb", false, true,
"human-monitor-command", HMP("OK\\r\\n"),
"device_add", QMP_OK);
DO_TEST_DETACH("base-live", "cdrom-usb", true, true,
"device_del", QMP_OK);
DO_TEST_DETACH("base-live", "cdrom-usb", false, false,
"device_del", QMP_DEVICE_DELETED("usb-disk4") QMP_OK,
"human-monitor-command", HMP(""));
DO_TEST_ATTACH("base-live", "cdrom-scsi", false, true,
"human-monitor-command", HMP("OK\\r\\n"),
"device_add", QMP_OK);
DO_TEST_DETACH("base-live", "cdrom-scsi", true, true,
"device_del", QMP_OK);
DO_TEST_DETACH("base-live", "cdrom-scsi", false, false,
"device_del", QMP_DEVICE_DELETED("scsi0-0-0-4") QMP_OK,
"human-monitor-command", HMP(""));
#define DO_TEST_CPU_GROUP(prefix, vcpus, modernhp, expectfail) \
do { \
cpudata.test = prefix; \

View File

@ -0,0 +1,6 @@
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/dev/null'/>
<target dev='sde' bus='scsi'/>
<readonly/>
</disk>

View File

@ -0,0 +1,6 @@
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/dev/null'/>
<target dev='sde' bus='usb'/>
<readonly/>
</disk>

View File

@ -0,0 +1,60 @@
<domain type='kvm' id='7'>
<name>hotplug</name>
<uuid>d091ea82-29e6-2e34-3005-f02617b36e87</uuid>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>4</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</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-x86_64</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/dev/null'/>
<backingStore/>
<target dev='sde' bus='scsi'/>
<readonly/>
<alias name='scsi0-0-0-4'/>
<address type='drive' controller='0' bus='0' target='0' unit='4'/>
</disk>
<controller type='usb' index='0'>
<alias name='usb'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='ide' index='0'>
<alias name='ide'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='scsi' index='0' model='virtio-scsi'>
<alias name='scsi0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</controller>
<controller type='pci' index='0' model='pci-root'>
<alias name='pci'/>
</controller>
<controller type='virtio-serial' index='0'>
<alias name='virtio-serial0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</controller>
<input type='mouse' bus='ps2'>
<alias name='input0'/>
</input>
<input type='keyboard' bus='ps2'>
<alias name='input1'/>
</input>
<audio id='1' type='none'/>
<memballoon model='none'/>
</devices>
<seclabel type='none' model='none'/>
</domain>

View File

@ -0,0 +1,60 @@
<domain type='kvm' id='7'>
<name>hotplug</name>
<uuid>d091ea82-29e6-2e34-3005-f02617b36e87</uuid>
<memory unit='KiB'>4194304</memory>
<currentMemory unit='KiB'>4194304</currentMemory>
<vcpu placement='static'>4</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
</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-x86_64</emulator>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw' cache='none'/>
<source file='/dev/null'/>
<backingStore/>
<target dev='sde' bus='usb'/>
<readonly/>
<alias name='usb-disk4'/>
<address type='usb' bus='0' port='1'/>
</disk>
<controller type='usb' index='0'>
<alias name='usb'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
</controller>
<controller type='ide' index='0'>
<alias name='ide'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
</controller>
<controller type='scsi' index='0' model='virtio-scsi'>
<alias name='scsi0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</controller>
<controller type='pci' index='0' model='pci-root'>
<alias name='pci'/>
</controller>
<controller type='virtio-serial' index='0'>
<alias name='virtio-serial0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
</controller>
<input type='mouse' bus='ps2'>
<alias name='input0'/>
</input>
<input type='keyboard' bus='ps2'>
<alias name='input1'/>
</input>
<audio id='1' type='none'/>
<memballoon model='none'/>
</devices>
<seclabel type='none' model='none'/>
</domain>