[pve-devel] [RFC qemu-server 2/3] Integrate replica in the qemu migration.
Wolfgang Link
w.link at proxmox.com
Mon Apr 3 16:53:37 CEST 2017
Now it is possible to migrate a VM offline when replica is enabled.
It will reduce replication to an minimal amount.
---
PVE/QemuMigrate.pm | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index e6f147e..f4daaaf 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -10,6 +10,7 @@ use PVE::INotify;
use PVE::Tools;
use PVE::Cluster;
use PVE::Storage;
+use PVE::ReplicaTools;
use PVE::QemuServer;
use Time::HiRes qw( usleep );
use PVE::RPCEnvironment;
@@ -435,6 +436,15 @@ sub phase1 {
sync_disks($self, $vmid);
+ # set new reptarget if necessary
+ if ($conf->{replica} =~ m/(?i:1|yes|on|true)/) {
+ if ($conf->{reptarget} eq $self->{node}) {
+ $conf->{reptarget} = $self->{opts}->{node};
+ }
+
+ PVE::ReplicaTools::job_remove($vmid);
+ PVE::QemuConfig->write_config($vmid, $conf);
+ }
};
sub phase1_cleanup {
@@ -842,13 +852,22 @@ sub phase3 {
my $volids = $self->{volumes};
return if $self->{phase2errors};
+ my $rep = $self->{vmconf}->{replica} =~ m/(?i:1|yes|on|true)/;
+ my $sync_vol;
+ $sync_vol = PVE::ReplicaTools::get_syncable_guestdisks($self->{vmconf}, 'qemu')
+ if defined($rep);
+
# destroy local copies
foreach my $volid (@$volids) {
- eval { PVE::Storage::vdisk_free($self->{storecfg}, $volid); };
- if (my $err = $@) {
- $self->log('err', "removing local copy of '$volid' failed - $err");
- $self->{errors} = 1;
- last if $err =~ /^interrupted by signal$/;
+
+ #do not destroy if new target is local_host
+ if (!defined( grep { /\Q$volid\E/ } @$sync_vol)) {
+ eval { PVE::Storage::vdisk_free($self->{storecfg}, $volid); };
+ if (my $err = $@) {
+ $self->log('err', "removing local copy of '$volid' failed - $err");
+ $self->{errors} = 1;
+ last if $err =~ /^interrupted by signal$/;
+ }
}
}
}
@@ -955,6 +974,11 @@ sub phase3_cleanup {
# clear migrate lock
my $cmd = [ @{$self->{rem_ssh}}, 'qm', 'unlock', $vmid ];
$self->cmd_logerr($cmd, errmsg => "failed to clear migrate lock");
+
+ if ($self->{vmconf}->{replica} =~ m/(?i:1|yes|on|true)/) {
+ my $cmd = [ @{$self->{rem_ssh}}, 'qm', 'set', $vmid, '--replica'];
+ $self->cmd_logerr($cmd, errmsg => "failed to activate replica");
+ }
}
sub final_cleanup {
--
2.1.4
More information about the pve-devel
mailing list