[pve-devel] [PATCH v3 guest-common 2/7] config: rollback: factor out helper for removing replication snapshots

Fabian Ebner f.ebner at proxmox.com
Thu Aug 12 13:01:06 CEST 2021


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 src/PVE/AbstractConfig.pm | 49 ++++++++++++++++++++++-----------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/src/PVE/AbstractConfig.pm b/src/PVE/AbstractConfig.pm
index 493bf97..0d1c7ca 100644
--- a/src/PVE/AbstractConfig.pm
+++ b/src/PVE/AbstractConfig.pm
@@ -943,14 +943,39 @@ sub snapshot_delete {
     });
 }
 
+# Remove replication snapshots to make a rollback possible.
+my $rollback_remove_replication_snapshots = sub {
+    my ($class, $vmid, $snap) = @_;
+
+    my $storecfg = PVE::Storage::config();
+
+    my $repl_conf = PVE::ReplicationConfig->new();
+    return if !$repl_conf->check_for_existing_jobs($vmid, 1);
+
+    my $volumes = $class->get_replicatable_volumes($storecfg, $vmid, $snap, 1);
+
+    # filter by what we actually iterate over below (excludes vmstate!)
+    my $volids = [];
+    $class->foreach_volume($snap, sub {
+	my ($vs, $volume) = @_;
+
+	my $volid_key = $class->volid_key();
+	my $volid = $volume->{$volid_key};
+
+	push @{$volids}, $volid if $volumes->{$volid};
+    });
+
+    # remove all local replication snapshots (jobid => undef)
+    my $logfunc = sub { my $line = shift; chomp $line; print "$line\n"; };
+    PVE::Replication::prepare($storecfg, $volids, undef, 1, undef, $logfunc);
+};
+
 # Rolls back to a given snapshot.
 sub snapshot_rollback {
     my ($class, $vmid, $snapname) = @_;
 
     my $prepare = 1;
 
-    my $storecfg = PVE::Storage::config();
-
     my $data = {};
 
     my $get_snapshot_config = sub {
@@ -972,25 +997,7 @@ sub snapshot_rollback {
 	$snap = $get_snapshot_config->($conf);
 
 	if ($prepare) {
-	    my $repl_conf = PVE::ReplicationConfig->new();
-	    if ($repl_conf->check_for_existing_jobs($vmid, 1)) {
-		my $volumes = $class->get_replicatable_volumes($storecfg, $vmid, $snap, 1);
-
-		# filter by what we actually iterate over below (excludes vmstate!)
-		my $volids = [];
-		$class->foreach_volume($snap, sub {
-		    my ($vs, $volume) = @_;
-
-		    my $volid_key = $class->volid_key();
-		    my $volid = $volume->{$volid_key};
-
-		    push @{$volids}, $volid if $volumes->{$volid};
-		});
-
-		# remove all local replication snapshots (jobid => undef)
-		my $logfunc = sub { my $line = shift; chomp $line; print "$line\n"; };
-		PVE::Replication::prepare($storecfg, $volids, undef, 1, undef, $logfunc);
-	    }
+	    $rollback_remove_replication_snapshots->($class, $vmid, $snap);
 
 	    $class->foreach_volume($snap, sub {
 	       my ($vs, $volume) = @_;
-- 
2.30.2






More information about the pve-devel mailing list