]> git.proxmox.com Git - qemu-server.git/commitdiff
PVE/QemuMigrate.pm: use new replication job helpers from AbstractMigrate
authorDietmar Maurer <dietmar@proxmox.com>
Wed, 21 Jun 2017 10:27:45 +0000 (12:27 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 21 Jun 2017 10:27:45 +0000 (12:27 +0200)
PVE/QemuMigrate.pm

index 0f330a89a6365186248e901ad393f65990635f8c..36f6fda54bfdadfa4baf267fc056da31612192e8 100644 (file)
@@ -851,47 +851,6 @@ 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();
-
-    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($vmstate));
-
-       my $cmd = [ @{$self->{rem_ssh}}, 'pvesr', 'set-state', $vmid, $state];
-       $self->cmd($cmd);
-    }
-};
-
-# switch replication job target
-my $switch_replication_job_target = sub {
-    my ($self, $vmid) = @_;
-    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) = @_;
 
@@ -916,11 +875,7 @@ sub phase3_cleanup {
     }
 
     # transfer replication state before move config
-    eval { $transfer_replication_state->($self, $vmid); };
-    if (my $err = $@) {
-       $self->log('err', "transfer replication state failed - $err");
-       $self->{errors} = 1;
-    }
+    $self->transfer_replication_state();
 
     # move config to remote node
     my $conffile = PVE::QemuConfig->config_file($vmid);
@@ -929,11 +884,7 @@ sub phase3_cleanup {
     die "Failed to move config to node '$self->{node}' - rename failed: $!\n"
         if !rename($conffile, $newconffile);
 
-    eval { $switch_replication_job_target->($self, $vmid); };
-    if (my $err = $@) {
-       $self->log('err', "switch replication job target failed - $err");
-       $self->{errors} = 1;
-    }
+    $self->switch_replication_job_target();
 
     if ($self->{livemigration}) {
        if ($self->{storage_migration}) {