From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pve-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
	by lore.proxmox.com (Postfix) with ESMTPS id 4BCE51FF170
	for <inbox@lore.proxmox.com>; Thu, 12 Jun 2025 16:03:23 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 7518F1F1FE;
	Thu, 12 Jun 2025 16:03:05 +0200 (CEST)
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu, 12 Jun 2025 16:02:45 +0200
Message-Id: <20250612140253.106555-15-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250612140253.106555-1-f.ebner@proxmox.com>
References: <20250612140253.106555-1-f.ebner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL -1.032 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 DMARC_MISSING             0.1 Missing DMARC policy
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 KAM_MAILER                  2 Automated Mailer Tag Left in Email
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
Subject: [pve-devel] [PATCH qemu-server 14/22] vm start/commandline: also
 clean up pci reservation when config_to_command() fails
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pve-devel-bounces@lists.proxmox.com
Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com>

The config_to_command() function already calls into
print_hostpci_devices() which makes reservations.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 PVE/QemuServer.pm | 56 +++++++++++++++++++++++++++--------------------
 1 file changed, 32 insertions(+), 24 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index dfd4351b..934adf60 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5649,31 +5649,32 @@ sub vm_start_nolock {
     my $memory = get_current_memory($conf->{memory});
     my $start_timeout = $params->{timeout} // config_aware_timeout($conf, $memory, $resume);
 
-    # Note that for certain cases like templates, the configuration is minimized, so need to ensure
-    # the rest of the function here uses the same configuration that was used to build the command
-    (my $cmd, my $vollist, my $spice_port, my $pci_devices, $conf) = config_to_command(
-	$storecfg,
-	$vmid,
-	$conf,
-	$defaults,
-	$forcemachine,
-	$forcecpu,
-	$params->{'live-restore-backing'},
-    );
-
-    push $cmd->@*, $state_cmdline->@*;
-    push @$vollist, $statefile if $statefile_is_a_volume;
-
+    my ($cmd, $vollist, $spice_port);
     my $pci_reserve_list = [];
-    for my $device (values $pci_devices->%*) {
-	next if $device->{mdev}; # we don't reserve for mdev devices
-	push $pci_reserve_list->@*, map { $_->{id} } $device->{ids}->@*;
-    }
-
-    # reserve all PCI IDs before actually doing anything with them
-    PVE::QemuServer::PCI::reserve_pci_usage($pci_reserve_list, $vmid, $start_timeout);
-
     eval {
+	# Note that for certain cases like templates, the configuration is minimized, so need to ensure
+	# the rest of the function here uses the same configuration that was used to build the command
+	($cmd, $vollist, $spice_port, my $pci_devices, $conf) = config_to_command(
+	    $storecfg,
+	    $vmid,
+	    $conf,
+	    $defaults,
+	    $forcemachine,
+	    $forcecpu,
+	    $params->{'live-restore-backing'},
+	);
+
+	push $cmd->@*, $state_cmdline->@*;
+	push @$vollist, $statefile if $statefile_is_a_volume;
+
+	for my $device (values $pci_devices->%*) {
+	    next if $device->{mdev}; # we don't reserve for mdev devices
+	    push $pci_reserve_list->@*, map { $_->{id} } $device->{ids}->@*;
+	}
+
+	# reserve all PCI IDs before actually doing anything with them
+	PVE::QemuServer::PCI::reserve_pci_usage($pci_reserve_list, $vmid, $start_timeout);
+
 	my $uuid;
 	for my $id (sort keys %$pci_devices) {
 	    my $d = $pci_devices->{$id};
@@ -5981,13 +5982,20 @@ sub vm_commandline {
 
     my $defaults = load_defaults();
 
-    my $cmd = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine, $forcecpu);
+    my $cmd;
+    eval {
+	$cmd = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine, $forcecpu);
+    };
+    my $err = $@;
+
     # if the vm is not running, we need to clean up the reserved/created devices
     if (!PVE::QemuServer::Helpers::vm_running_locally($vmid)) {
 	eval { cleanup_pci_devices($vmid, $conf) };
 	warn $@ if $@;
     }
 
+    die $err if $err;
+
     return PVE::Tools::cmd2string($cmd);
 }
 
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel