[pve-devel] [PATCH 6/6] mount hook : setup_mountpoints

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


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 src/PVE/LXC.pm         | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/lxc-pve-mount-hook |  2 ++
 2 files changed, 53 insertions(+)

diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 1a0a514..086dc60 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1838,4 +1838,55 @@ sub find_loopdev {
 	return $dev if $loopdevs->{$dev} eq $path;
     }
 }
+
+sub setup_mountpoints {
+    my ($conf, $vmid, $rootdir) = @_;
+
+    my $fn = "/etc/pve/storage.cfg";
+
+    return if ! -f $fn;
+
+    my $raw = PVE::Tools::file_get_contents($fn);
+    my $storage_cfg = PVE::Storage::Plugin->parse_config($fn, $raw);
+
+    my $bdevs = PVE::LXC::blockdevices_list();
+    my $loopdevs = PVE::LXC::loopdevices_list();
+
+    PVE::LXC::foreach_mountpoint($conf, sub {
+        my ($ms, $mountpoint) = @_;
+
+        my $volid = $mountpoint->{volume};
+        return if !$volid;
+
+        my ($storage, $volname) = PVE::Storage::parse_volume_id($volid);
+
+        my $scfg = PVE::Storage::storage_config($storage_cfg, $storage);
+
+        my $path = PVE::Storage::path($storage_cfg, $volid);
+
+        my ($vtype, undef, undef, undef, undef, $isBase, $format) =
+            PVE::Storage::parse_volname($storage_cfg, $volid);
+
+        if ($format ne 'subvol') {
+
+            if ($scfg->{type} eq 'dir' || $scfg->{type} eq 'nfs') {
+                $path = PVE::LXC::find_loopdev($loopdevs, $path);
+            }
+
+	    if(-l $path) {
+		$path = readlink($path);
+		$path =~ s/\.\.\/\.\.\//\/dev\//;
+	    }
+
+            if ($bdevs->{$path}) {
+                PVE::Tools::run_command(['mknod', '-m', '666', $rootdir.$path, 'b',  $bdevs->{$path}->{major}, $bdevs->{$path}->{minor}]);
+                write_cgroup_value("devices", $vmid, "devices.allow", "b $bdevs->{$path}->{major}:$bdevs->{$path}->{minor} rwm");
+            }
+
+            PVE::Tools::run_command(['mount', $path, $rootdir.$mountpoint->{mp}]) if $mountpoint->{mp} && $ms ne 'rootfs';
+        }
+
+    });
+}
+
 1;
diff --git a/src/lxc-pve-mount-hook b/src/lxc-pve-mount-hook
index f5f0867..5cc966d 100755
--- a/src/lxc-pve-mount-hook
+++ b/src/lxc-pve-mount-hook
@@ -82,6 +82,8 @@ __PACKAGE__->register_method ({
 	
 	my $mountpoint = $ENV{LXC_ROOTFS_MOUNT};
 
+	PVE::LXC::setup_mountpoints($conf, $param->{name}, $mountpoint);
+
 	my $lxc_setup = PVE::LXCSetup->new($conf, $mountpoint);
 	$lxc_setup->pre_start_hook();
 	
-- 
2.1.4




More information about the pve-devel mailing list