public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Jakob-Tobias Winter <tobias@stuttgart.de>
To: pve-devel@lists.proxmox.com
Cc: Jakob-Tobias Winter <tobias@stuttgart.de>
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	[thread overview]
Message-ID: <20261128151118.892037-1-tobias@stuttgart.de> (raw)

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




             reply	other threads:[~2026-11-28 15:22 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 15:11 Jakob-Tobias Winter [this message]
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 ` [RFC PATCH qemu-server 07/11] fix #6314: qm cleanup: report a guest poweroff to the HA stack Jakob-Tobias Winter
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-1-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal