[pve-devel] [RFC pve-container 2/3] Integrate replica in the lxc migration.
Wolfgang Link
w.link at proxmox.com
Mon Apr 3 16:53:45 CEST 2017
Now it is possible to migrate a CT when replica is enabled.
It will reduce replication to an minimal amount.
---
src/PVE/LXC/Migrate.pm | 34 +++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/src/PVE/LXC/Migrate.pm b/src/PVE/LXC/Migrate.pm
index 6b9687b..a897e6b 100644
--- a/src/PVE/LXC/Migrate.pm
+++ b/src/PVE/LXC/Migrate.pm
@@ -10,6 +10,7 @@ use PVE::INotify;
use PVE::Cluster;
use PVE::Storage;
use PVE::LXC;
+use PVE::ReplicaTools;
use base qw(PVE::AbstractMigrate);
@@ -270,6 +271,16 @@ sub phase1 {
PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{nodeip}, $sid);
}
+ # 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::LXC::Config->write_config($vmid, $conf);
+ }
+
my $conffile = PVE::LXC::Config->config_file($vmid);
my $newconffile = PVE::LXC::Config->config_file($vmid, $self->{node});
@@ -312,13 +323,21 @@ sub phase3 {
my $volids = $self->{volumes};
+ my $rep = $self->{vmconf}->{replica} =~ m/(?i:1|yes|on|true)/;
+ my $sync_vol;
+ $sync_vol = PVE::ReplicaTools::get_syncable_guestdisks($self->{vmconf}, 'lxc')
+ 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$/;
+ }
}
}
}
@@ -341,6 +360,11 @@ sub final_cleanup {
$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}}, 'pct', 'set', $vmid, '--replica'];
+ $self->cmd_logerr($cmd, errmsg => "failed to activate replica");
+ }
+
# in restart mode, we start the container on the target node
# after migration
if ($self->{opts}->{restart} && $self->{was_running}) {
--
2.1.4
More information about the pve-devel
mailing list