[pve-devel] [PATCH storage] fix #4289: pbs: wait for backup verification to finish before updating volume attribute

Christoph Heiss c.heiss at proxmox.com
Mon Jan 2 13:36:33 CET 2023


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 <c.heiss at proxmox.com>
---
 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






More information about the pve-devel mailing list