From nobody Mon Feb 9 10:27:28 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 1699257280773903.2579216568822; Sun, 5 Nov 2023 23:54:40 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9AA69198D; Mon, 6 Nov 2023 02:54:39 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A421A18E6; Mon, 6 Nov 2023 02:39:57 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4A8A418AF; Mon, 6 Nov 2023 02:39:10 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 D7B4C18BB for ; Mon, 6 Nov 2023 02:39:06 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-606-BbtfwubcPomRONP6WWyu9g-1; Mon, 06 Nov 2023 02:39:03 -0500 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (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 DBD77810FD0; Mon, 6 Nov 2023 07:39:02 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.32.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A1BB492BE0; Mon, 6 Nov 2023 07:39:02 +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_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: BbtfwubcPomRONP6WWyu9g-1 From: Laine Stump To: devel@lists.libvirt.org, libvir-list@redhat.com Subject: [libvirt PATCH v2 04/15] conf: normalize hostdev parsing to simplify adding new attr Date: Mon, 6 Nov 2023 02:38:49 -0500 Message-ID: <20231106073901.735582-5-laine@redhat.com> In-Reply-To: <20231106073901.735582-1-laine@redhat.com> References: <20231106073901.735582-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: BJN2TPJWK64AEVXTTDL4VOVNECC7QHTO X-Message-ID-Hash: BJN2TPJWK64AEVXTTDL4VOVNECC7QHTO 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: Joao Martins , Jason Gunthorpe , Cedric Le Goater 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: 1699257281457100001 The hostdev version of the subelement appears in four places: * The domain XML in the and elements (that's 2) * The network XML inside when the network is a pool of SRIOV VFs * the XML, which is used to communicate between the hypervisor driver and network driver. In order to make the pending addition of a new attribute to in all these cases simpler, this patch refactors the parsing of in all four places to use virXMLProp*() and virXMLFormatElement(). Making all of the different instances of the separate parse/format for look nearly identical will make it easier to see that the upcoming patch that converges all four to use a common parser/formatter is a functional NOP. Signed-off-by: Laine Stump Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 28 ++++++++++++++++------------ src/conf/network_conf.c | 26 ++++++++++++-------------- src/conf/network_conf.h | 2 +- src/conf/virnetworkportdef.c | 28 ++++++++++++++++++---------- src/conf/virnetworkportdef.h | 2 +- 5 files changed, 48 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4a3de08efa..1d3e46604a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6267,13 +6267,14 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, fl= ags) < 0) return -1; =20 - driver_node =3D virXPathNode("./driver", ctxt); - if (virXMLPropEnum(driver_node, "name", - virDeviceHostdevPCIDriverTypeFromString, - VIR_XML_PROP_NONZERO, - &pcisrc->backend) < 0) - return -1; - + if ((driver_node =3D virXPathNode("./driver", ctxt))) { + if (virXMLPropEnum(driver_node, "name", + virDeviceHostdevPCIDriverTypeFromString, + VIR_XML_PROP_NONZERO, + &pcisrc->backend) < 0) { + return -1; + } + } break; =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: @@ -23327,14 +23328,11 @@ virDomainHostdevDefFormatSubsysPCI(virBuffer *buf, unsigned int flags, bool includeTypeInAddr) { + g_auto(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) sourceAttrBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) sourceChildBuf =3D VIR_BUFFER_INIT_CHILD(buf); virDomainHostdevSubsysPCI *pcisrc =3D &def->source.subsys.u.pci; =20 - if (def->writeFiltering !=3D VIR_TRISTATE_BOOL_ABSENT) - virBufferAsprintf(&sourceAttrBuf, " writeFiltering=3D'%s'", - virTristateBoolTypeToString(def->writeFilter= ing)); - if (pcisrc->backend !=3D VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_DEFAULT) { const char *backend =3D virDeviceHostdevPCIDriverTypeToString(pcisrc->backend); @@ -23346,9 +23344,15 @@ virDomainHostdevDefFormatSubsysPCI(virBuffer *buf, return -1; } =20 - virBufferAsprintf(buf, "\n", backend); + virBufferAsprintf(&driverAttrBuf, " name=3D'%s'", backend); } =20 + virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); + + if (def->writeFiltering !=3D VIR_TRISTATE_BOOL_ABSENT) + virBufferAsprintf(&sourceAttrBuf, " writeFiltering=3D'%s'", + virTristateBoolTypeToString(def->writeFilter= ing)); + virPCIDeviceAddressFormat(&sourceChildBuf, pcisrc->addr, includeTypeIn= Addr); =20 if (pcisrc->origstates && diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 1a6fd86180..b9601cb307 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1334,8 +1334,8 @@ virNetworkForwardDefParseXML(const char *networkName, g_autofree xmlNodePtr *forwardNatNodes =3D NULL; g_autofree char *forwardDev =3D NULL; g_autofree char *forwardManaged =3D NULL; - g_autofree char *forwardDriverName =3D NULL; g_autofree char *type =3D NULL; + xmlNodePtr driverNode =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 ctxt->node =3D node; @@ -1356,18 +1356,13 @@ virNetworkForwardDefParseXML(const char *networkNam= e, def->managed =3D true; } =20 - forwardDriverName =3D virXPathString("string(./driver/@name)", ctxt); - if (forwardDriverName) { - int driverName - =3D virNetworkForwardDriverNameTypeFromString(forwardDriverNam= e); - - if (driverName <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown forward in n= etwork %2$s"), - forwardDriverName, networkName); + if ((driverNode =3D virXPathNode("./driver", ctxt))) { + if (virXMLPropEnum(driverNode, "name", + virNetworkForwardDriverNameTypeFromString, + VIR_XML_PROP_NONZERO, + &def->driverName) < 0) { return -1; } - def->driverName =3D driverName; } =20 /* bridge and hostdev modes can use a pool of physical interfaces */ @@ -2331,6 +2326,7 @@ 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); @@ -2361,8 +2357,7 @@ virNetworkDefFormatBuf(virBuffer *buf, virBufferAsprintf(buf, "%s>\n", shortforward ? "/" : ""); virBufferAdjustIndent(buf, 2); =20 - if (def->forward.driverName - !=3D VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT) { + if (def->forward.driverName) { const char *driverName =3D virNetworkForwardDriverNameTypeToString(def->forward.d= riverName); if (!driverName) { @@ -2371,8 +2366,11 @@ virNetworkDefFormatBuf(virBuffer *buf, def->forward.driverName); return -1; } - virBufferAsprintf(buf, "\n", driverName); + virBufferAsprintf(&driverAttrBuf, " name=3D'%s'", driverName); } + + virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); + if (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT) { if (virNetworkForwardNatDefFormat(buf, &def->forward) < 0) return -1; diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 5a1bdb1284..497ae765f2 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -216,7 +216,7 @@ typedef struct _virNetworkForwardDef virNetworkForwardD= ef; struct _virNetworkForwardDef { int type; /* One of virNetworkForwardType constants */ bool managed; /* managed attribute for hostdev mode */ - int driverName; /* enum virNetworkForwardDriverNameType */ + virNetworkForwardDriverNameType driverName; =20 /* If there are multiple forward devices (i.e. a pool of * interfaces), they will be listed here. diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index fc06ef41d5..402c0051ec 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -87,10 +87,10 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) xmlNodePtr addressNode; xmlNodePtr rxfiltersNode =3D NULL; xmlNodePtr plugNode =3D NULL; + xmlNodePtr driverNode =3D NULL; g_autofree char *mac =3D NULL; g_autofree char *macmgr =3D NULL; g_autofree char *mode =3D NULL; - g_autofree char *driver =3D NULL; =20 def =3D g_new0(virNetworkPortDef, 1); =20 @@ -223,14 +223,16 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) VIR_XML_PROP_NONE, &def->plug.hostdevpci.managed) < 0) return NULL; - driver =3D virXPathString("string(./plug/driver/@name)", ctxt); - if (driver && - (def->plug.hostdevpci.driver =3D - virNetworkForwardDriverNameTypeFromString(driver)) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing network port driver name")); - return NULL; + + if ((driverNode =3D virXPathNode("./plug/driver", ctxt))) { + if (virXMLPropEnum(driverNode, "name", + virNetworkForwardDriverNameTypeFromString, + VIR_XML_PROP_NONZERO, + &def->plug.hostdevpci.driver) < 0) { + return NULL; + } } + if (!(addressNode =3D virXPathNode("./plug/address", ctxt))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing network port PCI address")); @@ -319,6 +321,8 @@ 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; + virBufferAsprintf(buf, "plugtype)); =20 @@ -351,10 +355,14 @@ virNetworkPortDefFormatBuf(virBuffer *buf, } virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); - if (def->plug.hostdevpci.driver) - virBufferEscapeString(buf, "\n", + + if (def->plug.hostdevpci.driver) { + virBufferEscapeString(&driverAttrBuf, " name=3D'%s'", virNetworkForwardDriverNameTypeToStr= ing( def->plug.hostdevpci.driver)); + } + + virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); =20 virPCIDeviceAddressFormat(buf, def->plug.hostdevpci.addr, fals= e); virBufferAdjustIndent(buf, -2); diff --git a/src/conf/virnetworkportdef.h b/src/conf/virnetworkportdef.h index 48e73dbefd..bfe1dae9ea 100644 --- a/src/conf/virnetworkportdef.h +++ b/src/conf/virnetworkportdef.h @@ -69,7 +69,7 @@ struct _virNetworkPortDef { } direct; struct { virPCIDeviceAddress addr; /* PCI Address of device */ - int driver; /* virNetworkForwardDriverNameType */ + unsigned int driver; /* virNetworkForwardDriverNameType */ virTristateBool managed; } hostdevpci; } plug; --=20 2.41.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org