For extracting hostdev codes from qemu_hostdev.c to common library, change qemu
specific cfg->relaxedACS handling to be a flag, and pass it to hostdev
functions.
Signed-off-by: Chunyan Liu <cyliu(a)suse.com>
---
src/qemu/qemu_hostdev.c | 11 +++++++----
src/qemu/qemu_hostdev.h | 10 ++++++++--
src/qemu/qemu_hotplug.c | 11 +++++++++--
src/qemu/qemu_process.c | 5 ++++-
4 files changed, 28 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c
index a4ee611..32b5921 100644
--- a/src/qemu/qemu_hostdev.c
+++ b/src/qemu/qemu_hostdev.c
@@ -653,7 +653,8 @@ qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
const unsigned char *uuid,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs,
- virQEMUCapsPtr qemuCaps)
+ virQEMUCapsPtr qemuCaps,
+ unsigned int flags)
{
virPCIDeviceListPtr pcidevs = NULL;
int last_processed_hostdev_vf = -1;
@@ -686,8 +687,9 @@ qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
virPCIDevicePtr other;
+ bool strict_acs_check = !!(flags & VIR_HOSTDEV_STRICT_ACS_CHECK);
- if (!virPCIDeviceIsAssignable(dev, !cfg->relaxedACS)) {
+ if (!virPCIDeviceIsAssignable(dev, strict_acs_check)) {
virReportError(VIR_ERR_OPERATION_INVALID,
_("PCI device %s is not assignable"),
virPCIDeviceGetName(dev));
@@ -1199,14 +1201,15 @@ int
qemuPrepareHostDevices(virQEMUDriverPtr driver,
virDomainDefPtr def,
virQEMUCapsPtr qemuCaps,
- bool coldBoot)
+ bool coldBoot,
+ unsigned int flags)
{
if (!def->nhostdevs)
return 0;
if (qemuPrepareHostdevPCIDevices(driver, def->name, def->uuid,
def->hostdevs, def->nhostdevs,
- qemuCaps) < 0)
+ qemuCaps, flags) < 0)
return -1;
if (qemuPrepareHostUSBDevices(driver, def->name,
diff --git a/src/qemu/qemu_hostdev.h b/src/qemu/qemu_hostdev.h
index 6d5daa7..d0ed82f 100644
--- a/src/qemu/qemu_hostdev.h
+++ b/src/qemu/qemu_hostdev.h
@@ -27,6 +27,10 @@
# include "qemu_conf.h"
# include "domain_conf.h"
+typedef enum {
+ VIR_HOSTDEV_STRICT_ACS_CHECK = (1 << 0), /* strict acs check */
+} virHostdevFlag;
+
int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
virDomainDefPtr def);
int qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver,
@@ -40,7 +44,8 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
const unsigned char *uuid,
virDomainHostdevDefPtr *hostdevs,
int nhostdevs,
- virQEMUCapsPtr qemuCaps);
+ virQEMUCapsPtr qemuCaps,
+ unsigned int flags);
int
qemuPrepareHostUSBDevices(virQEMUDriverPtr driver,
const char *name,
@@ -54,7 +59,8 @@ int qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
int qemuPrepareHostDevices(virQEMUDriverPtr driver,
virDomainDefPtr def,
virQEMUCapsPtr qemuCaps,
- bool coldBoot);
+ bool coldBoot,
+ unsigned int flags);
void
qemuDomainReAttachHostUsbDevices(virQEMUDriverPtr driver,
const char *name,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 40b2b4e..420cb28 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1154,13 +1154,17 @@ qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
bool teardownlabel = false;
int backend;
unsigned long long memKB;
+ virQEMUDriverConfigPtr 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 (qemuPrepareHostdevPCIDevices(driver, vm->def->name, vm->def->uuid,
- &hostdev, 1, priv->qemuCaps) < 0)
- return -1;
+ &hostdev, 1, priv->qemuCaps, flags) < 0)
+ goto cleanup;
/* this could have been changed by qemuPrepareHostdevPCIDevices */
backend = hostdev->source.subsys.u.pci.backend;
@@ -1254,6 +1258,7 @@ qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
VIR_FREE(devstr);
VIR_FREE(configfd_name);
VIR_FORCE_CLOSE(configfd);
+ virObjectUnref(cfg);
return 0;
@@ -1274,6 +1279,8 @@ error:
VIR_FREE(configfd_name);
VIR_FORCE_CLOSE(configfd);
+cleanup:
+ virObjectUnref(cfg);
return -1;
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ffa939a..5e7672f 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3596,6 +3596,7 @@ int qemuProcessStart(virConnectPtr conn,
unsigned int stop_flags;
virQEMUDriverConfigPtr cfg;
virCapsPtr caps = NULL;
+ unsigned int hostdev_flags = 0;
VIR_DEBUG("vm=%p name=%s id=%d pid=%llu",
vm, vm->def->name, vm->def->id,
@@ -3685,8 +3686,10 @@ int qemuProcessStart(virConnectPtr conn,
/* Must be run before security labelling */
VIR_DEBUG("Preparing host devices");
+ if (!cfg->relaxedACS)
+ hostdev_flags |= VIR_HOSTDEV_STRICT_ACS_CHECK;
if (qemuPrepareHostDevices(driver, vm->def, priv->qemuCaps,
- !migrateFrom) < 0)
+ !migrateFrom, hostdev_flags) < 0)
goto cleanup;
VIR_DEBUG("Preparing chr devices");
--
1.9.0