From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id CD0F27B124 for ; Tue, 11 May 2021 15:00:03 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C9FEA22323 for ; Tue, 11 May 2021 15:00:03 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 40BA9222FB for ; Tue, 11 May 2021 15:00:01 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 1940142B99 for ; Tue, 11 May 2021 15:00:01 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 11 May 2021 14:59:54 +0200 Message-Id: <20210511125955.25105-6-f.ebner@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210511125955.25105-1-f.ebner@proxmox.com> References: <20210511125955.25105-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.002 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH zsync 5/6] snapshot_destroy: make interface agnostic to source/dest X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2021 13:00:03 -0000 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 --- 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