[pve-devel] [PATCH 1/5] add mountpoint_mount sub
Alexandre Derumier
aderumier at odiso.com
Fri Aug 21 08:05:47 CEST 2015
we need to reuse it later
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
src/PVE/LXC.pm | 29 +++++++++++++++++++++++++++++
src/lxc-pve-mount-hook | 25 ++-----------------------
2 files changed, 31 insertions(+), 23 deletions(-)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index aaeee7f..7b36ce5 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1876,4 +1876,33 @@ sub volid_path {
return $path;
}
+
+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..8652995 100755
--- a/src/lxc-pve-mount-hook
+++ b/src/lxc-pve-mount-hook
@@ -91,30 +91,9 @@ __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;
- }
+ return if $ms eq 'rootfs';
- PVE::Tools::run_command(['mount', $path, $mount_path]);
- };
- warn $@ if $@;
+ 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