[pve-devel] [PATCH zsync 5/6] snapshot_destroy: make interface agnostic to source/dest

Fabian Ebner f.ebner at proxmox.com
Tue May 11 14:59:54 CEST 2021


Also drop the 'method' parameter which is not used consistently (e.g. ignored
in the later half of the very same function, in snapshot_exist, vm_exists,...),
and not documented. Simply rely on the presence of the IP address as is done in
many other places already.

In snapshot_add, there is no need to try and destroy the snapshot on the
destination (did happen previously, because $dest was passed along), because we
just failed to create the snapshot on the source side.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 pve-zsync | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/pve-zsync b/pve-zsync
index c162230..1213361 100755
--- a/pve-zsync
+++ b/pve-zsync
@@ -694,7 +694,8 @@ sub sync {
 	    send_image($source, $dest, $param);
 
 	    for my $old_snap (@{$dest->{old_snap}}) {
-		snapshot_destroy($source, $dest, $param->{method}, $old_snap, $param->{source_user}, $param->{dest_user});
+		snapshot_destroy($source->{all}, $old_snap, $source->{ip}, $param->{source_user});
+		snapshot_destroy($dest_dataset, $old_snap, $dest->{ip}, $param->{dest_user});
 	    }
 	};
 
@@ -812,7 +813,7 @@ sub snapshot_add {
     };
 
     if (my $err = $@) {
-	snapshot_destroy($source, $dest, 'ssh', $snap_name, $source_user, $dest_user);
+	snapshot_destroy($source->{all}, $snap_name, $source->{ip}, $source_user);
 	die "$err\n";
     }
 }
@@ -967,14 +968,14 @@ sub prepare_prepended_target {
 }
 
 sub snapshot_destroy {
-    my ($source, $dest, $method, $snap, $source_user, $dest_user) = @_;
+    my ($dataset, $snap, $ip, $user) = @_;
 
     my @zfscmd = ('zfs', 'destroy');
-    my $snapshot = "$source->{all}\@$snap";
+    my $snapshot = "$dataset\@$snap";
 
     eval {
-	if($source->{ip} && $method eq 'ssh'){
-	    run_cmd(['ssh', "$source_user\@$source->{ip}", '--', @zfscmd, $snapshot]);
+	if ($ip) {
+	    run_cmd(['ssh', "$user\@$ip", '--', @zfscmd, $snapshot]);
 	} else {
 	    run_cmd([@zfscmd, $snapshot]);
 	}
@@ -982,18 +983,6 @@ sub snapshot_destroy {
     if (my $erro = $@) {
 	warn "WARN: $erro";
     }
-    if ($dest) {
-	my @ssh = $dest->{ip} ? ('ssh', "$dest_user\@$dest->{ip}", '--') : ();
-
-	my $path = target_dataset($source, $dest);
-
-	eval {
-	    run_cmd([@ssh, @zfscmd, "$path\@$snap"]);
-	};
-	if (my $erro = $@) {
-	    warn "WARN: $erro";
-	}
-    }
 }
 
 # check if snapshot for incremental sync exist on source side
@@ -1048,7 +1037,7 @@ sub send_image {
     };
 
     if (my $erro = $@) {
-	snapshot_destroy($source, undef, $param->{method}, $source->{new_snap}, $param->{source_user}, $param->{dest_user});
+	snapshot_destroy($source->{all}, $source->{new_snap}, $source->{ip}, $param->{source_user});
 	die $erro;
     };
 }
-- 
2.20.1






More information about the pve-devel mailing list