]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: support CDROM hotplug cdrom with USB/SCSI bus
authorminglei.liu <minglei.liu@smartx.com>
Wed, 6 Jul 2022 09:57:10 +0000 (02:57 -0700)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 20 Jul 2022 14:53:51 +0000 (16:53 +0200)
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>
src/qemu/qemu_hotplug.c
tests/qemuhotplugtest.c
tests/qemuhotplugtestdevices/qemuhotplug-cdrom-scsi.xml [new file with mode: 0644]
tests/qemuhotplugtestdevices/qemuhotplug-cdrom-usb.xml [new file with mode: 0644]
tests/qemuhotplugtestdomains/qemuhotplug-base-live+cdrom-scsi.xml [new file with mode: 0644]
tests/qemuhotplugtestdomains/qemuhotplug-base-live+cdrom-usb.xml [new file with mode: 0644]

index 6bc160de4a10dccd06c5d726c2596019da1c2c3a..ed63624cf6e62ad0053d47972a6e43a46c615c6f 100644 (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"),
index e98d9845e8a7fd1ff791ca5ea97b1aedcae3eec0..3c9dac241a78b39f55cafb57e095a7cf2d9e2009 100644 (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; \
diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-cdrom-scsi.xml b/tests/qemuhotplugtestdevices/qemuhotplug-cdrom-scsi.xml
new file mode 100644 (file)
index 0000000..da8b94b
--- /dev/null
@@ -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>
diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-cdrom-usb.xml b/tests/qemuhotplugtestdevices/qemuhotplug-cdrom-usb.xml
new file mode 100644 (file)
index 0000000..efb9740
--- /dev/null
@@ -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>
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+cdrom-scsi.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+cdrom-scsi.xml
new file mode 100644 (file)
index 0000000..c3242a5
--- /dev/null
@@ -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>
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+cdrom-usb.xml b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+cdrom-usb.xml
new file mode 100644 (file)
index 0000000..89317f5
--- /dev/null
@@ -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>