This is done so that we can re-use the same parser/formatter for
<network> and <networkport>
Signed-off-by: Laine Stump <laine(a)redhat.com>
---
src/conf/device_conf.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/conf/device_conf.h | 7 +++++++
src/conf/domain_conf.c | 28 +++++-----------------------
3 files changed, 53 insertions(+), 23 deletions(-)
diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
index 25a522671e..e022783816 100644
--- a/src/conf/device_conf.c
+++ b/src/conf/device_conf.c
@@ -55,6 +55,47 @@ VIR_ENUM_IMPL(virDomainDeviceAddress,
"unassigned",
);
+
+int
+virDeviceHostdevPCIDriverInfoParseXML(xmlNodePtr node,
+ virDeviceHostdevPCIDriverInfo *driver)
+{
+ if (virXMLPropEnum(node, "name",
+ virDeviceHostdevPCIDriverTypeFromString,
+ VIR_XML_PROP_NONZERO,
+ &driver->type) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
+
+
+int
+virDeviceHostdevPCIDriverInfoFormat(virBuffer *buf,
+ const virDeviceHostdevPCIDriverInfo *driver)
+{
+ g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
+
+ if (driver->type != VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_DEFAULT) {
+ const char *driverType
+ = virDeviceHostdevPCIDriverTypeToString(driver->type);
+
+ if (!driverType) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("unexpected pci hostdev driver type %1$d"),
+ driver->type);
+ return -1;
+ }
+
+ virBufferAsprintf(&driverAttrBuf, " name='%s'",
driverType);
+ }
+
+ virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
+ return 0;
+}
+
+
static int
virZPCIDeviceAddressParseXML(xmlNodePtr node,
virPCIDeviceAddress *addr)
diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h
index 3a7a6c3f99..9f4b9f5375 100644
--- a/src/conf/device_conf.h
+++ b/src/conf/device_conf.h
@@ -25,6 +25,7 @@
#include <libxml/xpath.h>
#include "internal.h"
+#include "virconftypes.h"
#include "virbuffer.h"
#include "virccw.h"
#include "virpci.h"
@@ -185,6 +186,12 @@ struct _virDomainDeviceInfo {
bool isolationGroupLocked;
};
+int virDeviceHostdevPCIDriverInfoParseXML(xmlNodePtr node,
+ virDeviceHostdevPCIDriverInfo *driver);
+
+int virDeviceHostdevPCIDriverInfoFormat(virBuffer *buf,
+ const virDeviceHostdevPCIDriverInfo *driver);
+
void virDomainDeviceInfoClear(virDomainDeviceInfo *info);
void virDomainDeviceInfoFree(virDomainDeviceInfo *info);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1d083c97ec..ea1348da5f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6267,13 +6267,9 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, flags) < 0)
return -1;
- if ((driver_node = virXPathNode("./driver", ctxt))) {
- if (virXMLPropEnum(driver_node, "name",
- virDeviceHostdevPCIDriverTypeFromString,
- VIR_XML_PROP_NONZERO,
- &pcisrc->driver.type) < 0) {
- return -1;
- }
+ if ((driver_node = virXPathNode("./driver", ctxt)) &&
+ virDeviceHostdevPCIDriverInfoParseXML(driver_node, &pcisrc->driver)
< 0) {
+ return -1;
}
break;
@@ -23328,26 +23324,12 @@ virDomainHostdevDefFormatSubsysPCI(virBuffer *buf,
unsigned int flags,
bool includeTypeInAddr)
{
- g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) sourceAttrBuf = VIR_BUFFER_INITIALIZER;
g_auto(virBuffer) sourceChildBuf = VIR_BUFFER_INIT_CHILD(buf);
virDomainHostdevSubsysPCI *pcisrc = &def->source.subsys.u.pci;
- if (pcisrc->driver.type != VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_DEFAULT) {
- const char *driverType
- = virDeviceHostdevPCIDriverTypeToString(pcisrc->driver.type);
-
- if (!driverType) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected pci hostdev driver type %1$d"),
- pcisrc->driver.type);
- return -1;
- }
-
- virBufferAsprintf(&driverAttrBuf, " name='%s'",
driverType);
- }
-
- virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
+ if (virDeviceHostdevPCIDriverInfoFormat(buf, &pcisrc->driver) < 0)
+ return -1;
if (def->writeFiltering != VIR_TRISTATE_BOOL_ABSENT)
virBufferAsprintf(&sourceAttrBuf, "
writeFiltering='%s'",
--
2.41.0