diff mbox series

[v4,8/9] syscalls/sync_file_range: Use C library wrapper if present

Message ID 1550739616-24054-9-git-send-email-sumit.garg@linaro.org
State Accepted
Commit c0dc8876fb1486ee85f6dd43e36ec5b3d9d9a4ed
Headers show
Series syscalls: add sync device test-cases | expand

Commit Message

Sumit Garg Feb. 21, 2019, 9 a.m. UTC
Add config check for C library wrapper for sync_file_range() syscall.
Also, check for sync_file_range() presence via dummy call rather than
kernel version check. And move fallback api to:
include/lapi/sync_file_range.h

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 configure.ac                                       |  1 +
 include/lapi/sync_file_range.h                     | 57 ++++++++++++++++++++
 m4/ltp-sync_file_range.m4                          | 10 ++++
 .../sync_file_range/check_sync_file_range.h        | 21 ++++++++
 .../syscalls/sync_file_range/sync_file_range01.c   | 62 ++--------------------
 5 files changed, 94 insertions(+), 57 deletions(-)
 create mode 100644 include/lapi/sync_file_range.h
 create mode 100644 m4/ltp-sync_file_range.m4
 create mode 100644 testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index 9122b6d..d15bff3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -232,6 +232,7 @@  LTP_CHECK_RLIMIT64
 LTP_DETECT_HOST_CPU
 LTP_CHECK_PERF_EVENT
 LTP_CHECK_SYNCFS
+LTP_CHECK_SYNC_FILE_RANGE
 
 if test "x$with_numa" = xyes; then
 	LTP_CHECK_SYSCALL_NUMA
diff --git a/include/lapi/sync_file_range.h b/include/lapi/sync_file_range.h
new file mode 100644
index 0000000..e2d35fc
--- /dev/null
+++ b/include/lapi/sync_file_range.h
@@ -0,0 +1,57 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines  Corp., 2008
+ */
+
+#ifndef SYNC_FILE_RANGE_H
+#define SYNC_FILE_RANGE_H
+
+#include <sys/types.h>
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_SYNC_FILE_RANGE)
+
+#ifdef TST_TEST_H__
+# define TST_SYSCALL tst_syscall
+#else
+# define TST_SYSCALL ltp_syscall
+#endif
+
+/*****************************************************************************
+ * Wraper function to call sync_file_range system call
+ ******************************************************************************/
+static inline long sync_file_range(int fd, off64_t offset, off64_t nbytes,
+				   unsigned int flags)
+{
+#if (defined(__arm__) || defined(__powerpc__) || defined(__powerpc64__))
+# if (__WORDSIZE == 32)
+#  if __BYTE_ORDER == __BIG_ENDIAN
+	return TST_SYSCALL(__NR_sync_file_range2, fd, flags,
+		(int)(offset >> 32), (int)offset, (int)(nbytes >> 32),
+		(int)nbytes);
+#  elif __BYTE_ORDER == __LITTLE_ENDIAN
+	return TST_SYSCALL(__NR_sync_file_range2, fd, flags, (int)offset,
+		       (int)(offset >> 32), nbytes, (int)(nbytes >> 32));
+#  endif
+# else
+	return TST_SYSCALL(__NR_sync_file_range2, fd, flags, offset, nbytes);
+# endif
+#elif (defined(__s390__) || defined(__s390x__)) && __WORDSIZE == 32
+	return TST_SYSCALL(__NR_sync_file_range, fd, (int)(offset >> 32),
+		(int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
+#elif defined(__mips__) && __WORDSIZE == 32
+# if __BYTE_ORDER == __BIG_ENDIAN
+	return TST_SYSCALL(__NR_sync_file_range, fd, 0, (int)(offset >> 32),
+		(int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
+# elif __BYTE_ORDER == __LITTLE_ENDIAN
+	return TST_SYSCALL(__NR_sync_file_range, fd, 0, (int)offset,
+		(int)(offset >> 32), (int)nbytes, (int)(nbytes >> 32), flags);
+# endif
+#else
+	return TST_SYSCALL(__NR_sync_file_range, fd, offset, nbytes, flags);
+#endif
+}
+#endif
+
+#endif /* SYNC_FILE_RANGE_H */
diff --git a/m4/ltp-sync_file_range.m4 b/m4/ltp-sync_file_range.m4
new file mode 100644
index 0000000..b47a091
--- /dev/null
+++ b/m4/ltp-sync_file_range.m4
@@ -0,0 +1,10 @@ 
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (c) 2019 Linaro Limited. All rights reserved.
+
+dnl
+dnl LTP_CHECK_SYNC_FILE_RANGE
+dnl ----------------------------
+dnl
+AC_DEFUN([LTP_CHECK_SYNC_FILE_RANGE],[
+AC_CHECK_FUNCS(sync_file_range,,)
+])
diff --git a/testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h b/testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h
new file mode 100644
index 0000000..4698c55
--- /dev/null
+++ b/testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h
@@ -0,0 +1,21 @@ 
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <sumit.garg@linaro.org>
+ */
+
+#ifndef CHECK_SYNC_FILE_RANGE_H
+#define CHECK_SYNC_FILE_RANGE_H
+
+int check_sync_file_range(void)
+{
+	int ret;
+
+	ret = sync_file_range(-1, 0, 0, 0);
+	if (ret == -1 && errno == EINVAL)
+		return 0;
+
+	return 1;
+}
+
+#endif /* CHECK_SYNC_FILE_RANGE_H */
diff --git a/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c b/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c
index cebb919..3a97183 100644
--- a/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c
+++ b/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c
@@ -92,7 +92,8 @@ 
 #include <unistd.h>
 
 #include "test.h"
-#include "lapi/syscalls.h"
+#include "lapi/sync_file_range.h"
+#include "check_sync_file_range.h"
 
 #ifndef SYNC_FILE_RANGE_WAIT_BEFORE
 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
@@ -190,48 +191,6 @@  void setup(void)
 	sfd = open(spl_file, O_RDWR | O_CREAT, 0700);
 }
 
-/*****************************************************************************
- * Wraper function to call sync_file_range system call
- ******************************************************************************/
-static inline long syncfilerange(int fd, off64_t offset, off64_t nbytes,
-				 unsigned int flags)
-{
-/* arm and powerpc */
-#if (defined(__arm__) || defined(__powerpc__) || defined(__powerpc64__))
-#if (__WORDSIZE == 32)
-#if __BYTE_ORDER == __BIG_ENDIAN
-	return ltp_syscall(__NR_sync_file_range2, fd, flags,
-		(int)(offset >> 32), (int)offset, (int)(nbytes >> 32),
-		(int)nbytes);
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-	return ltp_syscall(__NR_sync_file_range2, fd, flags, (int)offset,
-		       (int)(offset >> 32), nbytes, (int)(nbytes >> 32));
-#endif
-#else
-	return ltp_syscall(__NR_sync_file_range2, fd, flags, offset, nbytes);
-#endif
-
-/* s390 */
-#elif (defined(__s390__) || defined(__s390x__)) && __WORDSIZE == 32
-	return ltp_syscall(__NR_sync_file_range, fd, (int)(offset >> 32),
-		(int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
-
-/* mips */
-#elif defined(__mips__) && __WORDSIZE == 32
-#if __BYTE_ORDER == __BIG_ENDIAN
-	return ltp_syscall(__NR_sync_file_range, fd, 0, (int)(offset >> 32),
-		(int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-	return ltp_syscall(__NR_sync_file_range, fd, 0, (int)offset,
-		(int)(offset >> 32), (int)nbytes, (int)(nbytes >> 32), flags);
-#endif
-
-/* other */
-#else
-	return ltp_syscall(__NR_sync_file_range, fd, offset, nbytes, flags);
-#endif
-}
-
 /******************************************************************************/
 /*									    */
 /* Function:    main							  */
@@ -258,24 +217,13 @@  int main(int ac, char **av)
 
 	tst_parse_opts(ac, av, NULL, NULL);
 
-#if defined(__powerpc__) || defined(__powerpc64__)	/* for PPC, kernel version > 2.6.21 needed */
-	if (tst_kvercmp(2, 16, 22) < 0) {
-		tst_brkm(TCONF, NULL,
-			 "System doesn't support execution of the test");
-	}
-#else
-	/* For other archs, need kernel version > 2.6.16 */
-
-	if (tst_kvercmp(2, 6, 17) < 0) {
-		tst_brkm(TCONF, NULL,
-			 "System doesn't support execution of the test");
-	}
-#endif
+	if (!check_sync_file_range())
+		tst_brkm(TCONF, NULL, "sync_file_range() not supported");
 
 	setup();
 
 	for (test_index = 0; test_index < TST_TOTAL; test_index++) {
-		TEST(syncfilerange
+		TEST(sync_file_range
 		     (*(test_data[test_index].fd),
 		      test_data[test_index].offset,
 		      test_data[test_index].nbytes,