[pve-devel] [PATCH container 2/4] add a check_kernel_release helper
Wolfgang Bumiller
w.bumiller at proxmox.com
Thu Jan 30 09:27:31 CET 2020
Should this go to pve-common?
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
src/PVE/LXC.pm | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index c590fc8..9e25ad4 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -464,6 +464,30 @@ sub get_cgroup_subsystems {
return wantarray ? ($v1, $v2) : $v1;
}
+# Check if the kernel is at least $major.$minor. Return either just a boolean,
+# or a boolean and the kernel version's major minor numbers we parsed out of
+# uname's release string.
+sub check_kernel_release {
+ my ($major, $minor) = @_;
+
+ my (undef, undef, $release) = POSIX::uname();
+
+ my ($result, $k_major, $k_minor) = (0, 'unknown', 'unknown');
+
+ if ($release =~ /^(\d+)\.(\d+)(?:$|\.)/) {
+ ($k_major, $k_minor) = ($1, $2);
+
+ if (defined($minor)) {
+ $result = $k_major > $major
+ || ($k_major == $major && $k_minor >= $minor);
+ } else {
+ $result = $k_major >= $major;
+ }
+ }
+
+ return wantarray ? ($result, "$k_major.$k_minor") : $result;
+}
+
# With seccomp trap to userspace we now have the ability to optionally forward
# certain syscalls to the "host" to handle (via our pve-lxc-syscalld daemon).
#
--
2.20.1
More information about the pve-devel
mailing list