From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id A5C051FF0A8 for ; Sat, 28 Nov 2026 16:21:11 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C51482170D; Sat, 28 Nov 2026 16:21:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stuttgart.de; s=s1022; t=1795878689; bh=Op7IJ5EOGfLwNbJ1fu5tT5lo6tGc3gamjq3RGPnckJo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nWpSA3DwcQz+WpNO5fvzx2YkiKM9tXsDcV9JcGp2mNBNslI1egwKwzhM7AO6pwcJT 6M23IQQf2SBeTy5y2AG4Z0g3RUCGYR8Xmxmk8wWvxuzW+rdHuKm9DkBYRFNr9FVvPM Gf9jwiLG/HdRNy8zJR+lgLbsyAobVVr1FqzafkluOJVgjvyE7RWWlHlK9z0VXnh4qF g9IZn/tvd2kJbLcrw3AQCFwXZc81KiZXAUP0s+qVoFGXPXREkYExbQe0GcZLbTAX90 wNhlo5f3FAhJIYAc10qNDX5Ue/N0ZXGJ7kFmUrYbqI9acNp+PzVKSHibRBBPcOAa7p wlu0TgVpr3fow== From: Jakob-Tobias Winter To: pve-devel@lists.proxmox.com Subject: [RFC PATCH qemu-server 07/11] fix #6314: qm cleanup: report a guest poweroff to the HA stack Date: Sat, 28 Nov 2026 16:11:14 +0100 Message-ID: <20261128151118.892037-8-tobias@stuttgart.de> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261128151118.892037-1-tobias@stuttgart.de> References: <20261128151118.892037-1-tobias@stuttgart.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.030 Adjusted score from AWL reputation of From: address DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_PASS -0.001 SPF: HELO matches SPF record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: CMV7TGAJQVCXGJOGBJRHO7A6XO7OUOXI X-Message-ID-Hash: CMV7TGAJQVCXGJOGBJRHO7A6XO7OUOXI X-MailFrom: prvs=7495f99b94=tobias@stuttgart.de X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Jakob-Tobias Winter X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: An HA managed guest that gets powered off from within is started again by the HA stack. Only the cleanup after the guest knows that it was shut down cleanly on its own request, so let it tell the HA stack, which then requests the stopped state for the guest if it is configured to do so. QEMU reports a shutdown through the API in the same way. But such a shutdown does the cleanup itself, and so does a reboot through the API. So only report a guest whose cleanup is still pending, which the cleanup flag tells. As long as the flag cannot be used on a node, that is until the first boot after an upgrade from a version before 9.1.13, nothing gets reported. Do this before the cleanup itself, as the HA stack waits for the cleanup to be done before it starts a guest again that is not running anymore. Signed-off-by: Jakob-Tobias Winter --- Needs a versioned dependency on the pve-ha-manager release that has the helper. With an older one, the cleanup only logs that it could not tell the HA stack, and everything else works as before. src/PVE/CLI/qm.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/PVE/CLI/qm.pm b/src/PVE/CLI/qm.pm index 0b109fc5..37a8a534 100755 --- a/src/PVE/CLI/qm.pm +++ b/src/PVE/CLI/qm.pm @@ -43,6 +43,13 @@ use PVE::QemuServer::RunState; use PVE::QemuServer::DBusVMState; use PVE::QemuServer; +BEGIN { + if (!$ENV{PVE_GENERATING_DOCS}) { + require PVE::HA::Config; + import PVE::HA::Config; + } +} + use PVE::CLIHandler; use base qw(PVE::CLIHandler); @@ -1171,6 +1178,23 @@ __PACKAGE__->register_method({ my $can_use_cleanup_flag = PVE::QemuServer::RunState::can_use_cleanup_flag(); + if ( + $clean + && $guest + && $can_use_cleanup_flag + && PVE::QemuServer::RunState::cleanup_flag_exists($vmid) + ) { + # The guest got powered off from within, as a shutdown through the API would + # have done the cleanup already. Tell the HA stack before doing the cleanup, as + # it waits for that before it starts the guest again. + my $stop_requested = + eval { PVE::HA::Config::request_stop_on_poweroff("vm:$vmid") }; + warn "could not tell the HA stack about the poweroff of VM $vmid - $@" + if $@; + warn "Requested HA state 'stopped' for powered off VM $vmid\n" + if $stop_requested; + } + if (!$clean || $guest || $can_use_cleanup_flag) { # either we can use the new mechanism to check if cleanup is done, or # vm was shutdown from inside the guest or crashed base-commit: 2f13e34784c5e0fee0df5d7e9669e732f57ef359 -- 2.53.0