[pve-devel] [PATCH storage 1/3] plugin: add volume_snapshot_info function

Fabian Ebner f.ebner at proxmox.com
Tue Oct 19 09:54:50 CEST 2021


which allows for better choices of common replication snapshots.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

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






More information about the pve-devel mailing list