From nobody Mon Feb 9 08:28:17 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 1699258879737529.6240149548048; Mon, 6 Nov 2023 00:21:19 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A209F199B; Mon, 6 Nov 2023 03:21:18 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8D42B19B3; Mon, 6 Nov 2023 02:41:14 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 3A2731897; Mon, 6 Nov 2023 02:39:18 -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 2E4A5178A for ; Mon, 6 Nov 2023 02:39:17 -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-684-x-SpLi2aM7yPrsaV-PX8xA-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 799E881B162; Mon, 6 Nov 2023 07:39:03 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.32.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B4CF492BE0; Mon, 6 Nov 2023 07:39:03 +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: x-SpLi2aM7yPrsaV-PX8xA-1 From: Laine Stump To: devel@lists.libvirt.org, libvir-list@redhat.com Subject: [libvirt PATCH v2 06/15] conf: use virDeviceHostdevPCIDriverInfo in network and networkport objects Date: Mon, 6 Nov 2023 02:38:51 -0500 Message-ID: <20231106073901.735582-7-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: KNS5FRJXBSVHJXC7Y5VFTTA4SXIMNQIK X-Message-ID-Hash: KNS5FRJXBSVHJXC7Y5VFTTA4SXIMNQIK 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: 1699258880944100001 The next step in consolidating parsing/formatting of the element of these objects using a common struct and common code. This eliminates the virNetworkForwardDriverNameType enum which is nearly identical to virDeviceHostdevPCIDriverType (the only non-identical bit was just because they'd gotten out of sync over time) and replaces its uses with a virDeviceHostdevPCIDriverInfo (which is a struct that contains a virDeviceHostdevPCIDriverType). Signed-off-by: Laine Stump Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 48 +++--------------------------------- src/conf/network_conf.c | 21 ++++++---------- src/conf/network_conf.h | 17 ++----------- src/conf/virnetworkportdef.c | 10 ++++---- src/conf/virnetworkportdef.h | 4 ++- src/network/bridge_driver.c | 2 +- 6 files changed, 22 insertions(+), 80 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e322f1ffa7..82c1287986 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29836,29 +29836,8 @@ virDomainNetDefActualFromNetworkPort(virDomainNetD= ef *iface, } actual->data.hostdev.def.source.subsys.type =3D VIR_DOMAIN_HOSTDEV= _SUBSYS_TYPE_PCI; actual->data.hostdev.def.source.subsys.u.pci.addr =3D port->plug.h= ostdevpci.addr; - switch ((virNetworkForwardDriverNameType)port->plug.hostdevpci.dri= ver) { - case VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT: - actual->data.hostdev.def.source.subsys.u.pci.driver.type =3D - VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_DEFAULT; - break; - - case VIR_NETWORK_FORWARD_DRIVER_NAME_KVM: - actual->data.hostdev.def.source.subsys.u.pci.driver.type =3D - VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_KVM; - break; - - case VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO: - actual->data.hostdev.def.source.subsys.u.pci.driver.type =3D - VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_VFIO; - break; - - case VIR_NETWORK_FORWARD_DRIVER_NAME_LAST: - default: - virReportEnumRangeError(virNetworkForwardDriverNameType, - port->plug.hostdevpci.driver); - goto error; - } - + actual->data.hostdev.def.source.subsys.u.pci.driver.type + =3D port->plug.hostdevpci.driver.type; break; =20 case VIR_NETWORK_PORT_PLUG_TYPE_LAST: @@ -29959,27 +29938,8 @@ virDomainNetDefActualToNetworkPort(virDomainDef *d= om, } port->plug.hostdevpci.managed =3D virTristateBoolFromBool(actual->= data.hostdev.def.managed); port->plug.hostdevpci.addr =3D actual->data.hostdev.def.source.sub= sys.u.pci.addr; - switch (actual->data.hostdev.def.source.subsys.u.pci.driver.type) { - case VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_DEFAULT: - port->plug.hostdevpci.driver =3D VIR_NETWORK_FORWARD_DRIVER_NA= ME_DEFAULT; - break; - - case VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_KVM: - port->plug.hostdevpci.driver =3D VIR_NETWORK_FORWARD_DRIVER_NA= ME_KVM; - break; - - case VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_VFIO: - port->plug.hostdevpci.driver =3D VIR_NETWORK_FORWARD_DRIVER_NA= ME_VFIO; - break; - - case VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_XEN: - case VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_LAST: - default: - virReportEnumRangeError(virDeviceHostdevPCIDriverType, - actual->data.hostdev.def.source.subsys= .u.pci.driver.type); - return NULL; - } - + port->plug.hostdevpci.driver.type + =3D actual->data.hostdev.def.source.subsys.u.pci.driver.type; break; =20 case VIR_DOMAIN_NET_TYPE_CLIENT: diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index b9601cb307..e3ad4c7340 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -56,13 +56,6 @@ VIR_ENUM_IMPL(virNetworkForwardHostdevDevice, "none", "pci", "netdev", ); =20 -VIR_ENUM_IMPL(virNetworkForwardDriverName, - VIR_NETWORK_FORWARD_DRIVER_NAME_LAST, - "default", - "kvm", - "vfio", -); - VIR_ENUM_IMPL(virNetworkTaint, VIR_NETWORK_TAINT_LAST, "hook-script", @@ -1358,9 +1351,9 @@ virNetworkForwardDefParseXML(const char *networkName, =20 if ((driverNode =3D virXPathNode("./driver", ctxt))) { if (virXMLPropEnum(driverNode, "name", - virNetworkForwardDriverNameTypeFromString, + virDeviceHostdevPCIDriverTypeFromString, VIR_XML_PROP_NONZERO, - &def->driverName) < 0) { + &def->driver.type) < 0) { return -1; } } @@ -2351,19 +2344,19 @@ virNetworkDefFormatBuf(virBuffer *buf, || VIR_SOCKET_ADDR_VALID(&def->forward.addr.end) || def->forward.port.start || def->forward.port.end - || (def->forward.driverName - !=3D VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT) + || (def->forward.driver.type + !=3D VIR_DEVICE_HOSTDEV_PCI_DRIVER_TYPE_DEFAU= LT) || def->forward.natIPv6); virBufferAsprintf(buf, "%s>\n", shortforward ? "/" : ""); virBufferAdjustIndent(buf, 2); =20 - if (def->forward.driverName) { + if (def->forward.driver.type) { const char *driverName - =3D virNetworkForwardDriverNameTypeToString(def->forward.d= riverName); + =3D virDeviceHostdevPCIDriverTypeToString(def->forward.dri= ver.type); if (!driverName) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected hostdev driver name type %1$d= "), - def->forward.driverName); + def->forward.driver.type); return -1; } virBufferAsprintf(&driverAttrBuf, " name=3D'%s'", driverName); diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index 497ae765f2..1d7fd3ab6a 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -24,6 +24,7 @@ #define DNS_RECORD_LENGTH_SRV (512 - 30) /* Limit minus overhead as ment= ioned in RFC-2782 */ =20 #include "internal.h" +#include "virconftypes.h" #include "virsocketaddr.h" #include "virnetdevbandwidth.h" #include "virnetdevvportprofile.h" @@ -88,20 +89,6 @@ typedef enum { =20 VIR_ENUM_DECL(virNetworkDHCPLeaseTimeUnit); =20 -/* The backend driver used for devices from the pool. Currently used - * only for PCI devices (vfio vs. kvm), but could be used for other - * device types in the future. - */ -typedef enum { - VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT, /* kvm now, could change */ - VIR_NETWORK_FORWARD_DRIVER_NAME_KVM, /* force legacy kvm style */ - VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO, /* force vfio */ - - VIR_NETWORK_FORWARD_DRIVER_NAME_LAST -} virNetworkForwardDriverNameType; - -VIR_ENUM_DECL(virNetworkForwardDriverName); - typedef struct _virNetworkDHCPLeaseTimeDef virNetworkDHCPLeaseTimeDef; struct _virNetworkDHCPLeaseTimeDef { unsigned long long expiry; @@ -216,7 +203,7 @@ typedef struct _virNetworkForwardDef virNetworkForwardD= ef; struct _virNetworkForwardDef { int type; /* One of virNetworkForwardType constants */ bool managed; /* managed attribute for hostdev mode */ - virNetworkForwardDriverNameType driverName; + virDeviceHostdevPCIDriverInfo driver; =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 402c0051ec..77ef705e18 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -226,9 +226,9 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) =20 if ((driverNode =3D virXPathNode("./plug/driver", ctxt))) { if (virXMLPropEnum(driverNode, "name", - virNetworkForwardDriverNameTypeFromString, + virDeviceHostdevPCIDriverTypeFromString, VIR_XML_PROP_NONZERO, - &def->plug.hostdevpci.driver) < 0) { + &def->plug.hostdevpci.driver.type) < 0) { return NULL; } } @@ -356,10 +356,10 @@ virNetworkPortDefFormatBuf(virBuffer *buf, virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); =20 - if (def->plug.hostdevpci.driver) { + if (def->plug.hostdevpci.driver.type) { virBufferEscapeString(&driverAttrBuf, " name=3D'%s'", - virNetworkForwardDriverNameTypeToStr= ing( - def->plug.hostdevpci.driver)); + virDeviceHostdevPCIDriverTypeToStrin= g( + def->plug.hostdevpci.driver.type= )); } =20 virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); diff --git a/src/conf/virnetworkportdef.h b/src/conf/virnetworkportdef.h index bfe1dae9ea..9e51ab1a8b 100644 --- a/src/conf/virnetworkportdef.h +++ b/src/conf/virnetworkportdef.h @@ -22,6 +22,8 @@ #pragma once =20 #include "internal.h" +#include "virconftypes.h" +#include "device_conf.h" #include "virnetdevvlan.h" #include "virnetdevvportprofile.h" #include "virnetdevbandwidth.h" @@ -69,7 +71,7 @@ struct _virNetworkPortDef { } direct; struct { virPCIDeviceAddress addr; /* PCI Address of device */ - unsigned int driver; /* virNetworkForwardDriverNameType */ + virDeviceHostdevPCIDriverInfo driver; virTristateBool managed; } hostdevpci; } plug; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 4be740de2c..a9188c2436 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -3930,7 +3930,7 @@ networkAllocatePort(virNetworkObj *obj, return -1; } port->plug.hostdevpci.addr =3D dev->device.pci; - port->plug.hostdevpci.driver =3D netdef->forward.driverName; + port->plug.hostdevpci.driver.type =3D netdef->forward.driver.type; port->plug.hostdevpci.managed =3D virTristateBoolFromBool(netdef->= forward.managed); =20 if (port->virtPortProfile) { --=20 2.41.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org