[pve-devel] [PATCH guest-common 4/6] Also update sources in switch_replication_job_target

Fabian Ebner f.ebner at proxmox.com
Mon Aug 10 14:35:55 CEST 2020


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/ReplicationConfig.pm | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/PVE/ReplicationConfig.pm b/PVE/ReplicationConfig.pm
index 65436ea..fc3e792 100644
--- a/PVE/ReplicationConfig.pm
+++ b/PVE/ReplicationConfig.pm
@@ -228,23 +228,27 @@ sub find_local_replication_job {
     return undef;
 }
 
-# switch local replication job target
+# makes old_target the new source for all local jobs of this guest
+# makes new_target the target for the single local job with target old_target
 sub switch_replication_job_target {
     my ($vmid, $old_target, $new_target) = @_;
 
-    my $transfer_job = sub {
+    my $update_jobs = sub {
 	my $cfg = PVE::ReplicationConfig->new();
-	my $jobcfg = find_local_replication_job($cfg, $vmid, $old_target);
-
-	return if !$jobcfg;
+	foreach my $id (keys %{$cfg->{ids}}) {
+	    my $jobcfg = $cfg->{ids}->{$id};
 
-	$jobcfg->{target} = $new_target;
+	    next if $jobcfg->{guest} ne $vmid;
+	    next if $jobcfg->{type} ne 'local';
 
+	    $jobcfg->{target} = $new_target if $jobcfg->{target} eq $old_target;
+	    $jobcfg->{source} = $old_target;
+	}
 	$cfg->write();
     };
 
-    lock($transfer_job);
-};
+    lock($update_jobs);
+}
 
 sub delete_job {
     my ($jobid) = @_;
-- 
2.20.1





More information about the pve-devel mailing list