From bf9d912c2d4b3ea1baf8af69bb35123d35314c9f Mon Sep 17 00:00:00 2001 From: Alexandre Derumier Date: Tue, 18 Aug 2015 05:56:05 +0200 Subject: [PATCH] vm_stop_cleanup : detach loopdevices for non rootfs mountpoint Signed-off-by: Alexandre Derumier --- src/PVE/LXC.pm | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm index 472b810..8424261 100644 --- a/src/PVE/LXC.pm +++ b/src/PVE/LXC.pm @@ -1263,9 +1263,28 @@ sub vm_stop_cleanup { eval { if (!$keepActive) { + + my $loopdevs = loopdevices_list(); + PVE::LXC::foreach_mountpoint($conf, sub { my ($ms, $mountpoint) = @_; - PVE::Storage::deactivate_volumes($storage_cfg, [$mountpoint->{volume}]); + + my $volid = $mountpoint->{volume}; + #detach loopdevices of non rootfs mountpoints + my ($storage, $volname) = PVE::Storage::parse_volume_id($volid); + my $scfg = PVE::Storage::storage_config($storage_cfg, $storage); + my ($vtype, undef, undef, undef, undef, $isBase, $format) = + PVE::Storage::parse_volname($storage_cfg, $volid); + + if($ms ne 'rootfs' && $format eq 'raw' && ($scfg->{type} eq 'dir' || $scfg->{type} eq 'nfs')) { + my $path = PVE::Storage::path($storage_cfg, $volid); + foreach my $dev (keys %$loopdevs){ + PVE::Tools::run_command(['losetup', '-d', $dev]) if $loopdevs->{$dev} eq $path; + } + } + + PVE::Storage::deactivate_volumes($storage_cfg, [$volid]); + }); } }; -- 2.39.5