]> git.proxmox.com Git - pve-container.git/commitdiff
Rework snapshot config removal logic
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 20 Jan 2016 12:14:52 +0000 (13:14 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 21 Jan 2016 07:39:28 +0000 (08:39 +0100)
Correctly update parent relations in config file upon snapshot removal.

Previously, only the parent of the current state was updated/removed,
which led to broken parent relations if any snapshot other then the
immediate parent of the current snapshot was removed. To fix this,
the parent relation of all children snapshots of the removed snapshot
are updated/removed as well.

Based on code in qemu-server/PVE/QemuServer.pm and parts
of a patch by Gerrit Venema <gmoniker at gmail.com>

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
src/PVE/LXC.pm

index 2899fa966876139c1a57f4bed53625b8b07660c1..64d7d5c567c6579a3abdd8ad93857e7054fbdc5e 100644 (file)
@@ -1865,17 +1865,29 @@ sub snapshot_delete {
 
     my $storecfg = PVE::Storage::config();
 
-    my $del_snap =  sub {
+    my $unlink_parent = sub {
 
-       check_lock($conf);
+       my ($confref, $new_parent) = @_;
 
-       if ($conf->{parent} eq $snapname) {
-           if ($conf->{snapshots}->{$snapname}->{snapname}) {
-               $conf->{parent} = $conf->{snapshots}->{$snapname}->{parent};
+       if ($confref->{parent} && $confref->{parent} eq $snapname) {
+           if ($new_parent) {
+               $confref->{parent} = $new_parent;
            } else {
-               delete $conf->{parent};
+               delete $confref->{parent};
            }
        }
+    };
+
+    my $del_snap =  sub {
+
+       check_lock($conf);
+
+       my $parent = $conf->{snapshots}->{$snapname}->{parent};
+       foreach my $snapkey (keys %{$conf->{snapshots}}) {
+           &$unlink_parent($conf->{snapshots}->{$snapkey}, $parent);
+       }
+
+       &$unlink_parent($conf, $parent);
 
        delete $conf->{snapshots}->{$snapname};