Now if a new attribute is added to <driver>, we only need to update
the formatting/parsing in one place.
Signed-off-by: Laine Stump <laine(a)redhat.com>
Reviewed-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/network_conf.c | 23 ++++-------------------
src/conf/virnetworkportdef.c | 20 ++++++--------------
2 files changed, 10 insertions(+), 33 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index d732e90b6d..890c16b3b1 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1349,13 +1349,9 @@ virNetworkForwardDefParseXML(const char *networkName,
def->managed = true;
}
- if ((driverNode = virXPathNode("./driver", ctxt))) {
- if (virXMLPropEnum(driverNode, "name",
- virDeviceHostdevPCIDriverNameTypeFromString,
- VIR_XML_PROP_NONZERO,
- &def->driver.name) < 0) {
+ if ((driverNode = virXPathNode("./driver", ctxt)) &&
+ virDeviceHostdevPCIDriverInfoParseXML(driverNode, &def->driver) < 0) {
return -1;
- }
}
/* bridge and hostdev modes can use a pool of physical interfaces */
@@ -2317,7 +2313,6 @@ virNetworkDefFormatBuf(virBuffer *buf,
if (def->forward.type != VIR_NETWORK_FORWARD_NONE) {
const char *dev = NULL;
const char *mode = virNetworkForwardTypeToString(def->forward.type);
- g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
if (!def->forward.npfs)
dev = virNetworkDefForwardIf(def, 0);
@@ -2347,18 +2342,8 @@ virNetworkDefFormatBuf(virBuffer *buf,
virBufferAsprintf(buf, "%s>\n", shortforward ? "/" :
"");
virBufferAdjustIndent(buf, 2);
- if (def->forward.driver.name) {
- const char *driverName =
virDeviceHostdevPCIDriverNameTypeToString(def->forward.driver.name);
- if (!driverName) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("unexpected hostdev driver name %1$d "),
- def->forward.driver.name);
- return -1;
- }
- virBufferAsprintf(&driverAttrBuf, " name='%s'",
driverName);
- }
-
- virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
+ if (virDeviceHostdevPCIDriverInfoFormat(buf, &def->forward.driver) < 0)
+ return -1;
if (def->forward.type == VIR_NETWORK_FORWARD_NAT) {
if (virNetworkForwardNatDefFormat(buf, &def->forward) < 0)
diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c
index c7902f0174..49d00b2ea6 100644
--- a/src/conf/virnetworkportdef.c
+++ b/src/conf/virnetworkportdef.c
@@ -224,13 +224,10 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt)
&def->plug.hostdevpci.managed) < 0)
return NULL;
- if ((driverNode = virXPathNode("./plug/driver", ctxt))) {
- if (virXMLPropEnum(driverNode, "name",
- virDeviceHostdevPCIDriverNameTypeFromString,
- VIR_XML_PROP_NONZERO,
- &def->plug.hostdevpci.driver.name) < 0) {
- return NULL;
- }
+ if ((driverNode = virXPathNode("./plug/driver", ctxt)) &&
+ virDeviceHostdevPCIDriverInfoParseXML(driverNode,
+ &def->plug.hostdevpci.driver)
< 0) {
+ return NULL;
}
if (!(addressNode = virXPathNode("./plug/address", ctxt))) {
@@ -321,7 +318,6 @@ virNetworkPortDefFormatBuf(virBuffer *buf,
virTristateBoolTypeToString(def->trustGuestRxFilters));
if (def->plugtype != VIR_NETWORK_PORT_PLUG_TYPE_NONE) {
- g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER;
virBufferAsprintf(buf, "<plug type='%s'",
virNetworkPortPlugTypeToString(def->plugtype));
@@ -356,12 +352,8 @@ virNetworkPortDefFormatBuf(virBuffer *buf,
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
- if (def->plug.hostdevpci.driver.name) {
- virBufferEscapeString(&driverAttrBuf, "
name='%s'",
-
virDeviceHostdevPCIDriverNameTypeToString(def->plug.hostdevpci.driver.name));
- }
-
- virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
+ if (virDeviceHostdevPCIDriverInfoFormat(buf,
&def->plug.hostdevpci.driver) < 0)
+ return -1;
virPCIDeviceAddressFormat(buf, def->plug.hostdevpci.addr, false);
virBufferAdjustIndent(buf, -2);
--
2.43.0