From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [RFC v2 guest-common 4/4] replication: prepare: safeguard against removal if expected snapshot is missing
Date: Mon, 13 Jun 2022 12:29:59 +0200 [thread overview]
Message-ID: <20220613102959.36556-7-f.ebner@proxmox.com> (raw)
In-Reply-To: <20220613102959.36556-1-f.ebner@proxmox.com>
Such a check would also have prevented the issue in 1aa4d84
("ReplicationState: purge state from non local vms") and other
scenarios where state and disk state are inconsistent with regard to
the last_sync snapshot.
AFAICT, all existing callers intending to remove all snapshots use
last_sync=1 so chaning the behavior for other (non-zero) values should
be fine.
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
---
New in v2.
src/PVE/Replication.pm | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/PVE/Replication.pm b/src/PVE/Replication.pm
index 33fcc48..8591d0e 100644
--- a/src/PVE/Replication.pm
+++ b/src/PVE/Replication.pm
@@ -153,9 +153,9 @@ sub remote_finalize_local_job {
PVE::Tools::run_command($cmd, outfunc => $logger, errfunc => $logger);
}
-# Finds all local snapshots and removes replication snapshots not matching $last_sync. Use
-# last_sync=0 (or undef) to prevent removal (useful if VM was stolen). Use last_sync=1 to remove all
-# replication snapshots (limited to job if specified).
+# Finds all local snapshots and removes replication snapshots not matching $last_sync after checking
+# that it is present. Use last_sync=0 (or undef) to prevent removal (useful if VM was stolen). Use
+# last_sync=1 to remove all replication snapshots (limited to job if specified).
sub prepare {
my ($storecfg, $volids, $jobid, $last_sync, $parent_snapname, $logfunc) = @_;
@@ -173,12 +173,19 @@ sub prepare {
my $cleaned_replicated_volumes = {};
foreach my $volid (@$volids) {
my $info = PVE::Storage::volume_snapshot_info($storecfg, $volid);
+
+ my $removal_ok = !defined($snapname) || $info->{$snapname};
+ $removal_ok = 0 if $last_sync == 0; # last_sync=0 if the VM was stolen, don't remove!
+ $removal_ok = 1 if $last_sync == 1; # last_sync=1 is a special value used to remove all
+ $logfunc->("expected snapshot $snapname not present for $volid, not removing others")
+ if !$removal_ok && $last_sync > 1;
+
for my $snap (keys $info->%*) {
if ( # check if it's a stale replication snapshot
!(defined($snapname) && $snap eq $snapname) &&
!(defined($parent_snapname) && $snap eq $parent_snapname) &&
$snap =~ m/^\Q$prefix\E/ &&
- $last_sync != 0 # last_sync is 0 if the VM was stolen
+ $removal_ok
) {
$logfunc->("delete stale replication snapshot '$snap' on $volid");
eval {
--
2.30.2
next prev parent reply other threads:[~2022-06-13 10:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-13 10:29 [pve-devel] [PATCH-SERIES v2 manager/guest-common] replication: improve removal of stale snapshots/volumes Fabian Ebner
2022-06-13 10:29 ` [pve-devel] [PATCH v2 manager 1/2] pvesr: rename last_snapshots to local_snapshots Fabian Ebner
2022-06-13 10:29 ` [pve-devel] [PATCH v2 manager 2/2] pvesr: prepare local job: remove stale replicated volumes immediately Fabian Ebner
2022-06-13 10:29 ` [pve-devel] [PATCH v2 guest-common 1/4] replication: prepare: adapt/expand function comment Fabian Ebner
2022-06-13 10:29 ` [pve-devel] [PATCH v2 guest-common 2/4] replication: rename last_snapshots to local_snapshots Fabian Ebner
2022-06-13 10:29 ` [pve-devel] [PATCH v2 guest-common 3/4] replication: also consider storages from replication state upon removal Fabian Ebner
2022-06-13 10:29 ` Fabian Ebner [this message]
2022-07-27 11:22 ` [pve-devel] [PATCH-SERIES v2 manager/guest-common] replication: improve removal of stale snapshots/volumes Fiona Ebner
2022-08-02 9:08 ` [pve-devel] applied-series: " Fabian Grünbichler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220613102959.36556-7-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal