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@xxxxxxxxxx> --- src/conf/network_conf.c | 24 ++++-------------------- src/conf/virnetworkportdef.c | 21 ++++++--------------- 2 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index e3ad4c7340..2d78d588aa 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", - virDeviceHostdevPCIDriverTypeFromString, - VIR_XML_PROP_NONZERO, - &def->driver.type) < 0) { + if ((driverNode = virXPathNode("./driver", ctxt)) && + virDeviceHostdevPCIDriverInfoParseXML(driverNode, &def->driver) < 0) { return -1; - } } /* bridge and hostdev modes can use a pool of physical interfaces */ @@ -2319,7 +2315,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); @@ -2350,19 +2345,8 @@ virNetworkDefFormatBuf(virBuffer *buf, virBufferAsprintf(buf, "%s>\n", shortforward ? "/" : ""); virBufferAdjustIndent(buf, 2); - if (def->forward.driver.type) { - const char *driverName - = virDeviceHostdevPCIDriverTypeToString(def->forward.driver.type); - if (!driverName) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected hostdev driver name type %1$d "), - def->forward.driver.type); - 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 77ef705e18..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", - virDeviceHostdevPCIDriverTypeFromString, - VIR_XML_PROP_NONZERO, - &def->plug.hostdevpci.driver.type) < 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,13 +352,8 @@ virNetworkPortDefFormatBuf(virBuffer *buf, virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); - if (def->plug.hostdevpci.driver.type) { - virBufferEscapeString(&driverAttrBuf, " name='%s'", - virDeviceHostdevPCIDriverTypeToString( - def->plug.hostdevpci.driver.type)); - } - - 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.41.0 _______________________________________________ Devel mailing list -- devel@xxxxxxxxxxxxxxxxx To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx