[PATCH] qemu: support hotplug cdrom with usb/scsi bus

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Qemu support hotplug cdrom device with usb or scsi bus,
just unblock these devices in qemuDomainAttachDeviceDiskLiveInternal
and qemuDomainDetachPrepDisk.

Fixes: #261

Signed-off-by: minglei.liu <minglei.liu@xxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c                       | 13 +++-
 tests/qemuhotplugtest.c                       | 18 ++++++
 .../qemuhotplug-cdrom-scsi.xml                |  6 ++
 .../qemuhotplug-cdrom-usb.xml                 |  6 ++
 .../qemuhotplug-base-live+cdrom-scsi.xml      | 60 +++++++++++++++++++
 .../qemuhotplug-base-live+cdrom-usb.xml       | 60 +++++++++++++++++++
 6 files changed, 160 insertions(+), 3 deletions(-)
 create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-cdrom-scsi.xml
 create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-cdrom-usb.xml
 create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+cdrom-scsi.xml
 create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+cdrom-usb.xml

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 27e68370cf..d917086023 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -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;
@@ -5414,6 +5417,10 @@ qemuDomainDetachPrepDisk(virDomainObj *vm,
 
     case VIR_DOMAIN_DISK_DEVICE_CDROM:
     case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+        if ((virDomainDiskBus) disk->bus == VIR_DOMAIN_DISK_BUS_USB ||
+            (virDomainDiskBus) disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
+            break;
+        }
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
                        _("disk device type '%s' cannot be detached"),
                        virDomainDiskDeviceTypeToString(disk->device));
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index e98d9845e8..3c9dac241a 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -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
index 0000000000..da8b94bb22
--- /dev/null
+++ b/tests/qemuhotplugtestdevices/qemuhotplug-cdrom-scsi.xml
@@ -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
index 0000000000..efb974090c
--- /dev/null
+++ b/tests/qemuhotplugtestdevices/qemuhotplug-cdrom-usb.xml
@@ -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
index 0000000000..c3242a582f
--- /dev/null
+++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+cdrom-scsi.xml
@@ -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
index 0000000000..89317f5dc8
--- /dev/null
+++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+cdrom-usb.xml
@@ -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>
-- 
2.27.0




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux