This is done so that we can re-use the same parser/formatter for <network> and <networkport> Signed-off-by: Laine Stump <laine@xxxxxxxxxx> Reviewed-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/device_conf.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/conf/device_conf.h | 7 +++++++ src/conf/domain_conf.c | 27 +++++---------------------- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index a80b901214..68a8c7690a 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -55,6 +55,46 @@ VIR_ENUM_IMPL(virDomainDeviceAddress, "unassigned", ); + +int +virDeviceHostdevPCIDriverInfoParseXML(xmlNodePtr node, + virDeviceHostdevPCIDriverInfo *driver) +{ + if (virXMLPropEnum(node, "name", + virDeviceHostdevPCIDriverNameTypeFromString, + VIR_XML_PROP_NONZERO, + &driver->name) < 0) { + return -1; + } + + return 0; +} + + +int +virDeviceHostdevPCIDriverInfoFormat(virBuffer *buf, + const virDeviceHostdevPCIDriverInfo *driver) +{ + g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER; + + if (driver->name != VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) { + const char *driverName = virDeviceHostdevPCIDriverNameTypeToString(driver->name); + + if (!driverName) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected pci hostdev driver name %1$d"), + driver->name); + return -1; + } + + virBufferAsprintf(&driverAttrBuf, " name='%s'", driverName); + } + + 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 1f7e066142..0b3f17a3aa 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 e19a2817c4..b3c7b50f97 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6281,13 +6281,9 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, flags) < 0) return -1; - if ((driver_node = virXPathNode("./driver", ctxt))) { - if (virXMLPropEnum(driver_node, "name", - virDeviceHostdevPCIDriverNameTypeFromString, - VIR_XML_PROP_NONZERO, - &pcisrc->driver.name) < 0) { - return -1; - } + if ((driver_node = virXPathNode("./driver", ctxt)) && + virDeviceHostdevPCIDriverInfoParseXML(driver_node, &pcisrc->driver) < 0) { + return -1; } break; @@ -23373,25 +23369,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.name != VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) { - const char *driverName = virDeviceHostdevPCIDriverNameTypeToString(pcisrc->driver.name); - - if (!driverName) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected pci hostdev driver type %1$d"), - pcisrc->driver.name); - return -1; - } - - virBufferAsprintf(&driverAttrBuf, " name='%s'", driverName); - } - - 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.43.0 _______________________________________________ Devel mailing list -- devel@xxxxxxxxxxxxxxxxx To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx