[pve-devel] [PATCH 3/5] add mountpoint_deactivate sub
Alexandre Derumier
aderumier at odiso.com
Fri Aug 21 08:05:49 CEST 2015
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
src/PVE/LXC.pm | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index f10d72e..da9f72e 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1931,5 +1931,32 @@ sub mountpoint_activate {
}
}
+sub mountpoint_deactivate {
+ my ($ms, $volid, $storage_cfg) = @_;
+
+ return if !$volid || $volid =~ m|^/dev/.+|;
+
+ 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 || $ms ne 'rootfs') && $format eq 'raw' && ($scfg->{type} eq 'dir' || $scfg->{type} eq 'nfs')) {
+ my $path = PVE::Storage::path($storage_cfg, $volid);
+ my $loopdev;
+
+ my $parser = sub {
+ my $line = shift;
+ $loopdev = $line if $line =~m|^/dev/loop\d+$|;
+ };
+ PVE::Tools::run_command(['losetup', '--find', '--show', $path], outfunc => $parser);
+ PVE::Tools::run_command(['losetup', '-d', $loopdev]) if $loopdev;
+
+ }
+
+ PVE::Storage::deactivate_volumes($storage_cfg, [$volid]);
+
+}
+
1;
--
2.1.4
More information about the pve-devel
mailing list