]> git.proxmox.com Git - pve-common.git/commitdiff
SysFSTools: do not assume pci domain 0000
authorDominik Csapak <d.csapak@proxmox.com>
Tue, 12 Nov 2019 13:23:02 +0000 (14:23 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 19 Nov 2019 14:54:13 +0000 (15:54 +0100)
but prepend '0000' to ids where no domain is given, to keep the ability
to use the shorthand syntax (e.g. 00:01.0 instead of 0000:00:01.0)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
src/PVE/SysFSTools.pm

index 2da3a38894268cb33acd2ad3b4414fb16888cb39..a8d9a7f0e24fc3fd014c140b594d7d5da982128f 100644 (file)
@@ -73,9 +73,9 @@ sub lspci {
 
     dir_glob_foreach("$pcisysfs/devices", $pciregex, sub {
        my ($fullid, $domain, $bus, $slot, $function) = @_;
-       my $id = "$bus:$slot.$function";
+       my $id = "$domain:$bus:$slot.$function";
 
-       if (defined($filter) && !ref($filter) && $id !~ m/^\Q$filter\E/) {
+       if (defined($filter) && !ref($filter) && $id !~ m/^(0000:)?\Q$filter\E/) {
            return; # filter ids early
        }
 
@@ -279,13 +279,15 @@ sub pci_dev_group_bind_to_vfio {
     }
     die "Cannot find vfio-pci module!\n" if !-d $vfio_basedir;
 
+    $pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4}:/;
+
     # get IOMMU group devices
-    opendir(my $D, "$pcisysfs/devices/0000:$pciid/iommu_group/devices/") || die "Cannot open iommu_group: $!\n";
-      my @devs = grep /^0000:/, readdir($D);
+    opendir(my $D, "$pcisysfs/devices/$pciid/iommu_group/devices/") || die "Cannot open iommu_group: $!\n";
+      my @devs = grep /^[0-9a-f]{4}:/, readdir($D);
     closedir($D);
 
     foreach my $pciid (@devs) {
-       $pciid =~ m/^([:\.\da-f]+)$/ or die "PCI ID $pciid not valid!\n";
+       $pciid =~ m/^([:\.0-9a-f]+)$/ or die "PCI ID $pciid not valid!\n";
 
         # pci bridges, switches or root ports are not supported
         # they have a pci_bus subdirectory so skip them
@@ -301,7 +303,9 @@ sub pci_dev_group_bind_to_vfio {
 sub pci_create_mdev_device {
     my ($pciid, $uuid, $type) = @_;
 
-    my $basedir = "$pcisysfs/devices/0000:$pciid";
+    $pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4}:/;
+
+    my $basedir = "$pcisysfs/devices/$pciid";
     my $mdev_dir = "$basedir/mdev_supported_types";
 
     die "pci device '$pciid' does not support mediated devices \n"
@@ -336,7 +340,9 @@ sub pci_create_mdev_device {
 sub pci_cleanup_mdev_device {
     my ($pciid, $uuid) = @_;
 
-    my $basedir = "$pcisysfs/devices/0000:$pciid/$uuid";
+    $pciid = "0000:$pciid" if $pciid !~ m/^[0-9a-f]{4}:/;
+
+    my $basedir = "$pcisysfs/devices/$pciid/$uuid";
 
     if (! -e $basedir) {
        return 1; # no cleanup necessary if it does not exist