[pve-devel] [PATCH 2/5] add mountpoint_activate sub

Alexandre Derumier aderumier at odiso.com
Fri Aug 21 08:05:48 CEST 2015


activate volume and loopdevice if needed

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 src/PVE/LXC.pm            | 27 +++++++++++++++++++++++++++
 src/lxc-pve-prestart-hook | 14 +-------------
 2 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 7b36ce5..f10d72e 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1905,4 +1905,31 @@ sub mountpoint_mount {
     };
     warn $@ if $@;
 }
+
+sub mountpoint_activate {
+    my ($ms, $volid, $storage_cfg) = @_;
+
+    return if !$volid || $volid =~ m|^/dev/.+|;
+
+    PVE::Storage::activate_volumes($storage_cfg, [$volid]);
+
+    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);
+	return $loopdev;
+    }
+}
+
+
 1;
diff --git a/src/lxc-pve-prestart-hook b/src/lxc-pve-prestart-hook
index 2f3088b..81d81f3 100755
--- a/src/lxc-pve-prestart-hook
+++ b/src/lxc-pve-prestart-hook
@@ -82,19 +82,7 @@ __PACKAGE__->register_method ({
 	    my ($ms, $mountpoint) = @_;
 
 	    my $volid = $mountpoint->{volume};
-	    return if !$volid || $volid =~ m|^/dev/.+|;
-
-	    PVE::Storage::activate_volumes($storage_cfg, [$volid]);
-
-	    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 ne 'subvol' && ($scfg->{type} eq 'dir' || $scfg->{type} eq 'nfs')) {
-		my $path = PVE::Storage::path($storage_cfg, $volid);
-		PVE::Tools::run_command(['losetup', '--find', '--show', $path]);
-	    }
+	    PVE::LXC::mountpoint_activate($ms, $volid, $storage_cfg);
 	});
 
 	return undef;
-- 
2.1.4




More information about the pve-devel mailing list