[PATCH v3 06/10] qemu: Implement usb hub device hotplug

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

 



https://bugzilla.redhat.com/show_bug.cgi?id=1375423

Signed-off-by: Han Han <hhan@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c  |  9 ++++++-
 src/qemu/qemu_hotplug.c | 58 +++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_hotplug.h |  4 +++
 3 files changed, 70 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4209f017c7..774f6ac8b9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7710,12 +7710,19 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm,
         }
         break;
 
+    case VIR_DOMAIN_DEVICE_HUB:
+        ret = qemuDomainAttachHubDevice(driver, vm, dev->data.hub);
+        if (ret == 0) {
+            alias = dev->data.hub->info.alias;
+            dev->data.hub = NULL;
+        }
+        break;
+
     case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_FS:
     case VIR_DOMAIN_DEVICE_SOUND:
     case VIR_DOMAIN_DEVICE_VIDEO:
     case VIR_DOMAIN_DEVICE_GRAPHICS:
-    case VIR_DOMAIN_DEVICE_HUB:
     case VIR_DOMAIN_DEVICE_SMARTCARD:
     case VIR_DOMAIN_DEVICE_MEMBALLOON:
     case VIR_DOMAIN_DEVICE_NVRAM:
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0a63741b9e..1b6cc36bc8 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3303,6 +3303,64 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver,
 }
 
 
+int
+qemuDomainAttachHubDevice(virQEMUDriverPtr driver,
+                          virDomainObjPtr vm,
+                          virDomainHubDefPtr hub)
+{
+    int ret = -1;
+    char *devstr = NULL;
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virErrorPtr originalError = NULL;
+    bool releaseaddr = false;
+
+    if (priv->usbaddrs) {
+        if (virDomainUSBAddressEnsure(priv->usbaddrs, &hub->info) < 0)
+                goto cleanup;
+            releaseaddr = true;
+    }
+
+    if (qemuAssignDeviceHubAlias(vm->def, hub, -1) < 0)
+        goto cleanup;
+
+    if (!(devstr = qemuBuildHubDevStr(vm->def, hub, priv->qemuCaps)))
+        goto cleanup;
+
+    if (VIR_REALLOC_N(vm->def->hubs, vm->def->nhubs + 1) < 0)
+        goto cleanup;
+
+    qemuDomainObjEnterMonitor(driver, vm);
+    if (qemuMonitorAddDevice(priv->mon, devstr) < 0)
+        goto exit_monitor;
+
+    if (qemuDomainObjExitMonitor(driver, vm) < 0) {
+        releaseaddr = false;
+        goto cleanup;
+    }
+
+    VIR_APPEND_ELEMENT_COPY_INPLACE(vm->def->hubs, vm->def->nhubs, hub);
+
+    ret = 0;
+    releaseaddr = false;
+
+ cleanup:
+    if (ret < 0) {
+        virErrorPreserveLast(&originalError);
+        if (releaseaddr)
+            qemuDomainReleaseDeviceAddress(vm, &hub->info, NULL);
+        virErrorRestore(&originalError);
+    }
+
+    VIR_FREE(devstr);
+    return ret;
+
+ exit_monitor:
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
+        releaseaddr = false;
+    goto cleanup;
+}
+
+
 int
 qemuDomainAttachVsockDevice(virQEMUDriverPtr driver,
                             virDomainObjPtr vm,
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 0297e42a98..19b8950254 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -135,6 +135,10 @@ int qemuDomainAttachInputDevice(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
                                 virDomainInputDefPtr input);
 
+int qemuDomainAttachHubDevice(virQEMUDriverPtr driver,
+                          virDomainObjPtr vm,
+                          virDomainHubDefPtr hub);
+
 int qemuDomainAttachVsockDevice(virQEMUDriverPtr driver,
                                 virDomainObjPtr vm,
                                 virDomainVsockDefPtr vsock);
-- 
2.19.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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