[pve-devel] [PATCH v2 qemu-server 03/16] phase2 : add start_remote_tunnel
Alexandre Derumier
aderumier at odiso.com
Mon Mar 9 16:24:26 CET 2020
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/QemuMigrate.pm | 84 +++++++++++++++++++++++++---------------------
1 file changed, 45 insertions(+), 39 deletions(-)
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 6460480..6243d0d 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -557,45 +557,7 @@ sub phase2 {
my ($raddr, $rport, $ruri, $spice_port, $spice_ticket) = find_remote_ports($self, $vmid, $cmd);
- $self->log('info', "start remote tunnel");
-
- if ($migration_type eq 'secure') {
-
- if ($ruri =~ /^unix:/) {
- unlink $raddr;
- $self->{tunnel} = $self->fork_tunnel("$raddr:$raddr");
- $self->{tunnel}->{sock_addr} = $raddr;
-
- my $unix_socket_try = 0; # wait for the socket to become ready
- while (! -S $raddr) {
- $unix_socket_try++;
- if ($unix_socket_try > 100) {
- $self->{errors} = 1;
- $self->finish_tunnel($self->{tunnel});
- die "Timeout, migration socket $ruri did not get ready";
- }
-
- usleep(50000);
- }
-
- } elsif ($ruri =~ /^tcp:/) {
- my $tunnel_addr;
- if ($raddr eq "localhost") {
- # for backwards compatibility with older qemu-server versions
- my $pfamily = PVE::Tools::get_host_address_family($nodename);
- my $lport = PVE::Tools::next_migrate_port($pfamily);
- $tunnel_addr = "$lport:localhost:$rport";
- }
-
- $self->{tunnel} = $self->fork_tunnel($tunnel_addr);
-
- } else {
- die "unsupported protocol in migration URI: $ruri\n";
- }
- } else {
- #fork tunnel for insecure migration, to send faster commands like resume
- $self->{tunnel} = $self->fork_tunnel();
- }
+ start_remote_tunnel($self, $nodename, $migration_type, $raddr, $rport, $ruri);
my $start = time();
@@ -1115,4 +1077,48 @@ sub find_remote_ports {
return ($raddr, $rport, $ruri, $spice_port, $spice_ticket);
}
+sub start_remote_tunnel {
+ my ($self, $nodename, $migration_type, $raddr, $rport, $ruri) = @_;
+
+ $self->log('info', "start remote tunnel");
+
+ if ($migration_type eq 'secure') {
+
+ if ($ruri =~ /^unix:/) {
+ unlink $raddr;
+ $self->{tunnel} = $self->fork_tunnel("$raddr:$raddr");
+ $self->{tunnel}->{sock_addr} = $raddr;
+
+ my $unix_socket_try = 0; # wait for the socket to become ready
+ while (! -S $raddr) {
+ $unix_socket_try++;
+ if ($unix_socket_try > 100) {
+ $self->{errors} = 1;
+ $self->finish_tunnel($self->{tunnel});
+ die "Timeout, migration socket $ruri did not get ready";
+ }
+
+ usleep(50000);
+ }
+
+ } elsif ($ruri =~ /^tcp:/) {
+ my $tunnel_addr;
+ if ($raddr eq "localhost") {
+ # for backwards compatibility with older qemu-server versions
+ my $pfamily = PVE::Tools::get_host_address_family($nodename);
+ my $lport = PVE::Tools::next_migrate_port($pfamily);
+ $tunnel_addr = "$lport:localhost:$rport";
+ }
+
+ $self->{tunnel} = $self->fork_tunnel($tunnel_addr);
+
+ } else {
+ die "unsupported protocol in migration URI: $ruri\n";
+ }
+ } else {
+ #fork tunnel for insecure migration, to send faster commands like resume
+ $self->{tunnel} = $self->fork_tunnel();
+ }
+}
+
1;
--
2.20.1
More information about the pve-devel
mailing list