[pve-devel] [PATCH 8/9] zfs: move code fix metode call

Wolfgang Link w.link at proxmox.com
Fri Jan 23 10:32:44 CET 2015


duplicate code because can't refactor volume_snapshot_rollback

Signed-off-by: Wolfgang Link <w.link at proxmox.com>
---
 PVE/Storage/ZFSDirPlugin.pm |   48 +++++++++++++++++++++++++++++++++++++++++++
 PVE/Storage/ZFSPlugin.pm    |    4 ++--
 2 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/PVE/Storage/ZFSDirPlugin.pm b/PVE/Storage/ZFSDirPlugin.pm
index 7086c33..9081d01 100644
--- a/PVE/Storage/ZFSDirPlugin.pm
+++ b/PVE/Storage/ZFSDirPlugin.pm
@@ -389,6 +389,28 @@ sub volume_snapshot_delete {
     $class->zfs_request($scfg, undef, 'destroy', "$scfg->{pool}/$volname\@$snap");
 }
 
+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 = $_;
+        }
+    }
+    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 {
     my ($class, $storeid, $scfg, $volname, $exclusive, $cache) = @_;
     return 1;
@@ -399,4 +421,30 @@ sub deactivate_volume {
     return 1;
 }
 
+sub volume_has_feature {
+    my ($class, $scfg, $feature, $storeid, $volname, $snapname, $running) = @_;
+
+    my $features = {
+	snapshot => { current => 1, snap => 1},
+	clone => { base => 1},
+	template => { current => 1},
+	copy => { base => 1, current => 1},
+    };
+
+    my ($vtype, $name, $vmid, $basename, $basevmid, $isBase) =
+	$class->parse_volname($volname);
+
+    my $key = undef;
+
+    if ($snapname) {
+	$key = 'snap';
+    } else {
+	$key = $isBase ? 'base' : 'current';
+    }
+
+    return 1 if $features->{$feature}->{$key};
+
+    return undef;
+}
+
 1;
diff --git a/PVE/Storage/ZFSPlugin.pm b/PVE/Storage/ZFSPlugin.pm
index 8f4c098..28600dc 100644
--- a/PVE/Storage/ZFSPlugin.pm
+++ b/PVE/Storage/ZFSPlugin.pm
@@ -325,7 +325,7 @@ sub volume_snapshot_rollback {
 
     # abort rollback if snapshot is not the latest
     my @params = ('-t', 'snapshot', '-o', 'name', '-s', 'creation');
-    my $text = $class->zfs_request($scfg, undef, 'list', @params);
+    my $text = $class->zfs_request($class, $scfg, undef, 'list', @params);
     my @snapshots = split(/\n/, $text);
     my $recentsnap = undef;
     foreach (@snapshots) {
@@ -340,7 +340,7 @@ sub volume_snapshot_rollback {
 
     $class->zfs_delete_lu($scfg, $volname);
 
-    $class->zfs_request($scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap");
+    $class->zfs_request($class, $scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap");
 
     $class->zfs_import_lu($scfg, $volname);
 
-- 
1.7.10.4





More information about the pve-devel mailing list