[pve-devel] [PATCH qemu-server 03/15] phase2 : add start_remote_tunnel

Alexandre Derumier aderumier at odiso.com
Mon Apr 29 12:01:18 CEST 2019


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuMigrate.pm | 88 +++++++++++++++++++++++++++++-------------------------
 1 file changed, 48 insertions(+), 40 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 5c3c5d3..7a701a9 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -547,47 +547,9 @@ sub phase2 {
     my $cmd = generate_migrate_start_cmd($self, $vmid, $nodename, $migration_type);
 
     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();
 
     my $opt_bwlimit = $self->{opts}->{bwlimit};
@@ -1094,4 +1056,50 @@ sub find_remote_ports {
     return ($raddr, $rport, $ruri, $spice_port, $spice_ticket);
 }
 
+sub start_remote_tunnel {
+    my ($self, $nodename, $migration_type, $raddr, $rport, $ruri) = @_;
+
+    die "unable to detect remote migration address\n" if !$raddr;
+
+    $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.11.0




More information about the pve-devel mailing list