]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/ZFSPoolPlugin.pm
Include new storage function volume_snapshot_list.
[pve-storage.git] / PVE / Storage / ZFSPoolPlugin.pm
index 5b9837899350a6323802ad3e43eca0337adbd592..a21219125c3882f6d5a12156c9ff14ff8a7b9799 100644 (file)
@@ -7,6 +7,7 @@ use POSIX;
 use PVE::Tools qw(run_command);
 use PVE::Storage::Plugin;
 use PVE::RPCEnvironment;
+use Net::IP;
 
 use base qw(PVE::Storage::Plugin);
 
@@ -495,7 +496,11 @@ sub volume_send {
 
     my $cmdrecv = [];
 
-    push @$cmdrecv, 'ssh', '-o', 'BatchMode=yes', "root\@${ip}", '--' if $ip;
+    if ($ip) {
+       $ip = "[$ip]" if Net::IP::ip_is_ipv6($ip);
+       push @$cmdrecv, 'ssh', '-o', 'BatchMode=yes', "root\@${ip}", '--';
+    }
+
     push @$cmdrecv, 'zfs', 'recv', '-F', '--';
 
     $zpath = $target_path if defined($target_path);
@@ -541,6 +546,38 @@ sub volume_rollback_is_possible {
     return 1; 
 }
 
+sub volume_snapshot_list {
+    my ($class, $scfg, $storeid, $volname, $prefix, $ip) = @_;
+
+    my ($vtype, $name, $vmid) = $class->parse_volname($volname);
+
+    my $zpath = "$scfg->{pool}/$name";
+
+    $prefix = '' if !defined($prefix);
+    my $snaps = [];
+
+    my $cmd = ['zfs', 'list', '-r', '-H', '-S', 'name', '-t', 'snap', '-o',
+              'name', $zpath];
+
+    if ($ip) {
+       $ip = "[$ip]" if Net::IP::ip_is_ipv6($ip);
+       unshift @$cmd, 'ssh', '-o', ' BatchMode=yes', "root\@${ip}", '--';
+    }
+
+    my $outfunc = sub {
+       my $line = shift;
+
+       if ($line =~ m/^\Q$zpath\E@(\Q$prefix\E.*)$/) {
+           push @$snaps, $1;
+       }
+    };
+
+    eval { run_command( [$cmd], outfunc => $outfunc , errfunc => sub{}); };
+
+    # return an empty array if dataset does not exist.
+    return $snaps;
+}
+
 sub activate_storage {
     my ($class, $storeid, $scfg, $cache) = @_;