We are going to use qemuDomainAttachHostUSBDevice when
host usb device is plugged back to node.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
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 1a5b9aa0c2..a2dd37f630 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2478,8 +2478,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)
@@ -2504,7 +2514,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);
@@ -2517,7 +2527,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:
@@ -2530,9 +2541,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);
}
return ret;
}
--
2.23.0