[Ocfs2-test-devel] [PATCH 1/1] Ocfs2-test: Add api-compat for ocfs2 to use system call better.

Tristan Ye tristan.ye at oracle.com
Tue Apr 14 19:34:13 PDT 2009


This methodology was ported from ocfs2-1.4, it guarantees to use the latest
system call from mainline, and an alternative old version will be used from our
compat code only if the wanted call was not contained in kernel header. The patch
also fix a compiling error on some distributions with existing code.

We can easily remove the compat code from building infrastructure without main code
modified when the older kernel is desupported someday.

Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
 Config.make.in                                     |    2 ++
 Makefile                                           |    2 ++
 aclocal.m4                                         |    1 +
 .../splice_test.h => api-compat/include/splice.h   |   10 ++++------
 configure.in                                       |   14 ++++++++++++++
 kfeature.m4                                        |   17 +++++++++++++++++
 programs/splice/Makefile                           |    4 +++-
 programs/splice/splice_read.c                      |    9 ++++++++-
 programs/splice/splice_write.c                     |    9 ++++++++-
 9 files changed, 59 insertions(+), 9 deletions(-)
 rename programs/splice/splice_test.h => api-compat/include/splice.h (81%)
 create mode 100644 kfeature.m4

diff --git a/Config.make.in b/Config.make.in
index d6c9a75..a03274e 100644
--- a/Config.make.in
+++ b/Config.make.in
@@ -29,6 +29,8 @@ TESTDIR = $(libdir)/ocfs2-test
 
 top_builddir = .
 
+EXTRA_CFLAGS += @API_COMPAT_CFLAGS@
+
 INSTALL = @INSTALL@
 INSTALL_PROGRAM = @INSTALL_PROGRAM@
 INSTALL_LIBRARY = @INSTALL_PROGRAM@
diff --git a/Makefile b/Makefile
index d8d3f52..3aabe82 100644
--- a/Makefile
+++ b/Makefile
@@ -26,6 +26,8 @@ SUBDIRS = programs utilities tests suites
 
 SUBDIRS += vendor
 
+API_COMPAT_FILES = \
+        api-compat/include/splice.h
 
 DIST_FILES = \
 	COPYING					\
diff --git a/aclocal.m4 b/aclocal.m4
index 4c1b940..fb56765 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -1,3 +1,4 @@
 m4_include([pkg.m4])
 m4_include([runlog.m4])
 m4_include([python.m4])
+m4_include([kfeature.m4])
diff --git a/programs/splice/splice_test.h b/api-compat/include/splice.h
similarity index 81%
rename from programs/splice/splice_test.h
rename to api-compat/include/splice.h
index 5113bbb..08966c1 100644
--- a/programs/splice/splice_test.h
+++ b/api-compat/include/splice.h
@@ -1,11 +1,8 @@
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
+#ifndef API_SPLICE_H
+#define API_SPLICE_H
+
 #include <unistd.h>
 #include <fcntl.h>
-#include <assert.h>
-#include <errno.h>
-#include <limits.h>
 
 #if defined(__i386__)
 
@@ -37,3 +34,4 @@ int splice(int fdin, loff_t *off_in, int fdout,
 	return syscall(__NR_splice, fdin, off_in, fdout, off_out, len, flags);
 }
 
+#endif
diff --git a/configure.in b/configure.in
index 6461599..0e652d0 100644
--- a/configure.in
+++ b/configure.in
@@ -127,6 +127,20 @@ AC_MSG_RESULT($enable_third_party)
 dnl check for Python
 AM_PATH_PYTHON(2.3, , AC_MSG_ERROR([could not find Python 2.3 or higher.]))
 
+splice_compat_header=""
+API_COMPAT_HEADERS=""
+API_COMPAT_CFLAGS=""
+
+OCFS2_CHECK_HEADERS([splice() in bits/fcntl.h], bits/fcntl.h,
+  , splice_compat_header="splice.h", [splice (int __fdin])
+API_COMPAT_HEADERS="$API_COMPAT_HEADERS $splice_compat_header"
+
+for h in $API_COMPAT_HEADERS; do
+  API_COMPAT_CFLAGS="$API_COMPAT_CFLAGS -include \$(TOPDIR)/api-compat/include/$h"
+done
+AC_SUBST(API_COMPAT_CFLAGS)
+
+
 AC_CONFIG_FILES([
 Config.make
 vendor/common/ocfs2-test.spec-generic
diff --git a/kfeature.m4 b/kfeature.m4
new file mode 100644
index 0000000..5e1774b
--- /dev/null
+++ b/kfeature.m4
@@ -0,0 +1,17 @@
+AC_DEFUN([OCFS2_CHECK_HEADERS],
+  [AC_MSG_CHECKING([for $1])
+   kernel_check_regexp="m4_default([$5], [\<$1(])"
+
+   kernel_check_headers=
+   for kfile in $2; do
+     kernel_check_headers="$kernel_check_headers /usr/include/$kfile"
+   done
+
+   if grep "$kernel_check_regexp" $kernel_check_headers >/dev/null 2>&1 ; then
+     m4_default([$3], :)
+     AC_MSG_RESULT(yes)
+   else
+     m4_default([$4], :)
+     AC_MSG_RESULT(no)
+   fi
+])# OCFS2_CHECK_HEADERS
diff --git a/programs/splice/Makefile b/programs/splice/Makefile
index f1ecd1a..37159bf 100644
--- a/programs/splice/Makefile
+++ b/programs/splice/Makefile
@@ -6,7 +6,9 @@ TESTS = splice_read splice_write
 
 CFLAGS = -O2 -Wall -g
 
-SPLICE_READ_SOURCES = splice_read.c splice_test.h
+CFLAGS += $(EXTRA_CFLAGS)
+
+SPLICE_READ_SOURCES = splice_read.c
 SPLICE_READ_OBJECTS = $(patsubst %.c,%.o,$(SPLICE_READ_SOURCES))
 SPLICE_WRITE_SOURCES = splice_write.c
 SPLICE_WRITE_OBJECTS = $(patsubst %.c,%.o,$(SPLICE_WRITE_SOURCES))
diff --git a/programs/splice/splice_read.c b/programs/splice/splice_read.c
index c25522e..42e29bf 100644
--- a/programs/splice/splice_read.c
+++ b/programs/splice/splice_read.c
@@ -1,5 +1,12 @@
 /* splice_read.c */
-#include "splice_test.h"
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
 
 int main(int argc, char *argv[])
 {
diff --git a/programs/splice/splice_write.c b/programs/splice/splice_write.c
index a4d8c1a..e273fbc 100644
--- a/programs/splice/splice_write.c
+++ b/programs/splice/splice_write.c
@@ -1,5 +1,12 @@
 /* splice_write.c */
-#include "splice_test.h"
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <assert.h>
+#include <errno.h>
+#include <limits.h>
 
 int main(int argc, char *argv[])
 {
-- 
1.5.5




More information about the Ocfs2-test-devel mailing list