mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
qemu_hostdev: move cfg->relaxedACS as a flag
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.
This commit is contained in:
parent
0d4efed02b
commit
3a331da883
@ -653,7 +653,8 @@ qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
|
|||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
virDomainHostdevDefPtr *hostdevs,
|
virDomainHostdevDefPtr *hostdevs,
|
||||||
int nhostdevs,
|
int nhostdevs,
|
||||||
virQEMUCapsPtr qemuCaps)
|
virQEMUCapsPtr qemuCaps,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
virPCIDeviceListPtr pcidevs = NULL;
|
virPCIDeviceListPtr pcidevs = NULL;
|
||||||
int last_processed_hostdev_vf = -1;
|
int last_processed_hostdev_vf = -1;
|
||||||
@ -686,8 +687,9 @@ qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
|
|||||||
for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
|
for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {
|
||||||
virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
|
virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);
|
||||||
virPCIDevicePtr other;
|
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,
|
virReportError(VIR_ERR_OPERATION_INVALID,
|
||||||
_("PCI device %s is not assignable"),
|
_("PCI device %s is not assignable"),
|
||||||
virPCIDeviceGetName(dev));
|
virPCIDeviceGetName(dev));
|
||||||
@ -1199,14 +1201,15 @@ int
|
|||||||
qemuPrepareHostDevices(virQEMUDriverPtr driver,
|
qemuPrepareHostDevices(virQEMUDriverPtr driver,
|
||||||
virDomainDefPtr def,
|
virDomainDefPtr def,
|
||||||
virQEMUCapsPtr qemuCaps,
|
virQEMUCapsPtr qemuCaps,
|
||||||
bool coldBoot)
|
bool coldBoot,
|
||||||
|
unsigned int flags)
|
||||||
{
|
{
|
||||||
if (!def->nhostdevs)
|
if (!def->nhostdevs)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (qemuPrepareHostdevPCIDevices(driver, def->name, def->uuid,
|
if (qemuPrepareHostdevPCIDevices(driver, def->name, def->uuid,
|
||||||
def->hostdevs, def->nhostdevs,
|
def->hostdevs, def->nhostdevs,
|
||||||
qemuCaps) < 0)
|
qemuCaps, flags) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (qemuPrepareHostUSBDevices(driver, def->name,
|
if (qemuPrepareHostUSBDevices(driver, def->name,
|
||||||
|
@ -27,6 +27,10 @@
|
|||||||
# include "qemu_conf.h"
|
# include "qemu_conf.h"
|
||||||
# include "domain_conf.h"
|
# include "domain_conf.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
VIR_HOSTDEV_STRICT_ACS_CHECK = (1 << 0), /* strict acs check */
|
||||||
|
} virHostdevFlag;
|
||||||
|
|
||||||
int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
|
int qemuUpdateActivePciHostdevs(virQEMUDriverPtr driver,
|
||||||
virDomainDefPtr def);
|
virDomainDefPtr def);
|
||||||
int qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver,
|
int qemuUpdateActiveUsbHostdevs(virQEMUDriverPtr driver,
|
||||||
@ -40,7 +44,8 @@ int qemuPrepareHostdevPCIDevices(virQEMUDriverPtr driver,
|
|||||||
const unsigned char *uuid,
|
const unsigned char *uuid,
|
||||||
virDomainHostdevDefPtr *hostdevs,
|
virDomainHostdevDefPtr *hostdevs,
|
||||||
int nhostdevs,
|
int nhostdevs,
|
||||||
virQEMUCapsPtr qemuCaps);
|
virQEMUCapsPtr qemuCaps,
|
||||||
|
unsigned int flags);
|
||||||
int
|
int
|
||||||
qemuPrepareHostUSBDevices(virQEMUDriverPtr driver,
|
qemuPrepareHostUSBDevices(virQEMUDriverPtr driver,
|
||||||
const char *name,
|
const char *name,
|
||||||
@ -54,7 +59,8 @@ int qemuPrepareHostdevSCSIDevices(virQEMUDriverPtr driver,
|
|||||||
int qemuPrepareHostDevices(virQEMUDriverPtr driver,
|
int qemuPrepareHostDevices(virQEMUDriverPtr driver,
|
||||||
virDomainDefPtr def,
|
virDomainDefPtr def,
|
||||||
virQEMUCapsPtr qemuCaps,
|
virQEMUCapsPtr qemuCaps,
|
||||||
bool coldBoot);
|
bool coldBoot,
|
||||||
|
unsigned int flags);
|
||||||
void
|
void
|
||||||
qemuDomainReAttachHostUsbDevices(virQEMUDriverPtr driver,
|
qemuDomainReAttachHostUsbDevices(virQEMUDriverPtr driver,
|
||||||
const char *name,
|
const char *name,
|
||||||
|
@ -1161,13 +1161,17 @@ qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
|
|||||||
bool teardownlabel = false;
|
bool teardownlabel = false;
|
||||||
int backend;
|
int backend;
|
||||||
unsigned long long memKB;
|
unsigned long long memKB;
|
||||||
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
|
unsigned int flags = 0;
|
||||||
|
|
||||||
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
|
if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
if (!cfg->relaxedACS)
|
||||||
|
flags |= VIR_HOSTDEV_STRICT_ACS_CHECK;
|
||||||
if (qemuPrepareHostdevPCIDevices(driver, vm->def->name, vm->def->uuid,
|
if (qemuPrepareHostdevPCIDevices(driver, vm->def->name, vm->def->uuid,
|
||||||
&hostdev, 1, priv->qemuCaps) < 0)
|
&hostdev, 1, priv->qemuCaps, flags) < 0)
|
||||||
return -1;
|
goto cleanup;
|
||||||
|
|
||||||
/* this could have been changed by qemuPrepareHostdevPCIDevices */
|
/* this could have been changed by qemuPrepareHostdevPCIDevices */
|
||||||
backend = hostdev->source.subsys.u.pci.backend;
|
backend = hostdev->source.subsys.u.pci.backend;
|
||||||
@ -1261,6 +1265,7 @@ qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
|
|||||||
VIR_FREE(devstr);
|
VIR_FREE(devstr);
|
||||||
VIR_FREE(configfd_name);
|
VIR_FREE(configfd_name);
|
||||||
VIR_FORCE_CLOSE(configfd);
|
VIR_FORCE_CLOSE(configfd);
|
||||||
|
virObjectUnref(cfg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -1281,6 +1286,8 @@ error:
|
|||||||
VIR_FREE(configfd_name);
|
VIR_FREE(configfd_name);
|
||||||
VIR_FORCE_CLOSE(configfd);
|
VIR_FORCE_CLOSE(configfd);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virObjectUnref(cfg);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3595,6 +3595,7 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
unsigned int stop_flags;
|
unsigned int stop_flags;
|
||||||
virQEMUDriverConfigPtr cfg;
|
virQEMUDriverConfigPtr cfg;
|
||||||
virCapsPtr caps = NULL;
|
virCapsPtr caps = NULL;
|
||||||
|
unsigned int hostdev_flags = 0;
|
||||||
|
|
||||||
VIR_DEBUG("vm=%p name=%s id=%d pid=%llu",
|
VIR_DEBUG("vm=%p name=%s id=%d pid=%llu",
|
||||||
vm, vm->def->name, vm->def->id,
|
vm, vm->def->name, vm->def->id,
|
||||||
@ -3684,8 +3685,10 @@ int qemuProcessStart(virConnectPtr conn,
|
|||||||
|
|
||||||
/* Must be run before security labelling */
|
/* Must be run before security labelling */
|
||||||
VIR_DEBUG("Preparing host devices");
|
VIR_DEBUG("Preparing host devices");
|
||||||
|
if (!cfg->relaxedACS)
|
||||||
|
hostdev_flags |= VIR_HOSTDEV_STRICT_ACS_CHECK;
|
||||||
if (qemuPrepareHostDevices(driver, vm->def, priv->qemuCaps,
|
if (qemuPrepareHostDevices(driver, vm->def, priv->qemuCaps,
|
||||||
!migrateFrom) < 0)
|
!migrateFrom, hostdev_flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
VIR_DEBUG("Preparing chr devices");
|
VIR_DEBUG("Preparing chr devices");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user