From nobody Sun Feb 8 05:40:58 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1545663635005764.2198827654021; Mon, 24 Dec 2018 07:00:35 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F2DCC070E11; Mon, 24 Dec 2018 15:00:32 +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 2B9A161542; Mon, 24 Dec 2018 15:00:30 +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 CB4A63F5CA; Mon, 24 Dec 2018 15:00:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wBOF09eb001007 for ; Mon, 24 Dec 2018 10:00:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3787A60C66; Mon, 24 Dec 2018 15:00:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-112-27.ams2.redhat.com [10.36.112.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 238F618B04; Mon, 24 Dec 2018 15:00:04 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 24 Dec 2018 14:59:07 +0000 Message-Id: <20181224145915.8700-20-berrange@redhat.com> In-Reply-To: <20181224145915.8700-1-berrange@redhat.com> References: <20181224145915.8700-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 19/27] network: introduce networkNotifyPort 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 24 Dec 2018 15:00:33 +0000 (UTC) Separate network port notification code from the domain driver network callback implementation. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 159 ++++++++++++++++++++---------------- 1 file changed, 89 insertions(+), 70 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index ebce90d89a..25e856a7e2 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4806,46 +4806,26 @@ networkAllocateActualDevice(virNetworkPtr net, } =20 =20 -/* networkNotifyActualDevice: - * @dom: domain definition that @iface belongs to - * @iface: the domain's NetDef with an "actual" device already filled in. +/* networkNotifyPort: + * @obj: the network to notify + * @port: the port definition to notify * * Called to notify the network driver when libvirtd is restarted and * finds an already running domain. If appropriate it will force an * allocation of the actual->direct.linkdev to get everything back in * order, or re-attach the interface's tap device to the network's * bridge. - * - * No return value (but does log any failures) */ -static void -networkNotifyActualDevice(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface) +static int +networkNotifyPort(virNetworkObjPtr obj, + virNetworkPortDefPtr port) { - virNetworkDriverStatePtr driver =3D networkGetDriver(); - virDomainNetType actualType =3D virDomainNetGetActualType(iface); - virNetworkObjPtr obj; virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev =3D NULL; - virNetworkPortDefPtr port =3D NULL; size_t i; char *master =3D NULL; bool useOVS =3D false; - - 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 a interface for a virtual network")); - goto error; - } + int ret =3D -1; =20 netdef =3D virNetworkObjGetDef(obj); =20 @@ -4853,55 +4833,32 @@ networkNotifyActualDevice(virNetworkPtr net, virReportError(VIR_ERR_OPERATION_INVALID, _("network '%s' is not active"), netdef->name); - goto error; - } - - /* if we're restarting libvirtd after an upgrade from a version - * that didn't save bridge name in actualNetDef for - * actualType=3D=3Dnetwork, we need to copy it in so that it will be - * available in all cases - */ - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && - !iface->data.network.actual->data.bridge.brname && - (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, - netdef->bridge) < 0)) - goto error; - - /* Older libvirtd uses actualType=3D=3Dnetwork, but we now - * just use actualType=3D=3Dbridge, as nothing needs to - * distinguish the two cases, and this simplifies virt - * drive code */ - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { - iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - actualType =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - } - - if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) goto cleanup; + } =20 switch (port->plugtype) { case VIR_NETWORK_PORT_PLUG_TYPE_NONE: virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unexpectedly got a network port without a plug")= ); - goto error; + goto cleanup; =20 case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: /* see if we're connected to the correct bridge */ if (!netdef->bridge) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unexpectedly got a network port plugged into= a bridge")); - goto error; + goto cleanup; } =20 if (virNetDevGetMaster(port->plug.bridge.brname, &master) < 0) - goto error; + goto cleanup; =20 /* IFLA_MASTER for a tap on an OVS switch is always "ovs-system" */ if (STREQ_NULLABLE(master, "ovs-system")) { useOVS =3D true; VIR_FREE(master); if (virNetDevOpenvswitchInterfaceGetMaster(port->plug.bridge.b= rname, &master) < 0) - goto error; + goto cleanup; } =20 if (STRNEQ_NULLABLE(netdef->bridge, master)) { @@ -4926,14 +4883,14 @@ networkNotifyActualDevice(virNetworkPtr net, port->virtPortProfile, &port->vlan, 0, NULL) < 0) { - goto error; + goto cleanup; } } break; =20 case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: if (networkCreateInterfacePool(netdef) < 0) - goto error; + goto cleanup; =20 /* find the matching interface and increment its connections */ for (i =3D 0; i < netdef->forward.nifs; i++) { @@ -4952,7 +4909,7 @@ networkNotifyActualDevice(virNetworkPtr net, "in use by network port '%s'"), netdef->name, port->plug.direct.linkdev, port->uuid); - goto error; + goto cleanup; } =20 /* PASSTHROUGH mode and PRIVATE Mode + 802.1Qbh both require @@ -4968,14 +4925,14 @@ networkNotifyActualDevice(virNetworkPtr net, _("network '%s' claims dev=3D'%s' is already in= " "use by a different port"), netdef->name, port->plug.direct.linkdev); - goto error; + goto cleanup; } break; =20 case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: =20 if (networkCreateInterfacePool(netdef) < 0) - goto error; + goto cleanup; =20 /* find the matching interface and increment its connections */ for (i =3D 0; i < netdef->forward.nifs; i++) { @@ -4997,7 +4954,7 @@ networkNotifyActualDevice(virNetworkPtr net, port->plug.hostdevpci.addr.bus, port->plug.hostdevpci.addr.slot, port->plug.hostdevpci.addr.function); - goto error; + goto cleanup; } =20 /* PASSTHROUGH mode, PRIVATE Mode + 802.1Qbh, and hostdev (PCI @@ -5013,7 +4970,7 @@ networkNotifyActualDevice(virNetworkPtr net, netdef->name, dev->device.pci.domain, dev->device.pci.bus, dev->device.pci.slot, dev->device.pci.function); - goto error; + goto cleanup; } =20 break; @@ -5021,7 +4978,7 @@ networkNotifyActualDevice(virNetworkPtr net, case VIR_NETWORK_PORT_PLUG_TYPE_LAST: default: virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); - goto error; + goto cleanup; } =20 netdef->connections++; @@ -5034,18 +4991,80 @@ networkNotifyActualDevice(virNetworkPtr net, if (dev) dev->connections--; netdef->connections--; - goto error; + goto cleanup; } - networkLogAllocation(netdef, dev, &iface->mac, true); + networkLogAllocation(netdef, dev, &port->mac, true); =20 + ret =3D 0; cleanup: - virNetworkObjEndAPI(&obj); - virNetworkPortDefFree(port); VIR_FREE(master); - return; + return ret; +} =20 - error: - goto cleanup; + +static void +networkNotifyActualDevice(virNetworkPtr net, + virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virDomainNetType actualType =3D virDomainNetGetActualType(iface); + virNetworkObjPtr obj; + virNetworkDefPtr netdef; + virNetworkPortDefPtr port =3D NULL; + + obj =3D virNetworkObjFindByName(driver->networks, net->name); + if (!obj) { + virReportError(VIR_ERR_NO_NETWORK, + _("no network with matching name '%s'"), + net->name); + goto cleanup; + } + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Expected a interface for a virtual network")); + goto cleanup; + } + + netdef =3D virNetworkObjGetDef(obj); + + if (!virNetworkObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + netdef->name); + goto cleanup; + } + + /* if we're restarting libvirtd after an upgrade from a version + * that didn't save bridge name in actualNetDef for + * actualType=3D=3Dnetwork, we need to copy it in so that it will be + * available in all cases + */ + if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && + !iface->data.network.actual->data.bridge.brname && + (VIR_STRDUP(iface->data.network.actual->data.bridge.brname, + netdef->bridge) < 0)) + goto cleanup; + + /* Older libvirtd uses actualType=3D=3Dnetwork, but we now + * just use actualType=3D=3Dbridge, as nothing needs to + * distinguish the two cases, and this simplifies virt + * drive code */ + if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_NETWORK) { + iface->data.network.actual->type =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + actualType =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + } + + if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) + goto cleanup; + + if (networkNotifyPort(obj, port) < 0) + goto cleanup; + + cleanup: + virNetworkObjEndAPI(&obj); + virNetworkPortDefFree(port); } =20 =20 --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list