[pve-devel] [PATCH qemu-server 2/7] PVE/QemuServer: allow mapped pci deviced in config
Dominik Csapak
d.csapak at proxmox.com
Mon Jun 21 15:55:21 CEST 2021
and get the correct pci device during parsing
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PVE/QemuServer/PCI.pm | 22 ++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/PVE/QemuServer/PCI.pm b/PVE/QemuServer/PCI.pm
index 2ee142f..26bad63 100644
--- a/PVE/QemuServer/PCI.pm
+++ b/PVE/QemuServer/PCI.pm
@@ -4,6 +4,8 @@ use warnings;
use strict;
use PVE::JSONSchema;
+use PVE::HardwareMap;
+use PVE::HardwareMap::PCIPlugin;
use PVE::SysFSTools;
use base 'Exporter';
@@ -18,12 +20,13 @@ parse_hostpci
our $MAX_HOSTPCI_DEVICES = 16;
my $PCIRE = qr/([a-f0-9]{4}:)?[a-f0-9]{2}:[a-f0-9]{2}(?:\.[a-f0-9])?/;
+
my $hostpci_fmt = {
host => {
default_key => 1,
type => 'string',
- pattern => qr/$PCIRE(;$PCIRE)*/,
- format_description => 'HOSTPCIID[;HOSTPCIID2...]',
+ pattern => qr/(:?$PCIRE(;$PCIRE)*)|(:?$PVE::JSONSchema::CONFIGID_RE)/,
+ format_description => 'HOSTPCIID[;HOSTPCIID2...] or configured mapping id',
description => <<EODESCR,
Host PCI device pass through. The PCI ID of a host's PCI device or a list
of PCI virtual functions of the host. HOSTPCIID syntax is:
@@ -31,6 +34,8 @@ of PCI virtual functions of the host. HOSTPCIID syntax is:
'bus:dev.func' (hexadecimal numbers)
You can us the 'lspci' command to list existing PCI devices.
+
+Alternatively use the ID of a mapped pci device.
EODESCR
},
rombar => {
@@ -349,6 +354,19 @@ sub parse_hostpci {
my $res = PVE::JSONSchema::parse_property_string($hostpci_fmt, $value);
+ if ($res->{host} !~ m/:/) {
+ # we have no ordinary pci id, must be a mapping
+ my $device = PVE::HardwareMap::find_device_on_current_node('pci', $res->{host});
+ die "PCI device mapping not found for '$res->{host}'\n" if !defined($device);
+ eval {
+ PVE::HardwareMap::PCIPlugin->assert_device_valid($device);
+ };
+ if (my $err = $@) {
+ die "PCI device mapping invalid (hardware probably changed): $err\n";
+ }
+ $res->{host} = $device->{pcipath};
+ }
+
my @idlist = split(/;/, $res->{host});
delete $res->{host};
foreach my $id (@idlist) {
--
2.20.1
More information about the pve-devel
mailing list