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

Alexandre Derumier aderumier at odiso.com
Mon Aug 17 15:18:48 CEST 2015


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 src/PVE/LXCSetup/Base.pm | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/src/PVE/LXCSetup/Base.pm b/src/PVE/LXCSetup/Base.pm
index b4d8286..b4215f1 100644
--- a/src/PVE/LXCSetup/Base.pm
+++ b/src/PVE/LXCSetup/Base.pm
@@ -10,6 +10,8 @@ use Encode;
 
 use PVE::INotify;
 use PVE::Tools;
+use PVE::Storage;
+use PVE::Storage::Plugin;
 
 sub new {
     my ($class, $conf, $rootdir) = @_;
@@ -195,6 +197,50 @@ sub setup_init {
     die "please implement this inside subclass"
 }
 
+sub setup_mountpoints {
+    my ($self, $conf) = @_;
+
+    my $rootdir = $self->{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);
+	    }
+
+	    PVE::Tools::run_command(['mknod', '-m', '666', $rootdir.$path, 'b',  $bdevs->{$path}->{major}, $bdevs->{$path}->{minor}]) if $bdevs->{$path};
+
+	    PVE::Tools::run_command(['mount', $path, $rootdir.$mountpoint->{mp}]) if $mountpoint->{mp} && $ms ne 'rootfs';
+        }
+
+    });
+}
+
 sub setup_systemd_console {
     my ($self, $conf) = @_;
 
@@ -387,6 +433,7 @@ sub pre_start_hook {
     my ($self, $conf) = @_;
 
     $self->setup_init($conf);
+    $self->setup_mountpoints($conf);
     $self->setup_network($conf);
     $self->set_hostname($conf);
     $self->set_dns($conf);
-- 
2.1.4




More information about the pve-devel mailing list