conf: split out hostdev <driver> parse/format to their own functions

This is done so that we can re-use the same parser/formatter for
<network> and <networkport>

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 8bc3f01080
commit 195522ae87
3 changed files with 52 additions and 22 deletions

View File

@ -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)

View File

@ -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);

View File

@ -6283,13 +6283,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;
@ -23424,25 +23420,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'",