From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 8AB0B64104 for ; Thu, 29 Oct 2020 14:31:41 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 83BE49D5F for ; Thu, 29 Oct 2020 14:31:41 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B389A9CF9 for ; Thu, 29 Oct 2020 14:31:38 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6FF8B45F93 for ; Thu, 29 Oct 2020 14:31:38 +0100 (CET) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Thu, 29 Oct 2020 14:31:29 +0100 Message-Id: <20201029133132.28100-6-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201029133132.28100-1-f.ebner@proxmox.com> References: <20201029133132.28100-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.031 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [replicationconfig.pm, replicationstate.pm] Subject: [pve-devel] [PATCH v2 guest-common 5/8] job_status: simplify fixup of jobs for stolen guests X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Oct 2020 13:31:41 -0000 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 --- 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