[pve-devel] [PATCH v3 qemu-server 6/7] migrate : phase3_cleanup : migrate_external
Alexandre Derumier
aderumier at odiso.com
Tue Nov 27 16:38:08 CET 2018
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 9e963d3..ed8df71 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -1000,6 +1000,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};
@@ -1013,7 +1015,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->{opts}->{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);
@@ -1022,22 +1024,25 @@ sub phase3_cleanup {
}
}
- # transfer replication state before move config
- $self->transfer_replication_state() if $self->{replicated_volumes};
+ if (!$self->{opts}->{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 = $@) {
@@ -1049,14 +1054,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);
@@ -1114,7 +1119,7 @@ sub phase3_cleanup {
$self->{errors} = 1;
}
- if($self->{storage_migration}) {
+ if($self->{storage_migration} && !$self->{opts}->{migration_external}) {
# destroy local copies
my $volids = $self->{online_local_volumes};
@@ -1130,7 +1135,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
More information about the pve-devel
mailing list