[pve-devel] [PATCH qemu-server 2/2] use improved lspci
Dominik Csapak
d.csapak at proxmox.com
Fri Nov 16 16:29:50 CET 2018
since lspci does not split between id and function anymore,
there is no need to plug id + function together
also we can remove the capture groups from PCIRE
since parse_property_string does this check for us
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PVE/QemuServer.pm | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index f8c668c..f516e74 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -1204,8 +1204,7 @@ my $usbdesc = {
};
PVE::JSONSchema::register_standard_option("pve-qm-usb", $usbdesc);
-# NOTE: the match-groups of this regex are used in parse_hostpci
-my $PCIRE = qr/([a-f0-9]{2}:[a-f0-9]{2})(?:\.([a-f0-9]))?/;
+my $PCIRE = qr/[a-f0-9]{2}:[a-f0-9]{2}(?:\.[a-f0-9])?/;
my $hostpci_fmt = {
host => {
default_key => 1,
@@ -2114,16 +2113,12 @@ sub parse_hostpci {
my @idlist = split(/;/, $res->{host});
delete $res->{host};
foreach my $id (@idlist) {
- if ($id =~ /^$PCIRE$/) {
- if (defined($2)) {
- push @{$res->{pciid}}, { id => $1, function => $2 };
- } else {
- my $pcidevices = PVE::SysFSTools::lspci($1);
- $res->{pciid} = $pcidevices->{$1};
- }
- } else {
- # should have been caught by parse_property_string already
- die "failed to parse PCI id: $id\n";
+ if ($id =~ m/\./) { # full id 00:00.1
+ push @{$res->{pciid}}, {
+ id => $id,
+ };
+ } else { # partial id 00:00
+ $res->{pciid} = PVE::SysFSTools::lspci($id);
}
}
return $res;
@@ -3555,9 +3550,8 @@ sub config_to_command {
my $sysfspath;
if ($d->{mdev} && scalar(@$pcidevices) == 1) {
my $id = $pcidevices->[0]->{id};
- my $function = $pcidevices->[0]->{function};
my $uuid = PVE::SysFSTools::generate_mdev_uuid($vmid, $i);
- $sysfspath = "$pcisysfs/devices/0000:$id.$function/$uuid";
+ $sysfspath = "$pcisysfs/devices/0000:$id/$uuid";
} elsif ($d->{mdev}) {
warn "ignoring mediated device with multifunction device\n";
}
@@ -3573,7 +3567,7 @@ sub config_to_command {
if ($sysfspath) {
$devicestr .= ",sysfsdev=$sysfspath";
} else {
- $devicestr .= ",host=$pcidevice->{id}.$pcidevice->{function}";
+ $devicestr .= ",host=$pcidevice->{id}";
}
$devicestr .= ",id=$id$addr";
@@ -5165,7 +5159,7 @@ sub vm_start {
next if !$d;
my $pcidevices = $d->{pciid};
foreach my $pcidevice (@$pcidevices) {
- my $pciid = $pcidevice->{id}.".".$pcidevice->{function};
+ my $pciid = $pcidevice->{id};
my $info = PVE::SysFSTools::pci_device_info("0000:$pciid");
die "IOMMU not present\n" if !PVE::SysFSTools::check_iommu_support();
@@ -5426,7 +5420,7 @@ sub vm_stop_cleanup {
my $uuid = PVE::SysFSTools::generate_mdev_uuid($vmid, $hostpciindex);
foreach my $pci (@{$d->{pciid}}) {
- my $pciid = $pci->{id} . "." . $pci->{function};
+ my $pciid = $pci->{id};
PVE::SysFSTools::pci_cleanup_mdev_device($pciid, $uuid);
}
}
--
2.11.0
More information about the pve-devel
mailing list