add pve-bridge-hotplug script

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>
This commit is contained in:
Alexandre Derumier 2015-11-06 15:05:59 +01:00 committed by Dietmar Maurer
parent 8718099ce4
commit 208ba94e96
3 changed files with 44 additions and 3 deletions

View File

@ -93,6 +93,7 @@ install: ${PKGSOURCES}
install -m 0755 qm ${DESTDIR}${SBINDIR} install -m 0755 qm ${DESTDIR}${SBINDIR}
install -m 0755 qmrestore ${DESTDIR}${SBINDIR} install -m 0755 qmrestore ${DESTDIR}${SBINDIR}
install -m 0755 pve-bridge ${DESTDIR}${VARLIBDIR}/pve-bridge 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 -m 0755 pve-bridgedown ${DESTDIR}${VARLIBDIR}/pve-bridgedown
install -s -m 0755 vmtar ${DESTDIR}${LIBDIR} install -s -m 0755 vmtar ${DESTDIR}${LIBDIR}
install -s -m 0755 sparsecp ${DESTDIR}${LIBDIR} install -s -m 0755 sparsecp ${DESTDIR}${LIBDIR}

View File

@ -1257,7 +1257,7 @@ sub print_netdevice_full {
} }
sub print_netdev_full { sub print_netdev_full {
my ($vmid, $conf, $net, $netid) = @_; my ($vmid, $conf, $net, $netid, $hotplug) = @_;
my $i = ''; my $i = '';
if ($netid =~ m/^net(\d+)$/) { if ($netid =~ m/^net(\d+)$/) {
@ -1278,9 +1278,10 @@ sub print_netdev_full {
my $vmname = $conf->{name} || "vm$vmid"; my $vmname = $conf->{name} || "vm$vmid";
my $netdev = ""; my $netdev = "";
my $script = $hotplug ? "pve-bridge-hotplug" : "pve-bridge";
if ($net->{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 { } else {
$netdev = "type=user,id=$netid,hostname=$vmname"; $netdev = "type=user,id=$netid,hostname=$vmname";
} }
@ -3599,7 +3600,7 @@ sub qemu_set_link_status {
sub qemu_netdevadd { sub qemu_netdevadd {
my ($vmid, $conf, $device, $deviceid) = @_; 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); my %options = split(/[=,]/, $netdev);
vm_mon_cmd($vmid, "netdev_add", %options); vm_mon_cmd($vmid, "netdev_add", %options);

39
pve-bridge-hotplug Executable file
View File

@ -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;