]> git.proxmox.com Git - qemu-server.git/commitdiff
add pve-bridge-hotplug script
authorAlexandre Derumier <aderumier@odiso.com>
Fri, 6 Nov 2015 14:05:59 +0000 (15:05 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 6 Nov 2015 15:22:54 +0000 (16:22 +0100)
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@odiso.com>
Makefile
PVE/QemuServer.pm
pve-bridge-hotplug [new file with mode: 0755]

index 1f87b04d58a77c32130f8fd86dd5e12e31f7c74e..b163455219b6d40703112259e7ac5c1cdbbc0ed6 100644 (file)
--- 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}
index feb9db1b11d72a8fcbf80af055fee0b1f9362845..a109ea90f09c574219b3803eba5c0f6b0eb5fa0b 100644 (file)
@@ -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 (executable)
index 0000000..2131db5
--- /dev/null
@@ -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;