From: Jakob-Tobias Winter <tobias@stuttgart.de>
To: pve-devel@lists.proxmox.com
Cc: Jakob-Tobias Winter <tobias@stuttgart.de>
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 [thread overview]
Message-ID: <20261128151118.892037-8-tobias@stuttgart.de> (raw)
In-Reply-To: <20261128151118.892037-1-tobias@stuttgart.de>
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 <tobias@stuttgart.de>
---
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
next prev parent reply other threads:[~2026-11-28 15:21 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 15:11 [RFC PATCH cluster/ha-manager/qemu-server/manager/docs 00/11] fix #6314: ha: keep guests stopped that got powered off from within Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH cluster 01/11] datacenter config: add stop-on-poweroff to the HA settings Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH ha-manager 02/11] fix #6314: config: request stopped state for powered off guests Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH ha-manager 03/11] lrm: do not start a service again that is about to be stopped Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH ha-manager 04/11] sim: hardware: add poweroff command for services Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH ha-manager 05/11] test: add test cases for stop-on-poweroff Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH ha-manager 06/11] resources: add stop-on-poweroff property for virtual machines Jakob-Tobias Winter
2026-11-28 15:11 ` Jakob-Tobias Winter [this message]
2026-11-28 15:11 ` [RFC PATCH manager 08/11] ui: dc options: add stop-on-poweroff to the HA settings Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH manager 09/11] ui: ha: add stop-on-poweroff selector to the resource edit window Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH docs 10/11] ha-manager: document the stop-on-poweroff setting Jakob-Tobias Winter
2026-11-28 15:11 ` [RFC PATCH docs 11/11] ha-manager: document the stop-on-poweroff property of resources Jakob-Tobias Winter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261128151118.892037-8-tobias@stuttgart.de \
--to=tobias@stuttgart.de \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.