mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-14 14:05:45 +00:00
vm_start: split out lock + initial checks
to start breaking up vm_start before extending parts for new migration features like storage and network mapping. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
0c498cca36
commit
3898a56343
@ -4709,12 +4709,34 @@ sub vmconfig_update_disk {
|
|||||||
vm_deviceplug($storecfg, $conf, $vmid, $opt, $drive, $arch, $machine_type);
|
vm_deviceplug($storecfg, $conf, $vmid, $opt, $drive, $arch, $machine_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# see vm_start_nolock for parameters
|
||||||
|
sub vm_start {
|
||||||
|
my ($storecfg, $vmid, $params, $migrate_opts) = @_;
|
||||||
|
|
||||||
|
PVE::QemuConfig->lock_config($vmid, sub {
|
||||||
|
my $conf = PVE::QemuConfig->load_config($vmid, $migrate_opts->{migratedfrom});
|
||||||
|
|
||||||
|
die "you can't start a vm if it's a template\n" if PVE::QemuConfig->is_template($conf);
|
||||||
|
|
||||||
|
$params->{resume} = PVE::QemuConfig->has_lock($conf, 'suspended');
|
||||||
|
|
||||||
|
PVE::QemuConfig->check_lock($conf)
|
||||||
|
if !($params->{skiplock} || $params->{resume});
|
||||||
|
|
||||||
|
die "VM $vmid already running\n" if check_running($vmid, undef, $migrate_opts->{migratedfrom});
|
||||||
|
|
||||||
|
vm_start_nolock($storecfg, $vmid, $conf, $params, $migrate_opts);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# params:
|
# params:
|
||||||
# statefile => 'tcp', 'unix' for migration or path/volid for RAM state
|
# statefile => 'tcp', 'unix' for migration or path/volid for RAM state
|
||||||
# skiplock => 0/1, skip checking for config lock
|
# skiplock => 0/1, skip checking for config lock
|
||||||
# forcemachine => to force Qemu machine (rollback/migration)
|
# forcemachine => to force Qemu machine (rollback/migration)
|
||||||
# timeout => in seconds
|
# timeout => in seconds
|
||||||
# paused => start VM in paused state (backup)
|
# paused => start VM in paused state (backup)
|
||||||
|
# resume => resume from hibernation
|
||||||
# migrate_opts:
|
# migrate_opts:
|
||||||
# migratedfrom => source node
|
# migratedfrom => source node
|
||||||
# spice_ticket => used for spice migration, passed via tunnel/stdin
|
# spice_ticket => used for spice migration, passed via tunnel/stdin
|
||||||
@ -4723,27 +4745,16 @@ sub vmconfig_update_disk {
|
|||||||
# targetstorage = storageid/'1' - target storage for disks migrated over NBD
|
# targetstorage = storageid/'1' - target storage for disks migrated over NBD
|
||||||
# nbd_proto_version => int, 0 for TCP, 1 for UNIX
|
# nbd_proto_version => int, 0 for TCP, 1 for UNIX
|
||||||
# replicated_volumes = which volids should be re-used with bitmaps for nbd migration
|
# replicated_volumes = which volids should be re-used with bitmaps for nbd migration
|
||||||
sub vm_start {
|
sub vm_start_nolock {
|
||||||
my ($storecfg, $vmid, $params, $migrate_opts) = @_;
|
my ($storecfg, $vmid, $conf, $params, $migrate_opts) = @_;
|
||||||
|
|
||||||
PVE::QemuConfig->lock_config($vmid, sub {
|
|
||||||
my $statefile = $params->{statefile};
|
my $statefile = $params->{statefile};
|
||||||
|
my $resume = $params->{resume};
|
||||||
|
|
||||||
my $migratedfrom = $migrate_opts->{migratedfrom};
|
my $migratedfrom = $migrate_opts->{migratedfrom};
|
||||||
my $migration_type = $migrate_opts->{type};
|
my $migration_type = $migrate_opts->{type};
|
||||||
my $targetstorage = $migrate_opts->{targetstorage};
|
my $targetstorage = $migrate_opts->{targetstorage};
|
||||||
|
|
||||||
my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom);
|
|
||||||
|
|
||||||
die "you can't start a vm if it's a template\n" if PVE::QemuConfig->is_template($conf);
|
|
||||||
|
|
||||||
my $is_suspended = PVE::QemuConfig->has_lock($conf, 'suspended');
|
|
||||||
|
|
||||||
PVE::QemuConfig->check_lock($conf)
|
|
||||||
if !($params->{skiplock} || $is_suspended);
|
|
||||||
|
|
||||||
die "VM $vmid already running\n" if check_running($vmid, undef, $migratedfrom);
|
|
||||||
|
|
||||||
# clean up leftover reboot request files
|
# clean up leftover reboot request files
|
||||||
eval { clear_reboot_request($vmid); };
|
eval { clear_reboot_request($vmid); };
|
||||||
warn $@ if $@;
|
warn $@ if $@;
|
||||||
@ -4820,7 +4831,7 @@ sub vm_start {
|
|||||||
PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-start', 1);
|
PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'pre-start', 1);
|
||||||
|
|
||||||
my $forcemachine = $params->{forcemachine};
|
my $forcemachine = $params->{forcemachine};
|
||||||
if ($is_suspended) {
|
if ($resume) {
|
||||||
# enforce machine type on suspended vm to ensure HW compatibility
|
# enforce machine type on suspended vm to ensure HW compatibility
|
||||||
$forcemachine = $conf->{runningmachine};
|
$forcemachine = $conf->{runningmachine};
|
||||||
print "Resuming suspended VM\n";
|
print "Resuming suspended VM\n";
|
||||||
@ -4945,7 +4956,7 @@ sub vm_start {
|
|||||||
my $cpuunits = defined($conf->{cpuunits}) ? $conf->{cpuunits}
|
my $cpuunits = defined($conf->{cpuunits}) ? $conf->{cpuunits}
|
||||||
: $defaults->{cpuunits};
|
: $defaults->{cpuunits};
|
||||||
|
|
||||||
my $start_timeout = $params->{timeout} // config_aware_timeout($conf, $is_suspended);
|
my $start_timeout = $params->{timeout} // config_aware_timeout($conf, $resume);
|
||||||
my %run_params = (
|
my %run_params = (
|
||||||
timeout => $statefile ? undef : $start_timeout,
|
timeout => $statefile ? undef : $start_timeout,
|
||||||
umask => 0077,
|
umask => 0077,
|
||||||
@ -5073,7 +5084,7 @@ sub vm_start {
|
|||||||
property => "guest-stats-polling-interval",
|
property => "guest-stats-polling-interval",
|
||||||
value => 2) if (!defined($conf->{balloon}) || $conf->{balloon});
|
value => 2) if (!defined($conf->{balloon}) || $conf->{balloon});
|
||||||
|
|
||||||
if ($is_suspended) {
|
if ($resume) {
|
||||||
print "Resumed VM, removing state\n";
|
print "Resumed VM, removing state\n";
|
||||||
if (my $vmstate = $conf->{vmstate}) {
|
if (my $vmstate = $conf->{vmstate}) {
|
||||||
PVE::Storage::deactivate_volumes($storecfg, [$vmstate]);
|
PVE::Storage::deactivate_volumes($storecfg, [$vmstate]);
|
||||||
@ -5084,7 +5095,6 @@ sub vm_start {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-start');
|
PVE::GuestHelpers::exec_hookscript($conf, $vmid, 'post-start');
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub vm_commandline {
|
sub vm_commandline {
|
||||||
|
Loading…
Reference in New Issue
Block a user