mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-10-04 13:49:50 +00:00
resume suspended vm on start
if a vm has the 'suspended' lock, we resume with the saved state and remove the lock, the saved vmstate and the saved runningmachine after the vm started Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
parent
159719e55b
commit
7ceade4cb3
@ -3998,6 +3998,12 @@ sub config_to_command {
|
||||
push @$cmd, '-global', join(',', @$globalFlags)
|
||||
if scalar(@$globalFlags);
|
||||
|
||||
if (my $vmstate = $conf->{vmstate}) {
|
||||
my $statepath = PVE::Storage::path($storecfg, $vmstate);
|
||||
PVE::Storage::activate_volumes($storecfg, [$vmstate]);
|
||||
push @$cmd, '-loadstate', $statepath;
|
||||
}
|
||||
|
||||
# add custom args
|
||||
if ($conf->{args}) {
|
||||
my $aa = PVE::Tools::split_args($conf->{args});
|
||||
@ -5148,7 +5154,10 @@ sub vm_start {
|
||||
|
||||
die "you can't start a vm if it's a template\n" if PVE::QemuConfig->is_template($conf);
|
||||
|
||||
PVE::QemuConfig->check_lock($conf) if !$skiplock;
|
||||
my $is_suspended = PVE::QemuConfig->has_lock($conf, 'suspended');
|
||||
|
||||
PVE::QemuConfig->check_lock($conf)
|
||||
if !($skiplock || $is_suspended);
|
||||
|
||||
die "VM $vmid already running\n" if check_running($vmid, undef, $migratedfrom);
|
||||
|
||||
@ -5214,6 +5223,11 @@ sub vm_start {
|
||||
|
||||
PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-start', 1);
|
||||
|
||||
if ($is_suspended) {
|
||||
# enforce machine type on suspended vm to ensure HW compatibility
|
||||
$forcemachine = $conf->{runningmachine};
|
||||
}
|
||||
|
||||
my ($cmd, $vollist, $spice_port) = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine);
|
||||
|
||||
my $migrate_port = 0;
|
||||
@ -5411,6 +5425,13 @@ sub vm_start {
|
||||
property => "guest-stats-polling-interval",
|
||||
value => 2) if (!defined($conf->{balloon}) || $conf->{balloon});
|
||||
|
||||
if ($is_suspended && (my $vmstate = $conf->{vmstate})) {
|
||||
delete $conf->@{qw(lock vmstate runningmachine)};
|
||||
PVE::Storage::deactivate_volumes($storecfg, [$vmstate]);
|
||||
PVE::Storage::vdisk_free($storecfg, $vmstate);
|
||||
PVE::QemuConfig->write_config($vmid, $conf);
|
||||
}
|
||||
|
||||
PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-start');
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user