]> git.proxmox.com Git - pve-container.git/commitdiff
Integrate storage replica in lxc migration.
authorWolfgang Link <w.link@proxmox.com>
Mon, 24 Apr 2017 15:15:37 +0000 (17:15 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 28 Apr 2017 08:35:22 +0000 (10:35 +0200)
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

index 6b9687b8904735ce8e8e6fc60999b2a0bb24aa19..0d3452825daa6620a148ea86a6e612920f206226 100644 (file)
@@ -10,6 +10,7 @@ use PVE::INotify;
 use PVE::Cluster;
 use PVE::Storage;
 use PVE::LXC;
+use PVE::ReplicationTools;
 
 use base qw(PVE::AbstractMigrate);
 
@@ -270,6 +271,17 @@ sub phase1 {
        PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{nodeip}, $sid);
     }
 
+    # set new replica_target if we migrate to replica target.
+    if ($conf->{replica}) {
+       $self->log('info', "change replica target to Node: $self->{opts}->{node}");
+       if ($conf->{replica_target} eq $self->{node}) {
+           $conf->{replica_target} = $self->{opts}->{node};
+       }
+
+       PVE::ReplicationTools::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 +324,20 @@ sub phase3 {
 
     my $volids = $self->{volumes};
 
+    my $synced_volumes = PVE::ReplicationTools::get_syncable_guestdisks($self->{vmconf}, 'lxc')
+       if $self->{vmconf}->{replica};
+
     # 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 (!($self->{vmconf}->{replica} && defined($synced_volumes->{$volid})
+             && $self->{vmconf}->{replica_target} eq $self->{opts}->{node}) ) {
+           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}) {
+       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}) {