Re: [PATCH v2 03/11] qemu: support usb hostdev plugging back

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

 





On 9/9/19 8:33 AM, Nikolay Shirokovskiy wrote:
We are going to use qemuDomainAttachHostUSBDevice when
host usb device is plugged back to node.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
  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 b045735022..ea82cb54ef 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2437,8 +2437,18 @@ qemuDomainAttachHostUSBDevice(virQEMUDriverPtr driver,
      bool teardownlabel = false;
      bool teardowndevice = false;
      int ret = -1;
+    bool replug;
+    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)

Compilation didn't complain about it, but for clarity, you can initialize
'replug' up there to 'false' to avoid using an uninitialized value here
(since replug will not necessarily be set to 'true' in the for loop).


Looks good otherwise.

Reviewed-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>


          return -1;
if (qemuHostdevPrepareUSBDevices(driver, vm->def->name, &hostdev, 1, 0) < 0)
@@ -2463,7 +2473,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);
@@ -2476,7 +2486,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:
@@ -2489,9 +2500,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;

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