From nobody Mon Feb 9 14:15:18 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1704443562693120.08758290171443; Fri, 5 Jan 2024 00:32:42 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9F40719CC; Fri, 5 Jan 2024 03:32:41 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7B4C71855; Fri, 5 Jan 2024 03:20:59 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 7FC66180C; Fri, 5 Jan 2024 03:20:24 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 525111810 for ; Fri, 5 Jan 2024 03:20:20 -0500 (EST) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-685-pTR2wIF9PZKRavW_crr5Xw-1; Fri, 05 Jan 2024 03:20:18 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8B3F3280640F for ; Fri, 5 Jan 2024 08:20:18 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.16.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F8302026D6F; Fri, 5 Jan 2024 08:20:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: pTR2wIF9PZKRavW_crr5Xw-1 From: Laine Stump To: devel@lists.libvirt.org Subject: [PATCH v3 08/13] conf: use new common parser/formatter for hostdev driver in network XML Date: Fri, 5 Jan 2024 03:20:11 -0500 Message-ID: <20240105082016.281442-9-laine@redhat.com> In-Reply-To: <20240105082016.281442-1-laine@redhat.com> References: <20240105082016.281442-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 5MPM6LMYH4XCMIU5FIHRSSKBBYKKTRZQ X-Message-ID-Hash: 5MPM6LMYH4XCMIU5FIHRSSKBBYKKTRZQ X-MailFrom: laine@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Peter Krempa X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1704443564244100001 Now if a new attribute is added to , we only need to update the formatting/parsing in one place. Signed-off-by: Laine Stump Reviewed-by: Peter Krempa --- 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 =3D true; } =20 - if ((driverNode =3D virXPathNode("./driver", ctxt))) { - if (virXMLPropEnum(driverNode, "name", - virDeviceHostdevPCIDriverNameTypeFromString, - VIR_XML_PROP_NONZERO, - &def->driver.name) < 0) { + if ((driverNode =3D virXPathNode("./driver", ctxt)) && + virDeviceHostdevPCIDriverInfoParseXML(driverNode, &def->driver) < = 0) { return -1; - } } =20 /* bridge and hostdev modes can use a pool of physical interfaces */ @@ -2317,7 +2313,6 @@ virNetworkDefFormatBuf(virBuffer *buf, if (def->forward.type !=3D VIR_NETWORK_FORWARD_NONE) { const char *dev =3D NULL; const char *mode =3D virNetworkForwardTypeToString(def->forward.ty= pe); - g_auto(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; =20 if (!def->forward.npfs) dev =3D virNetworkDefForwardIf(def, 0); @@ -2347,18 +2342,8 @@ virNetworkDefFormatBuf(virBuffer *buf, virBufferAsprintf(buf, "%s>\n", shortforward ? "/" : ""); virBufferAdjustIndent(buf, 2); =20 - if (def->forward.driver.name) { - const char *driverName =3D virDeviceHostdevPCIDriverNameTypeTo= String(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=3D'%s'", driverName); - } - - virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); + if (virDeviceHostdevPCIDriverInfoFormat(buf, &def->forward.driver) = < 0) + return -1; =20 if (def->forward.type =3D=3D 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; =20 - if ((driverNode =3D virXPathNode("./plug/driver", ctxt))) { - if (virXMLPropEnum(driverNode, "name", - virDeviceHostdevPCIDriverNameTypeFromString, - VIR_XML_PROP_NONZERO, - &def->plug.hostdevpci.driver.name) < 0) { - return NULL; - } + if ((driverNode =3D virXPathNode("./plug/driver", ctxt)) && + virDeviceHostdevPCIDriverInfoParseXML(driverNode, + &def->plug.hostdevpci.dr= iver) < 0) { + return NULL; } =20 if (!(addressNode =3D virXPathNode("./plug/address", ctxt))) { @@ -321,7 +318,6 @@ virNetworkPortDefFormatBuf(virBuffer *buf, virTristateBoolTypeToString(def->trustGuestRxFil= ters)); =20 if (def->plugtype !=3D VIR_NETWORK_PORT_PLUG_TYPE_NONE) { - g_auto(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; =20 virBufferAsprintf(buf, "plugtype)); @@ -356,12 +352,8 @@ virNetworkPortDefFormatBuf(virBuffer *buf, virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); =20 - if (def->plug.hostdevpci.driver.name) { - virBufferEscapeString(&driverAttrBuf, " name=3D'%s'", - virDeviceHostdevPCIDriverNameTypeToS= tring(def->plug.hostdevpci.driver.name)); - } - - virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); + if (virDeviceHostdevPCIDriverInfoFormat(buf, &def->plug.hostde= vpci.driver) < 0) + return -1; =20 virPCIDeviceAddressFormat(buf, def->plug.hostdevpci.addr, fals= e); virBufferAdjustIndent(buf, -2); --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org