[pve-devel] [PATCH qemu-server v3 1/3] pci: refactor pci device preparation

Dominik Csapak d.csapak at proxmox.com
Thu Oct 7 15:45:29 CEST 2021


makes the vm start a bit less crowded

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/QemuServer.pm     | 14 +-------------
 PVE/QemuServer/PCI.pm | 20 ++++++++++++++++++++
 2 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index e5175b3..f78b2cc 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5389,19 +5389,7 @@ sub vm_start_nolock {
       foreach my $pcidevice (@$pcidevices) {
 	    my $pciid = $pcidevice->{id};
 
-	    my $info = PVE::SysFSTools::pci_device_info("$pciid");
-	    die "IOMMU not present\n" if !PVE::SysFSTools::check_iommu_support();
-	    die "no pci device info for device '$pciid'\n" if !$info;
-
-	    if ($d->{mdev}) {
-		my $uuid = PVE::SysFSTools::generate_mdev_uuid($vmid, $i);
-		PVE::SysFSTools::pci_create_mdev_device($pciid, $uuid, $d->{mdev});
-	    } else {
-		die "can't unbind/bind PCI group to VFIO '$pciid'\n"
-		    if !PVE::SysFSTools::pci_dev_group_bind_to_vfio($pciid);
-		die "can't reset PCI device '$pciid'\n"
-		    if $info->{has_fl_reset} && !PVE::SysFSTools::pci_dev_reset($info);
-	    }
+	    PVE::QemuServer::PCI::prepare_pci_device($vmid, $pciid, $i, $d->{mdev});
       }
     }
 
diff --git a/PVE/QemuServer/PCI.pm b/PVE/QemuServer/PCI.pm
index 5608207..b94a99a 100644
--- a/PVE/QemuServer/PCI.pm
+++ b/PVE/QemuServer/PCI.pm
@@ -461,4 +461,24 @@ sub print_hostpci_devices {
     return ($kvm_off, $gpu_passthrough, $legacy_igd);
 }
 
+sub prepare_pci_device {
+    my ($vmid, $pciid, $confslot, $mdev) = @_;
+
+    my $info = PVE::SysFSTools::pci_device_info("$pciid");
+    die "IOMMU not present\n" if !PVE::SysFSTools::check_iommu_support();
+    die "no pci device info for device '$pciid'\n" if !$info;
+
+    if ($mdev) {
+	my $uuid = PVE::SysFSTools::generate_mdev_uuid($vmid, $confslot);
+	PVE::SysFSTools::pci_create_mdev_device($pciid, $uuid, $mdev);
+    } else {
+	die "can't unbind/bind PCI group to VFIO '$pciid'\n"
+	    if !PVE::SysFSTools::pci_dev_group_bind_to_vfio($pciid);
+	die "can't reset PCI device '$pciid'\n"
+	    if $info->{has_fl_reset} && !PVE::SysFSTools::pci_dev_reset($info);
+    }
+
+    return;
+}
+
 1;
-- 
2.30.2






More information about the pve-devel mailing list