From nobody Wed Dec 17 06:08:43 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 1517844542401237.00801161323625; Mon, 5 Feb 2018 07:29:02 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3967318B257; Mon, 5 Feb 2018 15:29:01 +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 F323E5C54F; Mon, 5 Feb 2018 15:29:00 +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 A50F318033E2; Mon, 5 Feb 2018 15:29:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w15FSmRx002877 for ; Mon, 5 Feb 2018 10:28:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 21D865EE15; Mon, 5 Feb 2018 15:28:48 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id C087F5EDEA; Mon, 5 Feb 2018 15:28:46 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 5 Feb 2018 15:28:22 +0000 Message-Id: <20180205152829.12577-9-berrange@redhat.com> In-Reply-To: <20180205152829.12577-1-berrange@redhat.com> References: <20180205152829.12577-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v3 08/15] conf: expand network device callbacks to cover resolving NIC type 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 05 Feb 2018 15:29:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Currently the QEMU driver will call directly into the network driver impl to modify resolve the atual type of NICs with type=3Dnetwork. It has todo this before it has allocated the actual NIC. This introduces a callback system to allow us to decouple the QEMU driver from the network driver. This is a short term step, as it ought to be possible to achieve the same end goal by simply querying XML via the public network API. The QEMU code in question though, has no virConnectPtr conveniently available at this time. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/conf/domain_conf.c | 17 ++++++++++++++++- src/conf/domain_conf.h | 15 ++++++++++++++- src/libvirt_private.syms | 1 + src/network/bridge_driver.c | 10 +++++----- src/network/bridge_driver.h | 5 ----- src/qemu/qemu_alias.c | 3 +-- src/qemu/qemu_domain_address.c | 3 +-- tests/Makefile.am | 11 +++++++++-- tests/qemuxml2argvtest.c | 4 ++++ 9 files changed, 51 insertions(+), 18 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 205f99618d..80d349fc5a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28822,6 +28822,7 @@ static virDomainNetNotifyActualDeviceImpl netNotify; static virDomainNetReleaseActualDeviceImpl netRelease; static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed; static virDomainNetBandwidthUpdateImpl netBandwidthUpdate; +static virDomainNetResolveActualTypeImpl netResolveActualType; =20 =20 void @@ -28829,13 +28830,15 @@ virDomainNetSetDeviceImpl(virDomainNetAllocateAct= ualDeviceImpl allocate, virDomainNetNotifyActualDeviceImpl notify, virDomainNetReleaseActualDeviceImpl release, virDomainNetBandwidthChangeAllowedImpl bandwidth= ChangeAllowed, - virDomainNetBandwidthUpdateImpl bandwidthUpdate) + virDomainNetBandwidthUpdateImpl bandwidthUpdate, + virDomainNetResolveActualTypeImpl resolveActualT= ype) { netAllocate =3D allocate; netNotify =3D notify; netRelease =3D release; netBandwidthChangeAllowed =3D bandwidthChangeAllowed; netBandwidthUpdate =3D bandwidthUpdate; + netResolveActualType =3D resolveActualType; } =20 int @@ -28903,3 +28906,15 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr ifa= ce, =20 return netBandwidthUpdate(iface, newBandwidth); } + +int +virDomainNetResolveActualType(virDomainNetDefPtr iface) +{ + if (!netResolveActualType) { + virReportError(VIR_ERR_NO_SUPPORT, "%s", + _("Network device resolve type not available")); + return -1; + } + + return netResolveActualType(iface); +} diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 32948e181c..7a2f434ec8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3474,13 +3474,17 @@ 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); + virDomainNetBandwidthUpdateImpl bandwidthUpdate, + virDomainNetResolveActualTypeImpl resolveActualT= ype); =20 int virDomainNetAllocateActualDevice(virDomainDefPtr dom, @@ -3507,5 +3511,14 @@ 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); + =20 #endif /* __DOMAIN_CONF_H */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 45ae25e57c..f2801a0d73 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -459,6 +459,7 @@ virDomainNetNotifyActualDevice; virDomainNetReleaseActualDevice; virDomainNetRemove; virDomainNetRemoveHostdev; +virDomainNetResolveActualType; virDomainNetSetDeviceImpl; virDomainNetTypeFromString; virDomainNetTypeSharesHostView; diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index 9c0b3c0895..dd6e3402ea 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -5147,8 +5147,7 @@ networkReleaseActualDevice(virDomainDefPtr dom, =20 =20 =20 -/* networkGetActualType: - * @dom: domain definition that @iface belongs to +/* networkResolveActualType: * @iface: the original NetDef from the domain * * Looks up the network reference by iface, and returns the actual @@ -5156,8 +5155,8 @@ networkReleaseActualDevice(virDomainDefPtr dom, * * Returns 0 on success, -1 on failure. */ -int -networkGetActualType(virDomainNetDefPtr iface) +static int +networkResolveActualType(virDomainNetDefPtr iface) { virNetworkDriverStatePtr driver =3D networkGetDriver(); virNetworkObjPtr obj =3D NULL; @@ -5718,7 +5717,8 @@ networkRegister(void) networkNotifyActualDevice, networkReleaseActualDevice, networkBandwidthChangeAllowed, - networkBandwidthUpdate); + networkBandwidthUpdate, + networkResolveActualType); =20 return 0; } diff --git a/src/network/bridge_driver.h b/src/network/bridge_driver.h index 6fa6432d13..2cf886a7e6 100644 --- a/src/network/bridge_driver.h +++ b/src/network/bridge_driver.h @@ -36,10 +36,6 @@ networkRegister(void); =20 # if WITH_NETWORK =20 -int -networkGetActualType(virDomainNetDefPtr iface) - ATTRIBUTE_NONNULL(1); - int networkDnsmasqConfContents(virNetworkObjPtr obj, const char *pidfile, @@ -49,7 +45,6 @@ networkDnsmasqConfContents(virNetworkObjPtr obj, =20 # else /* Define no-op replacements that don't drag in any link dependencies. */ -# define networkGetActualType(iface) (iface->type) # define networkDnsmasqConfContents(network, pidfile, configstr, \ dctx, caps) 0 =20 diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index e8c1256b75..ae30f7df82 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -27,7 +27,6 @@ #include "viralloc.h" #include "virlog.h" #include "virstring.h" -#include "network/bridge_driver.h" =20 #define QEMU_DRIVE_HOST_PREFIX "drive-" =20 @@ -271,7 +270,7 @@ qemuAssignDeviceNetAlias(virDomainDefPtr def, * We must use "-1" as the index because the caller doesn't know * that we're now looking for a unique hostdevN rather than netN */ - if (networkGetActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) + if (virDomainNetResolveActualType(net) =3D=3D VIR_DOMAIN_NET_TYPE_HOST= DEV) return qemuAssignDeviceHostdevAlias(def, &net->info.alias, -1); =20 if (idx =3D=3D -1) { diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 6272b1e91d..e28119e4b1 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -25,7 +25,6 @@ =20 #include "qemu_domain_address.h" #include "qemu_domain.h" -#include "network/bridge_driver.h" #include "viralloc.h" #include "virerror.h" #include "virlog.h" @@ -1064,7 +1063,7 @@ qemuDomainFillDeviceIsolationGroup(virDomainDefPtr de= f, * to is of type hostdev. All other kinds of network interfaces do= n't * require us to isolate the guest device, so we can skip them */ if (iface->type !=3D VIR_DOMAIN_NET_TYPE_NETWORK || - networkGetActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV) { + virDomainNetResolveActualType(iface) !=3D VIR_DOMAIN_NET_TYPE_= HOSTDEV) { goto skip; } =20 diff --git a/tests/Makefile.am b/tests/Makefile.am index 497bd21a25..d013aed5eb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -280,7 +280,7 @@ test_libraries +=3D virmocklibxl.la endif WITH_LIBXL =20 if WITH_QEMU -test_programs +=3D qemuxml2argvtest qemuxml2xmltest \ +test_programs +=3D qemuxml2xmltest \ qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \ qemumonitortest qemumonitorjsontest qemuhotplugtest \ qemuagenttest qemucapabilitiestest qemucaps2xmltest \ @@ -288,6 +288,11 @@ test_programs +=3D qemuxml2argvtest qemuxml2xmltest \ qemucommandutiltest \ qemublocktest \ $(NULL) +if WITH_NETWORK +# Dep on the network driver callback for resolving NIC +# actual type. XXX remove this dep. +test_programs +=3D qemuxml2xmltest +endif WITH_NETWORK test_helpers +=3D qemucapsprobe test_libraries +=3D libqemumonitortestutils.la \ libqemutestdriver.la \ @@ -582,7 +587,9 @@ qemucpumock_la_LIBADD =3D $(MOCKLIBS_LIBS) qemuxml2argvtest_SOURCES =3D \ qemuxml2argvtest.c testutilsqemu.c testutilsqemu.h \ testutils.c testutils.h -qemuxml2argvtest_LDADD =3D libqemutestdriver.la $(LDADDS) $(LIBXML_LIBS) +qemuxml2argvtest_LDADD =3D libqemutestdriver.la \ + ../src/libvirt_driver_network_impl.la \ + $(LDADDS) $(LIBXML_LIBS) =20 qemuxml2argvmock_la_SOURCES =3D \ qemuxml2argvmock.c diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index c8739909de..b341467143 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -25,6 +25,7 @@ # include "cpu/cpu_map.h" # include "virstring.h" # include "storage/storage_driver.h" +# include "network/bridge_driver.h" # include "virmock.h" =20 # define __QEMU_CAPSPRIV_H_ALLOW__ @@ -580,6 +581,9 @@ mymain(void) if (qemuTestDriverInit(&driver) < 0) return EXIT_FAILURE; =20 + if (networkRegister() < 0) + return EXIT_FAILURE; + driver.privileged =3D true; =20 VIR_FREE(driver.config->defaultTLSx509certdir); --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list