[pve-devel] [PATCH qemu-server] PVE/QemuMigrate.pm: use replication job, transfer replication state
Dietmar Maurer
dietmar at proxmox.com
Tue Jun 20 11:01:24 CEST 2017
Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
PVE/QemuMigrate.pm | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 53 insertions(+), 1 deletion(-)
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index bf0bb44..85fa6ff 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -13,6 +13,9 @@ use PVE::Storage;
use PVE::QemuServer;
use Time::HiRes qw( usleep );
use PVE::RPCEnvironment;
+use PVE::ReplicationConfig;
+use PVE::ReplicationState;
+use JSON;
use base qw(PVE::AbstractMigrate);
@@ -379,16 +382,30 @@ sub sync_disks {
}
}
+ my $rep_volumes;
+
$self->log('info', "copying disk images");
+ my $rep_cfg = PVE::ReplicationConfig->new();
+
+ if (my $jobcfg = $rep_cfg->find_local_replication_job($vmid, $self->{node})) {
+ my $start_time = time();
+ my $logfunc = sub { my ($msg) = @_; $self->log('info', $msg); };
+ $rep_volumes = PVE::Replication::run_replication(
+ 'PVE::QemuConfig', $jobcfg, $start_time, $start_time, $logfunc);
+ }
+
foreach my $volid (keys %$local_volumes) {
my ($sid, $volname) = PVE::Storage::parse_volume_id($volid);
if ($self->{running} && $self->{opts}->{targetstorage} && $local_volumes->{$volid} eq 'config') {
+ die "can't live migrate replicated volume - feature not implemented\n" if $rep_volumes->{$volid};
push @{$self->{online_local_volumes}}, $volid;
} else {
+ next if $rep_volumes->{$volid};
push @{$self->{volumes}}, $volid;
my $insecure = $self->{opts}->{migration_type} eq 'insecure';
- PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{ssh_info}, $sid, undef, undef, undef, undef, $insecure);
+ PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{ssh_info}, $sid,
+ undef, undef, undef, undef, $insecure);
}
}
};
@@ -833,6 +850,35 @@ sub phase3 {
}
}
+
+# transfer replication state for vmid to migration target node.
+my $transfer_replication_state = sub {
+ my ($self, $vmid) = @_;
+
+ my $stateobj = PVE::ReplicationState::read_state();
+
+ if (defined($stateobj->{$vmid})) {
+ # This have to be quoted when it run it over ssh.
+ my $state = PVE::Tools::shellquote(encode_json($stateobj->{$vmid}));
+
+ my $cmd = [ @{$self->{rem_ssh}}, 'pvesr', 'set-state', $vmid, $state];
+ $self->cmd($cmd);
+ }
+
+ my $transfer_job = sub {
+ my $rep_cfg = PVE::ReplicationConfig->new();
+ my $jobcfg = $rep_cfg->find_local_replication_job($vmid, $self->{node});
+
+ return if !$jobcfg;
+
+ $jobcfg->{target} = PVE::INotify::nodename();
+
+ $rep_cfg->write();
+ };
+
+ PVE::ReplicationConfig::lock($transfer_job);
+};
+
sub phase3_cleanup {
my ($self, $vmid, $err) = @_;
@@ -863,6 +909,12 @@ sub phase3_cleanup {
die "Failed to move config to node '$self->{node}' - rename failed: $!\n"
if !rename($conffile, $newconffile);
+ eval { $transfer_replication_state->($self, $vmid); };
+ if (my $err = $@) {
+ $self->log('err', "transfer replication state/job faile - $err");
+ $self->{errors} = 1;
+ }
+
if ($self->{livemigration}) {
if ($self->{storage_migration}) {
# remove drives referencing the nbd server from source
--
2.11.0
More information about the pve-devel
mailing list