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 34EAF1FF0A8 for ; Sat, 28 Nov 2026 16:22:53 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id C67DF218F1; Sat, 28 Nov 2026 16:21:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stuttgart.de; s=s1022; t=1795878688; bh=cWWBNxiuJqCtVcDCycOPJ9bNq2zCiVfoR8oIczr6OPc=; h=From:To:Cc:Subject:Date:From; b=l4yiUpatt6/Ta5hFs7CK4IfsQ5qBcrjXhTVe185AhyWqZ5wx45r59xu7D+rn+Zl26 cnAQYbadEE0VvdSOzvvIqC1xIZ9f3EIGrDFMDupYISPu1Obqn/z7F3e6AuHF8yI+Cx l21RU18eCP/uZkFskyDLUudT/Jqp8n3SqlvUbsoVmiC9NRc9uvgwRf9pGAhESWRO7m yWqeFSs83RdlFlEAu+6cO/onRrnZyjA4AWksav6QbDDFaplgMmemuPzIFmeINl70j+ 1UH82XSOPRikOKTtIa82FBsKgOjJiXAJPUB2P3SRgVkkVrjAIj7pV6Y5Ptja4tJcp4 7nH3Z9db5AF1Q== From: Jakob-Tobias Winter To: pve-devel@lists.proxmox.com Subject: [RFC PATCH cluster/ha-manager/qemu-server/manager/docs 00/11] fix #6314: ha: keep guests stopped that got powered off from within Date: Sat, 28 Nov 2026 16:11:07 +0100 Message-ID: <20261128151118.892037-1-tobias@stuttgart.de> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.126 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 POISEN_SPAM_PILL 0.1 Meta: its spam POISEN_SPAM_PILL_1 0.1 random spam to be learned in bayes POISEN_SPAM_PILL_3 0.1 random spam to be learned in bayes 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: WH7RZL7DQPWP656C6T2U2J6ACWUC2RWQ X-Message-ID-Hash: WH7RZL7DQPWP656C6T2U2J6ACWUC2RWQ 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 [0]. To keep it stopped, it has to be shut down through Proxmox VE, which someone who only has access to the guest cannot do, and which is not what people coming from other platforms expect. This series adds a setting, off by default, with which the HA stack sets the requested state to "stopped" for a virtual machine that got powered off from within the guest. The resource is then handled like one that was shut down through the API: it stays stopped, it is still recovered if its node fails, and starting it through the API requests the "started" state again. A VM that crashes is still started again. # pvesh set /cluster/options --ha stop-on-poweroff=1 # ha-manager set vm:100 --stop-on-poweroff 0 How it works ------------ qmeventd already tells "qm cleanup" whether QEMU reported a clean shutdown that was requested by the guest. The cleanup now passes that on to the HA stack (qemu-server), which sets the requested state if the setting applies (ha-manager 2/11). Two things need more than that: * QEMU reports a shutdown that the host asked for through ACPI or the guest agent in the same way, and the HA stack shuts guests down itself while their requested state stays "started": the LRM stops all services of a node that is shut down or rebooted, and relocating a service shuts its guest down first. With the patch sketched in [0] those guests would stay stopped. A shutdown or reboot through the API does the cleanup itself, and since qemu-server 9.1.13 a flag tells whether the cleanup after a guest is still left to do. So "qm cleanup" only reports a guest for which it is. On top of that, the HA stack only honors a report while the CRM state of the service is "started", the LRM of its node is in mode "active" and the HA stack is not disarmed. This covers a shutdown task that got aborted before its cleanup, and a guest that powers itself off while HA is disarmed in the "ignore" mode: its requested state would still be "stopped" after a direct start, and arming HA would stop it again. * The cleanup only runs once the QEMU process is gone, while the LRM looks about every 10 seconds whether its services are running. If its round comes in between, it starts the guest again, and the CRM stops it shortly after. With the setting enabled, the LRM therefore waits for a pending cleanup of the guest before it starts it, for at most 10 seconds, and then checks whether the service still is requested to be started (ha-manager 3/11). With the check, the guest stayed stopped in 8 of 8 poweroffs on a single node with real daemons; in 4 of them the round of the LRM came first and the check held it off. With the check switched off, and so with another order of the rounds after restarting the LRM, the guest was started again in 2 of 8. The series ---------- cluster 1 the setting in the HA settings of datacenter.cfg ha-manager 2-5 the request, the wait and check in the LRM, a simulator command for a guest that powers off, test cases ha-manager 6 optional: a property to override the cluster wide setting for single resources qemu-server 7 the report from the cleanup manager 8 checkbox in Datacenter -> Options -> HA Settings manager 9 optional: selector in the resource edit window docs 10, 11 description, 11 for the optional property The property for single resources (6, 9, 11) is a nice to have on top and can be left out without touching the rest. Open questions -------------- * The LRM asks the VM plugin whether the cleanup flag of qemu-server still exists. Making a start wait for a pending cleanup was discussed for qemu-server itself in [1]; if that is the better place, the LRM would only need the check of the requested state. * On a node that still uses the old cleanup, that is until the first boot after an upgrade from a qemu-server before 9.1.13, nothing is reported and guests are started again as before. Is that worth a sentence in the documentation? * qmeventd only passes on whether the guest requested the shutdown. So a few more things count as a poweroff from within: a guest that shuts down after a reboot through the API ran into its timeout, and a shutdown asked for by the watchdog device with the "shutdown" action, or through the guest agent or the monitor directly. Such a guest stays stopped like one that is not HA managed. Is that acceptable for an opt-in setting? * Containers are not covered: their post-stop hook cannot tell a stop by the host from one inside the container, and a backup in stop mode and "pct reboot" stop them without the HA stack knowing. * The name. "stop-on-poweroff" follows the title of [0] and the style of "auto-rebalance". * The series for bug 7213 [2] lets qmeventd report a reset to the cleanup. With it, such a reset has to be left out here as well, I can rebase onto whatever gets applied first. Dependencies between the packages are in the notes of the patches: qemu-server needs the pve-ha-manager with patch 2, and the checkbox a libpve-cluster-perl with patch 1. pve-ha-manager already depends on a qemu-server with the cleanup flag. Testing ------- * test suites of pve-ha-manager for every commit of the series, with six new simulator cases and a table test for the decision; test suite of qemu-server * real pve-ha-crm, pve-ha-lrm, qmeventd and pvedaemon of the packages of Proxmox VE 9.3 with the series, on a single node without KVM, with a VM that powers itself off through ACPI: the default (started again), the setting (stays stopped, can be started again, started again after its process got killed), the property of a resource in both directions, a VM that is not HA managed, a node in maintenance mode, a reboot through the API, a poweroff right after HA got disarmed and a shutdown through the API while it is disarmed, a node with the old cleanup, a cleanup that is held up until the next round of the LRM, and the poweroff repeated with and without the check in the LRM * both parts of the web interface in a browser * not tested: a cluster with more than one node, so node shutdown and relocation are only covered by the simulator and by the table test [0] https://bugzilla.proxmox.com/show_bug.cgi?id=6314 [1] https://lore.proxmox.com/pve-devel/28c91ab7-b41d-446e-b31c-5800ced4ad61@proxmox.com/ [2] https://lore.proxmox.com/pve-devel/20261022125111.236538-1-j.klocker@proxmox.com/ cluster: Jakob-Tobias Winter (1): datacenter config: add stop-on-poweroff to the HA settings src/PVE/DataCenterConfig.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) ha-manager: Jakob-Tobias Winter (5): fix #6314: config: request stopped state for powered off guests lrm: do not start a service again that is about to be stopped sim: hardware: add poweroff command for services test: add test cases for stop-on-poweroff resources: add stop-on-poweroff property for virtual machines src/PVE/API2/HA/Resources.pm | 7 + src/PVE/HA/Config.pm | 38 ++++ src/PVE/HA/LRM.pm | 24 +++ src/PVE/HA/Resources.pm | 14 ++ src/PVE/HA/Resources/PVEVM.pm | 13 ++ src/PVE/HA/Sim/Hardware.pm | 23 +++ src/PVE/HA/Tools.pm | 27 +++ src/test/Makefile | 1 + src/test/test-stop-on-poweroff1/README | 3 + src/test/test-stop-on-poweroff1/cmdlist | 5 + .../test-stop-on-poweroff1/datacenter.cfg | 5 + .../test-stop-on-poweroff1/hardware_status | 5 + src/test/test-stop-on-poweroff1/log.expect | 32 ++++ .../test-stop-on-poweroff1/manager_status | 1 + .../test-stop-on-poweroff1/service_config | 3 + src/test/test-stop-on-poweroff2/README | 2 + src/test/test-stop-on-poweroff2/cmdlist | 4 + .../test-stop-on-poweroff2/hardware_status | 5 + src/test/test-stop-on-poweroff2/log.expect | 27 +++ .../test-stop-on-poweroff2/manager_status | 1 + .../test-stop-on-poweroff2/service_config | 3 + src/test/test-stop-on-poweroff3/README | 4 + src/test/test-stop-on-poweroff3/cmdlist | 5 + .../test-stop-on-poweroff3/datacenter.cfg | 5 + .../test-stop-on-poweroff3/hardware_status | 5 + src/test/test-stop-on-poweroff3/log.expect | 34 ++++ .../test-stop-on-poweroff3/manager_status | 1 + .../test-stop-on-poweroff3/service_config | 3 + src/test/test-stop-on-poweroff4/README | 4 + src/test/test-stop-on-poweroff4/cmdlist | 4 + .../test-stop-on-poweroff4/datacenter.cfg | 5 + .../test-stop-on-poweroff4/hardware_status | 5 + src/test/test-stop-on-poweroff4/log.expect | 43 +++++ .../test-stop-on-poweroff4/manager_status | 1 + .../test-stop-on-poweroff4/service_config | 3 + src/test/test-stop-on-poweroff5/README | 5 + src/test/test-stop-on-poweroff5/cmdlist | 5 + .../test-stop-on-poweroff5/hardware_status | 5 + src/test/test-stop-on-poweroff5/log.expect | 41 +++++ .../test-stop-on-poweroff5/manager_status | 1 + .../test-stop-on-poweroff5/service_config | 4 + src/test/test-stop-on-poweroff6/README | 3 + src/test/test-stop-on-poweroff6/cmdlist | 4 + .../test-stop-on-poweroff6/datacenter.cfg | 5 + .../test-stop-on-poweroff6/hardware_status | 5 + src/test/test-stop-on-poweroff6/log.expect | 34 ++++ .../test-stop-on-poweroff6/manager_status | 1 + .../test-stop-on-poweroff6/service_config | 4 + src/test/test_stop_on_poweroff.pl | 173 ++++++++++++++++++ 49 files changed, 655 insertions(+) create mode 100644 src/test/test-stop-on-poweroff1/README create mode 100644 src/test/test-stop-on-poweroff1/cmdlist create mode 100644 src/test/test-stop-on-poweroff1/datacenter.cfg create mode 100644 src/test/test-stop-on-poweroff1/hardware_status create mode 100644 src/test/test-stop-on-poweroff1/log.expect create mode 100644 src/test/test-stop-on-poweroff1/manager_status create mode 100644 src/test/test-stop-on-poweroff1/service_config create mode 100644 src/test/test-stop-on-poweroff2/README create mode 100644 src/test/test-stop-on-poweroff2/cmdlist create mode 100644 src/test/test-stop-on-poweroff2/hardware_status create mode 100644 src/test/test-stop-on-poweroff2/log.expect create mode 100644 src/test/test-stop-on-poweroff2/manager_status create mode 100644 src/test/test-stop-on-poweroff2/service_config create mode 100644 src/test/test-stop-on-poweroff3/README create mode 100644 src/test/test-stop-on-poweroff3/cmdlist create mode 100644 src/test/test-stop-on-poweroff3/datacenter.cfg create mode 100644 src/test/test-stop-on-poweroff3/hardware_status create mode 100644 src/test/test-stop-on-poweroff3/log.expect create mode 100644 src/test/test-stop-on-poweroff3/manager_status create mode 100644 src/test/test-stop-on-poweroff3/service_config create mode 100644 src/test/test-stop-on-poweroff4/README create mode 100644 src/test/test-stop-on-poweroff4/cmdlist create mode 100644 src/test/test-stop-on-poweroff4/datacenter.cfg create mode 100644 src/test/test-stop-on-poweroff4/hardware_status create mode 100644 src/test/test-stop-on-poweroff4/log.expect create mode 100644 src/test/test-stop-on-poweroff4/manager_status create mode 100644 src/test/test-stop-on-poweroff4/service_config create mode 100644 src/test/test-stop-on-poweroff5/README create mode 100644 src/test/test-stop-on-poweroff5/cmdlist create mode 100644 src/test/test-stop-on-poweroff5/hardware_status create mode 100644 src/test/test-stop-on-poweroff5/log.expect create mode 100644 src/test/test-stop-on-poweroff5/manager_status create mode 100644 src/test/test-stop-on-poweroff5/service_config create mode 100644 src/test/test-stop-on-poweroff6/README create mode 100644 src/test/test-stop-on-poweroff6/cmdlist create mode 100644 src/test/test-stop-on-poweroff6/datacenter.cfg create mode 100644 src/test/test-stop-on-poweroff6/hardware_status create mode 100644 src/test/test-stop-on-poweroff6/log.expect create mode 100644 src/test/test-stop-on-poweroff6/manager_status create mode 100644 src/test/test-stop-on-poweroff6/service_config create mode 100755 src/test/test_stop_on_poweroff.pl qemu-server: Jakob-Tobias Winter (1): fix #6314: qm cleanup: report a guest poweroff to the HA stack src/PVE/CLI/qm.pm | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) manager: Jakob-Tobias Winter (2): ui: dc options: add stop-on-poweroff to the HA settings ui: ha: add stop-on-poweroff selector to the resource edit window www/manager6/dc/OptionView.js | 11 +++++++++++ www/manager6/ha/ResourceEdit.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) docs: Jakob-Tobias Winter (2): ha-manager: document the stop-on-poweroff setting ha-manager: document the stop-on-poweroff property of resources ha-manager.adoc | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) Summary over all repositories: 54 files changed, 773 insertions(+), 1 deletion(-) -- 2.53.0