diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm index af849d35..085aa16f 100644 --- a/PVE/QemuMigrate.pm +++ b/PVE/QemuMigrate.pm @@ -6,6 +6,7 @@ use PVE::AbstractMigrate; use IO::File; use IPC::Open2; use PVE::INotify; +use PVE::Tools; use PVE::Cluster; use PVE::Storage; use PVE::QemuServer; @@ -328,7 +329,7 @@ sub phase2 { $self->log('info', "starting migration tunnel"); ## create tunnel to remote port - my $lport = PVE::QemuServer::next_migrate_port(); + my $lport = PVE::Tools::next_migrate_port(); $self->{tunnel} = $self->fork_tunnel($self->{nodeip}, $lport, $rport); $self->log('info', "starting online/live migration on port $lport"); diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index b020b535..ae817f75 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -2540,25 +2540,6 @@ sub pidfile_name { return "${var_run_tmpdir}/$vmid.pid"; } -sub next_migrate_port { - - for (my $p = 60000; $p < 60010; $p++) { - - my $sock = IO::Socket::INET->new(Listen => 5, - LocalAddr => 'localhost', - LocalPort => $p, - ReuseAddr => 1, - Proto => 0); - - if ($sock) { - close($sock); - return $p; - } - } - - die "unable to find free migration port"; -} - sub vm_devices_list { my ($vmid) = @_; @@ -3002,7 +2983,7 @@ sub vm_start { if ($statefile) { if ($statefile eq 'tcp') { - $migrate_port = next_migrate_port(); + $migrate_port = PVE::Tools::next_migrate_port(); my $migrate_uri = "tcp:localhost:${migrate_port}"; push @$cmd, '-incoming', $migrate_uri; push @$cmd, '-S';