[pve-devel] [PATCH 2/6] forbid snapshot delete if it's a template
Alexandre Derumier
aderumier at odiso.com
Thu Nov 29 10:37:52 CET 2012
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/QemuServer.pm | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 35c0f69..dc96b91 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2867,6 +2867,8 @@ sub qemu_volume_snapshot {
sub qemu_volume_snapshot_delete {
my ($vmid, $deviceid, $storecfg, $volid, $snap) = @_;
+ die "you can't delete a snapshot if it's a template" if is_template($vmid, $snap);
+
my $running = PVE::QemuServer::check_running($vmid);
return if !PVE::Storage::volume_snapshot_delete($storecfg, $volid, $snap, $running);
@@ -4128,4 +4130,23 @@ sub template_delete {
}
+sub is_template {
+ my ($vmid, $snapname, $checkall) = @_;
+
+ my $conf = PVE::QemuServer::load_config($vmid);
+
+ return 1 if (defined($conf->{snapshots}->{$snapname}->{template}) && $snapname);
+ return 1 if ($conf->{template} && !$snapname);
+
+ if($checkall){
+ my $snaphash = $conf->{snapshots} || {};
+ foreach my $snapname (keys %$snaphash) {
+ return 1 if defined($snaphash->{$snapname}->{template});
+ }
+ }
+
+ return undef;
+
+}
+
1;
--
1.7.10.4
More information about the pve-devel
mailing list