pvesr: prepare local job: remove stale replicated volumes immediately

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>
This commit is contained in:
Fiona Ebner 2022-06-13 12:29:55 +02:00 committed by Fabian Grünbichler
parent e3e0e09637
commit 55b1af44fd

View 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};