[pve-devel] [PATCH 9/9] mount hook : mount blockdevs

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


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

diff --git a/src/PVE/LXCSetup/Base.pm b/src/PVE/LXCSetup/Base.pm
index b4d8286..76f8f7d 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,43 @@ 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);
+
+        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 +426,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