]> git.proxmox.com Git - pve-container.git/commitdiff
Check volume usage in snapshots before deleting
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 24 Feb 2016 11:28:33 +0000 (12:28 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 25 Feb 2016 07:53:13 +0000 (08:53 +0100)
src/PVE/LXC.pm

index 4ba91257958858ca5f5ce83968c40333b44b0fd7..6046c46bd79bfb0e722f1dce9127cb68c6dac005 100644 (file)
@@ -1199,7 +1199,7 @@ sub verify_searchdomain_list {
 }
 
 sub is_volume_in_use {
-    my ($config, $volid) = @_;
+    my ($config, $volid, $include_snapshots) = @_;
     my $used = 0;
 
     foreach_mountpoint($config, sub {
@@ -1210,6 +1210,13 @@ sub is_volume_in_use {
        }
     });
 
+    my $snapshots = $config->{snapshots};
+    if ($include_snapshots && $snapshots) {
+       foreach my $snap (keys %$snapshots) {
+           $used ||= is_volume_in_use($snapshots->{$snap}, $volid);
+       }
+    }
+
     return $used;
 }
 
@@ -1425,6 +1432,8 @@ sub update_pct_config {
        my $storage_cfg = PVE::Storage::config();
        foreach my $volume (@deleted_volumes) {
            next if $used_volids->{$volume}; # could have been re-added, too
+           # also check for references in snapshots
+           next if is_volume_in_use($conf, $volume, 1);
            delete_mountpoint_volume($storage_cfg, $vmid, $volume);
        }
     }