]> git.proxmox.com Git - pve-common.git/commitdiff
SysFSTools: implement filter by id in lspci
authorDominik Csapak <d.csapak@proxmox.com>
Fri, 16 Nov 2018 15:17:48 +0000 (16:17 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 19 Nov 2018 12:42:29 +0000 (13:42 +0100)
use the new filter parameter as a filter for devices

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

index 87568fbb0f0093d474bdeeb883196bfbb7c39ad0..660f94bbeae3ee6176e7eac1cfbe975f72f0041f 100644 (file)
@@ -11,12 +11,14 @@ 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 $pciregex = "([a-f0-9]{4}):([a-f0-9]{2}):([a-f0-9]{2})\.([a-f0-9])";
 
 sub lspci {
+    my ($filter) = @_;
 
     my $devices = {};
 
     dir_glob_foreach("$pcisysfs/devices", $pciregex, sub {
             my (undef, undef, $bus, $slot, $function) = @_;
            my $id = "$bus:$slot";
 
     my $devices = {};
 
     dir_glob_foreach("$pcisysfs/devices", $pciregex, sub {
             my (undef, undef, $bus, $slot, $function) = @_;
            my $id = "$bus:$slot";
+           return if defined($filter) && $id ne $filter;
            my $res = { id => $id, function => $function};
            push @{$devices->{$id}}, $res;
     });
            my $res = { id => $id, function => $function};
            push @{$devices->{$id}}, $res;
     });