[pve-devel] [PATCH 3/5] add mountpoint_mount sub
Alexandre Derumier
aderumier at odiso.com
Fri Aug 21 17:10:17 CEST 2015
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
src/PVE/LXC.pm | 30 ++++++++++++++++++++++++++++++
src/lxc-pve-mount-hook | 26 ++------------------------
2 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 2f9b98b..b90848b 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1920,4 +1920,34 @@ sub dettach_loops {
}
}
+
+sub mountpoint_mount {
+ my ($ms, $mountpoint, $rootdir, $storage_cfg, $loopdevs) = @_;
+
+ my $volid = $mountpoint->{volume};
+ my $mount = $mountpoint->{mp};
+
+ return if !$volid || !$mount;
+
+ eval {
+ my $mount_path = $rootdir.$mount;
+ File::Path::mkpath($mount_path);
+
+ if ($volid =~ m|^/dev/.+|) {
+ PVE::Tools::run_command(['mount', $volid, $mount_path]);
+ return;
+ }
+
+ my $path = PVE::LXC::volid_path($volid, $ms, $storage_cfg, $loopdevs);
+
+ if ($path !~ m|^/dev/.+|) {
+ PVE::Tools::run_command(['mount', '-o', 'bind', $path, $mount_path]);
+ return;
+ }
+
+ PVE::Tools::run_command(['mount', $path, $mount_path]);
+ };
+ warn $@ if $@;
+}
+
1;
diff --git a/src/lxc-pve-mount-hook b/src/lxc-pve-mount-hook
index 0655d3c..0b99e68 100755
--- a/src/lxc-pve-mount-hook
+++ b/src/lxc-pve-mount-hook
@@ -91,30 +91,8 @@ __PACKAGE__->register_method ({
my $setup_mountpoint = sub {
my ($ms, $mountpoint) = @_;
- my $volid = $mountpoint->{volume};
- return if !$volid || $ms eq 'rootfs' || !$mountpoint->{mp};
-
- eval {
- my $mount_path = $rootdir.$mountpoint->{mp};
- if (! -d $mount_path) {
- mkdir($mount_path) || $! == EEXIST || die "unable to create directory '$mount_path' - $!\n";
- }
-
- if ($volid =~ m|^/dev/.+|) {
- PVE::Tools::run_command(['mount', $volid, $mount_path]);
- return;
- }
-
- my $path = PVE::LXC::volid_path($volid, $ms, $storage_cfg, $loopdevs);
-
- if ($path !~ m|^/dev/.+|) {
- PVE::Tools::run_command(['mount', '-o', 'bind', $path, $mount_path]);
- return;
- }
-
- PVE::Tools::run_command(['mount', $path, $mount_path]);
- };
- warn $@ if $@;
+ return if $ms eq 'rootfs';
+ PVE::LXC::mountpoint_mount($ms, $mountpoint, $rootdir, $storage_cfg, $loopdevs);
};
my $setup_cgroup_device = sub {
--
2.1.4
More information about the pve-devel
mailing list