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 1512292DCE for ; Mon, 2 Jan 2023 13:37:43 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id E1FA62FA3F for ; Mon, 2 Jan 2023 13:37:42 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (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 for ; Mon, 2 Jan 2023 13:37:42 +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 EF1D7443BC for ; Mon, 2 Jan 2023 13:37:41 +0100 (CET) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Mon, 2 Jan 2023 13:36:33 +0100 Message-Id: <20230102123633.2493599-3-c.heiss@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230102123633.2493599-1-c.heiss@proxmox.com> References: <20230102123633.2493599-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.004 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment 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 storage] fix #4289: pbs: wait for backup verification to finish before updating volume attribute 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: Mon, 02 Jan 2023 12:37:43 -0000 This fixes an "unable to set protected flag" error when backing up to a PBS datastore that has the 'Verify New' flag set. This happens due to the volume being locked for verifiying after the backup completes, but before the request to update the 'protected' volume flag is made. Thus delay the volume flag update until the verify job is finished. Signed-off-by: Christoph Heiss --- PVE/Storage.pm | 4 ++-- PVE/Storage/PBSPlugin.pm | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 89c7116..47cb266 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -248,7 +248,7 @@ sub get_volume_attribute { } sub update_volume_attribute { - my ($cfg, $volid, $attribute, $value) = @_; + my ($cfg, $volid, $attribute, $value, $logfunc) = @_; my ($storeid, $volname) = parse_volume_id($volid); my $scfg = storage_config($cfg, $storeid); @@ -278,7 +278,7 @@ sub update_volume_attribute { } } - return $plugin->update_volume_attribute($scfg, $storeid, $volname, $attribute, $value); + return $plugin->update_volume_attribute($scfg, $storeid, $volname, $attribute, $value, $logfunc); } sub volume_size_info { diff --git a/PVE/Storage/PBSPlugin.pm b/PVE/Storage/PBSPlugin.pm index 4320974..1cdbc11 100644 --- a/PVE/Storage/PBSPlugin.pm +++ b/PVE/Storage/PBSPlugin.pm @@ -906,8 +906,30 @@ sub get_volume_attribute { return; } +sub wait_for_verify_finish { + my ($conn, $node, $datastore, $attrs) = @_; + + my $param = { + running => 'true', + since => $attrs->{'backup-time'}, + store => $datastore, + typefilter => 'verify', + }; + + my $taskname = sprintf('%s:%s/%s/%X', + $datastore, + @{$attrs}{qw(backup-type backup-id backup-time)}, + ); + + while (1) { + my $res = eval { $conn->get("/api2/json/nodes/$node/tasks", $param); }; + last if !grep { $_->{worker_id} eq $taskname } @$res; + sleep(1); + } +} + sub update_volume_attribute { - my ($class, $scfg, $storeid, $volname, $attribute, $value) = @_; + my ($class, $scfg, $storeid, $volname, $attribute, $value, $logfunc) = @_; if ($attribute eq 'notes') { return $class->update_volume_notes($scfg, $storeid, $volname, $value); @@ -921,6 +943,9 @@ sub update_volume_attribute { my $conn = pbs_api_connect($scfg, $password); my $datastore = $scfg->{datastore}; + $logfunc->('info', 'waiting for server to finish backup verification...') if $logfunc; + wait_for_verify_finish($conn, $scfg->{server}, $datastore, $param); + eval { $conn->put("/api2/json/admin/datastore/$datastore/$attribute", $param); }; if (my $err = $@) { die "Server is not recent enough to support feature '$attribute'\n" -- 2.30.2