[libvirt] [PATCH v4 06/29] network: move re-attach of bridge device out of network driver

Daniel P. Berrangé berrange at redhat.com
Wed Apr 17 17:19:06 UTC 2019


During initial NIC setup the hypervisor drivers are responsible for
attaching the TAP device to the bridge device. Any fixup after libvirtd
restarts should thus also be their responsibility.

Reviewed-by: Laine Stump <laine at laine.org>
Signed-off-by: Daniel P. Berrangé <berrange at redhat.com>
---
 src/conf/domain_conf.c      | 20 +++++++++++++++++++-
 src/conf/domain_conf.h      |  2 +-
 src/network/bridge_driver.c | 27 ++++++---------------------
 3 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1dde45a6fd..b94b70aabc 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -54,6 +54,7 @@
 #include "virsecret.h"
 #include "virstring.h"
 #include "virnetdev.h"
+#include "virnetdevtap.h"
 #include "virnetdevmacvlan.h"
 #include "virhostdev.h"
 #include "virmdev.h"
@@ -30444,8 +30445,25 @@ virDomainNetNotifyActualDevice(virConnectPtr conn,
     if (!(net = virNetworkLookupByName(conn, iface->data.network.name)))
         return;
 
-    netNotify(net, dom, iface);
+    if (netNotify(net, dom, iface) < 0)
+        goto cleanup;
+
+    if (virDomainNetGetActualType(iface) == VIR_DOMAIN_NET_TYPE_BRIDGE) {
+        /*
+         * NB: we can't notify the guest of any MTU change anyway,
+         * so there is no point in trying to learn the actualMTU
+         * (final arg to virNetDevTapReattachBridge())
+         */
+        if (virNetDevTapReattachBridge(iface->ifname,
+                                       iface->data.network.actual->data.bridge.brname,
+                                       &iface->mac, dom->uuid,
+                                       virDomainNetGetActualVirtPortProfile(iface),
+                                       virDomainNetGetActualVlan(iface),
+                                       iface->mtu, NULL) < 0)
+            goto cleanup;
+    }
 
+ cleanup:
     virObjectUnref(net);
 }
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5910ed0beb..fb053a7ca3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3552,7 +3552,7 @@ typedef int
                                         virDomainDefPtr dom,
                                         virDomainNetDefPtr iface);
 
-typedef void
+typedef int
 (*virDomainNetNotifyActualDeviceImpl)(virNetworkPtr net,
                                       virDomainDefPtr dom,
                                       virDomainNetDefPtr iface);
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 4055939ade..8b36376761 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -4793,12 +4793,11 @@ networkAllocateActualDevice(virNetworkPtr net,
  * 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, or re-attach the interface's tap device to the network's
- * bridge.
+ * order.
  *
- * No return value (but does log any failures)
+ * Returns 0 on success, -1 on failure.
  */
-static void
+static int
 networkNotifyActualDevice(virNetworkPtr net,
                           virDomainDefPtr dom,
                           virDomainNetDefPtr iface)
@@ -4809,6 +4808,7 @@ networkNotifyActualDevice(virNetworkPtr net,
     virNetworkDefPtr netdef;
     virNetworkForwardIfDefPtr dev = NULL;
     size_t i;
+    int ret = -1;
 
     obj = virNetworkObjFindByName(driver->networks, net->name);
     if (!obj) {
@@ -4833,22 +4833,6 @@ networkNotifyActualDevice(virNetworkPtr net,
         goto error;
     }
 
-    /* see if we're connected to the correct bridge */
-    if (netdef->bridge) {
-        /*
-         * NB: we can't notify the guest of any MTU change anyway,
-         * so there is no point in trying to learn the actualMTU
-         * (final arg to virNetDevTapReattachBridge())
-         */
-        if (virNetDevTapReattachBridge(iface->ifname, netdef->bridge,
-                                       &iface->mac, dom->uuid,
-                                       virDomainNetGetActualVirtPortProfile(iface),
-                                       virDomainNetGetActualVlan(iface),
-                                       iface->mtu, NULL) < 0) {
-            goto error;
-        }
-    }
-
     if (!iface->data.network.actual ||
         (actualType != VIR_DOMAIN_NET_TYPE_DIRECT &&
          actualType != VIR_DOMAIN_NET_TYPE_HOSTDEV)) {
@@ -4977,10 +4961,11 @@ networkNotifyActualDevice(virNetworkPtr net,
         goto error;
     }
     networkLogAllocation(netdef, actualType, dev, iface, true);
+    ret = 0;
 
  cleanup:
     virNetworkObjEndAPI(&obj);
-    return;
+    return ret;
 
  error:
     goto cleanup;
-- 
2.20.1




More information about the libvir-list mailing list