[pve-devel] [PATCH] add pve-bridge-hotplug script

Alexandre Derumier aderumier at odiso.com
Fri Nov 6 15:05:59 CET 2015


use it for nic hotplug, because pve-bridge script will
not work after a live migration, because of the PVE_MIGRATED_FROM env var.

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 Makefile           |  1 +
 PVE/QemuServer.pm  |  7 ++++---
 pve-bridge-hotplug | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 3 deletions(-)
 create mode 100755 pve-bridge-hotplug

diff --git a/Makefile b/Makefile
index 1f87b04..b163455 100644
--- a/Makefile
+++ b/Makefile
@@ -93,6 +93,7 @@ install: ${PKGSOURCES}
 	install -m 0755 qm ${DESTDIR}${SBINDIR}
 	install -m 0755 qmrestore ${DESTDIR}${SBINDIR}
 	install -m 0755 pve-bridge ${DESTDIR}${VARLIBDIR}/pve-bridge
+	install -m 0755 pve-bridge-hotplug ${DESTDIR}${VARLIBDIR}/pve-bridge-hotplug
 	install -m 0755 pve-bridgedown ${DESTDIR}${VARLIBDIR}/pve-bridgedown
 	install -s -m 0755 vmtar ${DESTDIR}${LIBDIR}
 	install -s -m 0755 sparsecp ${DESTDIR}${LIBDIR}
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index feb9db1..a109ea9 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1257,7 +1257,7 @@ sub print_netdevice_full {
 }
 
 sub print_netdev_full {
-    my ($vmid, $conf, $net, $netid) = @_;
+    my ($vmid, $conf, $net, $netid, $hotplug) = @_;
 
     my $i = '';
     if ($netid =~ m/^net(\d+)$/) {
@@ -1278,9 +1278,10 @@ sub print_netdev_full {
     my $vmname = $conf->{name} || "vm$vmid";
 
     my $netdev = "";
+    my $script = $hotplug ? "pve-bridge-hotplug" : "pve-bridge";
 
     if ($net->{bridge}) {
-        $netdev = "type=tap,id=$netid,ifname=${ifname},script=/var/lib/qemu-server/pve-bridge,downscript=/var/lib/qemu-server/pve-bridgedown$vhostparam";
+        $netdev = "type=tap,id=$netid,ifname=${ifname},script=/var/lib/qemu-server/$script,downscript=/var/lib/qemu-server/pve-bridgedown$vhostparam";
     } else {
         $netdev = "type=user,id=$netid,hostname=$vmname";
     }
@@ -3599,7 +3600,7 @@ sub qemu_set_link_status {
 sub qemu_netdevadd {
     my ($vmid, $conf, $device, $deviceid) = @_;
 
-    my $netdev = print_netdev_full($vmid, $conf, $device, $deviceid);
+    my $netdev = print_netdev_full($vmid, $conf, $device, $deviceid, 1);
     my %options =  split(/[=,]/, $netdev);
 
     vm_mon_cmd($vmid, "netdev_add",  %options);
diff --git a/pve-bridge-hotplug b/pve-bridge-hotplug
new file mode 100755
index 0000000..2131db5
--- /dev/null
+++ b/pve-bridge-hotplug
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use PVE::QemuServer;
+use PVE::Tools qw(run_command);
+use PVE::Network;
+
+my $iface = shift;
+
+die "no interface specified\n" if !$iface;
+
+die "got strange interface name '$iface'\n" 
+    if $iface !~ m/^tap(\d+)i(\d+)$/;
+
+my $vmid = $1;
+my $netid = "net$2";
+
+my $conf = PVE::QemuServer::load_config($vmid);
+
+my $netconf = $conf->{$netid};
+
+$netconf = $conf->{pending}->{$netid} if defined($conf->{pending}->{$netid}); 
+ 
+die "unable to get network config '$netid'\n"
+    if !defined($netconf);
+
+my $net = PVE::QemuServer::parse_net($netconf);
+die "unable to parse network config '$netid'\n" if !$net;
+
+PVE::Network::tap_create($iface, $net->{bridge});
+
+# if ovs is under this bridge all traffic control settings will be flushed.
+# so we need to call tap_rate_limit after tap_plug
+PVE::Network::tap_plug($iface, $net->{bridge}, $net->{tag}, $net->{firewall});
+
+PVE::Network::tap_rate_limit($iface, $net->{rate}) if $net->{rate};
+
+exit 0;
-- 
2.1.4



More information about the pve-devel mailing list