The next step in consolidating parsing/formatting of the <driver>
element of these objects using a common struct and common code. This
eliminates the virNetworkForwardDriverNameType enum which is nearly
identical to virDeviceHostdevPCIDriverName (the only non-identical bit
was just because they'd gotten out of sync over time) and replaces its
uses with a virDeviceHostdevPCIDriverInfo (which is a struct that
contains a virDeviceHostdevPCIDriverName).
Signed-off-by: Laine Stump <laine(a)redhat.com>
Reviewed-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 43 ++----------------------------------
src/conf/network_conf.c | 23 ++++++-------------
src/conf/network_conf.h | 17 ++------------
src/conf/virnetworkportdef.c | 8 +++----
src/conf/virnetworkportdef.h | 4 +++-
src/network/bridge_driver.c | 2 +-
6 files changed, 19 insertions(+), 78 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 887b871589..e19a2817c4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29914,26 +29914,7 @@ virDomainNetDefActualFromNetworkPort(virDomainNetDef *iface,
}
actual->data.hostdev.def.source.subsys.type =
VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI;
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.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.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.driver.name =
VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO;
- break;
-
- case VIR_NETWORK_FORWARD_DRIVER_NAME_LAST:
- default:
- virReportEnumRangeError(virNetworkForwardDriverNameType,
- port->plug.hostdevpci.driver);
- goto error;
- }
-
+ actual->data.hostdev.def.source.subsys.u.pci.driver.name =
port->plug.hostdevpci.driver.name;
break;
case VIR_NETWORK_PORT_PLUG_TYPE_LAST:
@@ -30034,27 +30015,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.driver.name) {
- case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT:
- port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT;
- break;
-
- case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_KVM:
- port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_KVM;
- break;
-
- case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_VFIO:
- port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO;
- break;
-
- case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_XEN:
- case VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_LAST:
- default:
- virReportEnumRangeError(virDeviceHostdevPCIDriverName,
-
actual->data.hostdev.def.source.subsys.u.pci.driver.name);
- return NULL;
- }
-
+ port->plug.hostdevpci.driver.name =
actual->data.hostdev.def.source.subsys.u.pci.driver.name;
break;
case VIR_DOMAIN_NET_TYPE_CLIENT:
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 984ff564b2..d732e90b6d 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -56,13 +56,6 @@ VIR_ENUM_IMPL(virNetworkForwardHostdevDevice,
"none", "pci", "netdev",
);
-VIR_ENUM_IMPL(virNetworkForwardDriverName,
- VIR_NETWORK_FORWARD_DRIVER_NAME_LAST,
- "default",
- "kvm",
- "vfio",
-);
-
VIR_ENUM_IMPL(virNetworkTaint,
VIR_NETWORK_TAINT_LAST,
"hook-script",
@@ -1358,9 +1351,9 @@ virNetworkForwardDefParseXML(const char *networkName,
if ((driverNode = virXPathNode("./driver", ctxt))) {
if (virXMLPropEnum(driverNode, "name",
- virNetworkForwardDriverNameTypeFromString,
+ virDeviceHostdevPCIDriverNameTypeFromString,
VIR_XML_PROP_NONZERO,
- &def->driverName) < 0) {
+ &def->driver.name) < 0) {
return -1;
}
}
@@ -2349,19 +2342,17 @@ virNetworkDefFormatBuf(virBuffer *buf,
|| VIR_SOCKET_ADDR_VALID(&def->forward.addr.end)
|| def->forward.port.start
|| def->forward.port.end
- || (def->forward.driverName
- != VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT)
+ || (def->forward.driver.name !=
VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT)
|| def->forward.natIPv6);
virBufferAsprintf(buf, "%s>\n", shortforward ? "/" :
"");
virBufferAdjustIndent(buf, 2);
- if (def->forward.driverName) {
- const char *driverName
- = virNetworkForwardDriverNameTypeToString(def->forward.driverName);
+ if (def->forward.driver.name) {
+ const char *driverName =
virDeviceHostdevPCIDriverNameTypeToString(def->forward.driver.name);
if (!driverName) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected hostdev driver name type %1$d "),
- def->forward.driverName);
+ _("unexpected hostdev driver name %1$d "),
+ def->forward.driver.name);
return -1;
}
virBufferAsprintf(&driverAttrBuf, " name='%s'",
driverName);
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 497ae765f2..1d7fd3ab6a 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -24,6 +24,7 @@
#define DNS_RECORD_LENGTH_SRV (512 - 30) /* Limit minus overhead as mentioned in
RFC-2782 */
#include "internal.h"
+#include "virconftypes.h"
#include "virsocketaddr.h"
#include "virnetdevbandwidth.h"
#include "virnetdevvportprofile.h"
@@ -88,20 +89,6 @@ typedef enum {
VIR_ENUM_DECL(virNetworkDHCPLeaseTimeUnit);
-/* The backend driver used for devices from the pool. Currently used
- * only for PCI devices (vfio vs. kvm), but could be used for other
- * device types in the future.
- */
-typedef enum {
- VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT, /* kvm now, could change */
- VIR_NETWORK_FORWARD_DRIVER_NAME_KVM, /* force legacy kvm style */
- VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO, /* force vfio */
-
- VIR_NETWORK_FORWARD_DRIVER_NAME_LAST
-} virNetworkForwardDriverNameType;
-
-VIR_ENUM_DECL(virNetworkForwardDriverName);
-
typedef struct _virNetworkDHCPLeaseTimeDef virNetworkDHCPLeaseTimeDef;
struct _virNetworkDHCPLeaseTimeDef {
unsigned long long expiry;
@@ -216,7 +203,7 @@ typedef struct _virNetworkForwardDef virNetworkForwardDef;
struct _virNetworkForwardDef {
int type; /* One of virNetworkForwardType constants */
bool managed; /* managed attribute for hostdev mode */
- virNetworkForwardDriverNameType driverName;
+ virDeviceHostdevPCIDriverInfo driver;
/* If there are multiple forward devices (i.e. a pool of
* interfaces), they will be listed here.
diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c
index ac17313f83..c7902f0174 100644
--- a/src/conf/virnetworkportdef.c
+++ b/src/conf/virnetworkportdef.c
@@ -226,9 +226,9 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
if ((driverNode = virXPathNode("./plug/driver", ctxt))) {
if (virXMLPropEnum(driverNode, "name",
- virNetworkForwardDriverNameTypeFromString,
+ virDeviceHostdevPCIDriverNameTypeFromString,
VIR_XML_PROP_NONZERO,
- &def->plug.hostdevpci.driver) < 0) {
+ &def->plug.hostdevpci.driver.name) < 0) {
return NULL;
}
}
@@ -356,9 +356,9 @@ virNetworkPortDefFormatBuf(virBuffer *buf,
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
- if (def->plug.hostdevpci.driver) {
+ if (def->plug.hostdevpci.driver.name) {
virBufferEscapeString(&driverAttrBuf, "
name='%s'",
-
virNetworkForwardDriverNameTypeToString(def->plug.hostdevpci.driver));
+
virDeviceHostdevPCIDriverNameTypeToString(def->plug.hostdevpci.driver.name));
}
virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
diff --git a/src/conf/virnetworkportdef.h b/src/conf/virnetworkportdef.h
index bfe1dae9ea..9e51ab1a8b 100644
--- a/src/conf/virnetworkportdef.h
+++ b/src/conf/virnetworkportdef.h
@@ -22,6 +22,8 @@
#pragma once
#include "internal.h"
+#include "virconftypes.h"
+#include "device_conf.h"
#include "virnetdevvlan.h"
#include "virnetdevvportprofile.h"
#include "virnetdevbandwidth.h"
@@ -69,7 +71,7 @@ struct _virNetworkPortDef {
} direct;
struct {
virPCIDeviceAddress addr; /* PCI Address of device */
- unsigned int driver; /* virNetworkForwardDriverNameType */
+ virDeviceHostdevPCIDriverInfo driver;
virTristateBool managed;
} hostdevpci;
} plug;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 4be740de2c..d156333626 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -3930,7 +3930,7 @@ networkAllocatePort(virNetworkObj *obj,
return -1;
}
port->plug.hostdevpci.addr = dev->device.pci;
- port->plug.hostdevpci.driver = netdef->forward.driverName;
+ port->plug.hostdevpci.driver.name = netdef->forward.driver.name;
port->plug.hostdevpci.managed =
virTristateBoolFromBool(netdef->forward.managed);
if (port->virtPortProfile) {
--
2.43.0