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 0196E8D906 for ; Wed, 9 Nov 2022 09:23:41 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DDFCF197D9 for ; Wed, 9 Nov 2022 09:23:40 +0100 (CET) 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 for ; Wed, 9 Nov 2022 09:23:40 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 146484308A for ; Wed, 9 Nov 2022 09:23:40 +0100 (CET) Message-ID: Date: Wed, 9 Nov 2022 09:23:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:107.0) Gecko/20100101 Thunderbird/107.0 Content-Language: en-GB To: Proxmox VE development discussion , Dominik Csapak References: <20220920125041.3636561-1-d.csapak@proxmox.com> <20220920125041.3636561-14-d.csapak@proxmox.com> From: Thomas Lamprecht In-Reply-To: <20220920125041.3636561-14-d.csapak@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.033 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 NICE_REPLY_A -0.001 Looks like a legit reply (A) 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] Subject: Re: [pve-devel] [PATCH qemu-server v3 04/13] PCI: reuse parsed info from print_hostpci_devices 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: Wed, 09 Nov 2022 08:23:41 -0000 Am 20/09/2022 um 14:50 schrieb Dominik Csapak: > instead of parsing the config again when trying to reserver/prepare the > pci devices. also split the preparing into non-mdev devices and mdev > devices, this will come in handy later. I'd rather factor out the parsing parts, see below. > diff --git a/PVE/QemuServer/PCI.pm b/PVE/QemuServer/PCI.pm > index 7406246..b5284ef 100644 > --- a/PVE/QemuServer/PCI.pm > +++ b/PVE/QemuServer/PCI.pm > @@ -422,12 +422,17 @@ sub print_hostpci_devices { > my $kvm_off = 0; > my $gpu_passthrough = 0; > my $legacy_igd = 0; > + my $parsed_devices = {}; > > my $pciaddr; > for (my $i = 0; $i < $MAX_HOSTPCI_DEVICES; $i++) { > my $id = "hostpci$i"; > my $d = parse_hostpci($conf->{$id}); > next if !$d; > + $parsed_devices->{$i} = { > + device => $d, > + used => [], > + }; note that iff we'd do that I'd want a comment on the sub describing the parsed_device "struct" and its field; if it sounds like I'm really missing rust here you'd be spot on.. > > if (my $pcie = $d->{pcie}) { > die "q35 machine model is not enabled" if !$q35; > @@ -449,6 +454,7 @@ sub print_hostpci_devices { > } > > my $pcidevices = $d->{pciid}; > + $parsed_devices->{$i}->{used} = $pcidevices; so, this is already included in $parsed_devices->{$i} which contains the full $d anyway, what gives? How about splitting out the looping over all possible "hostpci$i" with the checks and transformations done with the parsed $d into an parse_hostpci_devices returning only the hash and pass then that to print_hostpci_devices (which then can probably drop some parameters), that may be even better outcome in terms of readability and maintainability than the "03/13 refactor print_pci_device", especially if you don't plan to reuse that anyway (only skimmed remaining patches), so hopefully a cleaner separation. for (my $i = 0; $i < $MAX_HOSTPCI_DEVICES; $i++) > my $multifunction = @$pcidevices > 1; > > if ($d->{'legacy-igd'}) { > @@ -503,7 +509,7 @@ sub print_hostpci_devices { > } > } > > - return ($kvm_off, $gpu_passthrough, $legacy_igd); > + return ($kvm_off, $gpu_passthrough, $legacy_igd, $parsed_devices); > } > > sub prepare_pci_device {