[pve-devel] [PATCH] add openvswitch support to tap_plug / tap_unplug
Alexandre Derumier
aderumier at odiso.com
Wed Dec 18 15:13:11 CET 2013
Note: I force removal of openvswitch tap configuration at begin of tap_plug,
because openvswitch don't auto-delete tap config on tap interface deletion.
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
data/PVE/Network.pm | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/data/PVE/Network.pm b/data/PVE/Network.pm
index 1b755c0..380b334 100644
--- a/data/PVE/Network.pm
+++ b/data/PVE/Network.pm
@@ -68,20 +68,36 @@ sub tap_create {
sub tap_plug {
my ($iface, $bridge, $tag) = @_;
- my $newbridge = activate_bridge_vlan($bridge, $tag);
- copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge;
-
- system ("/sbin/brctl addif $newbridge $iface") == 0 ||
- die "can't add interface to bridge\n";
+ #cleanup old port config from any openvswitch bridge
+ eval {run_command("/usr/bin/ovs-vsctl del-port $iface", outfunc => sub {}, errfunc => sub {}) };
+
+ if (-d "/sys/class/net/$bridge/bridge"){
+ my $newbridge = activate_bridge_vlan($bridge, $tag);
+ copy_bridge_config($bridge, $newbridge) if $bridge ne $newbridge;
+
+ system ("/sbin/brctl addif $newbridge $iface") == 0 ||
+ die "can't add interface to bridge\n";
+ }else{
+ my $cmd = "/usr/bin/ovs-vsctl add-port $bridge $iface";
+ $cmd .= " tag=$tag" if $tag;
+ system ($cmd) == 0 ||
+ die "can't add interface to bridge\n";
+ }
}
sub tap_unplug {
my ($iface, $bridge, $tag) = @_;
- $bridge .= "v$tag" if $tag;
+ if (-d "/sys/class/net/$bridge/bridge"){
- system ("/sbin/brctl delif $bridge $iface") == 0 ||
- die "can't del interface from bridge\n";
+ $bridge .= "v$tag" if $tag;
+
+ 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";
+ }
}
sub copy_bridge_config {
--
1.7.10.4
More information about the pve-devel
mailing list