From nobody Sat Feb 7 15:15:34 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=1558627656; cv=none; d=zoho.com; s=zohoarc; b=V3fzqmJJHv8drDHk/Mbn3MykBaSWFCh7uuRmakEOqpjMXQI7fd6vhge2bqYJorttyJ2MoTXGbfoRA/fpqfCsl+IV3sZbtxwsCUyt5/G+jna+gprBwyew6fpJvGVN/aCKDdd2XNJDS+ToRSC9dG09ukN/E/NF4r2wwj1QDITJ64g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558627656; 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=ZDavsb1PkOroGuLK5JGN/M/utFll8s8fGP6Y4L7DkLs=; b=PjoLYstpMRKHBRagVP4equiONbPk/5b2GFgHG01+70r2KuVF5EqcnY7Go/CksOZdcl0AgO/BBwmelPw/bJh9JMdyXAN+QmcBalhDUXct02G+lNjEycB8JurBS0Vrx+6FVWxnbEx/33qWr4OlEO1pOjxXqa4qJL5c0j9tMdctVwM= 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 155862765601447.35967557549486; Thu, 23 May 2019 09:07:36 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B4C1C057F2F; Thu, 23 May 2019 16:06:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 516014138; Thu, 23 May 2019 16:06:46 +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 00FDD1806B14; Thu, 23 May 2019 16:06:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x4NFXHWY006620 for ; Thu, 23 May 2019 11:33:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6EAC079599; Thu, 23 May 2019 15:33:17 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-64.ams2.redhat.com [10.36.112.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41522620CA; Thu, 23 May 2019 15:33:16 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 23 May 2019 16:32:44 +0100 Message-Id: <20190523153302.28526-6-berrange@redhat.com> In-Reply-To: <20190523153302.28526-1-berrange@redhat.com> References: <20190523153302.28526-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: Laine Stump Subject: [libvirt] [PATCH v6 05/23] 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 23 May 2019 16:07: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 7374da0ac7..35dea0f819 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 @@ -4381,17 +4382,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, @@ -4406,9 +4406,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)) { @@ -4418,62 +4415,57 @@ 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: @@ -4483,38 +4475,28 @@ networkAllocateActualDevice(virNetworkPtr net, * NETWORK; we just keep the info from the portgroup in * iface->data.network.actual */ - iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_NETWORK; + port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_NETWORK; =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 @@ -4532,42 +4514,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; } @@ -4581,28 +4540,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; } @@ -4620,22 +4575,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; } @@ -4664,8 +4619,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 */ @@ -4691,7 +4646,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; } @@ -4704,30 +4659,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 " @@ -4736,16 +4691,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++; @@ -4763,9 +4717,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.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list