Storage: add method volume_rollback_is_possible

add method volume_rollback_is_possible and redactor
Improve error handling
If snapshot is not reversible catch it before vm will lock and shutdown.
This is the case if zfs has an younger snapshot.

Signed-off-by: Wolfgang Link <w.link@proxmox.com>
This commit is contained in:
Wolfgang Link
2015-02-12 08:41:35 +01:00
committed by Dietmar Maurer
parent a4034b9f19
commit 1597f1f9ad
4 changed files with 35 additions and 9 deletions

View File

@ -144,6 +144,21 @@ sub volume_resize {
}
}
sub volume_rollback_is_possible {
my ($cfg, $volid, $snap) = @_;
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_rollback_is_possible($scfg, $storeid, $volname, $snap);
} elsif ($volid =~ m|^(/.+)$| && -e $volid) {
die "snapshot rollback device $volid is not possible";
} else {
die "can't parse volume id";
}
}
sub volume_snapshot {
my ($cfg, $volid, $snap, $running) = @_;

View File

@ -656,6 +656,12 @@ sub volume_snapshot {
return undef;
}
sub volume_rollback_is_possible {
my ($class, $scfg, $storeid, $volname, $snap) = @_;
return 1;
}
sub volume_snapshot_rollback {
my ($class, $scfg, $storeid, $volname, $snap) = @_;

View File

@ -311,11 +311,8 @@ sub volume_snapshot_rollback {
my ($class, $scfg, $storeid, $volname, $snap) = @_;
# abort rollback if snapshot is not the latest
my $recentsnap = $class->zfs_get_latest_snapshot($scfg, $volname);
if ($snap ne $recentsnap) {
die "cannot rollback, more recent snapshots exist\n";
}
$class->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
$class->zfs_delete_lu($scfg, $volname);
$class->zfs_request($class, $scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap");

View File

@ -412,14 +412,22 @@ sub volume_snapshot_rollback {
my ($class, $scfg, $storeid, $volname, $snap) = @_;
# abort rollback if snapshot is not the latest
my $recentsnap = $class->zfs_get_latest_snapshot($scfg, $volname);
if ($snap ne $recentsnap) {
die "cannot rollback, more recent snapshots exist\n";
}
$class->volume_rollback_is_possible($scfg, $storeid, $volname, $snap);
zfs_request($class, $scfg, undef, 'rollback', "$scfg->{pool}/$volname\@$snap");
}
sub volume_rollback_is_possible {
my ($class, $scfg, $storeid, $volname, $snap) = @_;
my $recentsnap = $class->zfs_get_latest_snapshot($scfg, $volname);
if ($snap ne $recentsnap) {
die "can't rollback, more recent snapshots exist\n";
}
return 1;
}
sub activate_storage {
my ($class, $storeid, $scfg, $cache) = @_;