The hostdevices are the only devices which have dependencies
outside of themselves such that, other functions of the PCI
card should also have been detached from host driver before
attempting the hotplug.
This patch moves the detach to the beginning of the hotplug
so that the following patch can detach all funtions first before
attempting to hotplug any.
We need not move the detach for net devices using SRIOV as
all SRIOV devices are single function devices and can be independently
detached as usual.
Signed-off-by: Shivaprasad G Bhat <sbhat(a)linux.vnet.ibm.com>
---
src/qemu/qemu_hotplug.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 1bf87d963e..214e169980 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -888,6 +888,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
bool charDevPlugged = false;
bool netdevPlugged = false;
bool hostPlugged = false;
+ virDomainHostdevDefPtr hostdev = NULL;
/* preallocate new slot for device */
if (VIR_REALLOC_N(vm->def->nets, vm->def->nnets + 1) < 0)
@@ -998,9 +999,16 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
* as a hostdev (the hostdev code will reach over into the
* netdev-specific code as appropriate), then also added to
* the nets list (see cleanup:) if successful.
+ *
+ * qemuDomainAttachHostDevice uses a connection to resolve
+ * a SCSI hostdev secret, which is not this case, so pass NULL.
*/
- ret = qemuDomainAttachHostDevice(driver, vm,
- virDomainNetGetActualHostdev(net));
+ hostdev = virDomainNetGetActualHostdev(net);
+ if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def,
+ hostdev, priv->qemuCaps) < 0)
+ goto cleanup;
+ if ((ret = qemuDomainAttachHostDevice(driver, vm, hostdev)) < 0)
+ qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
goto cleanup;
break;
@@ -1312,10 +1320,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
return -1;
- if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def,
- hostdev, priv->qemuCaps) < 0)
- return -1;
-
backend = hostdev->source.subsys.u.pci.backend;
/* Temporarily add the hostdev to the domain definition. This is needed
@@ -1405,8 +1409,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
if (releaseaddr)
qemuDomainReleaseDeviceAddress(vm, info, NULL);
- qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
-
VIR_FREE(devstr);
VIR_FREE(configfd_name);
VIR_FORCE_CLOSE(configfd);
@@ -2588,6 +2590,8 @@ qemuDomainAttachHostDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainHostdevDefPtr hostdev)
{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("hotplug is not supported for hostdev mode
'%s'"),
@@ -2597,9 +2601,14 @@ qemuDomainAttachHostDevice(virQEMUDriverPtr driver,
switch (hostdev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
+ if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def,
+ hostdev, priv->qemuCaps) < 0)
+ goto error;
if (qemuDomainAttachHostPCIDevice(driver, vm,
- hostdev) < 0)
+ hostdev) < 0) {
+ qemuHostdevReAttachPCIDevices(driver, vm->def->name, &hostdev, 1);
goto error;
+ }
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: