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 B223967550 for ; Thu, 30 Jul 2020 13:29:53 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id A4C3316ACE for ; Thu, 30 Jul 2020 13:29:23 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 3058516AAF for ; Thu, 30 Jul 2020 13:29:22 +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 F2D9843403 for ; Thu, 30 Jul 2020 13:29:21 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Thu, 30 Jul 2020 13:29:13 +0200 Message-Id: <20200730112915.15402-1-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.060 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 manager 1/3] Hold the guest migration lock when changing the replication config 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, 30 Jul 2020 11:29:53 -0000 The guest migration lock is already held when running replications, but it also makes sense to hold it when updating the replication config itself. Otherwise, it can happen that the migration does not know the de-facto state of replication. For example: 1. migration starts 2. replication job is deleted 3. migration reads the replication config 4. migration runs the replication which causes the replicated disks to be removed, because the job is marked for removal 5. migration will continue without replication Note that the migration doesn't actually fail, but it's probably not the desired behavior either. Suggested-by: Fabian Grünbichler Signed-off-by: Fabian Ebner --- PVE/API2/ReplicationConfig.pm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/PVE/API2/ReplicationConfig.pm b/PVE/API2/ReplicationConfig.pm index 2b4ecd10..e5262068 100644 --- a/PVE/API2/ReplicationConfig.pm +++ b/PVE/API2/ReplicationConfig.pm @@ -9,6 +9,7 @@ use PVE::JSONSchema qw(get_standard_option); use PVE::RPCEnvironment; use PVE::ReplicationConfig; use PVE::Cluster; +use PVE::GuestHelpers; use PVE::RESTHandler; @@ -144,7 +145,9 @@ __PACKAGE__->register_method ({ $cfg->write(); }; - PVE::ReplicationConfig::lock($code); + PVE::GuestHelpers::guest_migration_lock($guest, 10, sub { + PVE::ReplicationConfig::lock($code); + }); return undef; }}); @@ -167,6 +170,7 @@ __PACKAGE__->register_method ({ my $id = extract_param($param, 'id'); my $digest = extract_param($param, 'digest'); my $delete = extract_param($param, 'delete'); + my ($guest_id) = PVE::ReplicationConfig::parse_replication_job_id($id); my $code = sub { my $cfg = PVE::ReplicationConfig->new(); @@ -199,7 +203,9 @@ __PACKAGE__->register_method ({ $cfg->write(); }; - PVE::ReplicationConfig::lock($code); + PVE::GuestHelpers::guest_migration_lock($guest_id, 10, sub { + PVE::ReplicationConfig::lock($code); + }); return undef; }}); @@ -237,10 +243,12 @@ __PACKAGE__->register_method ({ my $rpcenv = PVE::RPCEnvironment::get(); + my $id = extract_param($param, 'id'); + my ($guest_id) = PVE::ReplicationConfig::parse_replication_job_id($id); + my $code = sub { my $cfg = PVE::ReplicationConfig->new(); - my $id = $param->{id}; if ($param->{force}) { raise_param_exc({ 'keep' => "conflicts with parameter 'force'" }) if $param->{keep}; delete $cfg->{ids}->{$id}; @@ -262,7 +270,9 @@ __PACKAGE__->register_method ({ $cfg->write(); }; - PVE::ReplicationConfig::lock($code); + PVE::GuestHelpers::guest_migration_lock($guest_id, 10, sub { + PVE::ReplicationConfig::lock($code); + }); return undef; }}); -- 2.20.1