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

Dominik Csapak d.csapak at proxmox.com
Wed Oct 17 11:59:21 CEST 2018


On 10/17/18 11:18 AM, Wolfgang Bumiller wrote:
> On Tue, Oct 16, 2018 at 12:07:06PM +0200, Dominik Csapak wrote:
>> instead of letting qemu handle a reset, add '-no-reboot' by default
>> (>= qemu 3.0) 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>
>> ---
>>   PVE/CLI/qm.pm     | 22 ++++++++++++++++++++++
>>   PVE/QemuServer.pm |  7 ++++++-
>>   2 files changed, 28 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 4838e79..7dad560 100644
>> --- a/PVE/QemuServer.pm
>> +++ b/PVE/QemuServer.pm
>> @@ -3402,7 +3402,12 @@ 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, 3, 0)) {
> 
> I see no way to get back to the old behavior on a newer qemu now?
> reboot: 0 => --no-reboot
> reboot: 1 => --no-reboot
> 

yes, but in the case of reboot: 1 and no reboot config at all, we reboot 
the vm, while keeping the reboot: 0 does not reboot the vm

i meant that we keep the behaviour in a more abstract way, not a
strict way ( e.g. have always a 'real' reboot, but allow to skip the 
restarting)

>> +	push @$cmd, '-no-reboot' if  defined($conf->{reboot}) && $conf->{reboot} == 0;
>> +    }
>>   
>>       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