From nobody Mon Feb 9 10:47:51 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 1704443149969306.23277663649264; Fri, 5 Jan 2024 00:25:49 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id D9BB61891; Fri, 5 Jan 2024 03:25:48 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E19B218C9; Fri, 5 Jan 2024 03:20:40 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2D75D184D; 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 46D7B180C 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-al0MItJqP1SKGLj50iX4Tg-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 65F24280640E 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 495802026D6F; 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: al0MItJqP1SKGLj50iX4Tg-1 From: Laine Stump To: devel@lists.libvirt.org Subject: [PATCH v3 07/13] conf: split out hostdev parse/format to their own functions Date: Fri, 5 Jan 2024 03:20:10 -0500 Message-ID: <20240105082016.281442-8-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: 3IERAR4PUQIQAGLL2FF7UW7BPXJHV4OQ X-Message-ID-Hash: 3IERAR4PUQIQAGLL2FF7UW7BPXJHV4OQ 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: 1704443150610100001 This is done so that we can re-use the same parser/formatter for and Signed-off-by: Laine Stump Reviewed-by: Peter Krempa --- src/conf/device_conf.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/conf/device_conf.h | 7 +++++++ src/conf/domain_conf.c | 27 +++++---------------------- 3 files changed, 52 insertions(+), 22 deletions(-) diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index a80b901214..68a8c7690a 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -55,6 +55,46 @@ VIR_ENUM_IMPL(virDomainDeviceAddress, "unassigned", ); =20 + +int +virDeviceHostdevPCIDriverInfoParseXML(xmlNodePtr node, + virDeviceHostdevPCIDriverInfo *drive= r) +{ + if (virXMLPropEnum(node, "name", + virDeviceHostdevPCIDriverNameTypeFromString, + VIR_XML_PROP_NONZERO, + &driver->name) < 0) { + return -1; + } + + return 0; +} + + +int +virDeviceHostdevPCIDriverInfoFormat(virBuffer *buf, + const virDeviceHostdevPCIDriverInfo *d= river) +{ + g_auto(virBuffer) driverAttrBuf =3D VIR_BUFFER_INITIALIZER; + + if (driver->name !=3D VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAULT) { + const char *driverName =3D virDeviceHostdevPCIDriverNameTypeToStri= ng(driver->name); + + if (!driverName) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected pci hostdev driver name %1$d"), + driver->name); + return -1; + } + + virBufferAsprintf(&driverAttrBuf, " name=3D'%s'", driverName); + } + + virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); + return 0; +} + + static int virZPCIDeviceAddressParseXML(xmlNodePtr node, virPCIDeviceAddress *addr) diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index 1f7e066142..0b3f17a3aa 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -25,6 +25,7 @@ #include =20 #include "internal.h" +#include "virconftypes.h" #include "virbuffer.h" #include "virccw.h" #include "virpci.h" @@ -185,6 +186,12 @@ struct _virDomainDeviceInfo { bool isolationGroupLocked; }; =20 +int virDeviceHostdevPCIDriverInfoParseXML(xmlNodePtr node, + virDeviceHostdevPCIDriverInfo *d= river); + +int virDeviceHostdevPCIDriverInfoFormat(virBuffer *buf, + const virDeviceHostdevPCIDriverInf= o *driver); + void virDomainDeviceInfoClear(virDomainDeviceInfo *info); void virDomainDeviceInfoFree(virDomainDeviceInfo *info); =20 diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e19a2817c4..b3c7b50f97 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6281,13 +6281,9 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, fl= ags) < 0) return -1; =20 - if ((driver_node =3D virXPathNode("./driver", ctxt))) { - if (virXMLPropEnum(driver_node, "name", - virDeviceHostdevPCIDriverNameTypeFromString, - VIR_XML_PROP_NONZERO, - &pcisrc->driver.name) < 0) { - return -1; - } + if ((driver_node =3D virXPathNode("./driver", ctxt)) && + virDeviceHostdevPCIDriverInfoParseXML(driver_node, &pcisrc->dr= iver) < 0) { + return -1; } break; =20 @@ -23373,25 +23369,12 @@ 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 (pcisrc->driver.name !=3D VIR_DEVICE_HOSTDEV_PCI_DRIVER_NAME_DEFAUL= T) { - const char *driverName =3D virDeviceHostdevPCIDriverNameTypeToStri= ng(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=3D'%s'", driverName); - } - - virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); + if (virDeviceHostdevPCIDriverInfoFormat(buf, &pcisrc->driver) < 0) + return -1; =20 if (def->writeFiltering !=3D VIR_TRISTATE_BOOL_ABSENT) virBufferAsprintf(&sourceAttrBuf, " writeFiltering=3D'%s'", --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org