[pve-devel] [PATCH qemu-server] Change target in replication-state when replication direction is switched.
Dietmar Maurer
dietmar at proxmox.com
Wed Jun 21 10:51:01 CEST 2017
> diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
> index 8e541bf..0c931c5 100644
> --- a/PVE/QemuMigrate.pm
> +++ b/PVE/QemuMigrate.pm
> @@ -859,8 +859,21 @@ my $transfer_replication_state = sub {
> my $stateobj = PVE::ReplicationState::read_state();
>
> if (defined($stateobj->{$vmid})) {
> +
> + my $tmp_state = {};
> +
> + my $mig_node = $self->{node};
> + my $new_target = PVE::INotify::nodename();
> + foreach my $key (keys %{$stateobj->{$vmid}}) {
> + if ($key =~ /^(.*\/)\Q$mig_node\E$/) {
> + $tmp_state->{"$1$new_target"} = $stateobj->{$vmid}->{$key};
> + } else {
> + $tmp_state->{$key} = $stateobj->{$vmid}->{$key};
> + }
> + }
> +
I do really like that loop, we can do without:
diff --git a/PVE/QemuMigrate.pm b/PVE/QemuMigrate.pm
index 8e541bf..0f330a8 100644
--- a/PVE/QemuMigrate.pm
+++ b/PVE/QemuMigrate.pm
@@ -858,9 +858,17 @@ my $transfer_replication_state = sub {
my $stateobj = PVE::ReplicationState::read_state();
- if (defined($stateobj->{$vmid})) {
+ my $target_node = $self->{node};
+ my $local_node = PVE::INotify::nodename();
+
+ my $oldid = PVE::ReplicationConfig::Cluster->get_unique_target_id({ target
=> $target_node });
+ my $newid = PVE::ReplicationConfig::Cluster->get_unique_target_id({ target
=> $local_node });
+
+ if (defined(my $vmstate = $stateobj->{$vmid})) {
+ $vmstate->{$newid} = delete($vmstate->{$oldid}) if
defined($vmstate->{$oldid});
+
# This have to be quoted when it run it over ssh.
- my $state = PVE::Tools::shellquote(encode_json($stateobj->{$vmid}));
+ my $state = PVE::Tools::shellquote(encode_json($vmstate));
my $cmd = [ @{$self->{rem_ssh}}, 'pvesr', 'set-state', $vmid, $state];
$self->cmd($cmd);
More information about the pve-devel
mailing list