From: Shivaprasad G Bhat <sbhat(a)linux.vnet.ibm.com>
No functional change.
Signed-off-by: Shivaprasad G Bhat <sbhat(a)linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/qemu/qemu_hotplug.c | 80 ++++++++++++++++++++++++++---------------
src/qemu/qemu_hotplug.h | 5 +++
2 files changed, 56 insertions(+), 29 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 3571dead89..172747b2e2 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1014,6 +1014,55 @@ qemuDomainAttachUSBMassStorageDevice(virQEMUDriverPtr driver,
}
+int qemuDomainAttachPCIHostDevicePrepare(virQEMUDriverPtr driver,
+ virDomainDefPtr def,
+ virDomainHostdevDefPtr hostdev,
+ virQEMUCapsPtr qemuCaps)
+{
+ g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+ unsigned int flags = 0;
+ int backend;
+
+ if (!cfg->relaxedACS)
+ flags |= VIR_HOSTDEV_STRICT_ACS_CHECK;
+ if (qemuHostdevPreparePCIDevices(driver, def->name, def->uuid,
+ &hostdev, 1, qemuCaps, flags) < 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(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;
+ }
+
+ return 0;
+
+ error:
+ qemuHostdevReAttachPCIDevices(driver, def->name, &hostdev, 1);
+ return -1;
+}
+
+
static int
qemuDomainAttachDeviceDiskLiveInternal(virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -1557,44 +1606,17 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
bool teardowndevice = false;
bool teardownmemlock = false;
int backend;
- g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
- unsigned int flags = 0;
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
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)
+ 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;
- }
-
if (qemuDomainAdjustMaxMemLockHostdev(vm, hostdev) < 0)
goto error;
teardownmemlock = true;
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 4a49e04a15..9df4a4e5f7 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -122,6 +122,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);
--
2.26.2