Olaf Hering wrote:
> I'm about to remove /etc/sysconfig/network/if-up.d/xen which is supposed
> to collect vif* and tap* interfaces connected to a bridge interface.
> Right now it runs only when xend is running, and today wicked will not call
> such scripts anyway.
>   

Ah, interesting.  I didn't know those would no longer be called.

> I wonder how KVM deals with disappearing bridges?

It doesn't.

>  In the end any
> replacement script can very well handle KVM, Xen and whatever host type
> is in use. So a Xen specific tool is not required.
>   

Agreed.  I now recall brief discussions with Marius around this topic. 
In fact, I even created a hack in libvirt (attached) to record the
adding/removing of vif/tap devices from the bridge.  I never got around
to thoroughly testing this hack to gain enough confidence to add it to
our libvirt package.

Jim

commit 9a06bafecb099a7879cb92fd6026db9ec594a643
Author: Jim Fehlig <[email protected]>
Date:   Wed Jun 19 10:16:04 2013 -0600

    Register ports connected to a bridge
    
    When connecting a port to a bridge, register the connection
    in a well-known location (/var/lib/run/libvirt/port_registration/$portname).
    Remove the registration when the port is removed from the bridge.
    
    Hypervisor drivers that use virNetDevBridge{Add,Remove}Port() will have
    their virtual interfaces which connect to bridges registered, allowing
    reconnection of those interfaces upon bridge restart.

diff --git a/src/util/virnetdevbridge.c b/src/util/virnetdevbridge.c
index 130829c..9956b50 100644
--- a/src/util/virnetdevbridge.c
+++ b/src/util/virnetdevbridge.c
@@ -34,6 +34,9 @@
 #include <sys/socket.h>
 #include <net/if.h>
 #include <netinet/in.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #ifdef __linux__
 # include <linux/sockios.h>
@@ -296,6 +299,8 @@ int virNetDevBridgeAddPort(const char *brname,
     int fd = -1;
     int ret = -1;
     struct ifreq ifr;
+    char *reg_path;
+    int reg_fd;
 
     if ((fd = virNetDevSetupControl(brname, &ifr)) < 0)
         return -1;
@@ -312,6 +317,20 @@ int virNetDevBridgeAddPort(const char *brname,
         goto cleanup;
     }
 
+    /*
+     * Register the port in a well known location so it can be reconnected
+     * when the hosting bridge is restarted.
+     */
+    if (virAsprintf(&reg_path,
+                    "/var/run/libvirt/port_registrations/%s",
+                    ifname) > 0) {
+        if ((reg_fd = open(reg_path, O_CREAT)) > 0) {
+            ignore_value(safewrite(reg_fd, brname, strlen(brname)));
+            VIR_FORCE_CLOSE(reg_fd);
+        }
+        VIR_FREE(reg_path);
+    }
+
     ret = 0;
 cleanup:
     VIR_FORCE_CLOSE(fd);
@@ -343,6 +362,17 @@ int virNetDevBridgeRemovePort(const char *brname,
     int fd = -1;
     int ret = -1;
     struct ifreq ifr;
+    char *reg_path;
+
+    /*
+     * Remove any port registration.
+     */
+    if (virAsprintf(&reg_path,
+                    "/var/run/libvirt/port_registrations/%s",
+                    ifname) > 0) {
+        ignore_value(unlink(reg_path));
+        VIR_FREE(reg_path);
+    }
 
     if ((fd = virNetDevSetupControl(brname, &ifr)) < 0)
         return -1;

Reply via email to