mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-10-04 21:14:21 +00:00
vm_start: condense signature
as preparation for refactoring it further. remote migration will add another 1-2 parameters, and it is already unwieldly enough as it is. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
6a039d06e9
commit
0c498cca36
@ -2114,9 +2114,24 @@ __PACKAGE__->register_method({
|
|||||||
|
|
||||||
syslog('info', "start VM $vmid: $upid\n");
|
syslog('info', "start VM $vmid: $upid\n");
|
||||||
|
|
||||||
PVE::QemuServer::vm_start($storecfg, $vmid, $stateuri, $skiplock, $migratedfrom, undef, $machine,
|
my $migrate_opts = {
|
||||||
$spice_ticket, $migration_network, $migration_type, $targetstorage, $timeout,
|
migratedfrom => $migratedfrom,
|
||||||
$nbd_protocol_version, $replicated_volumes);
|
spice_ticket => $spice_ticket,
|
||||||
|
network => $migration_network,
|
||||||
|
type => $migration_type,
|
||||||
|
targetstorage => $targetstorage,
|
||||||
|
nbd_proto_version => $nbd_protocol_version,
|
||||||
|
replicated_volumes => $replicated_volumes,
|
||||||
|
};
|
||||||
|
|
||||||
|
my $params = {
|
||||||
|
statefile => $stateuri,
|
||||||
|
skiplock => $skiplock,
|
||||||
|
forcemachine => $machine,
|
||||||
|
timeout => $timeout,
|
||||||
|
};
|
||||||
|
|
||||||
|
PVE::QemuServer::vm_start($storecfg, $vmid, $params, $migrate_opts);
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2584,7 +2599,7 @@ __PACKAGE__->register_method({
|
|||||||
PVE::QemuServer::vm_resume($vmid, $skiplock, $nocheck);
|
PVE::QemuServer::vm_resume($vmid, $skiplock, $nocheck);
|
||||||
} else {
|
} else {
|
||||||
my $storecfg = PVE::Storage::config();
|
my $storecfg = PVE::Storage::config();
|
||||||
PVE::QemuServer::vm_start($storecfg, $vmid, undef, $skiplock);
|
PVE::QemuServer::vm_start($storecfg, $vmid, { skiplock => $skiplock });
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -392,7 +392,11 @@ sub __snapshot_rollback_vm_start {
|
|||||||
my ($class, $vmid, $vmstate, $data) = @_;
|
my ($class, $vmid, $vmstate, $data) = @_;
|
||||||
|
|
||||||
my $storecfg = PVE::Storage::config();
|
my $storecfg = PVE::Storage::config();
|
||||||
PVE::QemuServer::vm_start($storecfg, $vmid, $vmstate, undef, undef, undef, $data->{forcemachine});
|
my $params = {
|
||||||
|
statefile => $vmstate,
|
||||||
|
forcemachine => $data->{forcemachine},
|
||||||
|
};
|
||||||
|
PVE::QemuServer::vm_start($storecfg, $vmid, $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub __snapshot_rollback_get_unused {
|
sub __snapshot_rollback_get_unused {
|
||||||
|
@ -4709,12 +4709,30 @@ sub vmconfig_update_disk {
|
|||||||
vm_deviceplug($storecfg, $conf, $vmid, $opt, $drive, $arch, $machine_type);
|
vm_deviceplug($storecfg, $conf, $vmid, $opt, $drive, $arch, $machine_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# params:
|
||||||
|
# statefile => 'tcp', 'unix' for migration or path/volid for RAM state
|
||||||
|
# skiplock => 0/1, skip checking for config lock
|
||||||
|
# forcemachine => to force Qemu machine (rollback/migration)
|
||||||
|
# timeout => in seconds
|
||||||
|
# paused => start VM in paused state (backup)
|
||||||
|
# migrate_opts:
|
||||||
|
# migratedfrom => source node
|
||||||
|
# spice_ticket => used for spice migration, passed via tunnel/stdin
|
||||||
|
# network => CIDR of migration network
|
||||||
|
# type => secure/insecure - tunnel over encrypted connection or plain-text
|
||||||
|
# targetstorage = storageid/'1' - target storage for disks migrated over NBD
|
||||||
|
# nbd_proto_version => int, 0 for TCP, 1 for UNIX
|
||||||
|
# replicated_volumes = which volids should be re-used with bitmaps for nbd migration
|
||||||
sub vm_start {
|
sub vm_start {
|
||||||
my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused,
|
my ($storecfg, $vmid, $params, $migrate_opts) = @_;
|
||||||
$forcemachine, $spice_ticket, $migration_network, $migration_type,
|
|
||||||
$targetstorage, $timeout, $nbd_protocol_version, $replicated_volumes) = @_;
|
|
||||||
|
|
||||||
PVE::QemuConfig->lock_config($vmid, sub {
|
PVE::QemuConfig->lock_config($vmid, sub {
|
||||||
|
my $statefile = $params->{statefile};
|
||||||
|
|
||||||
|
my $migratedfrom = $migrate_opts->{migratedfrom};
|
||||||
|
my $migration_type = $migrate_opts->{type};
|
||||||
|
my $targetstorage = $migrate_opts->{targetstorage};
|
||||||
|
|
||||||
my $conf = PVE::QemuConfig->load_config($vmid, $migratedfrom);
|
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);
|
die "you can't start a vm if it's a template\n" if PVE::QemuConfig->is_template($conf);
|
||||||
@ -4722,7 +4740,7 @@ sub vm_start {
|
|||||||
my $is_suspended = PVE::QemuConfig->has_lock($conf, 'suspended');
|
my $is_suspended = PVE::QemuConfig->has_lock($conf, 'suspended');
|
||||||
|
|
||||||
PVE::QemuConfig->check_lock($conf)
|
PVE::QemuConfig->check_lock($conf)
|
||||||
if !($skiplock || $is_suspended);
|
if !($params->{skiplock} || $is_suspended);
|
||||||
|
|
||||||
die "VM $vmid already running\n" if check_running($vmid, undef, $migratedfrom);
|
die "VM $vmid already running\n" if check_running($vmid, undef, $migratedfrom);
|
||||||
|
|
||||||
@ -4766,7 +4784,7 @@ sub vm_start {
|
|||||||
foreach my $opt (sort keys %$local_volumes) {
|
foreach my $opt (sort keys %$local_volumes) {
|
||||||
|
|
||||||
my ($volid, $storeid, $volname) = @{$local_volumes->{$opt}};
|
my ($volid, $storeid, $volname) = @{$local_volumes->{$opt}};
|
||||||
if ($replicated_volumes->{$volid}) {
|
if ($migrate_opts->{replicated_volumes}->{$volid}) {
|
||||||
# re-use existing, replicated volume with bitmap on source side
|
# re-use existing, replicated volume with bitmap on source side
|
||||||
$local_volumes->{$opt} = $conf->{${opt}};
|
$local_volumes->{$opt} = $conf->{${opt}};
|
||||||
print "re-using replicated volume: $opt - $volid\n";
|
print "re-using replicated volume: $opt - $volid\n";
|
||||||
@ -4801,6 +4819,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};
|
||||||
if ($is_suspended) {
|
if ($is_suspended) {
|
||||||
# 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};
|
||||||
@ -4811,10 +4830,12 @@ sub vm_start {
|
|||||||
|
|
||||||
my $migration_ip;
|
my $migration_ip;
|
||||||
my $get_migration_ip = sub {
|
my $get_migration_ip = sub {
|
||||||
my ($cidr, $nodename) = @_;
|
my ($nodename) = @_;
|
||||||
|
|
||||||
return $migration_ip if defined($migration_ip);
|
return $migration_ip if defined($migration_ip);
|
||||||
|
|
||||||
|
my $cidr = $migrate_opts->{network};
|
||||||
|
|
||||||
if (!defined($cidr)) {
|
if (!defined($cidr)) {
|
||||||
my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
|
my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
|
||||||
$cidr = $dc_conf->{migration}->{network};
|
$cidr = $dc_conf->{migration}->{network};
|
||||||
@ -4854,7 +4875,7 @@ sub vm_start {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($migration_type eq 'insecure') {
|
if ($migration_type eq 'insecure') {
|
||||||
$localip = $get_migration_ip->($migration_network, $nodename);
|
$localip = $get_migration_ip->($nodename);
|
||||||
$localip = "[$localip]" if Net::IP::ip_is_ipv6($localip);
|
$localip = "[$localip]" if Net::IP::ip_is_ipv6($localip);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4883,7 +4904,7 @@ sub vm_start {
|
|||||||
push @$vollist, $statefile;
|
push @$vollist, $statefile;
|
||||||
push @$cmd, '-loadstate', $statepath;
|
push @$cmd, '-loadstate', $statepath;
|
||||||
}
|
}
|
||||||
} elsif ($paused) {
|
} elsif ($params->{paused}) {
|
||||||
push @$cmd, '-S';
|
push @$cmd, '-S';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4924,7 +4945,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 = $timeout // config_aware_timeout($conf, $is_suspended);
|
my $start_timeout = $params->{timeout} // config_aware_timeout($conf, $is_suspended);
|
||||||
my %run_params = (
|
my %run_params = (
|
||||||
timeout => $statefile ? undef : $start_timeout,
|
timeout => $statefile ? undef : $start_timeout,
|
||||||
umask => 0077,
|
umask => 0077,
|
||||||
@ -4996,7 +5017,7 @@ sub vm_start {
|
|||||||
|
|
||||||
#start nbd server for storage migration
|
#start nbd server for storage migration
|
||||||
if ($targetstorage) {
|
if ($targetstorage) {
|
||||||
$nbd_protocol_version //= 0;
|
my $nbd_protocol_version = $migrate_opts->{nbd_proto_version} // 0;
|
||||||
|
|
||||||
my $migrate_storage_uri;
|
my $migrate_storage_uri;
|
||||||
# nbd_protocol_version > 0 for unix socket support
|
# nbd_protocol_version > 0 for unix socket support
|
||||||
@ -5006,7 +5027,7 @@ sub vm_start {
|
|||||||
$migrate_storage_uri = "nbd:unix:$socket_path";
|
$migrate_storage_uri = "nbd:unix:$socket_path";
|
||||||
} else {
|
} else {
|
||||||
my $nodename = nodename();
|
my $nodename = nodename();
|
||||||
my $localip = $get_migration_ip->($migration_network, $nodename);
|
my $localip = $get_migration_ip->($nodename);
|
||||||
my $pfamily = PVE::Tools::get_host_address_family($nodename);
|
my $pfamily = PVE::Tools::get_host_address_family($nodename);
|
||||||
my $storage_migrate_port = PVE::Tools::next_migrate_port($pfamily);
|
my $storage_migrate_port = PVE::Tools::next_migrate_port($pfamily);
|
||||||
|
|
||||||
@ -5030,8 +5051,8 @@ sub vm_start {
|
|||||||
|
|
||||||
if ($spice_port) {
|
if ($spice_port) {
|
||||||
print "spice listens on port $spice_port\n";
|
print "spice listens on port $spice_port\n";
|
||||||
if ($spice_ticket) {
|
if ($migrate_opts->{spice_ticket}) {
|
||||||
mon_cmd($vmid, "set_password", protocol => 'spice', password => $spice_ticket);
|
mon_cmd($vmid, "set_password", protocol => 'spice', password => $migrate_opts->{spice_ticket});
|
||||||
mon_cmd($vmid, "expire_password", protocol => 'spice', time => "+30");
|
mon_cmd($vmid, "expire_password", protocol => 'spice', time => "+30");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -676,7 +676,11 @@ sub enforce_vm_running_for_backup {
|
|||||||
eval {
|
eval {
|
||||||
$self->loginfo("starting kvm to execute backup task");
|
$self->loginfo("starting kvm to execute backup task");
|
||||||
# start with skiplock
|
# start with skiplock
|
||||||
PVE::QemuServer::vm_start($self->{storecfg}, $vmid, undef, 1, undef, 1);
|
my $params = {
|
||||||
|
skiplock => 1,
|
||||||
|
paused => 1,
|
||||||
|
};
|
||||||
|
PVE::QemuServer::vm_start($self->{storecfg}, $vmid, $params);
|
||||||
};
|
};
|
||||||
die $@ if $@;
|
die $@ if $@;
|
||||||
}
|
}
|
||||||
|
@ -356,13 +356,13 @@ sub do_snapshots_with_qemu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub vm_start {
|
sub vm_start {
|
||||||
my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused, $forcemachine) = @_;
|
my ($storecfg, $vmid, $params, $migrate_opts) = @_;
|
||||||
|
|
||||||
die "Storage config not mocked! aborting\n"
|
die "Storage config not mocked! aborting\n"
|
||||||
if defined($storecfg);
|
if defined($storecfg);
|
||||||
|
|
||||||
die "statefile and forcemachine must be both defined or undefined! aborting\n"
|
die "statefile and forcemachine must be both defined or undefined! aborting\n"
|
||||||
if defined($statefile) xor defined($forcemachine);
|
if defined($params->{statefile}) xor defined($params->{forcemachine});
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user