]> git.proxmox.com Git - pve-storage.git/commitdiff
zfs: implement zfs_get_latest_snapshot
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 23 Jan 2015 11:38:21 +0000 (12:38 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 23 Jan 2015 11:57:38 +0000 (12:57 +0100)
To improve code sharing.

PVE/Storage/ZFSDirPlugin.pm
PVE/Storage/ZFSPlugin.pm

index 11ee78339fc58274825d8b95d4d59bab30c4ad6f..cac6a72cc59c8ca68f76c0b04e77561a701cb614 100644 (file)
@@ -352,6 +352,25 @@ sub zfs_find_free_diskname {
     die "unable to allocate an image name for VM $vmid in storage '$storeid'\n";
 }
 
+sub zfs_get_latest_snapshot {
+    my ($class, $scfg, $volname) = @_;
+
+    # abort rollback if snapshot is not the latest
+    my @params = ('-t', 'snapshot', '-o', 'name', '-s', 'creation');
+    my $text = zfs_request($class, $scfg, undef, 'list', @params);
+    my @snapshots = split(/\n/, $text);
+
+    my $recentsnap;
+    foreach (@snapshots) {
+        if (/$scfg->{pool}\/$volname/) {
+            s/^.*@//;
+            $recentsnap = $_;
+        }
+    }
+
+    return $recentsnap;
+}
+
 sub status {
     my ($class, $storeid, $scfg, $cache) = @_;
 
@@ -392,22 +411,12 @@ sub volume_snapshot_rollback {
     my ($class, $scfg, $storeid, $volname, $snap) = @_;
 
     # abort rollback if snapshot is not the latest
-    my @params = ('-t', 'snapshot', '-o', 'name', '-s', 'creation');
-    my $text = zfs_request($class, $scfg, undef,'list', @params);
-    my @snapshots = split(/\n/, $text);
-    my $recentsnap = undef;
-    foreach (@snapshots) {
-        if (/$scfg->{pool}\/$volname/) {
-            s/^.*@//;
-            $recentsnap = $_;
-        }
-    }
+    my $recentsnap = $class->zfs_get_latest_snapshot($scfg, $volname);
     if ($snap ne $recentsnap) {
         die "cannot rollback, more recent snapshots exist\n";
     }
 
     zfs_request($class, $scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap");
 }
 
 sub activate_volume {
index 3595913bfcb00e3e57e4e9ff0dbe8e283a64bfa2..22d8ccaa2ae9ba137c2a122c018ebbc58f591172 100644 (file)
@@ -324,16 +324,7 @@ sub volume_snapshot_rollback {
     my ($class, $scfg, $storeid, $volname, $snap) = @_;
 
     # abort rollback if snapshot is not the latest
-    my @params = ('-t', 'snapshot', '-o', 'name', '-s', 'creation');
-    my $text = $class->zfs_request($class, $scfg, undef, 'list', @params);
-    my @snapshots = split(/\n/, $text);
-    my $recentsnap = undef;
-    foreach (@snapshots) {
-        if (/$scfg->{pool}\/$volname/) {
-            s/^.*@//;
-            $recentsnap = $_;
-        }
-    }
+    my $recentsnap = $class->zfs_get_latest_snapshot($scfg, $volname);
     if ($snap ne $recentsnap) {
         die "cannot rollback, more recent snapshots exist\n";
     }