]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: introduce get_linux_version()
authorIlya Dryomov <ilya.dryomov@inktank.com>
Mon, 16 Dec 2013 16:57:21 +0000 (18:57 +0200)
committerIlya Dryomov <ilya.dryomov@inktank.com>
Mon, 16 Dec 2013 16:57:21 +0000 (18:57 +0200)
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 <ilya.dryomov@inktank.com>
configure.ac
src/common/Makefile.am
src/common/linux_version.c [new file with mode: 0644]
src/common/linux_version.h [new file with mode: 0644]

index 4c3afa36720330963ea0c532e92af2e3a2ccf5e4..aa053b10d38ea933ae1121724c22a07e6a34730d 100644 (file)
@@ -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 \
index 080e276d39afa6c49281c0acb4b29e86d83e1ffa..ecc40d246c6abdca969598689aa2e070e1e4e967 100644 (file)
@@ -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 (file)
index 0000000..b83dc71
--- /dev/null
@@ -0,0 +1,25 @@
+#include "common/linux_version.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/utsname.h>
+
+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 (file)
index 0000000..5588c55
--- /dev/null
@@ -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 <linux/version.h>
+#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 */