From f721624b8ea9b2550a22a172aa7ec5ad08bc7f37 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Thu, 12 Apr 2018 17:04:56 +0200 Subject: [PATCH] collect device list for nested pci-bridges when using q35 as machine type, there are nested pci-bridges, but we only checked the first layer this resulted in not being able to hotplug scsi devices, because scsihw0 was deeper in the pci-bridge construct, we did not see it and tried to add it (which fails of course) this patch checks all bridges, regardless how deeply nested they are Signed-off-by: Dominik Csapak --- PVE/QemuServer.pm | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 7e531b0c..015c7251 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -3601,21 +3601,22 @@ sub vm_devices_list { my ($vmid) = @_; my $res = vm_mon_cmd($vmid, 'query-pci'); + my $devices_to_check = []; my $devices = {}; foreach my $pcibus (@$res) { - foreach my $device (@{$pcibus->{devices}}) { - next if !$device->{'qdev_id'}; - if ($device->{'pci_bridge'}) { - $devices->{$device->{'qdev_id'}} = 1; - foreach my $bridge_device (@{$device->{'pci_bridge'}->{devices}}) { - next if !$bridge_device->{'qdev_id'}; - $devices->{$bridge_device->{'qdev_id'}} = 1; - $devices->{$device->{'qdev_id'}}++; - } - } else { - $devices->{$device->{'qdev_id'}} = 1; - } + push @$devices_to_check, @{$pcibus->{devices}}, + } + + while (@$devices_to_check) { + my $to_check = []; + for my $d (@$devices_to_check) { + $devices->{$d->{'qdev_id'}} = 1 if $d->{'qdev_id'}; + next if !$d->{'pci_bridge'}; + + $devices->{$d->{'qdev_id'}} += scalar(@{$d->{'pci_bridge'}->{devices}}); + push @$to_check, @{$d->{'pci_bridge'}->{devices}}; } + $devices_to_check = $to_check; } my $resblock = vm_mon_cmd($vmid, 'query-block'); -- 2.39.5