[pve-devel] [PATCH 5/9] vm_stop_cleanup : detach loopdevices for non rootfs mountpoint

Alexandre Derumier aderumier at odiso.com
Sun Aug 16 19:43:02 CEST 2015


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 src/PVE/LXC.pm | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 10a89f2..2d11075 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1266,9 +1266,25 @@ 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);
+		if($ms ne 'rootfs' && ($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