[pve-devel] [PATCH v4 container 01/12] tools: add can_use_new_mount_api helper

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Nov 20 08:30:56 CET 2019


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 src/PVE/LXC/Tools.pm | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/PVE/LXC/Tools.pm b/src/PVE/LXC/Tools.pm
index bebd7d8..ce37cee 100644
--- a/src/PVE/LXC/Tools.pm
+++ b/src/PVE/LXC/Tools.pm
@@ -2,6 +2,8 @@
 
 package PVE::LXC::Tools;
 
+use Errno qw(ENOSYS);
+
 use PVE::SafeSyslog;
 
 # LXC introduced an `lxc.hook.version` property which allows hooks to be executed in different
@@ -130,4 +132,20 @@ sub cgroup_do_write($$) {
     return 1;
 }
 
+# Check whether the kernel supports the new mount api. This is used in the pre-start hook and in
+# the hotplugging code.
+my $cached_can_use_new_mount_api = undef;
+sub can_use_new_mount_api() {
+    if (!defined($cached_can_use_new_mount_api)) {
+	if (PVE::Tools::move_mount(-1, 0, -1, 0, 0)) {
+	    # This should not be possible...
+	    die "kernel behaved unexpectedly: move_mount(-1, NULL, -1, NULL) did not fail!\n";
+	}
+	# On older kernels the syscall doesn't exist and we get ENOSYS. (For newer kernels this call
+	# will fail with EFAULT instead, since we pass in a NULL pointer as file system name.)
+	$cached_can_use_new_mount_api = ($! != ENOSYS);
+    }
+    return $cached_can_use_new_mount_api;
+}
+
 1;
-- 
2.20.1





More information about the pve-devel mailing list