From nobody Sun Feb 8 17:36:45 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=1555521635; cv=none; d=zoho.com; s=zohoarc; b=hNwMuLAhHoet3JCkwTAnf7OlwVth8FeMCSDnZqpoMD7PewVZQpbGFFMhoOUXSEJrqMGMVhx1ZIERBoDhB0QLQKADcuhIvr7Hf0mK0B98b2NpZyatgI8jKFx5S6jF0s2GY8lJa7uZS2+jjlQhdJ2XZMDf3FdFkaJIetA/FnyjS4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555521635; 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=/W0reQ5KWHwwFQh74WlM7qXjtbZaZiOtxgNuk9QilKw=; b=Yh1YahGy8Qj8xHcoi0ZYMWKbUjEkvnrKUryIZKBvJvqYvJGXEpVoqq7NwaEHb1jaTasLJOLIBzMTM7GEbrNlXJ9C/ZzDmW9MJWSx/Zlx/OvVo4xnjeG82m0UPJgT6cRgw+Zs/PHRy7feMzkdZSfAtsTF0AKXt6cJUlQlCcLHhvI= 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 1555521635125502.12208688443786; Wed, 17 Apr 2019 10:20:35 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 910993008CDB; Wed, 17 Apr 2019 17:20:33 +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 6CA3B608C8; Wed, 17 Apr 2019 17:20:33 +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 3521F3F5CF; Wed, 17 Apr 2019 17:20:33 +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 x3HHKHUm030687 for ; Wed, 17 Apr 2019 13:20:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id BAA185D71B; Wed, 17 Apr 2019 17:20:17 +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 564725D6A6; Wed, 17 Apr 2019 17:20:16 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 18:19:16 +0100 Message-Id: <20190417171929.9399-17-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 16/29] network: introduce networkAllocatePort 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 17 Apr 2019 17:20:34 +0000 (UTC) Separate network port allocation code from the domain driver network callback implementation. Reviewed-by: Laine Stump Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 143 +++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 66 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index f8b58b3a25..ff5677f6a7 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4368,60 +4368,38 @@ networkLogAllocation(virNetworkDefPtr netdef, * "backend" function table. */ =20 -/* networkAllocateActualDevice: - * @dom: domain definition that @iface belongs to - * @iface: the original NetDef from the domain +/* networkAllocatePort: + * @obj: the network to allocate from + * @port: the port definition to allocate * - * Looks up the network reference by iface, allocates a physical + * Looks up the network reference by port, allocates a physical * device from that network (if appropriate), and returns with the - * virDomainActualNetDef filled in accordingly. If there are no - * changes to be made in the netdef, then just leave the actualdef - * empty. + * port configuration filled in accordingly. * * Returns 0 on success, -1 on failure. */ static int -networkAllocateActualDevice(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface) +networkAllocatePort(virNetworkObjPtr obj, + virNetworkPortDefPtr port) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj =3D NULL; virNetworkDefPtr netdef =3D NULL; virPortGroupDefPtr portgroup =3D NULL; virNetworkForwardIfDefPtr dev =3D NULL; size_t i; int ret =3D -1; virNetDevVPortProfilePtr portprofile =3D NULL; - virNetworkPortDefPtr port =3D NULL; - - VIR_DEBUG("Allocating port from net %s", net->name); - obj =3D virNetworkObjFindByName(driver->networks, net->name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - net->name); - goto error; - } - - if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Expected an interface for a virtual network")); - goto error; - } =20 netdef =3D virNetworkObjGetDef(obj); + VIR_DEBUG("Allocating port from net %s", netdef->name); =20 if (!virNetworkObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("network '%s' is not active"), netdef->name); - goto error; + goto cleanup; } =20 - if (!(port =3D virDomainNetDefToNetworkPort(dom, iface))) - goto error; - 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 @@ -4433,7 +4411,7 @@ networkAllocateActualDevice(virNetworkPtr net, if (portgroup && portgroup->bandwidth && virNetDevBandwidthCopy(&port->bandwidth, portgroup->bandwidth) < 0) - goto error; + goto cleanup; } =20 if (port->vlan.nTags =3D=3D 0) { @@ -4444,7 +4422,7 @@ networkAllocateActualDevice(virNetworkPtr net, vlan =3D &netdef->vlan; =20 if (vlan && virNetDevVlanCopy(&port->vlan, vlan) < 0) - goto error; + goto cleanup; } =20 if (!port->trustGuestRxFilters) { @@ -4462,7 +4440,7 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->virtPortProfile, portgroup ? portgroup->virtPortProfile : NULL) <= 0) { - goto error; + goto cleanup; } if (portprofile) { VIR_FREE(port->virtPortProfile); @@ -4478,7 +4456,7 @@ networkAllocateActualDevice(virNetworkPtr net, port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; =20 if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0) - goto error; + goto cleanup; port->plug.bridge.macTableManager =3D netdef->macTableManager; =20 if (port->virtPortProfile) { @@ -4487,18 +4465,18 @@ networkAllocateActualDevice(virNetworkPtr net, "'%s' which uses IP forwarding"), virNetDevVPortTypeToString(port->virtPortProfil= e->virtPortType), netdef->name); - goto error; + goto cleanup; } =20 if (networkPlugBandwidth(obj, &port->mac, port->bandwidth, &port->= class_id) < 0) - goto error; + goto cleanup; break; =20 case VIR_NETWORK_FORWARD_HOSTDEV: { port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI; =20 if (networkCreateInterfacePool(netdef) < 0) - goto error; + goto cleanup; =20 /* pick first dev with 0 connections */ for (i =3D 0; i < netdef->forward.nifs; i++) { @@ -4512,7 +4490,7 @@ networkAllocateActualDevice(virNetworkPtr net, _("network '%s' requires exclusive access " "to interfaces, but none are available"), netdef->name); - goto error; + goto cleanup; } port->plug.hostdevpci.addr =3D dev->device.pci; port->plug.hostdevpci.driver =3D netdef->forward.driverName; @@ -4528,7 +4506,7 @@ networkAllocateActualDevice(virNetworkPtr net, "via PCI passthrough"), virNetDevVPortTypeToString(port->virtPortPr= ofile->virtPortType), netdef->name); - goto error; + goto cleanup; } } break; @@ -4542,7 +4520,7 @@ networkAllocateActualDevice(virNetworkPtr net, =20 port->plugtype =3D VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE; if (VIR_STRDUP(port->plug.bridge.brname, netdef->bridge) < 0) - goto error; + goto cleanup; port->plug.bridge.macTableManager =3D netdef->macTableManager; =20 if (port->virtPortProfile) { @@ -4553,12 +4531,12 @@ networkAllocateActualDevice(virNetworkPtr net, "'%s' which uses a bridge device"), virNetDevVPortTypeToString(port->virtPo= rtProfile->virtPortType), netdef->name); - goto error; + goto cleanup; } } =20 if (networkPlugBandwidth(obj, &port->mac, port->bandwidth, &po= rt->class_id) < 0) - goto error; + goto cleanup; break; } =20 @@ -4592,7 +4570,7 @@ networkAllocateActualDevice(virNetworkPtr net, "'%s' which uses a macvtap device"), virNetDevVPortTypeToString(port->virtPortPr= ofile->virtPortType), netdef->name); - goto error; + goto cleanup; } } =20 @@ -4604,12 +4582,12 @@ networkAllocateActualDevice(virNetworkPtr net, _("network '%s' uses a direct mode, but " "has no forward dev and no interface pool"), netdef->name); - goto error; + goto cleanup; } else { /* pick an interface from the pool */ =20 if (networkCreateInterfacePool(netdef) < 0) - goto error; + goto cleanup; =20 /* PASSTHROUGH mode, and PRIVATE Mode + 802.1Qbh both * require exclusive access to a device, so current @@ -4644,26 +4622,26 @@ networkAllocateActualDevice(virNetworkPtr net, _("network '%s' requires exclusive access " "to interfaces, but none are available"), netdef->name); - goto error; + goto cleanup; } if (VIR_STRDUP(port->plug.direct.linkdev, dev->device.dev) < 0) - goto error; + goto cleanup; } break; =20 case VIR_NETWORK_FORWARD_LAST: default: virReportEnumRangeError(virNetworkForwardType, netdef->forward.typ= e); - goto error; + goto cleanup; } =20 if (virNetworkObjMacMgrAdd(obj, driver->dnsmasqStateDir, - dom->name, &port->mac) < 0) - goto error; + port->ownername, &port->mac) < 0) + goto cleanup; =20 if (virNetDevVPortProfileCheckComplete(port->virtPortProfile, true) < = 0) - goto error; + goto cleanup; =20 /* make sure that everything now specified for the device is * actually supported on this type of network. NB: network, @@ -4688,7 +4666,7 @@ networkAllocateActualDevice(virNetworkPtr net, "is requesting a vlan tag, but that is not " "supported for this type of network"), netdef->name); - goto error; + goto cleanup; } } =20 @@ -4699,7 +4677,7 @@ networkAllocateActualDevice(virNetworkPtr net, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("bandwidth settings are not supported " "for hostdev interfaces")); - goto error; + goto cleanup; } =20 netdef->connections++; @@ -4713,28 +4691,61 @@ networkAllocateActualDevice(virNetworkPtr net, netdef->connections--; if (dev) dev->connections--; - goto error; + goto cleanup; } - networkLogAllocation(netdef, dev, &iface->mac, true); - - VIR_DEBUG("Populating net def"); - if (virDomainNetDefActualFromNetworkPort(iface, port) < 0) - goto error; + networkLogAllocation(netdef, dev, &port->mac, true); =20 VIR_DEBUG("Port allocated"); - ret =3D 0; =20 + ret =3D 0; cleanup: - virNetworkPortDefFree(port); - virNetworkObjEndAPI(&obj); return ret; +} =20 - error: - if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + +static int +networkAllocateActualDevice(virNetworkPtr net, + virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkPortDefPtr port =3D NULL; + virNetworkObjPtr obj; + int ret =3D -1; + + obj =3D virNetworkObjFindByName(driver->networks, net->name); + if (!obj) { + virReportError(VIR_ERR_NO_NETWORK, + _("no network with matching name '%s'"), + net->name); + return -1; + } + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected an interface for a virtual network")); + goto cleanup; + } + + if (!(port =3D virDomainNetDefToNetworkPort(dom, iface))) + goto cleanup; + + if (networkAllocatePort(obj, port) < 0) + goto cleanup; + + VIR_DEBUG("Populating net def"); + if (virDomainNetDefActualFromNetworkPort(iface, port) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + if (ret < 0) { virDomainActualNetDefFree(iface->data.network.actual); iface->data.network.actual =3D NULL; } - goto cleanup; + virNetworkPortDefFree(port); + virNetworkObjEndAPI(&obj); + return ret; } =20 =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list