[pve-devel] [PATCH qemu-server v2 2/5] refactor pci regex

Dominik Csapak d.csapak at proxmox.com
Wed Nov 14 10:44:25 CET 2018


Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* new in v2
* correct use of regex in lspci

 PVE/QemuServer/PCI.pm | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuServer/PCI.pm b/PVE/QemuServer/PCI.pm
index 7f5a4bf..4d75028 100644
--- a/PVE/QemuServer/PCI.pm
+++ b/PVE/QemuServer/PCI.pm
@@ -159,13 +159,15 @@ sub print_pcie_addr {
 }
 
 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;
     });
@@ -206,7 +208,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