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 4/8] fix #7213: config: add `powercycle` sub-property to `reboot`
Date: Thu, 22 Oct 2026 14:51:07 +0200	[thread overview]
Message-ID: <20261022125111.236538-5-j.klocker@proxmox.com> (raw)
In-Reply-To: <20261022125111.236538-1-j.klocker@proxmox.com>

A guest-initiated reboot is handled by QEMU itself, so the process keeps
running and the VM stays on the configuration and QEMU binary it was
started with. Pending changes therefore remain pending.

With `powercycle` set, start the VM with `-no-reboot` so that QEMU exits
on a reset instead. `qm cleanup` then starts the VM again, which makes
it a full start and applies pending changes. Note that `-no-reboot`
covers resets requested through the API as well, so those also become a
full stop and start.

Convert `reboot` to a property string to carry the new sub-property.
Existing configurations stay valid, as the previous boolean value is the
default key.

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

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 1efeeb66..011d175f 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -237,6 +237,27 @@ my $spice_enhancements_fmt = {
     },
 };
 
+my $reboot_fmt = {
+    enabled => {
+        default_key => 1,
+        type => 'boolean',
+        default => 1,
+        optional => 1,
+        description => "Allow reboot. If set to '0' the VM is shut down instead of rebooted"
+            . " and stays off, whether the reboot was requested from inside the guest or"
+            . " through the API. An explicit reset through the API still restarts the VM.",
+    },
+    powercycle => {
+        type => 'boolean',
+        optional => 1,
+        default => 0,
+        description => "Stop and start the VM on a reset instead of resetting it in place, so"
+            . " pending changes are applied and the currently installed QEMU version is used."
+            . " Applies to resets initiated by the guest as well as through the API. Ignored"
+            . " when reboot is disabled.",
+    },
+};
+
 my $confdesc = {
     onboot => {
         optional => 1,
@@ -263,9 +284,9 @@ my $confdesc = {
     },
     reboot => {
         optional => 1,
-        type => 'boolean',
-        description => "Allow reboot. If set to '0' the VM exit on reboot.",
-        default => 1,
+        type => 'string',
+        format => $reboot_fmt,
+        description => "Reboot behavior and its properties.",
     },
     lock => {
         optional => 1,
@@ -1685,6 +1706,16 @@ sub parse_vga {
     return $res;
 }
 
+sub parse_reboot {
+    my ($value) = @_;
+
+    return { enabled => 1 } if !defined($value) || $value eq '';
+
+    my $res = eval { parse_property_string($reboot_fmt, $value) };
+    warn $@ if $@;
+    return $res // {};
+}
+
 sub qemu_created_version_fixups {
     my ($conf, $forcemachine, $kvmver) = @_;
 
@@ -3231,6 +3262,8 @@ sub config_to_command {
         push @$cmd, '-name', "$vmname,debug-threads=on";
     }
 
+    my $reboot = parse_reboot($conf->{reboot});
+    push @$cmd, '-no-reboot' if !($reboot->{enabled} // 1) || $reboot->{powercycle};
     push @$cmd, '-no-shutdown';
 
     my $use_virtio = 0;
@@ -3414,8 +3447,6 @@ sub config_to_command {
 
     push $machineFlags->@*, 'acpi=off' if defined($conf->{acpi}) && $conf->{acpi} == 0;
 
-    push @$cmd, '-no-reboot' if defined($conf->{reboot}) && $conf->{reboot} == 0;
-
     if ($vga->{type} && $vga->{type} !~ m/^serial\d+$/ && $vga->{type} ne 'none') {
         push @$devices, '-device',
             print_vga_device($conf, $vga, $arch, $machine_version, undef, $qxlnum);
-- 
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 ` Jakob Klocker [this message]
2026-10-22 12:51 ` [PATCH qemu-server v2 5/8] fix #7213: qm: cleanup: add `reset` parameter to honor `powercycle` Jakob Klocker
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-5-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