add bridge hotplug

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier 2012-08-20 13:06:59 +02:00 committed by Dietmar Maurer
parent 3c770faaf8
commit 40f28a9fd9

View File

@ -2350,6 +2350,8 @@ sub vm_deviceplug {
my $devices_list = vm_devices_list($vmid);
return 1 if defined($devices_list->{$deviceid});
qemu_bridgeadd($storecfg, $conf, $vmid, $deviceid); #add bridge if we need it for the device
if ($deviceid =~ m/^(virtio)(\d+)$/) {
return undef if !qemu_driveadd($storecfg, $vmid, $device);
my $devicefull = print_drivedevice_full($storecfg, $conf, $vmid, $device);
@ -2389,6 +2391,14 @@ sub vm_deviceplug {
}
}
if ($deviceid =~ m/^(pci\.)(\d+)$/) {
my $bridgeid = $2;
my $pciaddr = print_pci_addr($deviceid);
my $devicefull = "pci-bridge,id=pci.$bridgeid,chassis_nr=$bridgeid$pciaddr";
qemu_deviceadd($vmid, $devicefull);
return undef if !qemu_deviceaddverify($vmid, $deviceid);
}
return 1;
}
@ -2516,6 +2526,26 @@ sub qemu_findorcreatescsihw {
return 1;
}
sub qemu_bridgeadd {
my ($storecfg, $conf, $vmid, $device) = @_;
my $bridges = {};
my $bridgeid = undef;
print_pci_addr($device, $bridges);
while (my ($k, $v) = each %$bridges) {
$bridgeid = $k;
}
return if $bridgeid < 1;
my $bridge = "pci.$bridgeid";
my $devices_list = vm_devices_list($vmid);
if(!defined($devices_list->{$bridge})) {
return undef if !vm_deviceplug($storecfg, $conf, $vmid, $bridge);
}
return 1;
}
sub qemu_netdevadd {
my ($vmid, $conf, $device, $deviceid) = @_;