replication: prepare: simplify code

No functional change is intended.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
This commit is contained in:
Fabian Ebner 2021-11-26 11:52:31 +01:00 committed by Fabian Grünbichler
parent ff574bf8d2
commit 244583a40b

View File

@ -176,32 +176,28 @@ sub prepare {
foreach my $volid (@$volids) { foreach my $volid (@$volids) {
my $info = PVE::Storage::volume_snapshot_info($storecfg, $volid); my $info = PVE::Storage::volume_snapshot_info($storecfg, $volid);
for my $snap (keys $info->%*) { for my $snap (keys $info->%*) {
if ((defined($snapname) && ($snap eq $snapname)) || if ( # check if it's a stale replication snapshot
(defined($parent_snapname) && ($snap eq $parent_snapname))) { !(defined($snapname) && $snap eq $snapname) &&
$last_snapshots->{$volid}->{$snap} = $info->{$snap}; !(defined($parent_snapname) && $snap eq $parent_snapname) &&
} elsif ($snap =~ m/^\Q$prefix\E/) { $snap =~ m/^\Q$prefix\E/ &&
if ($last_sync != 0) { $last_sync != 0 # last_sync is 0 if the VM was stolen
$logfunc->("delete stale replication snapshot '$snap' on $volid"); ) {
eval { $logfunc->("delete stale replication snapshot '$snap' on $volid");
PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snap); eval {
$cleaned_replicated_volumes->{$volid} = 1; PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snap);
}; $cleaned_replicated_volumes->{$volid} = 1;
};
# If deleting the snapshot fails, we can not be sure if it was due to an error or a timeout. # If deleting the snapshot fails, we can not be sure if it was due to an error or a timeout.
# The likelihood that the delete has worked out is high at a timeout. # The likelihood that the delete has worked out is high at a timeout.
# If it really fails, it will try to remove on the next run. # If it really fails, it will try to remove on the next run.
if (my $err = $@) { if (my $err = $@) {
# warn is for syslog/journal. # warn is for syslog/journal.
warn $err; warn $err;
# logfunc will written in replication log. # logfunc will written in replication log.
$logfunc->("delete stale replication snapshot error: $err"); $logfunc->("delete stale replication snapshot error: $err");
}
# Last_sync=0 and a replication snapshot only occur, if the VM was stolen
} else {
$last_snapshots->{$volid}->{$snap} = $info->{$snap};
} }
# Other snapshots might need to serve as replication base after rollback
} else { } else {
$last_snapshots->{$volid}->{$snap} = $info->{$snap}; $last_snapshots->{$volid}->{$snap} = $info->{$snap};
} }