mirror of
git://git.proxmox.com/git/qemu-server.git
synced 2025-02-15 05:57:39 +03:00
Integrate replica in the qemu migration.
Now it is possible to migrate a VM offline when replica is enabled. It will reduce replication to an minimal amount.
This commit is contained in:
parent
9edac22f5f
commit
63d02c7074
@ -10,6 +10,7 @@ use PVE::INotify;
|
||||
use PVE::Tools;
|
||||
use PVE::Cluster;
|
||||
use PVE::Storage;
|
||||
use PVE::ReplicationTools;
|
||||
use PVE::QemuServer;
|
||||
use Time::HiRes qw( usleep );
|
||||
use PVE::RPCEnvironment;
|
||||
@ -437,6 +438,16 @@ sub phase1 {
|
||||
|
||||
sync_disks($self, $vmid);
|
||||
|
||||
# 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::QemuConfig->write_config($vmid, $conf);
|
||||
}
|
||||
};
|
||||
|
||||
sub phase1_cleanup {
|
||||
@ -844,13 +855,22 @@ sub phase3 {
|
||||
my $volids = $self->{volumes};
|
||||
return if $self->{phase2errors};
|
||||
|
||||
my $synced_volumes = PVE::ReplicationTools::get_syncable_guestdisks($self->{vmconf}, 'qemu')
|
||||
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$/;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -964,6 +984,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}) {
|
||||
my $cmd = [ @{$self->{rem_ssh}}, 'qm', 'set', $vmid, '--replica'];
|
||||
$self->cmd_logerr($cmd, errmsg => "failed to activate replica");
|
||||
}
|
||||
}
|
||||
|
||||
sub final_cleanup {
|
||||
|
Loading…
x
Reference in New Issue
Block a user