[pve-devel] [PATCH qemu-server 6/7] migrate : phase2_cleanup : migrate_external

Alexandre Derumier aderumier at odiso.com
Mon Oct 29 16:38:51 CET 2018


we destroy target vm in case of failure in phase2
---
 PVE/QemuMigrate.pm | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 6eb629b..856a7db 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -907,6 +907,9 @@ sub phase2_cleanup {
     my ($self, $vmid, $err) = @_;
 
     return if !$self->{errors};
+
+    my $targetvmid = $self->{opts}->{targetvmid} ? $self->{opts}->{targetvmid} : $vmid;
+
     $self->{phase2errors} = 1;
 
     $self->log('info', "aborting phase 2 - cleanup resources");
@@ -940,13 +943,26 @@ sub phase2_cleanup {
 
     my $nodename = PVE::INotify::nodename();
  
-    my $cmd = [@{$self->{rem_ssh}}, 'qm', 'stop', $vmid, '--skiplock', '--migratedfrom', $nodename];
+    my $cmd = [@{$self->{rem_ssh}}, 'qm', 'stop', $targetvmid, '--skiplock'];
+    push @$cmd, '--migratedfrom', $nodename if !$self->{migration_external};
+
     eval{ PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
     if (my $err = $@) {
         $self->log('err', $err);
         $self->{errors} = 1;
     }
 
+    if ($self->{migration_external}) {
+	my $cmd = [@{$self->{rem_ssh}}, 'qm', 'destroy', $targetvmid, '--skiplock'];
+
+	eval{ PVE::Tools::run_command($cmd, outfunc => sub {}, errfunc => sub {}) };
+	if (my $err = $@) {
+	    $self->log('err', $err);
+	    $self->{errors} = 1;
+	}
+
+    }
+
     if ($self->{tunnel}) {
 	eval { finish_tunnel($self, $self->{tunnel});  };
 	if (my $err = $@) {
-- 
2.11.0




More information about the pve-devel mailing list