[pve-devel] [PATCH 1/3] improve tap_unplug

Alexandre Derumier aderumier at odiso.com
Tue May 6 10:50:45 CEST 2014


and cleanup bridges

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 data/PVE/Network.pm |   57 +++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 49 insertions(+), 8 deletions(-)

diff --git a/data/PVE/Network.pm b/data/PVE/Network.pm
index 4677bf9..fa56c8b 100644
--- a/data/PVE/Network.pm
+++ b/data/PVE/Network.pm
@@ -88,17 +88,19 @@ sub tap_plug {
 }
 
 sub tap_unplug {
-    my ($iface, $bridge, $tag) = @_;
-
-    if (-d "/sys/class/net/$bridge/bridge") {
-	$bridge .= "v$tag" if $tag;
+    my ($iface, $bridge, $tag, $tapfirewall) = @_;
 
+    my $path= "/sys/class/net/$iface/brport/bridge";
+    if (-l $path) {
+	$bridge = basename(readlink($path));
+	#avoid insecure dependency;
+	($bridge) = $bridge =~ /(\S+)/;
 	system("/sbin/brctl delif $bridge $iface") == 0 ||
-	    die "can't del interface from bridge\n";
-    } else {
-	system ("/usr/bin/ovs-vsctl del-port $iface") == 0 ||
-	    die "can't del interface from bridge\n";
+	    die "can't del interface $iface from bridge $bridge\n";
     }
+
+    bridge_cleanup($iface);
+
 }
 
 sub copy_bridge_config {
@@ -193,4 +195,43 @@ sub activate_bridge_vlan {
     return $bridgevlan;
 }
 
+sub bridge_cleanup {
+    my ($iface) = @_;
+
+    my $iface_suffix = undef;
+    my $vmid = undef;
+
+    if ($iface =~ m/^tap((\d+)i(\d+))$/){
+	$iface_suffix = $1;
+	$vmid = $2;
+    }elsif ($iface =~ m/^veth((\d+)\.(\d+))$/){
+	$iface_suffix = $1;
+	$vmid = $2;
+    }else{
+	die "wrong interface name $iface";
+    }
+
+    my $ovsintport = "ovsint$iface_suffix";
+    my $vethfw = "link$iface_suffix";
+
+    eval {run_command("/usr/bin/ovs-vsctl del-port $iface", outfunc => sub {}, errfunc => sub {}) };
+
+    #cleanup old port config from any openvswitch bridge
+    if (-d "/sys/class/net/$ovsintport") {
+	eval {run_command("/usr/bin/ovs-vsctl del-port $ovsintport", outfunc => sub {}, errfunc => sub {}) };
+    }
+
+    #cleanup old vethfw interface
+    if (-d "/sys/class/net/$vethfw") {
+	run_command("/sbin/ip link delete dev $vethfw", outfunc => sub {}, errfunc => sub {});
+    }
+
+    my $bridgetap = "fwbr$iface_suffix";
+
+    # cleanup fwbrtap bridge
+    if (-d "/sys/class/net/$bridgetap") {
+	run_command("/sbin/ip link set dev $bridgetap down", outfunc => sub {}, errfunc => sub {});
+	run_command("/sbin/brctl delbr $bridgetap", outfunc => sub {}, errfunc => sub {});
+    }
+}
 1;
-- 
1.7.10.4




More information about the pve-devel mailing list