]> git.proxmox.com Git - pve-storage.git/commitdiff
plugin: add volume_snapshot_info function
authorFabian Ebner <f.ebner@proxmox.com>
Tue, 19 Oct 2021 07:54:50 +0000 (09:54 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Mon, 8 Nov 2021 09:35:53 +0000 (10:35 +0100)
which allows for better choices of common replication snapshots.

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
PVE/Storage.pm
PVE/Storage/Plugin.pm
PVE/Storage/ZFSPoolPlugin.pm

index e314bfc389163a2129b9713bbcc08e2d9e3e2aa5..f9582d0d9bc0e0f6ebe5fbb3862ecc4c6970d957 100755 (executable)
@@ -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) = @_;
 
index e1f9335a973e206c1248d76e4602f01952419e80..d4b3615b7b3937e7e68ea020ed79635a3e819303 100644 (file)
@@ -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) = @_;
 
index b73d895d1a19205d0b68bc9613f1915c437fdf26..01d074387a750ec1f1884a2bef3518fb41599dc0 100644 (file)
@@ -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) = @_;