[pve-devel] [PATCH common 2/5] SysFSTools.pm: refactor pci regex

Dominik Csapak d.csapak at proxmox.com
Fri Nov 16 16:17:47 CET 2018


Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 src/PVE/SysFSTools.pm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/src/PVE/SysFSTools.pm b/src/PVE/SysFSTools.pm
index 8906f19..87568fb 100644
--- a/src/PVE/SysFSTools.pm
+++ b/src/PVE/SysFSTools.pm
@@ -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");
-- 
2.11.0





More information about the pve-devel mailing list