we don't move original config
---
 PVE/QemuMigrate.pm | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 856a7db..a36ce85 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -992,6 +992,8 @@ sub phase3 {
 sub phase3_cleanup {
     my ($self, $vmid, $err) = @_;
 
+    my $targetvmid = $self->{opts}->{targetvmid} ? $self->{opts}->{targetvmid} 
: $vmid;
+
     my $conf = $self->{vmconf};
     return if $self->{phase2errors};
 
@@ -1005,7 +1007,7 @@ sub phase3_cleanup {
            eval { PVE::QemuServer::qemu_blockjobs_cancel($vmid, 
$self->{storage_migration_jobs}) };
            eval { PVE::QemuMigrate::cleanup_remotedisks($self) };
            die "Failed to completed storage migration\n";
-       } else {
+       } elsif (!$self->{migration_external}) {
            foreach my $target_drive (keys %{$self->{target_drive}}) {
                my $drive = PVE::QemuServer::parse_drive($target_drive, 
$self->{target_drive}->{$target_drive}->{volid});
                $conf->{$target_drive} = PVE::QemuServer::print_drive($vmid, 
$drive);
@@ -1014,22 +1016,25 @@ sub phase3_cleanup {
        }
     }
 
-    # transfer replication state before move config
-    $self->transfer_replication_state() if $self->{replicated_volumes};
+    if (!$self->{migration_external}) {
 
-    # move config to remote node
-    my $conffile = PVE::QemuConfig->config_file($vmid);
-    my $newconffile = PVE::QemuConfig->config_file($vmid, $self->{node});
+       # transfer replication state before move config
+       $self->transfer_replication_state() if $self->{replicated_volumes};
 
-    die "Failed to move config to node '$self->{node}' - rename failed: $!\n"
-        if !rename($conffile, $newconffile);
+       # move config to remote node
+       my $conffile = PVE::QemuConfig->config_file($vmid);
+       my $newconffile = PVE::QemuConfig->config_file($vmid, $self->{node});
 
-    $self->switch_replication_job_target() if $self->{replicated_volumes};
+       die "Failed to move config to node '$self->{node}' - rename failed: 
$!\n"
+           if !rename($conffile, $newconffile);
+
+       $self->switch_replication_job_target() if $self->{replicated_volumes};
+    }
 
     if ($self->{livemigration}) {
        if ($self->{storage_migration}) {
            # stop nbd server on remote vm - requirement for resume since 2.9
-           my $cmd = [@{$self->{rem_ssh}}, 'qm', 'nbdstop', $vmid];
+           my $cmd = [@{$self->{rem_ssh}}, 'qm', 'nbdstop', $targetvmid];
 
            eval{ PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => 
sub {}) };
            if (my $err = $@) {
@@ -1041,14 +1046,14 @@ sub phase3_cleanup {
        # config moved and nbd server stopped - now we can resume vm on target
        if ($tunnel && $tunnel->{version} && $tunnel->{version} >= 1) {
            eval {
-               $self->write_tunnel($tunnel, 30, "resume $vmid");
+               $self->write_tunnel($tunnel, 30, "resume $targetvmid");
            };
            if (my $err = $@) {
                $self->log('err', $err);
                $self->{errors} = 1;
            }
        } else {
-           my $cmd = [@{$self->{rem_ssh}}, 'qm', 'resume', $vmid, 
'--skiplock', '--nocheck'];
+           my $cmd = [@{$self->{rem_ssh}}, 'qm', 'resume', $targetvmid, 
'--skiplock', '--nocheck'];
            my $logf = sub {
                my $line = shift;
                $self->log('err', $line);
@@ -1106,7 +1111,7 @@ sub phase3_cleanup {
        $self->{errors} = 1;
     }
 
-    if($self->{storage_migration}) {
+    if($self->{storage_migration} && !$self->{migration_external}) {
        # destroy local copies
        my $volids = $self->{online_local_volumes};
 
@@ -1122,7 +1127,7 @@ sub phase3_cleanup {
     }
 
     # clear migrate lock
-    my $cmd = [ @{$self->{rem_ssh}}, 'qm', 'unlock', $vmid ];
+    my $cmd = [ @{$self->{rem_ssh}}, 'qm', 'unlock', $targetvmid ];
     $self->cmd_logerr($cmd, errmsg => "failed to clear migrate lock");
 }
 
-- 
2.11.0

_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to