From nobody Sun Feb 8 05:41:02 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 1545663599919900.3898623755828; Mon, 24 Dec 2018 06:59:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1EB545F789; Mon, 24 Dec 2018 14:59:58 +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 E32181054FD3; Mon, 24 Dec 2018 14:59:57 +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 A47B03F60A; Mon, 24 Dec 2018 14:59:57 +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 wBOExoGK000892 for ; Mon, 24 Dec 2018 09:59:50 -0500 Received: by smtp.corp.redhat.com (Postfix) id 2D17460C74; Mon, 24 Dec 2018 14:59:50 +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 57DED60C68; Mon, 24 Dec 2018 14:59:49 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 24 Dec 2018 14:59:03 +0000 Message-Id: <20181224145915.8700-16-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 15/27] network: convert networkNotifyActualDevice 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Mon, 24 Dec 2018 14:59:58 +0000 (UTC) Convert the virDomainNetDef object into a virNetworkPortDef object at the start of networkNotifyActualDevice. This largely decouples the method impl from the domain object type. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/network/bridge_driver.c | 127 +++++++++++++++++------------------- 1 file changed, 61 insertions(+), 66 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 594574db8c..109d284791 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4822,8 +4822,10 @@ networkNotifyActualDevice(virNetworkPtr net, virNetworkObjPtr obj; virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev =3D NULL; + virNetworkPortDefPtr port =3D NULL; size_t i; char *master =3D NULL; + bool useOVS =3D false; =20 obj =3D virNetworkObjFindByName(driver->networks, net->name); if (!obj) { @@ -4868,29 +4870,42 @@ networkNotifyActualDevice(virNetworkPtr net, actualType =3D VIR_DOMAIN_NET_TYPE_BRIDGE; } =20 - /* see if we're connected to the correct bridge */ - if (netdef->bridge) { - bool useOVS =3D false; + if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) + goto cleanup; + + 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; =20 - if (virNetDevGetMaster(iface->ifname, &master) < 0) + 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; + } + + if (virNetDevGetMaster(port->plug.bridge.brname, &master) < 0) goto error; =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(iface->ifname, &mas= ter) < 0) + if (virNetDevOpenvswitchInterfaceGetMaster(port->plug.bridge.b= rname, &master) < 0) goto error; } =20 if (STRNEQ_NULLABLE(netdef->bridge, master)) { /* disconnect from current (incorrect) bridge */ if (master) { - VIR_INFO("Removing %s from %s", iface->ifname, master); + VIR_INFO("Removing %s from %s", port->plug.bridge.brname, = master); if (useOVS) - ignore_value(virNetDevOpenvswitchRemovePort(master, if= ace->ifname)); + ignore_value(virNetDevOpenvswitchRemovePort(master, po= rt->plug.bridge.brname)); else - ignore_value(virNetDevBridgeRemovePort(master, iface->= ifname)); + ignore_value(virNetDevBridgeRemovePort(master, port->p= lug.bridge.brname)); } =20 /* attach/reattach to correct bridge. @@ -4898,51 +4913,28 @@ networkNotifyActualDevice(virNetworkPtr net, * so there is no point in trying to learn the actualMTU * (final arg to virNetDevTapAttachBridge()) */ - VIR_INFO("Attaching %s to %s", iface->ifname, netdef->bridge); - if (virNetDevTapAttachBridge(iface->ifname, netdef->bridge, - &iface->mac, dom->uuid, - virDomainNetGetActualVirtPortProf= ile(iface), - virDomainNetGetActualVlan(iface), - iface->mtu, NULL) < 0) { + VIR_INFO("Attaching %s to %s", port->plug.bridge.brname, netde= f->bridge); + /* XXXXXXXXXXXXXXX MTU is bad perhaps ? */ + if (virNetDevTapAttachBridge(port->plug.bridge.brname, netdef-= >bridge, + &port->mac, port->owneruuid, + port->virtPortProfile, + &port->vlan, + 0, NULL) < 0) { goto error; } } - } - - if (!iface->data.network.actual || - (actualType !=3D VIR_DOMAIN_NET_TYPE_DIRECT && - actualType !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV)) { - VIR_DEBUG("Nothing to claim from network %s", iface->data.network.= name); - goto success; - } - - if (networkCreateInterfacePool(netdef) < 0) - goto error; - - if (netdef->forward.nifs =3D=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("network '%s' uses a direct or hostdev mode, " - "but has no forward dev and no interface pool"), - netdef->name); - goto error; - } - - if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_DIRECT) { - const char *actualDev; + break; =20 - actualDev =3D virDomainNetGetActualDirectDev(iface); - if (!actualDev) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("the interface uses a direct mode, " - "but has no source dev")); + case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: + if (networkCreateInterfacePool(netdef) < 0) goto error; - } =20 /* find the matching interface and increment its connections */ for (i =3D 0; i < netdef->forward.nifs; i++) { if (netdef->forward.ifs[i].type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_NETDEV && - STREQ(actualDev, netdef->forward.ifs[i].device.dev)) { + STREQ(port->plug.direct.linkdev, + netdef->forward.ifs[i].device.dev)) { dev =3D &netdef->forward.ifs[i]; break; } @@ -4951,8 +4943,9 @@ networkNotifyActualDevice(virNetworkPtr net, if (!dev) { virReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' doesn't have dev=3D'%s' " - "in use by domain"), - netdef->name, actualDev); + "in use by network port '%s'"), + netdef->name, port->plug.direct.linkdev, + port->uuid); goto error; } =20 @@ -4963,31 +4956,26 @@ networkNotifyActualDevice(virNetworkPtr net, if ((dev->connections > 0) && ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PASSTHROUGH)= || ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PRIVATE) && - iface->data.network.actual->virtPortProfile && - (iface->data.network.actual->virtPortProfile->virtPortType - =3D=3D VIR_NETDEV_VPORT_PROFILE_8021QBH)))) { + port->virtPortProfile && + (port->virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT= _PROFILE_8021QBH)))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' claims dev=3D'%s' is already in= " - "use by a different domain"), - netdef->name, actualDev); + "use by a different port"), + netdef->name, port->plug.direct.linkdev); goto error; } - } else /* if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) */ { - virDomainHostdevDefPtr hostdev; + break; =20 - hostdev =3D virDomainNetGetActualHostdev(iface); - if (!hostdev) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("the interface uses a hostdev mode, " - "but has no hostdev")); + case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: + + if (networkCreateInterfacePool(netdef) < 0) goto error; - } =20 /* find the matching interface and increment its connections */ for (i =3D 0; i < netdef->forward.nifs; i++) { if (netdef->forward.ifs[i].type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV_DEVICE_PCI && - virPCIDeviceAddressEqual(&hostdev->source.subsys.u.pci.add= r, + virPCIDeviceAddressEqual(&port->plug.hostdevpci.addr, &netdef->forward.ifs[i].device.pc= i)) { dev =3D &netdef->forward.ifs[i]; break; @@ -4997,12 +4985,12 @@ networkNotifyActualDevice(virNetworkPtr net, if (!dev) { virReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' doesn't have " - "PCI device %04x:%02x:%02x.%x in use by domai= n"), + "PCI device %04x:%02x:%02x.%x in use by netwo= rk port"), netdef->name, - hostdev->source.subsys.u.pci.addr.domain, - hostdev->source.subsys.u.pci.addr.bus, - hostdev->source.subsys.u.pci.addr.slot, - hostdev->source.subsys.u.pci.addr.function); + port->plug.hostdevpci.addr.domain, + port->plug.hostdevpci.addr.bus, + port->plug.hostdevpci.addr.slot, + port->plug.hostdevpci.addr.function); goto error; } =20 @@ -5015,15 +5003,21 @@ networkNotifyActualDevice(virNetworkPtr net, virReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' claims the PCI device at " "domain=3D%d bus=3D%d slot=3D%d function=3D%d= " - "is already in use by a different domain"), + "is already in use by a different network por= t"), netdef->name, dev->device.pci.domain, dev->device.pci.bus, dev->device.pci.slot, dev->device.pci.function); goto error; } + + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_LAST: + default: + virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); + goto error; } =20 - success: netdef->connections++; if (dev) dev->connections++; @@ -5040,6 +5034,7 @@ networkNotifyActualDevice(virNetworkPtr net, =20 cleanup: virNetworkObjEndAPI(&obj); + virNetworkPortDefFree(port); VIR_FREE(master); return; =20 --=20 2.19.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list