]> git.proxmox.com Git - pve-storage.git/commitdiff
Include new storage function volume_snapshot_list.
authorWolfgang Link <w.link@proxmox.com>
Mon, 24 Apr 2017 15:15:27 +0000 (17:15 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 28 Apr 2017 08:05:27 +0000 (10:05 +0200)
Returns a list of snapshots (youngest snap first) form a given volid.
It is possible to use a prefix to filter the list.

PVE/Storage.pm
PVE/Storage/Plugin.pm
PVE/Storage/ZFSPlugin.pm
PVE/Storage/ZFSPoolPlugin.pm

index 47948188a623ac16e753391f7d05922027b8f3d9..8fe9f4b013a873a8101deaec27ce7380b8b1cf93 100755 (executable)
@@ -280,6 +280,23 @@ sub volume_has_feature {
     }
 }
 
+sub volume_snapshot_list {
+    my ($cfg, $volid, $prefix, $ip) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid, 1);
+    if ($storeid) {
+       my $scfg = storage_config($cfg, $storeid);
+       my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+       return $plugin->volume_snapshot_list($scfg, $storeid, $volname, $prefix, $ip);
+    } elsif ($volid =~ m|^(/.+)$| && -e $volid) {
+       die "send file/device '$volid' is not possible\n";
+    } else {
+       die "unable to parse volume ID '$volid'\n";
+    }
+    # return an empty array if dataset does not exist.
+    # youngest snap first
+}
+
 sub get_image_dir {
     my ($cfg, $storeid, $vmid) = @_;
 
index d0df1f98b1d267a55012e668c2987d8c52464a29..641ab045a8b85581f6e8b8b72b93f8d4b2c24027 100644 (file)
@@ -832,6 +832,15 @@ sub status {
     return ($res->{total}, $res->{avail}, $res->{used}, 1);
 }
 
+sub volume_snapshot_list {
+    my ($class, $scfg, $storeid, $volname, $prefix, $ip) = @_;
+
+    # implement in subclass
+    die "Volume_snapshot_list is not implemented for $class";
+
+    # retrun an empty array if dataset does not exist.
+}
+
 sub activate_storage {
     my ($class, $storeid, $scfg, $cache) = @_;
 
index 900719303fbb7ca23cb1e187872e35ec3452f7ce..c7c7ba30025be7118da6119a04f4ea31bb505721 100644 (file)
@@ -369,6 +369,12 @@ sub volume_has_feature {
     return undef;
 }
 
+sub volume_snapshot_list {
+    my ($class, $scfg, $storeid, $volname, $prefix, $ip) = @_;
+    # return an empty array if dataset does not exist.
+    die "Volume_snapshot_list is not implemented for ZFS over iSCSI.\n";
+}
+
 sub activate_storage {
     my ($class, $storeid, $scfg, $cache) = @_;
 
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) = @_;