No functional change.
Signed-off-by: Shivaprasad G Bhat <sbhat(a)linux.vnet.ibm.com>
---
src/qemu/qemu_hotplug.c | 90 +++++++++++++++++++++++++++++------------------
src/qemu/qemu_hotplug.h | 5 +++
2 files changed, 60 insertions(+), 35 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index e0a5300f08..1bf87d963e 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -688,6 +688,57 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
return 0;
}
+int qemuDomainAttachPCIHostDevicePrepare(virQEMUDriverPtr driver,
+ virDomainDefPtr def,
+ virDomainHostdevDefPtr hostdev,
+ virQEMUCapsPtr qemuCaps)
+{
+ virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+ unsigned int flags = 0;
+ int ret = -1;
+ int backend;
+
+ if (!cfg->relaxedACS)
+ flags |= VIR_HOSTDEV_STRICT_ACS_CHECK;
+ if (qemuHostdevPreparePCIDevices(driver, def->name, def->uuid,
+ &hostdev, 1, qemuCaps, flags) < 0)
+ goto exit;
+
+ /* this could have been changed by qemuHostdevPreparePCIDevices */
+ backend = hostdev->source.subsys.u.pci.backend;
+
+ switch ((virDomainHostdevSubsysPCIBackendType) backend) {
+ case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("VFIO PCI device assignment is not "
+ "supported by this version of qemu"));
+ goto error;
+ }
+ break;
+
+ case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
+ case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM:
+ break;
+
+ case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN:
+ case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST:
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("QEMU does not support device assignment mode
'%s'"),
+ virDomainHostdevSubsysPCIBackendTypeToString(backend));
+ goto error;
+ break;
+ }
+
+ ret = 0;
+ exit:
+ virObjectUnref(cfg);
+ return ret;
+ error:
+ qemuHostdevReAttachPCIDevices(driver, def->name, &hostdev, 1);
+ goto exit;
+}
+
int
qemuDomainAttachDeviceDiskLive(virQEMUDriverPtr driver,
@@ -1257,44 +1308,16 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
bool teardownlabel = false;
bool teardowndevice = false;
int backend;
- virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
- unsigned int flags = 0;
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
- goto cleanup;
+ return -1;
- if (!cfg->relaxedACS)
- flags |= VIR_HOSTDEV_STRICT_ACS_CHECK;
- if (qemuHostdevPreparePCIDevices(driver, vm->def->name, vm->def->uuid,
- &hostdev, 1, priv->qemuCaps, flags) < 0)
- goto cleanup;
+ if (qemuDomainAttachPCIHostDevicePrepare(driver, vm->def,
+ hostdev, priv->qemuCaps) < 0)
+ return -1;
- /* this could have been changed by qemuHostdevPreparePCIDevices */
backend = hostdev->source.subsys.u.pci.backend;
- switch ((virDomainHostdevSubsysPCIBackendType) backend) {
- case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
- if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
- _("VFIO PCI device assignment is not "
- "supported by this version of qemu"));
- goto error;
- }
- break;
-
- case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
- case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM:
- break;
-
- case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN:
- case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_TYPE_LAST:
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("QEMU does not support device assignment mode
'%s'"),
- virDomainHostdevSubsysPCIBackendTypeToString(backend));
- goto error;
- break;
- }
-
/* Temporarily add the hostdev to the domain definition. This is needed
* because qemuDomainAdjustMaxMemLock() requires the hostdev to be already
* part of the domain definition, but other functions like
@@ -1366,7 +1389,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
VIR_FREE(devstr);
VIR_FREE(configfd_name);
VIR_FORCE_CLOSE(configfd);
- virObjectUnref(cfg);
return 0;
@@ -1389,8 +1411,6 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
VIR_FREE(configfd_name);
VIR_FORCE_CLOSE(configfd);
- cleanup:
- virObjectUnref(cfg);
return -1;
}
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index b2f5fa688b..db0e1df79a 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -154,6 +154,11 @@ void qemuDomainRemoveVcpuAlias(virQEMUDriverPtr driver,
virDomainObjPtr vm,
const char *alias);
+int qemuDomainAttachPCIHostDevicePrepare(virQEMUDriverPtr driver,
+ virDomainDefPtr def,
+ virDomainHostdevDefPtr dev,
+ virQEMUCapsPtr qemuCaps);
+
int
qemuDomainChrInsert(virDomainDefPtr vmdef,
virDomainChrDefPtr chr);