[pve-devel] [PATCH qemu-server v2 5/5] implement a 'real' reboot for vms

Dominik Csapak d.csapak at proxmox.com
Wed Oct 17 14:31:23 CEST 2018


instead of letting qemu handle a reset, add '-no-reboot' by default
(>= qemu 2.12) and use our cleanup to start the vm again

this has the advantage that pending changes will be applied
on a reboot from within the guest, starts with a new qemu version
and enables us to have a 'reboot' button in the future
(more work for this is needed)

it still respects the 'reboot' config we had

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* correctly add -no-reboot
* check for 2.12 instead of 3.0
 PVE/CLI/qm.pm     | 22 ++++++++++++++++++++++
 PVE/QemuServer.pm |  6 +++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
index 6a14c12..8772e8c 100755
--- a/PVE/CLI/qm.pm
+++ b/PVE/CLI/qm.pm
@@ -758,6 +758,8 @@ __PACKAGE__->register_method({
 	my $guest = $param->{'guest-requested'};
 	my $reset = $param->{'was-reset'};
 
+	my $needs_reset = 0;
+
 	my $storecfg = PVE::Storage::config();
 
 	PVE::QemuConfig->lock_config($vmid, sub {
@@ -780,8 +782,28 @@ __PACKAGE__->register_method({
 		# vm was shutdown from inside the guest or crashed, doing api cleanup
 		PVE::QemuServer::vm_stop_cleanup($storecfg, $vmid, $conf, 0, 0);
 	    }
+
+	    if ((!defined($conf->{reboot}) || $conf->{reboot}) && $reset) {
+		$needs_reset = 1;
+	    }
 	});
 
+	if ($needs_reset) {
+	    my $rpcenv = PVE::RPCEnvironment::get();
+	    my $authuser = $rpcenv->get_user();
+	    # got reset parameter, we should start the vm again
+	    my $realcmd = sub {
+		my $upid = shift;
+
+		syslog('info', "restart VM $vmid: $upid\n");
+
+		PVE::QemuServer::vm_start($storecfg, $vmid);
+		return;
+	    };
+
+	    $rpcenv->fork_worker('qmrestart', $vmid, $authuser, $realcmd);
+	}
+
 	return undef;
     }});
 
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 2667946..8e98188 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3402,7 +3402,11 @@ sub config_to_command {
 
     push @$cmd, '-no-acpi' if defined($conf->{acpi}) && $conf->{acpi} == 0;
 
-    push @$cmd, '-no-reboot' if  defined($conf->{reboot}) && $conf->{reboot} == 0;
+    # we add it by default and check in the cleanup call if we want to start it again
+    if ((defined($conf->{reboot}) && $conf->{reboot} == 0) ||
+	qemu_machine_feature_enabled($machine_type, $kvmver, 2, 12)) {
+	push @$cmd, '-no-reboot';
+    }
 
     push @$cmd, '-vga', $vga if $vga && $vga !~ m/^serial\d+$/; # for kvm 77 and later
 
-- 
2.11.0





More information about the pve-devel mailing list