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 181CD766A6 for ; Tue, 19 Oct 2021 09:55:11 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 005AF29929 for ; Tue, 19 Oct 2021 09:55:11 +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) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id 3866C298DB for ; Tue, 19 Oct 2021 09:55:09 +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 7861A468D0 for ; Tue, 19 Oct 2021 09:55:03 +0200 (CEST) From: Fabian Ebner To: pve-devel@lists.proxmox.com Date: Tue, 19 Oct 2021 09:54:50 +0200 Message-Id: <20211019075459.14328-2-f.ebner@proxmox.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211019075459.14328-1-f.ebner@proxmox.com> References: <20211019075459.14328-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.271 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% 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 storage 1/3] plugin: add volume_snapshot_info function 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, 19 Oct 2021 07:55:11 -0000 which allows for better choices of common replication snapshots. Signed-off-by: Fabian Ebner --- If this is applied without the following patches, it still needs an APIVER+APIAGE bump and API changelog entry. PVE/Storage.pm | 9 +++++++++ PVE/Storage/Plugin.pm | 10 ++++++++++ PVE/Storage/ZFSPoolPlugin.pm | 22 ++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index e314bfc..f9582d0 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -371,6 +371,15 @@ sub volume_has_feature { } } +sub volume_snapshot_info { + my ($cfg, $volid) = @_; + + my ($storeid, $volname) = parse_volume_id($volid); + my $scfg = storage_config($cfg, $storeid); + my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); + return $plugin->volume_snapshot_info($scfg, $storeid, $volname); +} + sub volume_snapshot_list { my ($cfg, $volid) = @_; diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index e1f9335..d4b3615 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -1212,6 +1212,16 @@ sub status { return ($res->{total}, $res->{avail}, $res->{used}, 1); } +# Returns a hash with the snapshot names as keys and the following data: +# id - Unique id to distinguish different snapshots even if the have the same name. +# timestamp - Creation time of the snapshot (seconds since epoch). +# Returns an empty hash if the volume does not exist. +sub volume_snapshot_info { + my ($class, $scfg, $storeid, $volname) = @_; + + die "volume_snapshot_info is not implemented for $class"; +} + sub volume_snapshot_list { my ($class, $scfg, $storeid, $volname) = @_; diff --git a/PVE/Storage/ZFSPoolPlugin.pm b/PVE/Storage/ZFSPoolPlugin.pm index b73d895..01d0743 100644 --- a/PVE/Storage/ZFSPoolPlugin.pm +++ b/PVE/Storage/ZFSPoolPlugin.pm @@ -510,6 +510,28 @@ sub volume_rollback_is_possible { return 1; } +sub volume_snapshot_info { + my ($class, $scfg, $storeid, $volname) = @_; + + my $vname = ($class->parse_volname($volname))[1]; + + my @params = ('-Hp', '-t', 'snapshot', '-o', 'name,guid,creation', "$scfg->{pool}\/$vname"); + my $text = $class->zfs_request($scfg, undef, 'list', @params); + my @lines = split(/\n/, $text); + + my $info = {}; + for my $line (@lines) { + my ($snapshot, $guid, $creation) = split(/\s+/, $line); + (my $snap_name = $snapshot) =~ s/^.*@//; + + $info->{$snap_name} = { + id => $guid, + timestamp => $creation, + }; + } + return $info; +} + sub volume_snapshot_list { my ($class, $scfg, $storeid, $volname) = @_; -- 2.30.2