]> git.proxmox.com Git - qemu-server.git/commitdiff
collect device list for nested pci-bridges
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 12 Apr 2018 15:04:56 +0000 (17:04 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 13 Apr 2018 12:44:22 +0000 (14:44 +0200)
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 <d.csapak@proxmox.com>
PVE/QemuServer.pm

index 7e531b0c4d98a1dfbe4a0594db01cafc7c329a6d..015c725175ea411e95f2024445c3d5618c748fd6 100644 (file)
@@ -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');