[libvirt] [PATCH v2 08/15] conf: expand network device callbacks to cover resolving NIC type

Daniel P. Berrangé berrange at redhat.com
Wed Jan 31 16:21:30 UTC 2018


Currently the QEMU driver will call directly into the network driver
impl to modify resolve the atual type of NICs with type=network. 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é <berrange at redhat.com>
---
 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              |  4 +++-
 tests/qemuxml2argvtest.c       |  4 ++++
 9 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 61c36be025..fac08af52b 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -28806,6 +28806,7 @@ static virDomainNetNotifyActualDeviceImpl netNotify;
 static virDomainNetReleaseActualDeviceImpl netRelease;
 static virDomainNetBandwidthChangeAllowedImpl netBandwidthChangeAllowed;
 static virDomainNetBandwidthUpdateImpl netBandwidthUpdate;
+static virDomainNetResolveActualTypeImpl netResolveActualType;
 
 
 void
@@ -28813,13 +28814,15 @@ virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
                           virDomainNetNotifyActualDeviceImpl notify,
                           virDomainNetReleaseActualDeviceImpl release,
                           virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
-                          virDomainNetBandwidthUpdateImpl bandwidthUpdate)
+                          virDomainNetBandwidthUpdateImpl bandwidthUpdate,
+                          virDomainNetResolveActualTypeImpl resolveActualType)
 {
     netAllocate = allocate;
     netNotify = notify;
     netRelease = release;
     netBandwidthChangeAllowed = bandwidthChangeAllowed;
     netBandwidthUpdate = bandwidthUpdate;
+    netResolveActualType = resolveActualType;
 }
 
 int
@@ -28887,3 +28890,15 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
 
     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 dee49a2014..135b802731 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3474,13 +3474,17 @@ typedef int
 (*virDomainNetBandwidthUpdateImpl)(virDomainNetDefPtr iface,
                                    virNetDevBandwidthPtr newBandwidth);
 
+typedef int
+(*virDomainNetResolveActualTypeImpl)(virDomainNetDefPtr iface);
+
 
 void
 virDomainNetSetDeviceImpl(virDomainNetAllocateActualDeviceImpl allocate,
                           virDomainNetNotifyActualDeviceImpl notify,
                           virDomainNetReleaseActualDeviceImpl release,
                           virDomainNetBandwidthChangeAllowedImpl bandwidthChangeAllowed,
-                          virDomainNetBandwidthUpdateImpl bandwidthUpdate);
+                          virDomainNetBandwidthUpdateImpl bandwidthUpdate,
+                          virDomainNetResolveActualTypeImpl resolveActualType);
 
 int
 virDomainNetAllocateActualDevice(virDomainDefPtr dom,
@@ -3507,5 +3511,14 @@ virDomainNetBandwidthUpdate(virDomainNetDefPtr iface,
                             virNetDevBandwidthPtr newBandwidth)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
+/* 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);
+
 
 #endif /* __DOMAIN_CONF_H */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4cd96067a0..173226f31e 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -457,6 +457,7 @@ virDomainNetNotifyActualDevice;
 virDomainNetReleaseActualDevice;
 virDomainNetRemove;
 virDomainNetRemoveHostdev;
+virDomainNetResolveActualType;
 virDomainNetSetDeviceImpl;
 virDomainNetTypeFromString;
 virDomainNetTypeSharesHostView;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index ee200f1343..76747670e9 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -5105,8 +5105,7 @@ networkReleaseActualDevice(virDomainDefPtr dom,
 
 
 
-/* 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
@@ -5114,8 +5113,8 @@ networkReleaseActualDevice(virDomainDefPtr dom,
  *
  * Returns 0 on success, -1 on failure.
  */
-int
-networkGetActualType(virDomainNetDefPtr iface)
+static int
+networkResolveActualType(virDomainNetDefPtr iface)
 {
     virNetworkDriverStatePtr driver = networkGetDriver();
     virNetworkObjPtr obj = NULL;
@@ -5622,7 +5621,8 @@ networkRegister(void)
         networkNotifyActualDevice,
         networkReleaseActualDevice,
         networkBandwidthChangeAllowed,
-        networkBandwidthUpdate);
+        networkBandwidthUpdate,
+        networkResolveActualType);
 
     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);
 
 # if WITH_NETWORK
 
-int
-networkGetActualType(virDomainNetDefPtr iface)
-    ATTRIBUTE_NONNULL(1);
-
 int
 networkDnsmasqConfContents(virNetworkObjPtr obj,
                            const char *pidfile,
@@ -49,7 +45,6 @@ networkDnsmasqConfContents(virNetworkObjPtr obj,
 
 # 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
 
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 37fe2aa802..da71c6e7b7 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"
 
 #define QEMU_DRIVE_HOST_PREFIX "drive-"
 
@@ -275,7 +274,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) == VIR_DOMAIN_NET_TYPE_HOSTDEV)
+    if (virDomainNetResolveActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV)
         return qemuAssignDeviceHostdevAlias(def, &net->info.alias, -1);
 
     if (idx == -1) {
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 600de85f87..047cb29486 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -25,7 +25,6 @@
 
 #include "qemu_domain_address.h"
 #include "qemu_domain.h"
-#include "network/bridge_driver.h"
 #include "viralloc.h"
 #include "virerror.h"
 #include "virlog.h"
@@ -1053,7 +1052,7 @@ qemuDomainFillDeviceIsolationGroup(virDomainDefPtr def,
          * to is of type hostdev. All other kinds of network interfaces don't
          * require us to isolate the guest device, so we can skip them */
         if (iface->type != VIR_DOMAIN_NET_TYPE_NETWORK ||
-            networkGetActualType(iface) != VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+            virDomainNetResolveActualType(iface) != VIR_DOMAIN_NET_TYPE_HOSTDEV) {
             goto skip;
         }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 497bd21a25..d9b3a99477 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -582,7 +582,9 @@ qemucpumock_la_LIBADD = $(MOCKLIBS_LIBS)
 qemuxml2argvtest_SOURCES = \
 	qemuxml2argvtest.c testutilsqemu.c testutilsqemu.h \
 	testutils.c testutils.h
-qemuxml2argvtest_LDADD = libqemutestdriver.la $(LDADDS) $(LIBXML_LIBS)
+qemuxml2argvtest_LDADD = libqemutestdriver.la \
+	../src/libvirt_driver_network_impl.la \
+	$(LDADDS) $(LIBXML_LIBS)
 
 qemuxml2argvmock_la_SOURCES = \
 	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"
 
 # define __QEMU_CAPSPRIV_H_ALLOW__
@@ -580,6 +581,9 @@ mymain(void)
     if (qemuTestDriverInit(&driver) < 0)
         return EXIT_FAILURE;
 
+    if (networkRegister() < 0)
+        return EXIT_FAILURE;
+
     driver.privileged = true;
 
     VIR_FREE(driver.config->defaultTLSx509certdir);
-- 
2.14.3




More information about the libvir-list mailing list