From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 0B7EB7373D for ; Thu, 7 Oct 2021 15:45:34 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E77C61AC5D for ; Thu, 7 Oct 2021 15:45:33 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id D01CD1AC4A for ; Thu, 7 Oct 2021 15:45:32 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9EBFD458A8 for ; Thu, 7 Oct 2021 15:45:32 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Thu, 7 Oct 2021 15:45:29 +0200 Message-Id: <20211007134531.1693674-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211007134531.1693674-1-d.csapak@proxmox.com> References: <20211007134531.1693674-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.303 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [pci.pm, qemuserver.pm] Subject: [pve-devel] [PATCH qemu-server v3 1/3] pci: refactor pci device preparation X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Oct 2021 13:45:34 -0000 makes the vm start a bit less crowded Signed-off-by: Dominik Csapak --- 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