From a315b9ff56c882760a1949cb2eadc0331d7dad90 Mon Sep 17 00:00:00 2001 From: Chris Allen Date: Tue, 11 Mar 2014 17:32:17 -0700 Subject: [PATCH] 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 --- 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");