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 978908A961 for ; Wed, 27 Jul 2022 15:29:26 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 8764D6030 for ; Wed, 27 Jul 2022 15:28:56 +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 for ; Wed, 27 Jul 2022 15:28:55 +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 1E8B043EAF for ; Wed, 27 Jul 2022 15:28:55 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Wed, 27 Jul 2022 15:28:54 +0200 Message-Id: <20220727132854.1942366-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.091 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 Subject: [pve-devel] [PATCH qemu-server] cleanup pci devices in more situations 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, 27 Jul 2022 13:29:26 -0000 if the preparing of pci devices or the start of the vm fails, we need to cleanup the pci devices (reservations *and* mdevs), or else it might happen that there are leftovers which must be manually removed. to include also mdevs now, refactor the cleanup code from 'vm_stop_cleanup' into it's own function, and call that instead of only 'remove_pci_reservation' also print the errors of the cleanup steps with 'warn', otherwise we might discard important errors Signed-off-by: Dominik Csapak --- PVE/QemuServer.pm | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 7d9cf22..72f0f58 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -5602,7 +5602,7 @@ sub vm_start_nolock { } }; if (my $err = $@) { - eval { PVE::QemuServer::PCI::remove_pci_reservation($pci_id_list) }; + eval { cleanup_pci_devices($vmid, $conf) }; warn $@ if $@; die $err; } @@ -5698,7 +5698,9 @@ sub vm_start_nolock { if (my $err = $@) { # deactivate volumes if start fails eval { PVE::Storage::deactivate_volumes($storecfg, $vollist); }; - eval { PVE::QemuServer::PCI::remove_pci_reservation($pci_id_list) }; + warn $@ if $@; + eval { cleanup_pci_devices($vmid, $conf) }; + warn $@ if $@; die "start failed: $err"; } @@ -5863,6 +5865,25 @@ sub get_vm_volumes { return $vollist; } +sub cleanup_pci_devices { + my ($vmid, $conf) = @_; + + my $ids = []; + foreach my $key (keys %$conf) { + next if $key !~ m/^hostpci(\d+)$/; + my $hostpciindex = $1; + my $d = parse_hostpci($conf->{$key}); + my $uuid = PVE::SysFSTools::generate_mdev_uuid($vmid, $hostpciindex); + + foreach my $pci (@{$d->{pciid}}) { + my $pciid = $pci->{id}; + push @$ids, $pci->{id}; + PVE::SysFSTools::pci_cleanup_mdev_device($pciid, $uuid); + } + } + PVE::QemuServer::PCI::remove_pci_reservation($ids); +} + sub vm_stop_cleanup { my ($storecfg, $vmid, $conf, $keepActive, $apply_pending_changes) = @_; @@ -5894,20 +5915,7 @@ sub vm_stop_cleanup { unlink '/dev/shm/pve-shm-' . ($ivshmem->{name} // $vmid); } - my $ids = []; - foreach my $key (keys %$conf) { - next if $key !~ m/^hostpci(\d+)$/; - my $hostpciindex = $1; - my $d = parse_hostpci($conf->{$key}); - my $uuid = PVE::SysFSTools::generate_mdev_uuid($vmid, $hostpciindex); - - foreach my $pci (@{$d->{pciid}}) { - my $pciid = $pci->{id}; - push @$ids, $pci->{id}; - PVE::SysFSTools::pci_cleanup_mdev_device($pciid, $uuid); - } - } - PVE::QemuServer::PCI::remove_pci_reservation($ids); + cleanup_pci_devices($vmid, $conf); vmconfig_apply_pending($vmid, $conf, $storecfg) if $apply_pending_changes; }; -- 2.30.2