[pve-devel] [PATCH v2 qemu-server 04/16] phase2 : add livemigrate_storage

Alexandre Derumier aderumier at odiso.com
Mon Mar 9 16:24:27 CET 2020


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

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 6243d0d..5063b7b 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -559,34 +559,12 @@ sub phase2 {
 
     start_remote_tunnel($self, $nodename, $migration_type, $raddr, $rport, $ruri);
 
+    livemigrate_storage($self, $vmid);
+
     my $start = time();
 
     my $opt_bwlimit = $self->{opts}->{bwlimit};
 
-    if (defined($self->{online_local_volumes})) {
-	$self->{storage_migration} = 1;
-	$self->{storage_migration_jobs} = {};
-	$self->log('info', "starting storage migration");
-
-	die "The number of local disks does not match between the source and the destination.\n"
-	    if (scalar(keys %{$self->{target_drive}}) != scalar @{$self->{online_local_volumes}});
-	foreach my $drive (keys %{$self->{target_drive}}){
-	    my $target = $self->{target_drive}->{$drive};
-	    my $nbd_uri = $target->{nbd_uri};
-
-	    my $source_drive = PVE::QemuServer::parse_drive($drive, $conf->{$drive});
-	    my $target_drive = PVE::QemuServer::parse_drive($drive, $target->{drivestr});
-
-	    my $source_sid = PVE::Storage::Plugin::parse_volume_id($source_drive->{file});
-	    my $target_sid = PVE::Storage::Plugin::parse_volume_id($target_drive->{file});
-
-	    my $bwlimit = PVE::Storage::get_bandwidth_limit('migration', [$source_sid, $target_sid], $opt_bwlimit);
-
-	    $self->log('info', "$drive: start migration to $nbd_uri");
-	    PVE::QemuServer::qemu_drive_mirror($vmid, $drive, $nbd_uri, $vmid, undef, $self->{storage_migration_jobs}, 1, undef, $bwlimit);
-	}
-    }
-
     $self->log('info', "starting online/live migration on $ruri");
     $self->{livemigration} = 1;
 
@@ -1121,4 +1099,35 @@ sub start_remote_tunnel {
     }
 }
 
+sub livemigrate_storage {
+    my ($self, $vmid) = @_;
+
+    my $conf = $self->{vmconf};
+    my $opt_bwlimit = $self->{opts}->{bwlimit};
+
+    if (defined($self->{online_local_volumes})) {
+	$self->{storage_migration} = 1;
+	$self->{storage_migration_jobs} = {};
+	$self->log('info', "starting storage migration");
+
+	die "The number of local disks does not match between the source and the destination.\n"
+	    if (scalar(keys %{$self->{target_drive}}) != scalar @{$self->{online_local_volumes}});
+	foreach my $drive (keys %{$self->{target_drive}}){
+	    my $target = $self->{target_drive}->{$drive};
+	    my $nbd_uri = $target->{nbd_uri};
+
+	    my $source_drive = PVE::QemuServer::parse_drive($drive, $conf->{$drive});
+	    my $target_drive = PVE::QemuServer::parse_drive($drive, $target->{drivestr});
+
+	    my $source_sid = PVE::Storage::Plugin::parse_volume_id($source_drive->{file});
+	    my $target_sid = PVE::Storage::Plugin::parse_volume_id($target_drive->{file});
+
+	    my $bwlimit = PVE::Storage::get_bandwidth_limit('migration', [$source_sid, $target_sid], $opt_bwlimit);
+
+	    $self->log('info', "$drive: start migration to $nbd_uri");
+	    PVE::QemuServer::qemu_drive_mirror($vmid, $drive, $nbd_uri, $vmid, undef, $self->{storage_migration_jobs}, 1, undef, $bwlimit);
+	}
+    }
+}
+
 1;
-- 
2.20.1




More information about the pve-devel mailing list