public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fabian Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH zsync 5/6] snapshot_destroy: make interface agnostic to source/dest
Date: Tue, 11 May 2021 14:59:54 +0200	[thread overview]
Message-ID: <20210511125955.25105-6-f.ebner@proxmox.com> (raw)
In-Reply-To: <20210511125955.25105-1-f.ebner@proxmox.com>

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@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





  parent reply	other threads:[~2021-05-11 13:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-11 12:59 [pve-devel] [PATCH-SERIES zsync] fix #3351: allow keeping a different number of snapshots on source and destination Fabian Ebner
2021-05-11 12:59 ` [pve-devel] [PATCH zsync 1/6] param_to_job: handle --maxsnap 0 on creation Fabian Ebner
2021-05-11 12:59 ` [pve-devel] [PATCH zsync 2/6] usage: improve maxsnap description Fabian Ebner
2021-05-11 12:59 ` [pve-devel] [PATCH zsync 3/6] remove all old snapshots belonging to a job Fabian Ebner
2021-05-11 12:59 ` [pve-devel] [PATCH zsync 4/6] snapshot_get: make interface agnostic to source/dest Fabian Ebner
2021-05-11 12:59 ` Fabian Ebner [this message]
2021-05-11 12:59 ` [pve-devel] [PATCH zsync 6/6] fix #3351: allow keeping a different number of snapshots on source and destination Fabian Ebner
2021-05-24 16:00   ` Bruce Wainer
2021-05-25  5:10     ` Thomas Lamprecht
2021-05-25 12:02 ` [pve-devel] applied-series: [PATCH-SERIES zsync] " Thomas Lamprecht

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=20210511125955.25105-6-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal