]> git.proxmox.com Git - qemu-server.git/blobdiff - PVE/QemuMigrate.pm
d/control: update dh version dependency and standard version
[qemu-server.git] / PVE / QemuMigrate.pm
index bb65d634cfcbf98b898ed80fff0d91b504a5e33d..65f39b6e778ff62977b656c355d594479084daa0 100644 (file)
@@ -218,10 +218,10 @@ sub prepare {
        $self->{forcemachine} = PVE::QemuServer::qemu_machine_pxe($vmid, $conf);
 
     }
-
-    if (my $loc_res = PVE::QemuServer::check_local_resources($conf, 1)) {
+    my $loc_res = PVE::QemuServer::check_local_resources($conf, 1);
+    if (scalar @$loc_res) {
        if ($self->{running} || !$self->{opts}->{force}) {
-           die "can't migrate VM which uses local devices\n";
+           die "can't migrate VM which uses local devices: " . join(", ", @$loc_res) . "\n";
        } else {
            $self->log('info', "migrating VM which uses local devices");
        }
@@ -458,16 +458,23 @@ sub sync_disks {
            if ($self->{running} && $ref eq 'config') {
                push @{$self->{online_local_volumes}}, $volid;
            } elsif ($ref eq 'generated') {
+               die "can't live migrate VM with local cloudinit disk. use a shared storage instead\n" if $self->{running};
                # skip all generated volumes but queue them for deletion in phase3_cleanup
                push @{$self->{volumes}}, $volid;
                next;
            } else {
                next if $rep_volumes->{$volid};
                push @{$self->{volumes}}, $volid;
-               my $insecure = $self->{opts}->{migration_type} eq 'insecure';
+               my $opts = $self->{opts};
+               my $insecure = $opts->{migration_type} eq 'insecure';
                my $with_snapshots = $local_volumes->{$volid}->{snapshots};
+               # use 'migrate' limit for transfer to other node
+               my $bwlimit = PVE::Storage::get_bandwidth_limit('migrate', [$targetsid, $sid], $opts->{bwlimit});
+               # JSONSchema and get_bandwidth_limit use kbps - storage_migrate bps
+               $bwlimit = $bwlimit * 1024 if defined($bwlimit);
+
                PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{ssh_info}, $targetsid,
-                                             undef, undef, undef, undef, $insecure, $with_snapshots);
+                                             undef, undef, undef, $bwlimit, $insecure, $with_snapshots);
            }
        }
     };
@@ -655,6 +662,8 @@ sub phase2 {
 
     my $start = time();
 
+    my $opt_bwlimit = $self->{opts}->{bwlimit};
+
     if (defined($self->{online_local_volumes})) {
        $self->{storage_migration} = 1;
        $self->{storage_migration_jobs} = {};
@@ -663,9 +672,14 @@ sub phase2 {
        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 $nbd_uri = $self->{target_drive}->{$drive}->{nbd_uri};
+           my $target = $self->{target_drive}->{$drive};
+           my $nbd_uri = $target->{nbd_uri};
+           my $source_sid = PVE::Storage::Plugin::parse_volume_id($conf->{$drive});
+           my $target_sid = PVE::Storage::Plugin::parse_volume_id($target->{volid});
+           my $bwlimit = PVE::Storage::get_bandwidth_limit('migrate', [$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);
+           PVE::QemuServer::qemu_drive_mirror($vmid, $drive, $nbd_uri, $vmid, undef, $self->{storage_migration_jobs}, 1, undef, $bwlimit);
        }
     }
 
@@ -735,8 +749,8 @@ sub phase2 {
        $self->log('info', "spice client_migrate_info");
 
        eval {
-           PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "client_migrate_info", protocol => 'spice', 
-                                               hostname => $proxyticket, 'tls-port' => $spice_port, 
+           PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "client_migrate_info", protocol => 'spice',
+                                               hostname => $proxyticket, 'port' => 0, 'tls-port' => $spice_port,
                                                'cert-subject' => $subject);
        };
        $self->log('info', "client_migrate_info error: $@") if $@;
@@ -841,7 +855,7 @@ sub phase2 {
 
 
            $lstat = $stat->{ram}->{transferred};
-           
+
        } else {
            die $merr if $merr;
            die "unable to parse migration status '$stat->{status}' - aborting\n";
@@ -885,7 +899,7 @@ sub phase2_cleanup {
     }
 
     my $nodename = PVE::INotify::nodename();
+
     my $cmd = [@{$self->{rem_ssh}}, 'qm', 'stop', $vmid, '--skiplock', '--migratedfrom', $nodename];
     eval{ PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
     if (my $err = $@) {