mirror of
https://github.com/openvswitch/ovs
synced 2025-08-30 22:05:19 +00:00
util: Support checking for kernel versions.
Extract checking for a given kernel version to a separate function. It will be used also in the next patch. Acked-by: Mike Pattrick <mkp@redhat.com> Acked-by: Eelco Chaudron <echaudro@redhat.com> Acked-by: Aaron Conole <aconole@redhat.com> Signed-off-by: Felix Huettner <felix.huettner@mail.schwarz> Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
This commit is contained in:
committed by
Ilya Maximets
parent
b5e6829254
commit
6439d694ae
27
lib/util.c
27
lib/util.c
@@ -27,6 +27,7 @@
|
||||
#include <string.h>
|
||||
#ifdef __linux__
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/utsname.h>
|
||||
#endif
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
@@ -2500,3 +2501,29 @@ OVS_CONSTRUCTOR(winsock_start) {
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
bool
|
||||
ovs_kernel_is_version_or_newer(int target_major, int target_minor)
|
||||
{
|
||||
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
|
||||
static int current_major, current_minor = -1;
|
||||
|
||||
if (ovsthread_once_start(&once)) {
|
||||
struct utsname utsname;
|
||||
|
||||
if (uname(&utsname) == -1) {
|
||||
VLOG_WARN("uname failed (%s)", ovs_strerror(errno));
|
||||
} else if (!ovs_scan(utsname.release, "%d.%d",
|
||||
¤t_major, ¤t_minor)) {
|
||||
VLOG_WARN("uname reported bad OS release (%s)", utsname.release);
|
||||
}
|
||||
ovsthread_once_done(&once);
|
||||
}
|
||||
if (current_major == -1 || current_minor == -1) {
|
||||
return false;
|
||||
}
|
||||
return current_major > target_major || (
|
||||
current_major == target_major && current_minor >= target_minor);
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user