public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 guest-common 5/8] job_status: simplify fixup of jobs for stolen guests
Date: Thu, 29 Oct 2020 14:31:29 +0100	[thread overview]
Message-ID: <20201029133132.28100-6-f.ebner@proxmox.com> (raw)
In-Reply-To: <20201029133132.28100-1-f.ebner@proxmox.com>

by using switch_replication_job_target_nolock.

If a job is scheduled for removal and the guest was
stolen, it still makes sense to correct the job entry,
which didn't happen previously.

AFAICT, this was the only user of swap_source_target_nolock.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---

Changes from v1:
    * split into two parts (see previous patch)

 PVE/ReplicationConfig.pm | 13 -------------
 PVE/ReplicationState.pm  | 32 +++++++++++++-------------------
 2 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/PVE/ReplicationConfig.pm b/PVE/ReplicationConfig.pm
index 6ba87ae..fd856a0 100644
--- a/PVE/ReplicationConfig.pm
+++ b/PVE/ReplicationConfig.pm
@@ -279,19 +279,6 @@ sub remove_vmid_jobs {
     lock($code);
 }
 
-sub swap_source_target_nolock {
-    my ($jobid) = @_;
-
-    my $cfg = __PACKAGE__->new();
-    my $job = $cfg->{ids}->{$jobid};
-    my $tmp = $job->{source};
-    $job->{source} = $job->{target};
-    $job->{target} = $tmp;
-    $cfg->write();
-
-    return $cfg->{ids}->{$jobid};
-}
-
 package PVE::ReplicationConfig::Cluster;
 
 use base qw(PVE::ReplicationConfig);
diff --git a/PVE/ReplicationState.pm b/PVE/ReplicationState.pm
index 80d45d6..81a1b31 100644
--- a/PVE/ReplicationState.pm
+++ b/PVE/ReplicationState.pm
@@ -251,22 +251,21 @@ sub job_status {
 	    # only consider guest on local node
 	    next if $vms->{ids}->{$vmid}->{node} ne $local_node;
 
+	    # source is optional in schema, but we set it automatically
+	    if (!defined($jobcfg->{source})) {
+		$jobcfg->{source} = $local_node;
+		$cfg->write();
+	    }
+
+	    # fix jobs for stolen guest
+	    $cfg->switch_replication_job_target_nolock($vmid, $local_node, $jobcfg->{source})
+		if $local_node ne $jobcfg->{source};
+
 	    my $target = $jobcfg->{target};
-	    if (!$jobcfg->{remove_job}) {
-		# check if vm was stolen (swapped source target)
-		if ($target eq $local_node) {
-		    my $source = $jobcfg->{source};
-		    if (defined($source) && $source ne $target) {
-			$jobcfg = PVE::ReplicationConfig::swap_source_target_nolock($jobid);
-			$cfg->{ids}->{$jobid} = $jobcfg;
-		    } else {
-			# never sync to local node
-			next;
-		    }
-		}
+	    # never sync to local node
+	    next if !$jobcfg->{remove_job} && $target eq $local_node;
 
-		next if !$get_disabled && $jobcfg->{disable};
-	    }
+	    next if !$get_disabled && $jobcfg->{disable};
 
 	    my $state = extract_job_state($stateobj, $jobcfg);
 	    $jobcfg->{state} = $state;
@@ -293,11 +292,6 @@ sub job_status {
 
 	    $jobcfg->{next_sync} = $next_sync;
 
-	    if (!defined($jobcfg->{source}) || $jobcfg->{source} ne $local_node) {
-		$jobcfg->{source} = $cfg->{ids}->{$jobid}->{source} = $local_node;
-		PVE::ReplicationConfig::write($cfg);
-	    }
-
 	    $jobs->{$jobid} = $jobcfg;
 	}
     };
-- 
2.20.1





  parent reply	other threads:[~2020-10-29 13:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-29 13:31 [pve-devel] [PATCH-SERIES v2] some replication-related improvements Fabian Ebner
2020-10-29 13:31 ` [pve-devel] [PATCH v2 guest-common 1/8] job_status: read only after acquiring the lock Fabian Ebner
2020-10-29 13:31 ` [pve-devel] [PATCH v2 guest-common 2/8] clarify what the source property is used for in a replication job Fabian Ebner
2020-10-29 13:31 ` [pve-devel] [PATCH v2 guest-common 3/8] also update sources in switch_replication_job_target Fabian Ebner
2020-10-29 13:31 ` [pve-devel] [PATCH v2 guest-common 4/8] create nolock variant for switch_replication_job_target Fabian Ebner
2020-10-29 13:31 ` Fabian Ebner [this message]
2020-10-29 13:31 ` [pve-devel] [PATCH v2 qemu-server 6/8] Repeat check for replication target in locked section Fabian Ebner
2020-10-29 13:31 ` [pve-devel] [PATCH v2 qemu-server 7/8] fix checks for transfering replication state/switching job target Fabian Ebner
2020-10-29 13:31 ` [pve-devel] [PATCH/RFC v2 qemu-server 8/8] don't migrate replicated VM whose replication job is marked for removal Fabian Ebner
2020-11-09  9:48 ` [pve-devel] applied-series: [PATCH-SERIES v2] some replication-related improvements Fabian Grünbichler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201029133132.28100-6-f.ebner@proxmox.com \
    --to=f.ebner@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal