From nobody Sun Feb 8 16:50:12 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=1557848942; cv=none; d=zoho.com; s=zohoarc; b=XoZfvalk4QFztbU4b0Pf8LACkQZ+dVUUX9obWn7sWuD3LjJKtxep55noqoilv5C5xf84zgIsJ00NnWnxuIdyb7hLYz0TZTsCeSmKqXPUA4kc4c30GyfBtv8cTmQEpIP8fLOKhuldj2EbeOCLhnx0inLzek+pokdLYOKwtEvvebY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557848942; 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=1xOnmvsDkUNoDeg2+h4BlzP2QM0omChjAtD27jGmUmc=; b=YhHo3MRjpVIXIkWgJMhO9j9g3CUPo7esdWVUt4Q/dawNC3WRKgGzkpciGTmLySg7ArhVF/K6aa1m7fl/w+AkF49GAb4aHB+kAW5OoHcQtEx647PL63fv7fgju0hsdfnEtOAPvwFKphRPKsmvo5nKAfaLNYOyAjXfz1sRmFmndM4= 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 155784894282474.99123567641914; Tue, 14 May 2019 08:49:02 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4196C301BE65; Tue, 14 May 2019 15:49:01 +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 0C75F2B9E3; Tue, 14 May 2019 15:49:01 +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 BF5A53FAF5; Tue, 14 May 2019 15:49:00 +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 x4EFmqON031816 for ; Tue, 14 May 2019 11:48:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6E16319808; Tue, 14 May 2019 15:48:52 +0000 (UTC) Received: from dhcp-17-248.lcy.redhat.com (unknown [10.42.17.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA106600C5; Tue, 14 May 2019 15:48:51 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Tue, 14 May 2019 16:48:23 +0100 Message-Id: <20190514154836.6427-12-berrange@redhat.com> In-Reply-To: <20190514154836.6427-1-berrange@redhat.com> References: <20190514154836.6427-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 v5 11/24] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 14 May 2019 15:49:01 +0000 (UTC) Separate network port notification 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 | 106 +++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 43 deletions(-) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 0954b5515b..7446978be4 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -4751,61 +4751,38 @@ 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. - * - * Returns 0 on success, -1 on failure. */ static int -networkNotifyActualDevice(virNetworkPtr net, - virDomainDefPtr dom, - virDomainNetDefPtr iface) +networkNotifyPort(virNetworkObjPtr obj, + virNetworkPortDefPtr port) { - virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj; virNetworkDefPtr netdef; virNetworkForwardIfDefPtr dev =3D NULL; - virNetworkPortDefPtr port =3D NULL; size_t i; int ret =3D -1; =20 - 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; - } - netdef =3D virNetworkObjGetDef(obj); =20 if (!virNetworkObjIsActive(obj)) { virReportError(VIR_ERR_OPERATION_INVALID, _("network '%s' is not active"), netdef->name); - goto error; - } - - 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_NETWORK: case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: @@ -4813,13 +4790,13 @@ networkNotifyActualDevice(virNetworkPtr net, if (!netdef->bridge) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unexpectedly got a network port without a ne= twork bridge")); - 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++) { @@ -4838,7 +4815,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 @@ -4854,14 +4831,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++) { @@ -4883,7 +4860,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 @@ -4899,7 +4876,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; @@ -4907,7 +4884,7 @@ networkNotifyActualDevice(virNetworkPtr net, case VIR_NETWORK_PORT_PLUG_TYPE_LAST: default: virReportEnumRangeError(virNetworkPortPlugType, port->plugtype); - goto error; + goto cleanup; } =20 netdef->connections++; @@ -4920,18 +4897,61 @@ 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); + ret =3D 0; + cleanup: + return ret; +} + + +static int +networkNotifyActualDevice(virNetworkPtr net, + virDomainDefPtr dom, + virDomainNetDefPtr iface) +{ + virNetworkDriverStatePtr driver =3D networkGetDriver(); + virNetworkObjPtr obj; + virNetworkDefPtr netdef; + virNetworkPortDefPtr port =3D NULL; + 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); + 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 cleanup; + } + + netdef =3D virNetworkObjGetDef(obj); + + if (!virNetworkObjIsActive(obj)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("network '%s' is not active"), + netdef->name); + goto cleanup; + } + + if (!(port =3D virDomainNetDefActualToNetworkPort(dom, iface))) + goto cleanup; + + if (networkNotifyPort(obj, port) < 0) + goto cleanup; + + ret =3D 0; cleanup: virNetworkObjEndAPI(&obj); 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