From nobody Sun Feb 8 07:25:14 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=1558627668; cv=none; d=zoho.com; s=zohoarc; b=SBPotMJUiWwMI6aDsYiqGmptzbsLyzgBDxrocfCp6WmzZtcIuu1wYFilHFMR2/enVg5//yJR+c9ZP+KhTUCUaiyJvxnQtvf2iX0V3g5X2c14n/07ILPWIXI4EUFVDNV2c6h8rH41ubNmRYvQZGafIibS1NIr2zVDuX04B3mUERI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1558627668; 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=HcW33nCiFgO3JKNVwjgNvpCvKmdepwiznwwTRhQ8dVo=; b=FxyZ7nctfYFyHLNXRy27PLlQCZeRU557XeFknS3VHSD6LBjQY8Y3be7Ts5k0cnD7GVxcGgdrS5uXOQ4d8Mquj/Rk8YDZdLXd3rGPpQ+Nn2CTNY5MrEMgeIUvJjmQOOHHwrGEh4zRU28OM54QE6y9XI+96bNf8Q1/4Jf+PCNfc4E= 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 1558627668667919.8473227568816; Thu, 23 May 2019 09:07:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4070E30B4AD0; Thu, 23 May 2019 16:07:33 +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 191A468369; Thu, 23 May 2019 16:07:27 +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 62FC31806B15; Thu, 23 May 2019 16:07:22 +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 x4NFXLB5006664 for ; Thu, 23 May 2019 11:33:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 273066134E; Thu, 23 May 2019 15:33:21 +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 CF2867BE7C; Thu, 23 May 2019 15:33:19 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 23 May 2019 16:32:46 +0100 Message-Id: <20190523153302.28526-8-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 07/23] network: convert networkReleaseActualDevice 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 23 May 2019 16:07:37 +0000 (UTC) Convert the virDomainNetDef object into a virNetworkPortDef object at the start of networkReleaseActualDevice. 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 | 140 +++++++++++++++--------------------- 1 file changed, 58 insertions(+), 82 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 3c69003480..615aec7142 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4939,10 +4939,10 @@ networkReleaseActualDevice(virNetworkPtr net, virDomainNetDefPtr iface) { virNetworkDriverStatePtr driver =3D networkGetDriver(); - virDomainNetType actualType =3D virDomainNetGetActualType(iface); virNetworkObjPtr obj; virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev =3D NULL; + virNetworkPortDefPtr port =3D NULL; size_t i; int ret =3D -1; =20 @@ -4951,77 +4951,50 @@ networkReleaseActualDevice(virNetworkPtr net, virReportError(VIR_ERR_NO_NETWORK, _("no network with matching name '%s'"), net->name); - goto error; + goto cleanup; } =20 if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Expected an interface for a virtual network")); - goto error; + goto cleanup; } =20 + if (iface->data.network.actual =3D=3D NULL) { + ret =3D 0; + goto cleanup; + } + + if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) + goto cleanup; + netdef =3D virNetworkObjGetDef(obj); =20 - 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: - if (iface->data.network.actual && - networkUnplugBandwidth(obj, iface->bandwidth, - &iface->data.network.actual->class_id) = < 0) - goto error; + switch ((virNetworkPortPlugType)port->plugtype) { + case VIR_NETWORK_PORT_PLUG_TYPE_NONE: + VIR_DEBUG("Releasing network device with no plug type"); break; =20 - case VIR_NETWORK_FORWARD_BRIDGE: - if (iface->data.network.actual && - actualType =3D=3D VIR_DOMAIN_NET_TYPE_BRIDGE && - networkUnplugBandwidth(obj, iface->bandwidth, - &iface->data.network.actual->class_id) = < 0) - goto error; - break; - case VIR_NETWORK_FORWARD_PRIVATE: - case VIR_NETWORK_FORWARD_VEPA: - case VIR_NETWORK_FORWARD_PASSTHROUGH: - case VIR_NETWORK_FORWARD_HOSTDEV: + case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK: + case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: + if (networkUnplugBandwidth(obj, port->bandwidth, + &port->class_id) < 0) + goto cleanup; break; =20 - case VIR_NETWORK_FORWARD_LAST: - default: - virReportEnumRangeError(virNetworkForwardType, netdef->forward.typ= e); - 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 release to network %s", iface->data.network.= name); - goto success; - } - - if (netdef->forward.nifs =3D=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("network '%s' uses a direct/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; - - actualDev =3D virDomainNetGetActualDirectDev(iface); - if (!actualDev) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("the interface uses a direct mode, " - "but has no source dev")); - goto error; + case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: + if (netdef->forward.nifs =3D=3D 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("network '%s' uses a direct mode, but " + "has no forward dev and no interface pool"), + netdef->name); + goto cleanup; } =20 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].de= vice.dev)) { dev =3D &netdef->forward.ifs[i]; break; } @@ -5031,23 +5004,24 @@ networkReleaseActualDevice(virNetworkPtr net, virReportError(VIR_ERR_INTERNAL_ERROR, _("network '%s' doesn't have dev=3D'%s' " "in use by domain"), - netdef->name, actualDev); - goto error; + netdef->name, port->plug.direct.linkdev); + goto cleanup; } - } else /* if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) */ { - virDomainHostdevDefPtr hostdev; + break; =20 - hostdev =3D virDomainNetGetActualHostdev(iface); - if (!hostdev) { + case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: + if (netdef->forward.nifs =3D=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("the interface uses a hostdev mode, but= has no hostdev")); - goto error; + _("network '%s' uses a hostdev mode, but " + "has no forward dev and no interface pool"), + netdef->name); + goto cleanup; } =20 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; @@ -5059,26 +5033,30 @@ networkReleaseActualDevice(virNetworkPtr net, _("network '%s' doesn't have " "PCI device %04x:%02x:%02x.%x in use by domai= n"), 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); - goto error; + port->plug.hostdevpci.addr.domain, + port->plug.hostdevpci.addr.bus, + port->plug.hostdevpci.addr.slot, + port->plug.hostdevpci.addr.function); + goto cleanup; } + break; + + case VIR_NETWORK_PORT_PLUG_TYPE_LAST: + default: + virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); + goto cleanup; } =20 - success: - virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, dom->name, &iface= ->mac); + virNetworkObjMacMgrDel(obj, driver->dnsmasqStateDir, dom->name, &port-= >mac); + + netdef->connections--; + if (dev) + dev->connections--; + /* finally we can call the 'unplugged' hook script if any */ + networkRunHook(obj, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGED, + VIR_HOOK_SUBOP_BEGIN); + networkLogAllocation(netdef, dev, &port->mac, false); =20 - if (iface->data.network.actual) { - netdef->connections--; - if (dev) - dev->connections--; - /* finally we can call the 'unplugged' hook script if any */ - networkRunHook(obj, dom, iface, VIR_HOOK_NETWORK_OP_IFACE_UNPLUGGE= D, - VIR_HOOK_SUBOP_BEGIN); - networkLogAllocation(netdef, dev, &iface->mac, false); - } ret =3D 0; cleanup: virNetworkObjEndAPI(&obj); @@ -5086,10 +5064,8 @@ networkReleaseActualDevice(virNetworkPtr net, virDomainActualNetDefFree(iface->data.network.actual); iface->data.network.actual =3D NULL; } + virNetworkPortDefFree(port); return ret; - - error: - goto cleanup; } =20 =20 --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list