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 8F0421FF0EA for ; Thu, 13 Aug 2026 13:27:44 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 3CE43215E7; Thu, 13 Aug 2026 13:27:31 +0200 (CEST) From: Jakob Klocker To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server 3/6] fix #7213: qm: cleanup: add `reset` parameter to honor `powercycle` Date: Thu, 13 Aug 2026 13:27:14 +0200 Message-ID: <20260813112717.272254-4-j.klocker@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260813112717.272254-1-j.klocker@proxmox.com> References: <20260813112717.272254-1-j.klocker@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 1 AWL -0.567 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) KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods RDNS_NONE 1.274 Delivered to internal network by a host with no rDNS SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record Message-ID-Hash: 5EQI3QZ63LZSZ75474RKYTA2ERY5OCWD X-Message-ID-Hash: 5EQI3QZ63LZSZ75474RKYTA2ERY5OCWD X-MailFrom: jklocker@iris.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 CC: Jakob Klocker 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 guest reset and `powercycle` is set, in addition to the existing case of an explicit reboot request. Both cases stay gated on `enabled`, so a VM with reboot disabled always stays off. A reset also has to be treated like a guest-initiated shutdown when deciding whether to run the cleanup, as it does not go through the regular stop path either. Link: https://bugzilla.proxmox.com/show_bug.cgi?id=7213 Signed-off-by: Jakob Klocker --- src/PVE/CLI/qm.pm | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/PVE/CLI/qm.pm b/src/PVE/CLI/qm.pm index f35b8a30..c64f8ebb 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 || $reset || $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 PVE::QemuServer::vm_stop_cleanup($storecfg, $vmid, $conf, 0, 0, 1); @@ -1160,9 +1170,12 @@ __PACKAGE__->register_method({ PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-stop'); } + my $reboot = PVE::QemuServer::parse_reboot($conf->{reboot}); my $reboot_requested = eval { PVE::QemuServer::clear_reboot_request($vmid) }; warn $@ if $@; - $restart = $reboot_requested && ($conf->{reboot} // 1); + + $restart = ($reboot_requested || ($reset && $reboot->{powercycle})) + && ($reboot->{enabled} // 1); }, ); @@ -1473,7 +1486,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