From 4defdb73a574002b0b75388e9e4206a553577918 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabian=20Gr=C3=BCnbichler?= Date: Wed, 24 Feb 2016 12:28:33 +0100 Subject: [PATCH] Check volume usage in snapshots before deleting --- src/PVE/LXC.pm | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 4ba9125..6046c46 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -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); } } -- 2.39.2