[libvirt] [PATCH 3/3] network: properly check for taps that are connected to an OVS bridge

Laine Stump laine at laine.org
Sun Jul 1 23:46:58 UTC 2018


When libvirtd is restarted, it checks that each guest tap device is
still attached to the bridge device that the configuration info says
it should be connected to. If not, the tap will be disconnected from
[wherever it is] and connected to [wherever it should be].

The previous code that did this did not account for:

1) the IFLA_MASTER attribute in a netdev's ifinfo will be set to
   "ovs-system" for any tap device connected to an OVS bridge, *not*
   to the name of the bridge it is attached to.

2) virNetDevRemovePort() only works for devices that are attached to a
   standard Linux host bridge. If a device is currently attached to an
   OVS bridge, then virNetDevOpenvswitchRemovePort() must be called
   instead.

The result was an error message like this:

  error : virNetDevBridgeRemovePort:743 :
          Unable to remove bridge ovs-system port vnet1:
          Operation not supported

This patch remedies those problems, and adds a couple of information
log messages to aid in debugging any future problem.

Resolves: https://bugzilla.redhat.com/1596176
Signed-off-by: Laine Stump <laine at laine.org>
---
 src/network/bridge_driver.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index ac849581ec..da3c32e305 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -64,6 +64,7 @@
 #include "virnetdev.h"
 #include "virnetdevip.h"
 #include "virnetdevbridge.h"
+#include "virnetdevopenvswitch.h"
 #include "virnetdevtap.h"
 #include "virnetdevvportprofile.h"
 #include "virpci.h"
@@ -4823,19 +4824,35 @@ networkNotifyActualDevice(virDomainDefPtr dom,
 
     /* see if we're connected to the correct bridge */
     if (netdef->bridge) {
+        bool useOVS = false;
+
         if (virNetDevGetMaster(iface->ifname, &master) < 0)
             goto error;
 
+        /* IFLA_MASTER for a tap on an OVS switch is always "ovs-system" */
+        if (STREQ_NULLABLE(master, "ovs-system")) {
+            useOVS = true;
+            VIR_FREE(master);
+            if (virNetDevOpenvswitchInterfaceGetMaster(iface->ifname, &master) < 0)
+                goto error;
+        }
+
         if (STRNEQ_NULLABLE(netdef->bridge, master)) {
             /* disconnect from current (incorrect) bridge */
-            if (master)
-                ignore_value(virNetDevBridgeRemovePort(master, iface->ifname));
+            if (master) {
+                VIR_INFO("Removing %s from %s", iface->ifname, master);
+                if (useOVS)
+                    ignore_value(virNetDevOpenvswitchRemovePort(master, iface->ifname));
+                else
+                    ignore_value(virNetDevBridgeRemovePort(master, iface->ifname));
+            }
 
             /* attach/reattach to correct 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 virNetDevTapAttachBridge())
              */
+            VIR_INFO("Attaching %s to %s", iface->ifname, netdef->bridge);
             if (virNetDevTapAttachBridge(iface->ifname, netdef->bridge,
                                          &iface->mac, dom->uuid,
                                          virDomainNetGetActualVirtPortProfile(iface),
-- 
2.14.4




More information about the libvir-list mailing list