From: Chen Hanxiao <chenhanxiao@xxxxxxxxxxxxxx> Some cgroup value range may change in the further kernel. Introduce kernel version check function for cgroup. This will be helpful to determine the proper values. Signed-off-by: Chen Hanxiao <chenhanxiao@xxxxxxxxxxxxxx> --- src/util/vircgroup.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index e99caf5..498bc20 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -38,6 +38,7 @@ #include <sys/types.h> #include <signal.h> #include <dirent.h> +#include <sys/utsname.h> #define __VIR_CGROUP_ALLOW_INCLUDE_PRIV_H__ #include "vircgrouppriv.h" @@ -74,6 +75,37 @@ typedef enum { */ } virCgroupFlags; +static int virCgroupGetKernelVersion(unsigned long *kernelVersion) +{ + struct utsname ver; + + uname(&ver); + + if (virParseVersionString(ver.release, kernelVersion, true) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown release: %s"), ver.release); + return -1; + } + + return 0; +} + +static bool virCgroupVersionCheck(const char * dstVersion) +{ + unsigned long currentVersion; + unsigned long version; + + if (virCgroupGetKernelVersion(¤tVersion) < 0) { + return -1; + } + + if (virParseVersionString(dstVersion, &version, true) < 0) { + return -1; + } + + return (((long long)currentVersion - (long long)version) >= 0) ? true : false; +} + + #ifdef VIR_CGROUP_SUPPORTED bool -- 1.8.2.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list