[pve-devel] [PATCH 2/6] vm_stop_cleanup : detach loopdevices for non rootfs mountpoint

Alexandre Derumier aderumier at odiso.com
Tue Aug 18 05:56:05 CEST 2015


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 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 10a89f2..c68207b 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1266,9 +1266,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.1.4




More information about the pve-devel mailing list