public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Jakob Klocker <j.klocker@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server v2 5/8] fix #7213: qm: cleanup: add `reset` parameter to honor `powercycle`
Date: Thu, 22 Oct 2026 14:51:08 +0200	[thread overview]
Message-ID: <20261022125111.236538-6-j.klocker@proxmox.com> (raw)
In-Reply-To: <20261022125111.236538-1-j.klocker@proxmox.com>

With `-no-reboot`, QEMU exits on a guest-initiated reset exactly like it
does on a regular shutdown, so `qm cleanup` cannot tell the two apart on
its own. Add an optional 'reset' parameter which qmeventd sets
accordingly.

Start the VM again if the shutdown was caused by a reset and either
`powercycle` is set or the reset was requested via QMP (`qm reset`,
API), in addition to the existing case of an explicit reboot request.
`powercycle` and reboot requests stay gated on `enabled`, so a guest
reboot with reboot disabled always leaves the VM off. An explicit
`qm reset` restarts the VM regardless, as that is the natural
expectation.

Link: https://bugzilla.proxmox.com/show_bug.cgi?id=7213
Signed-off-by: Jakob Klocker <j.klocker@proxmox.com>
---
 src/PVE/CLI/qm.pm | 24 +++++++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/PVE/CLI/qm.pm b/src/PVE/CLI/qm.pm
index f35b8a30..bc9cc6a9 100755
--- a/src/PVE/CLI/qm.pm
+++ b/src/PVE/CLI/qm.pm
@@ -1078,6 +1078,15 @@ __PACKAGE__->register_method({
                 description =>
                     "Indicates if the shutdown was requested by the guest or via qmp.",
             },
+            reset => {
+                type => 'boolean',
+                description =>
+                    "Indicates if the shutdown was caused by a reset request, either from"
+                    . " inside the guest or through QMP, which QEMU turns into a shutdown"
+                    . " when started with '-no-reboot'.",
+                optional => 1,
+                default => 0,
+            },
         },
     },
     returns => { type => 'null' },
@@ -1087,6 +1096,7 @@ __PACKAGE__->register_method({
         my $vmid = $param->{vmid};
         my $clean = $param->{'clean-shutdown'};
         my $guest = $param->{'guest-requested'};
+        my $reset = $param->{reset};
         my $restart = 0;
 
         # return if we do not have the config anymore
@@ -1149,7 +1159,7 @@ __PACKAGE__->register_method({
 
                 my $can_use_cleanup_flag = PVE::QemuServer::RunState::can_use_cleanup_flag();
 
-                if (!$clean || $guest || $can_use_cleanup_flag) {
+                if (!$clean || $guest || $can_use_cleanup_flag || $reset) {
                     # either we can use the new mechanism to check if cleanup is done, or
                     # vm was shutdown from inside the guest or crashed
                     PVE::QemuServer::vm_stop_cleanup($storecfg, $vmid, $conf, 0, 0, 1);
@@ -1160,9 +1170,15 @@ __PACKAGE__->register_method({
                     PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-stop');
                 }
 
+                my $reboot = PVE::QemuServer::parse_reboot($conf->{reboot});
+                my $reboot_enabled = $reboot->{enabled} // 1;
+                my $powercycle = $reboot_enabled && $reboot->{powercycle};
+
                 my $reboot_requested = eval { PVE::QemuServer::clear_reboot_request($vmid) };
                 warn $@ if $@;
-                $restart = $reboot_requested && ($conf->{reboot} // 1);
+
+                $restart = ($reset && ($powercycle || !$guest))
+                    || ($reboot_requested && $reboot_enabled);
             },
         );
 
@@ -1473,7 +1489,9 @@ our $cmddef = {
 
     importovf => [__PACKAGE__, 'importovf', ['vmid', 'manifest', 'storage']],
 
-    cleanup => [__PACKAGE__, 'cleanup', ['vmid', 'clean-shutdown', 'guest-requested'], {%node}],
+    cleanup => [
+        __PACKAGE__, 'cleanup', ['vmid', 'clean-shutdown', 'guest-requested', 'reset'], {%node},
+    ],
 
     cloudinit => {
         dump => [
-- 
2.47.3





  parent reply	other threads:[~2026-10-22 12:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-22 12:51 [PATCH docs/guest-common/manager/qemu-server v2 0/8] fix #7213: add `powercycle` reboot behavior Jakob Klocker
2026-10-22 12:51 ` [PATCH pve-guest-common v2 1/8] AbstractConfig: fix pending delete for options with value 0 Jakob Klocker
2026-10-22 12:51 ` [PATCH pve-docs v2 2/8] qm: add reboot behavior information Jakob Klocker
2026-10-22 12:51 ` [PATCH qemu-server v2 3/8] qm: do not restart VM when `reboot` is disabled Jakob Klocker
2026-10-22 12:51 ` [PATCH qemu-server v2 4/8] fix #7213: config: add `powercycle` sub-property to `reboot` Jakob Klocker
2026-10-22 12:51 ` Jakob Klocker [this message]
2026-10-22 12:51 ` [PATCH qemu-server v2 6/8] fix #7213: qmeventd: pass `reset` to `qm cleanup` Jakob Klocker
2026-10-22 12:51 ` [PATCH qemu-server v2 7/8] vm_reboot: warn when rebooting a VM with `reboot` disabled Jakob Klocker
2026-10-22 12:51 ` [PATCH pve-manager v2 8/8] ui: qemu: options: add editor for reboot behavior Jakob Klocker

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=20261022125111.236538-6-j.klocker@proxmox.com \
    --to=j.klocker@proxmox.com \
    --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