Signed-off-by: Fiona Ebner <f.eb...@proxmox.com> --- PVE/QemuServer.pm | 56 +++++++------------------------------ PVE/QemuServer/StateFile.pm | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 46 deletions(-)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 91b55cf9..25ba709d 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -5577,8 +5577,6 @@ sub vm_start_nolock { my $migration_type = $migrate_opts->{type}; my $nbd_protocol_version = $migrate_opts->{nbd_proto_version} // 0; - my $res = {}; - # clean up leftover reboot request files eval { clear_reboot_request($vmid); }; warn $@ if $@; @@ -5649,54 +5647,20 @@ sub vm_start_nolock { $nodename, $migrate_opts->{network}); } + my $res = {}; + my $statefile_is_a_volume; + my $state_cmdline = []; if ($statefile) { - if ($statefile eq 'tcp') { - my $migrate = $res->{migrate} = { proto => 'tcp' }; - $migrate->{addr} = "localhost"; - my $datacenterconf = PVE::Cluster::cfs_read_file('datacenter.cfg'); - my $nodename = nodename(); - - if (!defined($migration_type)) { - if (defined($datacenterconf->{migration}->{type})) { - $migration_type = $datacenterconf->{migration}->{type}; - } else { - $migration_type = 'secure'; - } - } - - if ($migration_type eq 'insecure') { - $migrate->{addr} = $migration_ip // die "internal error - no migration IP"; - $migrate->{addr} = "[$migrate->{addr}]" if Net::IP::ip_is_ipv6($migrate->{addr}); - } - - # see #4501: port reservation should be done close to usage - tell QEMU where to listen - # via QMP later - push @$cmd, '-incoming', 'defer'; - push @$cmd, '-S'; - - } elsif ($statefile eq 'unix') { - # should be default for secure migrations as a ssh TCP forward - # tunnel is not deterministic reliable ready and fails regurarly - # to set up in time, so use UNIX socket forwards - my $migrate = $res->{migrate} = { proto => 'unix' }; - $migrate->{addr} = "/run/qemu-server/$vmid.migrate"; - unlink $migrate->{addr}; - - $migrate->{uri} = "unix:$migrate->{addr}"; - push @$cmd, '-incoming', $migrate->{uri}; - push @$cmd, '-S'; - - } elsif (-e $statefile) { - push @$cmd, '-loadstate', $statefile; - } else { - my $statepath = PVE::Storage::path($storecfg, $statefile); - push @$vollist, $statefile; - push @$cmd, '-loadstate', $statepath; - } + ($state_cmdline, $res->{migrate}, $statefile_is_a_volume) = + PVE::QemuServer::StateFile::statefile_cmdline_option( + $storecfg, $vmid, $statefile, $migrate_opts, $migration_ip); + push @$vollist, $statefile if $statefile_is_a_volume; } elsif ($params->{paused}) { - push @$cmd, '-S'; + $state_cmdline = ['-S']; } + push $cmd->@*, $state_cmdline->@*; + my $memory = get_current_memory($conf->{memory}); my $start_timeout = $params->{timeout} // config_aware_timeout($conf, $memory, $resume); diff --git a/PVE/QemuServer/StateFile.pm b/PVE/QemuServer/StateFile.pm index e297839b..630ccca3 100644 --- a/PVE/QemuServer/StateFile.pm +++ b/PVE/QemuServer/StateFile.pm @@ -29,4 +29,60 @@ sub get_migration_ip { return PVE::Cluster::remote_node_ip($nodename, 1); } +# $migration_ip must be defined if using insecure TCP migration +sub statefile_cmdline_option { + my ($storecfg, $vmid, $statefile, $migrate_opts, $migration_ip) = @_; + + my $migration_type = $migrate_opts->{type}; + + my $statefile_is_a_volume = 0; + my $res = {}; + my $cmd = []; + + if ($statefile eq 'tcp') { + my $migrate = $res->{migrate} = { proto => 'tcp' }; + $migrate->{addr} = "localhost"; + my $datacenterconf = PVE::Cluster::cfs_read_file('datacenter.cfg'); + + if (!defined($migration_type)) { + if (defined($datacenterconf->{migration}->{type})) { + $migration_type = $datacenterconf->{migration}->{type}; + } else { + $migration_type = 'secure'; + } + } + + if ($migration_type eq 'insecure') { + $migrate->{addr} = $migration_ip // die "internal error - no migration IP"; + $migrate->{addr} = "[$migrate->{addr}]" if Net::IP::ip_is_ipv6($migrate->{addr}); + } + + # see #4501: port reservation should be done close to usage - tell QEMU where to listen + # via QMP later + push @$cmd, '-incoming', 'defer'; + push @$cmd, '-S'; + + } elsif ($statefile eq 'unix') { + # should be default for secure migrations as a ssh TCP forward + # tunnel is not deterministic reliable ready and fails regurarly + # to set up in time, so use UNIX socket forwards + my $migrate = $res->{migrate} = { proto => 'unix' }; + $migrate->{addr} = "/run/qemu-server/$vmid.migrate"; + unlink $migrate->{addr}; + + $migrate->{uri} = "unix:$migrate->{addr}"; + push @$cmd, '-incoming', $migrate->{uri}; + push @$cmd, '-S'; + + } elsif (-e $statefile) { + push @$cmd, '-loadstate', $statefile; + } else { + my $statepath = PVE::Storage::path($storecfg, $statefile); + $statefile_is_a_volume = 1; + push @$cmd, '-loadstate', $statepath; + } + + return ($cmd, $res->{migrate}, $statefile_is_a_volume); +} + 1; -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel