From nobody Sun Feb 8 12:37:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1555521624; cv=none; d=zoho.com; s=zohoarc; b=ZQZTrK+fCTTtoG2RV9THtyBDSMLe5M58jjt8Hx7efzVuFff3VsBu35cmALN4eMHQmeMGejUQ4fHAIgUtbOz6BqeRoZ70FL5yBbqbDf0MQRLHyBoYEpwkcaInXUWOSQ7LtjTbFM5IllAgZyGrSt1XOEoOgVuq4zgXEvlrrgb4qcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555521624; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=t0fmCkdc6eRSekR6H5wSnieyQdL6H8Yzra21V5vAqsk=; b=Wtq6mAzlGCIeQD8KqRowpyeEV8YTOd4UDmiTO4VMfF0mxAVDRMxjhnwbMHfEpFoojEJ17DE+VOzJgo3EC5QTVQ7lSQ0fFSdcdELE1QBWU20nVWXLL+w5QGfcl3R+OY60OjLulB9AgvsOB3SFF8Mm9Rxlk5GW4HQIacpSlR5vqsM= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155552162435242.49501129235182; Wed, 17 Apr 2019 10:20:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6A924319936F; Wed, 17 Apr 2019 17:20:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 453245C224; Wed, 17 Apr 2019 17:20:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F22023FA51; Wed, 17 Apr 2019 17:20:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HHK2Ya030617 for ; Wed, 17 Apr 2019 13:20:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id A96AE5D71B; Wed, 17 Apr 2019 17:20:02 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-35.ams2.redhat.com [10.36.112.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1180D5D721; Wed, 17 Apr 2019 17:19:59 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 18:19:11 +0100 Message-Id: <20190417171929.9399-12-berrange@redhat.com> In-Reply-To: <20190417171929.9399-1-berrange@redhat.com> References: <20190417171929.9399-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v4 11/29] network: convert networkAllocateActualDevice to virNetworkPortDef X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 17 Apr 2019 17:20:23 +0000 (UTC) Convert the virDomainNetDef object into a virNetworkPortDef object at the start of networkAllocateActualDevice. This largely decouples the method impl from the domain object type. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 222 +++++++++++++++--------------------- 1 file changed, 91 insertions(+), 131 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 68c876afad..fe05a3edda 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -67,6 +67,7 @@ #include "network_event.h" #include "virhook.h" #include "virjson.h" +#include "virnetworkportdef.h" =20 #define VIR_FROM_THIS VIR_FROM_NETWORK #define MAX_BRIDGE_ID 256 @@ -4390,17 +4391,16 @@ networkAllocateActualDevice(virNetworkPtr net, virDomainNetDefPtr iface) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virDomainNetType actualType =3D iface->type; virNetworkObjPtr obj =3D NULL; virNetworkDefPtr netdef =3D NULL; - virNetDevBandwidthPtr bandwidth =3D NULL; virPortGroupDefPtr portgroup =3D NULL; - virNetDevVPortProfilePtr virtport =3D iface->virtPortProfile; - virNetDevVlanPtr vlan =3D NULL; virNetworkForwardIfDefPtr dev =3D NULL; size_t i; int ret =3D -1; + virNetDevVPortProfilePtr portprofile =3D NULL; + virNetworkPortDefPtr port =3D NULL; =20 + VIR_DEBUG("Allocating port from net %s", net->name); obj =3D virNetworkObjFindByName(driver->networks, net->name); if (!obj) { virReportError(VIR_ERR_NO_NETWORK, @@ -4415,9 +4415,6 @@ networkAllocateActualDevice(virNetworkPtr net, goto error; } =20 - virDomainActualNetDefFree(iface->data.network.actual); - iface->data.network.actual =3D NULL; - netdef =3D virNetworkObjGetDef(obj); =20 if (!virNetworkObjIsActive(obj)) { @@ -4427,99 +4424,84 @@ networkAllocateActualDevice(virNetworkPtr net, goto error; } =20 - if (VIR_ALLOC(iface->data.network.actual) < 0) + if (!(port =3D virDomainNetDefToNetworkPort(dom, iface))) goto error; =20 + VIR_DEBUG("Interface port group %s", port->group); /* portgroup can be present for any type of network, in particular * for bandwidth information, so we need to check for that and * fill it in appropriately for all forward types. */ - portgroup =3D virPortGroupFindByName(netdef, iface->data.network.portg= roup); - - /* If there is already interface-specific bandwidth, just use that - * (already in NetDef). Otherwise, if there is bandwidth info in - * the portgroup, fill that into the ActualDef. - */ - - if (iface->bandwidth) - bandwidth =3D iface->bandwidth; - else if (portgroup && portgroup->bandwidth) - bandwidth =3D portgroup->bandwidth; + portgroup =3D virPortGroupFindByName(netdef, port->group); =20 - if (bandwidth && virNetDevBandwidthCopy(&iface->data.network.actual->b= andwidth, - bandwidth) < 0) - goto error; + if (!port->bandwidth) { + if (portgroup && portgroup->bandwidth && + virNetDevBandwidthCopy(&port->bandwidth, + portgroup->bandwidth) < 0) + goto error; + } =20 - /* copy appropriate vlan info to actualNet */ - if (iface->vlan.nTags > 0) - vlan =3D &iface->vlan; - else if (portgroup && portgroup->vlan.nTags > 0) - vlan =3D &portgroup->vlan; - else if (netdef->vlan.nTags > 0) - vlan =3D &netdef->vlan; + if (port->vlan.nTags =3D=3D 0) { + virNetDevVlanPtr vlan =3D NULL; + if (portgroup && portgroup->vlan.nTags > 0) + vlan =3D &portgroup->vlan; + else if (netdef->vlan.nTags > 0) + vlan =3D &netdef->vlan; =20 - if (vlan && virNetDevVlanCopy(&iface->data.network.actual->vlan, vlan)= < 0) - goto error; + if (vlan && virNetDevVlanCopy(&port->vlan, vlan) < 0) + goto error; + } =20 - if (iface->trustGuestRxFilters) - iface->data.network.actual->trustGuestRxFilters - =3D iface->trustGuestRxFilters; - else if (portgroup && portgroup->trustGuestRxFilters) - iface->data.network.actual->trustGuestRxFilters - =3D portgroup->trustGuestRxFilters; - else if (netdef->trustGuestRxFilters) - iface->data.network.actual->trustGuestRxFilters - =3D netdef->trustGuestRxFilters; + if (!port->trustGuestRxFilters) { + if (portgroup && portgroup->trustGuestRxFilters) + port->trustGuestRxFilters =3D portgroup->trustGuestRxFilters; + else if (netdef->trustGuestRxFilters) + port->trustGuestRxFilters =3D netdef->trustGuestRxFilters; + } =20 /* merge virtualports from interface, network, and portgroup to * arrive at actual virtualport to use */ - if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtPortP= rofile, - iface->virtPortProfile, + if (virNetDevVPortProfileMerge3(&portprofile, + port->virtPortProfile, netdef->virtPortProfile, portgroup ? portgroup->virtPortProfile : NULL) <= 0) { - goto error; + goto error; + } + if (portprofile) { + VIR_FREE(port->virtPortProfile); + port->virtPortProfile =3D portprofile; } - virtport =3D iface->data.network.actual->virtPortProfile; =20 + VIR_DEBUG("Processing forward type %d", netdef->forward.type); switch ((virNetworkForwardType) netdef->forward.type) { case VIR_NETWORK_FORWARD_NONE: case VIR_NETWORK_FORWARD_NAT: case VIR_NETWORK_FORWARD_ROUTE: case VIR_NETWORK_FORWARD_OPEN: - iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; =20 - /* we also store the bridge device and macTableManager settings - * in iface->data.network.actual->data.bridge for later use - * after the domain's tap device is created (to attach to the - * bridge and set flood/learning mode on the tap device) - */ - if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, - netdef->bridge) < 0) + if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0) goto error; - iface->data.network.actual->data.bridge.macTableManager - =3D netdef->macTableManager; + port->plug.bridge.macTableManager =3D netdef->macTableManager; =20 - if (virtport) { + if (port->virtPortProfile) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(" not supported for = network " "'%s' which uses IP forwarding"), - virNetDevVPortTypeToString(virtport->virtPortTy= pe), + virNetDevVPortTypeToString(port->virtPortProfil= e->virtPortType), netdef->name); goto error; } =20 - if (networkPlugBandwidth(obj, &iface->mac, iface->bandwidth, - iface->data.network.actual ? - &iface->data.network.actual->class_id : N= ULL) < 0) + if (networkPlugBandwidth(obj, &port->mac, port->bandwidth, &port->= class_id) < 0) goto error; break; =20 case VIR_NETWORK_FORWARD_HOSTDEV: { - virDomainHostdevSubsysPCIBackendType backend; + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI; =20 - iface->data.network.actual->type =3D actualType =3D VIR_DOMAIN_NET= _TYPE_HOSTDEV; if (networkCreateInterfacePool(netdef) < 0) goto error; =20 @@ -4537,42 +4519,19 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->name); goto error; } - iface->data.network.actual->data.hostdev.def.parentnet =3D iface; - iface->data.network.actual->data.hostdev.def.info =3D &iface->info; - iface->data.network.actual->data.hostdev.def.mode =3D VIR_DOMAIN_H= OSTDEV_MODE_SUBSYS; - iface->data.network.actual->data.hostdev.def.managed =3D netdef->f= orward.managed ? 1 : 0; - iface->data.network.actual->data.hostdev.def.source.subsys.type = =3D dev->type; - iface->data.network.actual->data.hostdev.def.source.subsys.u.pci.a= ddr =3D dev->device.pci; - - switch (netdef->forward.driverName) { - case VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT: - backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT; - break; - case VIR_NETWORK_FORWARD_DRIVER_NAME_KVM: - backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM; - break; - case VIR_NETWORK_FORWARD_DRIVER_NAME_VFIO: - backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO; - break; - default: - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unrecognized driver name value %d " - " in network '%s'"), - netdef->forward.driverName, netdef->name); - goto error; - } - iface->data.network.actual->data.hostdev.def.source.subsys.u.pci.b= ackend - =3D backend; + port->plug.hostdevpci.addr =3D dev->device.pci; + port->plug.hostdevpci.driver =3D netdef->forward.driverName; + port->plug.hostdevpci.managed =3D netdef->forward.managed; =20 - if (virtport) { + if (port->virtPortProfile) { /* make sure type is supported for hostdev connections */ - if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_8021Q= BG && - virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_8021Q= BH) { + if (port->virtPortProfile->virtPortType !=3D VIR_NETDEV_VPORT_= PROFILE_8021QBG && + port->virtPortProfile->virtPortType !=3D VIR_NETDEV_VPORT_= PROFILE_8021QBH) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(" not supported = for network " "'%s' which uses an SR-IOV Virtual Functi= on " "via PCI passthrough"), - virNetDevVPortTypeToString(virtport->virtPo= rtType), + virNetDevVPortTypeToString(port->virtPortPr= ofile->virtPortType), netdef->name); goto error; } @@ -4586,28 +4545,24 @@ networkAllocateActualDevice(virNetworkPtr net, * is VIR_DOMAIN_NET_TYPE_BRIDGE */ =20 - iface->data.network.actual->type =3D actualType =3D VIR_DOMAIN= _NET_TYPE_BRIDGE; - if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, - netdef->bridge) < 0) + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; + if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0) goto error; - iface->data.network.actual->data.bridge.macTableManager - =3D netdef->macTableManager; + port->plug.bridge.macTableManager =3D netdef->macTableManager; =20 - if (virtport) { + if (port->virtPortProfile) { /* only type=3D'openvswitch' is allowed for bridges */ - if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_O= PENVSWITCH) { + if (port->virtPortProfile->virtPortType !=3D VIR_NETDEV_VP= ORT_PROFILE_OPENVSWITCH) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(" not suppor= ted for network " "'%s' which uses a bridge device"), - virNetDevVPortTypeToString(virtport->vi= rtPortType), + virNetDevVPortTypeToString(port->virtPo= rtProfile->virtPortType), netdef->name); goto error; } } =20 - if (networkPlugBandwidth(obj, &iface->mac, iface->bandwidth, - iface->data.network.actual ? - &iface->data.network.actual->class_id= : NULL) < 0) + if (networkPlugBandwidth(obj, &port->mac, port->bandwidth, &po= rt->class_id) < 0) goto error; break; } @@ -4625,22 +4580,22 @@ networkAllocateActualDevice(virNetworkPtr net, */ =20 /* Set type=3Ddirect and appropriate */ - iface->data.network.actual->type =3D actualType =3D VIR_DOMAIN_NET= _TYPE_DIRECT; + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_DIRECT; =20 /* NO need to check the value returned from virNetDevMacVLanModeTy= peFromString * it must be valid for these forward type(bridge|private|vepa|pas= sthrough) */ - iface->data.network.actual->data.direct.mode =3D + port->plug.direct.mode =3D virNetDevMacVLanModeTypeFromString(virNetworkForwardTypeToStri= ng(netdef->forward.type)); =20 - if (virtport) { + if (port->virtPortProfile) { /* make sure type is supported for macvtap connections */ - if (virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_8021Q= BG && - virtport->virtPortType !=3D VIR_NETDEV_VPORT_PROFILE_8021Q= BH) { + if (port->virtPortProfile->virtPortType !=3D VIR_NETDEV_VPORT_= PROFILE_8021QBG && + port->virtPortProfile->virtPortType !=3D VIR_NETDEV_VPORT_= PROFILE_8021QBH) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _(" not supported = for network " "'%s' which uses a macvtap device"), - virNetDevVPortTypeToString(virtport->virtPo= rtType), + virNetDevVPortTypeToString(port->virtPortPr= ofile->virtPortType), netdef->name); goto error; } @@ -4669,8 +4624,8 @@ networkAllocateActualDevice(virNetworkPtr net, */ if ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PASSTHROU= GH) || ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PRIVATE)= && - iface->data.network.actual->virtPortProfile && - (iface->data.network.actual->virtPortProfile->virtPortType + port->virtPortProfile && + (port->virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT_PROFILE_8021QBH))) { =20 /* pick first dev with 0 connections */ @@ -4696,7 +4651,7 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->name); goto error; } - if (VIR_STRDUP(iface->data.network.actual->data.direct.linkdev, + if (VIR_STRDUP(port->plug.direct.linkdev, dev->device.dev) < 0) goto error; } @@ -4709,30 +4664,30 @@ networkAllocateActualDevice(virNetworkPtr net, } =20 if (virNetworkObjMacMgrAdd(obj, driver->dnsmasqStateDir, - dom->name, &iface->mac) < 0) + dom->name, &port->mac) < 0) goto error; =20 - if (virNetDevVPortProfileCheckComplete(virtport, true) < 0) + if (virNetDevVPortProfileCheckComplete(port->virtPortProfile, true) < = 0) goto error; =20 /* make sure that everything now specified for the device is * actually supported on this type of network. NB: network, * netdev, and iface->data.network.actual may all be NULL. */ + VIR_DEBUG("Sanity check port config"); =20 - if (virDomainNetGetActualVlan(iface)) { + if (port->vlan.nTags) { /* vlan configuration via libvirt is only supported for PCI * Passthrough SR-IOV devices (hostdev or macvtap passthru * mode) and openvswitch bridges. Otherwise log an error and * fail */ - if (!(actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV || - (actualType =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT && - virDomainNetGetActualDirectMode(iface) - =3D=3D VIR_NETDEV_MACVLAN_MODE_PASSTHRU) || - (actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && - virtport && virtport->virtPortType - =3D=3D VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH))) { + if (!(port->plugtype =3D=3D VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI= || + (port->plugtype =3D=3D VIR_NETWORK_PORT_PLUG_TYPE_DIRECT && + port->plug.direct.mode =3D=3D VIR_NETDEV_MACVLAN_MODE_PASST= HRU) || + (port->plugtype =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && + port->virtPortProfile && + port->virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT= _PROFILE_OPENVSWITCH))) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("an interface connecting to network '%s' " "is requesting a vlan tag, but that is not " @@ -4741,16 +4696,15 @@ networkAllocateActualDevice(virNetworkPtr net, goto error; } } - if (virDomainNetGetActualBandwidth(iface)) { - /* bandwidth configuration via libvirt is not supported for - * hostdev network devices - */ - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("bandwidth settings are not supported " - "for hostdev interfaces")); - goto error; - } + + /* bandwidth configuration via libvirt is not supported for + * hostdev network devices + */ + if (port->bandwidth && port->plugtype =3D=3D VIR_NETWORK_PORT_PLUG_TYP= E_HOSTDEV_PCI) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("bandwidth settings are not supported " + "for hostdev interfaces")); + goto error; } =20 netdef->connections++; @@ -4768,9 +4722,15 @@ networkAllocateActualDevice(virNetworkPtr net, } networkLogAllocation(netdef, dev, &iface->mac, true); =20 + VIR_DEBUG("Populating net def"); + if (virDomainNetDefActualFromNetworkPort(iface, port) < 0) + goto error; + + VIR_DEBUG("Port allocated"); ret =3D 0; =20 cleanup: + virNetworkPortDefFree(port); virNetworkObjEndAPI(&obj); return ret; =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list