[PATCH v3 04/12] qemu: support usb hostdev plugging back

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

 



We are going to use qemuDomainAttachHostUSBDevice when
host usb device is plugged back to node.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
Reviewed-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/qemu/qemu_hotplug.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 121e4b2821..780bfde002 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2524,8 +2524,18 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
     bool teardownlabel = false;
     bool teardowndevice = false;
     int ret = -1;
+    bool replug = false;
+    size_t i;
+
+    for (i = 0; i < vm->def->nhostdevs; i++) {
+        if (vm->def->hostdevs[i] == hostdev) {
+            replug = true;
+            break;
+        }
+    }
 
-    if (virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0)
+    if (!replug &&
+        virDomainUSBAddressEnsure(priv->usbaddrs, hostdev->info) < 0)
         return -1;
 
     if (qemuHostdevPrepareUSBDevices(driver, vm->def->name, &hostdev, 1, 0) < 0)
@@ -2550,7 +2560,7 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
     if (!(devstr = qemuBuildUSBHostdevDevStr(vm->def, hostdev, priv->qemuCaps)))
         goto cleanup;
 
-    if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0)
+    if (!replug && VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0)
         goto cleanup;
 
     qemuDomainObjEnterMonitor(driver, vm);
@@ -2563,7 +2573,8 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
     if (ret < 0)
         goto cleanup;
 
-    vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
+    if (!replug)
+        vm->def->hostdevs[vm->def->nhostdevs++] = hostdev;
 
     ret = 0;
  cleanup:
@@ -2576,9 +2587,17 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
         if (teardowndevice &&
             qemuDomainNamespaceTeardownHostdev(vm, hostdev) < 0)
             VIR_WARN("Unable to remove host device from /dev");
-        if (added)
+        if (added) {
             qemuHostdevReAttachUSBDevices(driver, vm->def->name, &hostdev, 1);
-        virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info);
+
+            if (replug) {
+                virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
+                usbsrc->bus = 0;
+                usbsrc->device = 0;
+            }
+        }
+        if (!replug)
+            virDomainUSBAddressRelease(priv->usbaddrs, hostdev->info);
     }
     VIR_FREE(devstr);
     return ret;
-- 
2.23.0

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