]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/SysFSTools.pm
SysFSTools: factor out PCI regex
[pve-common.git] / src / PVE / SysFSTools.pm
index 8906f19acd1e56497dc04188bc43d0aba9ee1c94..87568fbb0f0093d474bdeeb883196bfbb7c39ad0 100644 (file)
@@ -8,13 +8,15 @@ use IO::File;
 use PVE::Tools qw(file_read_firstline dir_glob_foreach);
 
 my $pcisysfs = "/sys/bus/pci";
+my $pciregex = "([a-f0-9]{4}):([a-f0-9]{2}):([a-f0-9]{2})\.([a-f0-9])";
 
 sub lspci {
 
     my $devices = {};
 
-    dir_glob_foreach("$pcisysfs/devices", '[a-f0-9]{4}:([a-f0-9]{2}:[a-f0-9]{2})\.([0-9])', sub {
-            my (undef, $id, $function) = @_;
+    dir_glob_foreach("$pcisysfs/devices", $pciregex, sub {
+            my (undef, undef, $bus, $slot, $function) = @_;
+           my $id = "$bus:$slot";
            my $res = { id => $id, function => $function};
            push @{$devices->{$id}}, $res;
     });
@@ -55,7 +57,7 @@ sub pci_device_info {
 
     my $res;
 
-    return undef if $name !~ m/^([a-f0-9]{4}):([a-f0-9]{2}):([a-f0-9]{2})\.([a-f0-9])$/;
+    return undef if $name !~ m/^${pciregex}$/;
     my ($domain, $bus, $slot, $func) = ($1, $2, $3, $4);
 
     my $irq = file_read_firstline("$pcisysfs/devices/$name/irq");