From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 5B8E51FF0C2 for ; Thu, 22 Oct 2026 14:52:25 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 670112194C; Thu, 22 Oct 2026 14:51:35 +0200 (CEST) From: Jakob Klocker 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 Message-ID: <20261022125111.236538-6-j.klocker@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261022125111.236538-1-j.klocker@proxmox.com> References: <20261022125111.236538-1-j.klocker@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1792673489266 X-SPAM-LEVEL: Spam detection results: 0 AWL 1.538 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: ECP3OTY6OUBLZIT34NSHUJDFYIBHOMUF X-Message-ID-Hash: ECP3OTY6OUBLZIT34NSHUJDFYIBHOMUF X-MailFrom: j.klocker@proxmox.com 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 X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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