]> git.proxmox.com Git - pve-manager.git/commitdiff
pvesr: prepare local job: remove stale replicated volumes immediately
authorFiona Ebner <f.ebner@proxmox.com>
Mon, 13 Jun 2022 10:29:55 +0000 (12:29 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Tue, 2 Aug 2022 09:05:06 +0000 (11:05 +0200)
Commit d8cd8e8cf9795dc9c2462a67e9ef89ad31759796 introduced a
regression where only stale replicated volumes with an older
timestamp would be cleaned up. This meant that after removing a volume
from the guest config, it would only be cleaned up the second time the
replication ran afterwards. And the volume could become completely
orphaned in case the relevant storage wasn't used by the job anymore.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
PVE/CLI/pvesr.pm

index a1be88af72e7c717bee81294248e1c05ea86889e..95dad64e9421f9f936f719240b8263c7b3522a61 100644 (file)
@@ -137,8 +137,18 @@ __PACKAGE__->register_method ({
            push @$volids, map { $_->{volid} } @$images;
        }
        my ($local_snapshots, $cleaned_replicated_volumes) = PVE::Replication::prepare($storecfg, $volids, $jobid, $last_sync, $parent_snapname, $logfunc);
-       foreach my $volid (keys %$cleaned_replicated_volumes) {
-           if (!$wanted_volids->{$volid}) {
+       for my $volid ($volids->@*) {
+           next if $wanted_volids->{$volid};
+
+           my $stale = $cleaned_replicated_volumes->{$volid};
+           # prepare() will not remove the last_sync snapshot, but if the volume was used by the
+           # job and is not wanted anymore, it is stale too. And not removing it now might cause
+           # it to be missed later, because the relevant storage might not get scanned anymore.
+           $stale ||= grep {
+               PVE::Replication::is_replication_snapshot($_, $jobid)
+           } keys %{$local_snapshots->{$volid} // {}};
+
+           if ($stale) {
                $logfunc->("$jobid: delete stale volume '$volid'");
                PVE::Storage::vdisk_free($storecfg, $volid);
                delete $local_snapshots->{$volid};