[pve-devel] [PATCH 2/8] forbid snapshot delete if it's a template

Alexandre Derumier aderumier at odiso.com
Tue Dec 4 12:19:05 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 04fb3be..b6b5d4e 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