Here's a patch to abort a ZFS rollback if the snapshot isn't the latest.
 This way we don't accidentally remove the LU for a snapshot we can't
rollback to.
From d749f409743f02c89d8aaa04b2726b3b10a8e41a Mon Sep 17 00:00:00 2001
From: Chris Allen <Chris Allen>
Date: Tue, 11 Mar 2014 17:32:17 -0700
Subject: [PATCH 6/6] Added code to abort a snapshot rollback in ZFS if the
 snapshot selected is not the most recent.  This is to
 avoid lu deletion when trying to rollback to a snapshot
 that isn't the newest.


Signed-off-by: Chris Allen <Chris Allen>
---
 PVE/Storage/ZFSPlugin.pm |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/PVE/Storage/ZFSPlugin.pm b/PVE/Storage/ZFSPlugin.pm
index 208e718..cb733d1 100644
--- a/PVE/Storage/ZFSPlugin.pm
+++ b/PVE/Storage/ZFSPlugin.pm
@@ -607,6 +607,21 @@ sub volume_snapshot {
 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($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_delete_lu($scfg, $volname);
 
     zfs_request($scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap");
-- 
1.7.10.4

_______________________________________________
pve-devel mailing list
[email protected]
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to