From: Ilya Dryomov Date: Mon, 16 Dec 2013 16:57:21 +0000 (+0200) Subject: common: introduce get_linux_version() X-Git-Tag: v0.75~96^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=fcf6e9878bed5ddc1e642844923b3ac7312dcd1e;p=ceph.git common: introduce get_linux_version() get_linux_version() returns a version of the currently running kernel, encoded as in int, and is contained in common/linux_version.[ch]. Signed-off-by: Ilya Dryomov --- diff --git a/configure.ac b/configure.ac index 4c3afa367203..aa053b10d38e 100644 --- a/configure.ac +++ b/configure.ac @@ -584,6 +584,7 @@ AC_CHECK_MEMBER([struct fiemap_extent.fe_logical], AC_CHECK_HEADERS([ \ arpa/inet.h \ + linux/version.h \ netdb.h \ netinet/in.h \ sys/file.h \ diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 080e276d39af..ecc40d246c6a 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -69,7 +69,9 @@ libcommon_la_SOURCES = \ common/bloom_filter.cc if LINUX -libcommon_la_SOURCES += common/secret.c +libcommon_la_SOURCES += \ + common/secret.c \ + common/linux_version.c endif # these should go out of libcommon @@ -195,7 +197,8 @@ noinst_HEADERS += \ common/AsyncReserver.h \ common/sync_filesystem.h \ common/cmdparse.h \ - common/hobject.h + common/hobject.h \ + common/linux_version.h noinst_LTLIBRARIES += libcommon.la diff --git a/src/common/linux_version.c b/src/common/linux_version.c new file mode 100644 index 000000000000..b83dc71e4ed4 --- /dev/null +++ b/src/common/linux_version.c @@ -0,0 +1,25 @@ +#include "common/linux_version.h" + +#include +#include +#include + +int get_linux_version(void) +{ + struct utsname ubuf; + int a, b, c; + int n; + + if (uname(&ubuf) || strcmp(ubuf.sysname, "Linux")) + return 0; + + n = sscanf(ubuf.release, "%d.%d.%d", &a, &b, &c); + switch (n) { + case 3: + return KERNEL_VERSION(a, b, c); + case 2: + return KERNEL_VERSION(a, b, 0); + default: + return 0; + } +} diff --git a/src/common/linux_version.h b/src/common/linux_version.h new file mode 100644 index 000000000000..5588c55ba220 --- /dev/null +++ b/src/common/linux_version.h @@ -0,0 +1,22 @@ +#ifndef CEPH_LINUX_VERSION_H +#define CEPH_LINUX_VERSION_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef HAVE_LINUX_VERSION_H +# include +#endif + +#ifndef KERNEL_VERSION +# define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) +#endif + +int get_linux_version(void); + +#ifdef __cplusplus +} +#endif + +#endif /* CEPH_LINUX_VERSION_H */