mirror of
git://git.proxmox.com/git/pve-common.git
synced 2025-01-06 21:17:37 +03:00
SysFSTools: factor out PCI regex
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
f0765c7174
commit
bf94e590f2
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user