From nobody Wed May 14 18:21:58 2025 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 1518197071577356.2048128334121; Fri, 9 Feb 2018 09:24:31 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 08F906B228; Fri, 9 Feb 2018 17:24:30 +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 9EF2360C89; Fri, 9 Feb 2018 17:24:29 +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 2600118033DF; Fri, 9 Feb 2018 17:24:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w19HOQsg030766 for ; Fri, 9 Feb 2018 12:24:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4D762F41DD; Fri, 9 Feb 2018 17:24:26 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8BB4CFA28B; Fri, 9 Feb 2018 17:24:25 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Fri, 9 Feb 2018 17:24:14 +0000 Message-Id: <20180209172419.3089-2-berrange@redhat.com> In-Reply-To: <20180209172419.3089-1-berrange@redhat.com> References: <20180209172419.3089-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/6] conf: reimplement virDomainNetResolveActualType in terms of public API 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 09 Feb 2018 17:24:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Now that we have the ability to easily open connections to secondary drivers, eg network:///system, it is possible to reimplement the virDomainNetResolveActualType method in terms of the public API. This avoids the need to have the network driver provide a callback for it. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: John Ferlan --- src/conf/domain_conf.c | 80 ++++++++++++++++++++++++++++++++++++++++-= ---- src/conf/domain_conf.h | 11 +------ src/network/bridge_driver.c | 76 +----------------------------------------- 3 files changed, 74 insertions(+), 93 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fb732a0c2a..4f50547580 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28823,7 +28823,6 @@ static virDomainNetNotifyActualDeviceImpl netNotify; static virDomainNetReleaseActualDeviceImpl netRelease; static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed; static virDomainNetBandwidthUpdateImpl netBandwidthUpdate; -static virDomainNetResolveActualTypeImpl netResolveActualType; =20 =20 void @@ -28831,15 +28830,13 @@ virDomainNetSetDeviceImpl(virDomainNetAllocateAct= ualDeviceImpl allocate, virDomainNetNotifyActualDeviceImpl notify, virDomainNetReleaseActualDeviceImpl release, virDomainNetBandwidthChangeAllowedImpl bandwidth= ChangeAllowed, - virDomainNetBandwidthUpdateImpl bandwidthUpdate, - virDomainNetResolveActualTypeImpl resolveActualT= ype) + virDomainNetBandwidthUpdateImpl bandwidthUpdate) { netAllocate =3D allocate; netNotify =3D notify; netRelease =3D release; netBandwidthChangeAllowed =3D bandwidthChangeAllowed; netBandwidthUpdate =3D bandwidthUpdate; - netResolveActualType =3D resolveActualType; } =20 int @@ -28908,16 +28905,83 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr if= ace, return netBandwidthUpdate(iface, newBandwidth); } =20 +/* virDomainNetResolveActualType: + * @iface: the original NetDef from the domain + * + * Looks up the network reference by iface, and returns the actual + * type of the connection without allocating any resources. + * + * Returns 0 on success, -1 on failure. + */ int virDomainNetResolveActualType(virDomainNetDefPtr iface) { - if (!netResolveActualType) { - virReportError(VIR_ERR_NO_SUPPORT, "%s", - _("Network device resolve type not available")); + virConnectPtr conn =3D NULL; + virNetworkPtr net =3D NULL; + char *xml =3D NULL; + virNetworkDefPtr def =3D NULL; + int ret =3D -1; + + if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) + return iface->type; + + if (iface->data.network.actual) + return iface->data.network.actual->type; + + if (!(conn =3D virGetConnectNetwork())) return -1; + + if (!(net =3D virNetworkLookupByName(conn, iface->data.network.name))) + goto cleanup; + + if (!(xml =3D virNetworkGetXMLDesc(net, 0))) + goto cleanup; + + if (!(def =3D virNetworkDefParseString(xml))) + goto cleanup; + + if ((def->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE) || + (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT) || + (def->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE) || + (def->forward.type =3D=3D VIR_NETWORK_FORWARD_OPEN)) { + /* for these forward types, the actual net type really *is* + * NETWORK; we just keep the info from the portgroup in + * iface->data.network.actual + */ + ret =3D VIR_DOMAIN_NET_TYPE_NETWORK; + + } else if ((def->forward.type =3D=3D VIR_NETWORK_FORWARD_BRIDGE) && + def->bridge) { + + /* + * is VIR_DOMAIN_NET_TYPE_BRIDGE + */ + + ret =3D VIR_DOMAIN_NET_TYPE_BRIDGE; + + } else if (def->forward.type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV) { + + ret =3D VIR_DOMAIN_NET_TYPE_HOSTDEV; + + } else if ((def->forward.type =3D=3D VIR_NETWORK_FORWARD_BRIDGE) || + (def->forward.type =3D=3D VIR_NETWORK_FORWARD_PRIVATE) || + (def->forward.type =3D=3D VIR_NETWORK_FORWARD_VEPA) || + (def->forward.type =3D=3D VIR_NETWORK_FORWARD_PASSTHROUGH))= { + + /* are all + * VIR_DOMAIN_NET_TYPE_DIRECT. + */ + + ret =3D VIR_DOMAIN_NET_TYPE_DIRECT; + } =20 - return netResolveActualType(iface); + cleanup: + virNetworkDefFree(def); + VIR_FREE(xml); + virObjectUnref(conn); + virObjectUnref(net); + return ret; } =20 =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6cd81ef2de..7b450ce8f1 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3476,17 +3476,13 @@ typedef int (*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface, virNetDevBandwidthPtr newBandwidth); =20 -typedef int -(*virDomainNetResolveActualTypeImpl)(virDomainNetDefPtr iface); - =20 void virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate, virDomainNetNotifyActualDeviceImpl notify, virDomainNetReleaseActualDeviceImpl release, virDomainNetBandwidthChangeAllowedImpl bandwidth= ChangeAllowed, - virDomainNetBandwidthUpdateImpl bandwidthUpdate, - virDomainNetResolveActualTypeImpl resolveActualT= ype); + virDomainNetBandwidthUpdateImpl bandwidthUpdate); =20 int virDomainNetAllocateActualDevice(virDomainDefPtr dom, @@ -3513,11 +3509,6 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface, virNetDevBandwidthPtr newBandwidth) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 -/* XXX this is a nasty hack and should be removed. It should - * be by via public API by fetching XML and parsing it. Not - * easy right now as code paths in QEMU reying on this don't - * have a virConnectPtr handy. - */ int virDomainNetResolveActualType(virDomainNetDefPtr iface) ATTRIBUTE_NONNULL(1); diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index dd6e3402ea..898c946101 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5146,79 +5146,6 @@ networkReleaseActualDevice(virDomainDefPtr dom, } =20 =20 - -/* networkResolveActualType: - * @iface: the original NetDef from the domain - * - * Looks up the network reference by iface, and returns the actual - * type of the connection without allocating any resources. - * - * Returns 0 on success, -1 on failure. - */ -static int -networkResolveActualType(virDomainNetDefPtr iface) -{ - virNetworkDriverStatePtr driver =3D networkGetDriver(); - virNetworkObjPtr obj =3D NULL; - virNetworkDefPtr netdef =3D NULL; - int ret =3D -1; - - if (!driver || iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK) - return iface->type; - - if (iface->data.network.actual) - return iface->data.network.actual->type; - - obj =3D virNetworkObjFindByName(driver->networks, iface->data.network.= name); - if (!obj) { - virReportError(VIR_ERR_NO_NETWORK, - _("no network with matching name '%s'"), - iface->data.network.name); - return -1; - } - netdef =3D virNetworkObjGetDef(obj); - - if ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_NONE) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_ROUTE) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_OPEN)) { - /* for these forward types, the actual net type really *is* - * NETWORK; we just keep the info from the portgroup in - * iface->data.network.actual - */ - ret =3D VIR_DOMAIN_NET_TYPE_NETWORK; - - } else if ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_BRIDGE) && - netdef->bridge) { - - /* - * is VIR_DOMAIN_NET_TYPE_BRIDGE - */ - - ret =3D VIR_DOMAIN_NET_TYPE_BRIDGE; - - } else if (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_HOSTDEV) { - - ret =3D VIR_DOMAIN_NET_TYPE_HOSTDEV; - - } else if ((netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_BRIDGE) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PRIVATE) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_VEPA) || - (netdef->forward.type =3D=3D VIR_NETWORK_FORWARD_PASSTHROUG= H)) { - - /* are all - * VIR_DOMAIN_NET_TYPE_DIRECT. - */ - - ret =3D VIR_DOMAIN_NET_TYPE_DIRECT; - - } - - virNetworkObjEndAPI(&obj); - return ret; -} - - /** * networkCheckBandwidth: * @net: network QoS @@ -5717,8 +5644,7 @@ networkRegister(void) networkNotifyActualDevice, networkReleaseActualDevice, networkBandwidthChangeAllowed, - networkBandwidthUpdate, - networkResolveActualType); + networkBandwidthUpdate); =20 return 0; } --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list