conf: put hostdev PCI backend into a struct

The new struct is virDeviceHostdevPCIDriverInfo, and the "backend"
enum in the hostdevDef will be replaced with a
virDeviceHostdevPCIDriverInfo named "driver'. Since the enum value in
this new struct is called "name", it means that all references to
"backend" will become "driver.name".

This will allow easily adding other items for new attributes in the
<driver> element / C struct, which will be useful once we are using
this new struct in multiple places.

Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Laine Stump 2024-01-04 20:12:51 -05:00
parent e7d31d8b00
commit e04ca000bd
16 changed files with 47 additions and 45 deletions

View File

@ -43,6 +43,10 @@ typedef enum {
VIR_ENUM_DECL(virDeviceHostdevPCIDriverName);
struct _virDeviceHostdevPCIDriverInfo {
virDeviceHostdevPCIDriverName name;
};
typedef enum {
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE = 0,
VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI,

View File

@ -6287,7 +6287,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
if (virXMLPropEnum(driver_node, "name",
virDeviceHostdevPCIDriverNameTypeFromString,
VIR_XML_PROP_NONZERO,
&pcisrc->backend) < 0) {
&pcisrc->driver.name) < 0) {
return -1;
}
}
@ -23429,17 +23429,17 @@ virDomainHostdevDefFormatSubsysPCI(virBuffer *buf,
g_auto(virBuffer) sourceChildBuf = VIR_BUFFER_INIT_CHILD(buf);
virDomainHostdevSubsysPCI *pcisrc = &def->source.subsys.u.pci;
if (pcisrc->backend != VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) {
const char *backend = virDeviceHostdevPCIDriverNameTypeToString(pcisrc->backend);
if (pcisrc->driver.name != VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) {
const char *driverName = virDeviceHostdevPCIDriverNameTypeToString(pcisrc->driver.name);
if (!backend) {
if (!driverName) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected pci hostdev driver name type %1$d"),
pcisrc->backend);
_("unexpected pci hostdev driver type %1$d"),
pcisrc->driver.name);
return -1;
}
virBufferAsprintf(&driverAttrBuf, " name='%s'", backend);
virBufferAsprintf(&driverAttrBuf, " name='%s'", driverName);
}
virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
@ -29967,15 +29967,15 @@ virDomainNetDefActualFromNetworkPort(virDomainNetDef *iface,
actual->data.hostdev.def.source.subsys.u.pci.addr = port->plug.hostdevpci.addr;
switch ((virNetworkForwardDriverNameType)port->plug.hostdevpci.driver) {
case VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT:
actual->data.hostdev.def.source.subsys.u.pci.backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT;
actual->data.hostdev.def.source.subsys.u.pci.driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT;
break;
case VIR_NETWORK_FORWARD_DRIVER_NAME_KVM:
actual->data.hostdev.def.source.subsys.u.pci.backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_KVM;
actual->data.hostdev.def.source.subsys.u.pci.driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_KVM;
break;
case VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO:
actual->data.hostdev.def.source.subsys.u.pci.backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
actual->data.hostdev.def.source.subsys.u.pci.driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
break;
case VIR_NETWORK_FORWARD_DRIVER_NAME_LAST:
@ -30085,7 +30085,7 @@ virDomainNetDefActualToNetworkPort(virDomainDef *dom,
}
port->plug.hostdevpci.managed = virTristateBoolFromBool(actual->data.hostdev.def.managed);
port->plug.hostdevpci.addr = actual->data.hostdev.def.source.subsys.u.pci.addr;
switch (actual->data.hostdev.def.source.subsys.u.pci.backend) {
switch (actual->data.hostdev.def.source.subsys.u.pci.driver.name) {
case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT:
port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT;
break;
@ -30099,14 +30099,10 @@ virDomainNetDefActualToNetworkPort(virDomainDef *dom,
break;
case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("Unexpected PCI backend 'xen'"));
break;
case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_LAST:
default:
virReportEnumRangeError(virDeviceHostdevPCIDriverName,
actual->data.hostdev.def.source.subsys.u.pci.backend);
actual->data.hostdev.def.source.subsys.u.pci.driver.name);
return NULL;
}
@ -31050,7 +31046,7 @@ virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
{
return hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
hostdev->source.subsys.u.pci.backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
hostdev->source.subsys.u.pci.driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
}

View File

@ -235,7 +235,7 @@ struct _virDomainHostdevSubsysUSB {
struct _virDomainHostdevSubsysPCI {
virPCIDeviceAddress addr; /* host address */
virDeviceHostdevPCIDriverName backend;
virDeviceHostdevPCIDriverInfo driver;
virBitmap *origstates;
};

View File

@ -66,6 +66,8 @@ typedef struct _virCapsHostSecModelLabel virCapsHostSecModelLabel;
typedef struct _virCapsStoragePool virCapsStoragePool;
typedef struct _virDeviceHostdevPCIDriverInfo virDeviceHostdevPCIDriverInfo;
typedef struct _virDomainABIStability virDomainABIStability;
typedef struct _virDomainActualNetDef virDomainActualNetDef;

View File

@ -243,14 +243,14 @@ virHostdevGetPCIHostDevice(const virDomainHostdevDef *hostdev,
virPCIDeviceSetManaged(actual, hostdev->managed);
if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
virPCIDeviceSetStubDriverType(actual, VIR_PCI_STUB_DRIVER_VFIO);
} else if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN) {
} else if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN) {
virPCIDeviceSetStubDriverType(actual, VIR_PCI_STUB_DRIVER_XEN);
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("pci backend driver type '%1$s' is not supported"),
virDeviceHostdevPCIDriverNameTypeToString(pcisrc->backend));
virDeviceHostdevPCIDriverNameTypeToString(pcisrc->driver.name));
return -1;
}

View File

@ -160,8 +160,8 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDef *dev,
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT)
pcisrc->backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT)
pcisrc->driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
}
if (dev->type == VIR_DOMAIN_DEVICE_VIDEO) {
@ -997,7 +997,7 @@ libxlNetworkPrepareDevices(virDomainDef *def)
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
pcisrc->backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
pcisrc->driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
if (virDomainHostdevInsert(def, hostdev) < 0)
return -1;

View File

@ -3397,13 +3397,13 @@ libxlDomainAttachNetDevice(libxlDriverPrivate *driver,
virDomainHostdevDef *hostdev = virDomainNetGetActualHostdev(net);
virDomainHostdevSubsysPCI *pcisrc = &hostdev->source.subsys.u.pci;
/* For those just allocated from a network pool whose backend is
/* For those just allocated from a network pool whose driver type is
* still VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT, we need to set
* backend correctly.
* driver name correctly.
*/
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
pcisrc->backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
pcisrc->driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN;
/* This is really a "smart hostdev", so it should be attached
* as a hostdev (the hostdev code will reach over into the

View File

@ -4707,8 +4707,8 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
g_autofree char *host = virPCIDeviceAddressAsString(&pcisrc->addr);
const char *failover_pair_id = NULL;
/* caller has to assign proper passthrough backend type */
switch (pcisrc->backend) {
/* caller has to assign proper passthrough driver name */
switch (pcisrc->driver.name) {
case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO:
break;
@ -4718,7 +4718,7 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_LAST:
virReportError(VIR_ERR_INTERNAL_ERROR,
_("invalid PCI passthrough type '%1$s'"),
virDeviceHostdevPCIDriverNameTypeToString(pcisrc->backend));
virDeviceHostdevPCIDriverNameTypeToString(pcisrc->driver.name));
return NULL;
}

View File

@ -10534,7 +10534,7 @@ qemuDomainGetHostdevPath(virDomainHostdevDef *dev,
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
switch (dev->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
if (!(tmpPath = virPCIDeviceAddressGetIOMMUGroupDev(&pcisrc->addr)))
return -1;
@ -11305,7 +11305,7 @@ qemuDomainPrepareHostdevPCI(virDomainHostdevDef *hostdev,
virQEMUCaps *qemuCaps)
{
bool supportsPassthroughVFIO = qemuHostdevHostSupportsPassthroughVFIO();
virDeviceHostdevPCIDriverName *driverName = &hostdev->source.subsys.u.pci.backend;
virDeviceHostdevPCIDriverName *driverName = &hostdev->source.subsys.u.pci.driver.name;
/* assign defaults for hostdev passthrough */
switch (*driverName) {

View File

@ -2437,7 +2437,7 @@ qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev,
const virDomainDef *def,
virQEMUCaps *qemuCaps)
{
int backend;
virDeviceHostdevPCIDriverName driverName;
/* forbid capabilities mode hostdev in this kind of hypervisor */
if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_CAPABILITIES) {
@ -2462,9 +2462,9 @@ qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev,
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
backend = hostdev->source.subsys.u.pci.backend;
driverName = hostdev->source.subsys.u.pci.driver.name;
if (backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
if (driverName == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_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"));

View File

@ -869,7 +869,7 @@ AppArmorSetSecurityHostdevLabel(virSecurityManager *mgr,
if (!pci)
goto done;
if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
if (!vfioGroupDev) {

View File

@ -1257,7 +1257,7 @@ virSecurityDACSetHostdevLabel(virSecurityManager *mgr,
if (!pci)
return -1;
if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
g_autofree char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
if (!vfioGroupDev)
@ -1418,7 +1418,7 @@ virSecurityDACRestoreHostdevLabel(virSecurityManager *mgr,
if (!pci)
return -1;
if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
g_autofree char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
if (!vfioGroupDev)

View File

@ -2201,7 +2201,7 @@ virSecuritySELinuxSetHostdevSubsysLabel(virSecurityManager *mgr,
if (!pci)
return -1;
if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
g_autofree char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
if (!vfioGroupDev)
@ -2437,7 +2437,7 @@ virSecuritySELinuxRestoreHostdevSubsysLabel(virSecurityManager *mgr,
if (!pci)
return -1;
if (pcisrc->backend == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
if (pcisrc->driver.name == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO) {
g_autofree char *vfioGroupDev = virPCIDeviceGetIOMMUGroupDev(pci);
if (!vfioGroupDev)

View File

@ -1092,7 +1092,7 @@ get_files(vahControl * ctl)
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: {
virPCIDevice *pci = virPCIDeviceNew(&dev->source.subsys.u.pci.addr);
virDeviceHostdevPCIDriverName driverName = dev->source.subsys.u.pci.backend;
virDeviceHostdevPCIDriverName driverName = dev->source.subsys.u.pci.driver.name;
if (driverName == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO ||
driverName == VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) {

View File

@ -10042,9 +10042,9 @@ testDomainAttachHostPCIDevice(testDriver *driver G_GNUC_UNUSED,
virDomainObj *vm,
virDomainHostdevDef *hostdev)
{
int backend = hostdev->source.subsys.u.pci.backend;
int driverName = hostdev->source.subsys.u.pci.driver.name;
switch (backend) {
switch (driverName) {
case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO:
case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT:
case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_KVM:
@ -10054,7 +10054,7 @@ testDomainAttachHostPCIDevice(testDriver *driver G_GNUC_UNUSED,
case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_LAST:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("test hypervisor does not support device assignment mode '%1$s'"),
virDeviceHostdevPCIDriverNameTypeToString(backend));
virDeviceHostdevPCIDriverNameTypeToString(driverName));
return -1;
}

View File

@ -134,7 +134,7 @@ myInit(void)
subsys->u.pci.addr.bus = 0;
subsys->u.pci.addr.slot = i + 1;
subsys->u.pci.addr.function = 0;
subsys->u.pci.backend = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
subsys->u.pci.driver.name = VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
}
for (i = 0; i < nhostdevs; i++) {