From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <f.ebner@proxmox.com>
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 79BA469E1E
 for <pve-devel@lists.proxmox.com>; Mon, 10 Aug 2020 14:36:34 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 70F13151CB
 for <pve-devel@lists.proxmox.com>; Mon, 10 Aug 2020 14:36:04 +0200 (CEST)
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 E736A151B4
 for <pve-devel@lists.proxmox.com>; Mon, 10 Aug 2020 14:36:02 +0200 (CEST)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B36A64455F
 for <pve-devel@lists.proxmox.com>; Mon, 10 Aug 2020 14:36:02 +0200 (CEST)
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Mon, 10 Aug 2020 14:35:57 +0200
Message-Id: <20200810123557.22618-6-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.20.1
In-Reply-To: <20200810123557.22618-1-f.ebner@proxmox.com>
References: <20200810123557.22618-1-f.ebner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL -0.008 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
Subject: [pve-devel] [PATCH/RFC guest-common 6/6] job_status: return jobs
 with target local node
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Mon, 10 Aug 2020 12:36:34 -0000

even if not scheduled for removal, while adapting
replicate to die gracefully except for the removal case.

Like this such invalid jobs are not hidden to the user anymore
(at least via the API, the GUI still hides them)

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

I think it's a bit weird that such jobs only show up once
they are scheduled for removal. I'll send a patch for the
GUI too if we do want the new behavior.

 PVE/Replication.pm      | 3 +++
 PVE/ReplicationState.pm | 5 +----
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/PVE/Replication.pm b/PVE/Replication.pm
index ae0f145..b5835bd 100644
--- a/PVE/Replication.pm
+++ b/PVE/Replication.pm
@@ -207,6 +207,9 @@ sub replicate {
 
     die "not implemented - internal error" if $jobcfg->{type} ne 'local';
 
+    die "job target is local node\n" if $jobcfg->{target} eq $local_node
+				     && !$jobcfg->{remove_job};
+
     my $dc_conf = PVE::Cluster::cfs_read_file('datacenter.cfg');
 
     my $migration_network;
diff --git a/PVE/ReplicationState.pm b/PVE/ReplicationState.pm
index e486bc7..0b751bb 100644
--- a/PVE/ReplicationState.pm
+++ b/PVE/ReplicationState.pm
@@ -261,10 +261,6 @@ sub job_status {
 	    $cfg->switch_replication_job_target_nolock($vmid, $local_node, $jobcfg->{source})
 		if $local_node ne $jobcfg->{source};
 
-	    my $target = $jobcfg->{target};
-	    # never sync to local node
-	    next if !$jobcfg->{remove_job} && $target eq $local_node;
-
 	    next if !$get_disabled && $jobcfg->{disable};
 
 	    my $state = extract_job_state($stateobj, $jobcfg);
@@ -280,6 +276,7 @@ sub job_status {
 	    } else  {
 		if (my $fail_count = $state->{fail_count}) {
 		    my $members = PVE::Cluster::get_members();
+		    my $target = $jobcfg->{target};
 		    if (!$fail_count || ($members->{$target} && $members->{$target}->{online})) {
 			$next_sync = $state->{last_try} + 60*($fail_count < 3 ? 5*$fail_count : 30);
 		    }
-- 
2.20.1