Skip to contentSkip to conversation

syscalls: add sync device test-cases

PATCH Superseded Sumit Garg 2 participants 18 messages Feb 19, 2019 – Feb 20, 2019 Library code

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Sumit Garg

author
#0 lore raw

v3 cover syscalls: add sync device test-cases

This patch-set adds common test for minimal sectors written on device for various sync related syscalls:
1. syncfs()
2. sync()
3. fsync()
4. fdatasync()
5. sync_file_range()

Also this test is run on all supported filesystems on a test block device.

Changes in v3:
1. Scope increased from single patch to this patch-set to add common test for sync(), fsync(), fdatasync() and sync_file_range() syscalls.
2. Move common functionality to library functions.
3. Use %lu rather than %s while parsing sectors written.
4. Add config check for C library wrapper and fallback definition for syncfs() and sync_file_range() syscalls.

Changes in v2:
1. Remove unused header file include.
2. Remove redundant tst_device check.
3. Remove redundant flags from tst_test struct.

Sumit Garg (7):
lib: Add library functions for sync related syscalls
syscalls: add syncfs() sync device test-case syscalls/sync: add sync device test-case syscalls/fsync: add sync device test-case syscalls/fdatasync: add sync device test-case syscalls/sync_file_range: Use C library wrapper if present syscalls/sync_file_range: add sync device test-case

 configure.ac                                       |  2 +
 include/lapi/sync_file_range.h                     | 64 +++++++++++++++++
 include/lapi/syncfs.h                              | 21 ++++++
 include/tst_sync_device.h                          | 17 +++++
 include/tst_test.h                                 |  7 ++
 lib/tst_sync_device.c                              | 80 ++++++++++++++++++++++
 m4/ltp-sync_file_range.m4                          | 10 +++
 m4/ltp-syncfs.m4                                   | 10 +++
 runtest/syscalls                                   |  6 ++
 testcases/kernel/syscalls/fdatasync/.gitignore     |  1 +
 testcases/kernel/syscalls/fdatasync/fdatasync03.c  | 61 +++++++++++++++++
 testcases/kernel/syscalls/fsync/.gitignore         |  1 +
 testcases/kernel/syscalls/fsync/fsync04.c          | 61 +++++++++++++++++
 testcases/kernel/syscalls/sync/.gitignore          |  1 +
 testcases/kernel/syscalls/sync/sync03.c            | 59 ++++++++++++++++
 .../kernel/syscalls/sync_file_range/.gitignore     |  1 +
 .../sync_file_range/check_sync_file_range.h        | 23 +++++++
 .../syscalls/sync_file_range/sync_file_range01.c   | 62 ++---------------
 .../syscalls/sync_file_range/sync_file_range02.c   | 70 +++++++++++++++++++
 testcases/kernel/syscalls/syncfs/.gitignore        |  1 +
 testcases/kernel/syscalls/syncfs/Makefile          |  8 +++
 testcases/kernel/syscalls/syncfs/check_syncfs.h    | 19 +++++
 testcases/kernel/syscalls/syncfs/syncfs01.c        | 64 +++++++++++++++++
 23 files changed, 592 insertions(+), 57 deletions(-)
 create mode 100644 include/lapi/sync_file_range.h
 create mode 100644 include/lapi/syncfs.h
 create mode 100644 include/tst_sync_device.h
 create mode 100644 lib/tst_sync_device.c
 create mode 100644 m4/ltp-sync_file_range.m4
 create mode 100644 m4/ltp-syncfs.m4
 create mode 100644 testcases/kernel/syscalls/fdatasync/fdatasync03.c
 create mode 100644 testcases/kernel/syscalls/fsync/fsync04.c
 create mode 100644 testcases/kernel/syscalls/sync/sync03.c
 create mode 100644 testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h
 create mode 100644 testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
 create mode 100644 testcases/kernel/syscalls/syncfs/.gitignore
 create mode 100644 testcases/kernel/syscalls/syncfs/Makefile
 create mode 100644 testcases/kernel/syscalls/syncfs/check_syncfs.h
 create mode 100644 testcases/kernel/syscalls/syncfs/syncfs01.c
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v3 1/7 lib: Add library functions for sync related syscalls

These library functions are used to add common test for minimal sectors written on device for various sync related syscalls.

---
 include/tst_sync_device.h | 17 ++++++++++
 lib/tst_sync_device.c     | 80 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100644 include/tst_sync_device.h
 create mode 100644 lib/tst_sync_device.c
include/tst_sync_device.h new file +17 -0
new file mode 100644
index 0000000..b07c490
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+#ifndef TST_SYNC_DEVICE_H__
+#define TST_SYNC_DEVICE_H__
+
+#include <stdbool.h>
+
+void tst_sync_device_init(const char *dev);
+int tst_sync_device_write(const char *file, unsigned int size_mb);
+bool tst_sync_device_check(unsigned int size_mb);
+void tst_sync_device_cleanup(void);
+
+#endif
lib/tst_sync_device.c new file +80 -0

80 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH v3 1/7 lib: Add library functions for sync related syscalls

Hi!

Quoted 69 lines
---
 include/tst_sync_device.h | 17 ++++++++++
 lib/tst_sync_device.c     | 80 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100644 include/tst_sync_device.h
 create mode 100644 lib/tst_sync_device.c
include/tst_sync_device.h new file +17 -0
new file mode 100644
index 0000000..b07c490
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+#ifndef TST_SYNC_DEVICE_H__
+#define TST_SYNC_DEVICE_H__
+
+#include <stdbool.h>
+
+void tst_sync_device_init(const char *dev);
+int tst_sync_device_write(const char *file, unsigned int size_mb);
+bool tst_sync_device_check(unsigned int size_mb);
+void tst_sync_device_cleanup(void);
+
+#endif
lib/tst_sync_device.c new file +32 -0
new file mode 100644
index 0000000..5a0a17c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "lapi/stat.h"
+#include "tst_sync_device.h"
+
+#define SIZE_MB			(1024*1024)
+#define MODE			0644
+
+static char dev_stat_path[1024];
+static char *buffer;
+static int fd;
+static unsigned long prev_write_sec;
+
+void tst_sync_device_init(const char *dev)
+{
+	struct stat st;
+
+	snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat",
+		 strrchr(dev, '/') + 1);
+
+	if (stat(dev_stat_path, &st) != 0)
+		tst_brk(TCONF, "Test device stat file: %s not found",

lib/tst_sync_device.c line 42

Quoted 10 lines
lib/tst_sync_device.c new file +10 -0
+			dev_stat_path);
+
+	buffer = SAFE_MALLOC(SIZE_MB);
+
+	memset(buffer, 0, SIZE_MB);
+}
+
+int tst_sync_device_write(const char *file, unsigned int size_mb)
+{
+	unsigned int counter;

^
It's kind of strange to name this variable anything else but i.

lib/tst_sync_device.c line 47

Quoted 4 lines
lib/tst_sync_device.c new file +4 -0
+	SAFE_FILE_SCANF(dev_stat_path, "%*s %*s %*s %*s %*s %*s %lu",
+			&prev_write_sec);
+
+	fd =  SAFE_OPEN(file, O_RDWR|O_CREAT, MODE);
            ^
	    Extra space.

lib/tst_sync_device.c line 49

Quoted 1 line
lib/tst_sync_device.c new file +1 -0
+	/* Filling the test file */

^
Useless comment, it's pretty clear what we do here.

Quoted 12 lines
lib/tst_sync_device.c new file +12 -0
+	for (counter = 0; counter < size_mb; counter++)
+		SAFE_WRITE(1, fd, buffer, SIZE_MB);
+
+	return fd;
+}
+
+bool tst_sync_device_check(unsigned int size_mb)
+{
+	unsigned long write_sec = 0;
+	bool res = false;
+
+	SAFE_FILE_SCANF(dev_stat_path, "%*s %*s %*s %*s %*s %*s %lu",

lib/tst_sync_device.c line 71

Quoted 10 lines
lib/tst_sync_device.c new file +10 -0
+			&write_sec);
+
+	if ((write_sec - prev_write_sec) * 512 >=
+	    (size_mb * SIZE_MB))
+		res = true;
+
+	SAFE_CLOSE(fd);
+
+	return res;
+}

I do not like that this API is tailored just to this specific usecase.

I would rather see the code that writes the file separated from the code that measures the bytes written.

Maybe we just need a tst_dev_bytes_written() function that would return the bytes written since the last call of the function so that we could do:

	fd = SAFE_OPEN(...);

	tst_dev_blocks_written(tst_device.dev);

	tst_fill_fd(fd, 0, TST_MB, size_mb);

	TEST(fdsync(fd));

	if (TST_RET)
		tst_brk(TFAIL | TTERRNO, "syncfd() failed with %i", TST_RET);

	written = tst_dev_blocks_written(tst_device.dev);

	SAFE_CLOSE(fd);

	if (written >= size_mb * TST_DEV_BLOCKS_IN_MB)
		tst_res(TPASS, ...);
	else
		tst_res(TFAIL, ...);

The test a bit longer, but the library functions are more reusable, if you do 'git grep -B 1 SAFE_WRITE' you can see that the tst_fill_fd function that loops over SAFE_WRITE could be used in a few places already.

Quoted 11 lines
lib/tst_sync_device.c new file +8 -0
+void tst_sync_device_cleanup(void)
+{
+	if (buffer)
+		free(buffer);
+
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
Signature · 1 line
2.7.4
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#3 lore raw

PATCH v3 1/7 lib: Add library functions for sync related syscalls

Quoted 76 lines · Cyril Hrubis

Hi!

Quoted 74 lines
---
 include/tst_sync_device.h | 17 ++++++++++
 lib/tst_sync_device.c     | 80 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 97 insertions(+)
 create mode 100644 include/tst_sync_device.h
 create mode 100644 lib/tst_sync_device.c
include/tst_sync_device.h new file +17 -0
new file mode 100644
index 0000000..b07c490
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+#ifndef TST_SYNC_DEVICE_H__
+#define TST_SYNC_DEVICE_H__
+
+#include <stdbool.h>
+
+void tst_sync_device_init(const char *dev);
+int tst_sync_device_write(const char *file, unsigned int size_mb);
+bool tst_sync_device_check(unsigned int size_mb);
+void tst_sync_device_cleanup(void);
+
+#endif
lib/tst_sync_device.c new file +37 -0
new file mode 100644
index 0000000..5a0a17c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "lapi/stat.h"
+#include "tst_sync_device.h"
+
+#define SIZE_MB                      (1024*1024)
+#define MODE                 0644
+
+static char dev_stat_path[1024];
+static char *buffer;
+static int fd;
+static unsigned long prev_write_sec;
+
+void tst_sync_device_init(const char *dev)
+{
+     struct stat st;
+
+     snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat",
+              strrchr(dev, '/') + 1);
+
+     if (stat(dev_stat_path, &st) != 0)
+             tst_brk(TCONF, "Test device stat file: %s not found",
+                     dev_stat_path);
+
+     buffer = SAFE_MALLOC(SIZE_MB);
+
+     memset(buffer, 0, SIZE_MB);
Quoted 9 lines

lib/tst_sync_device.c line 42

Quoted 5 lines
lib/tst_sync_device.c new file +5 -0
+}
+
+int tst_sync_device_write(const char *file, unsigned int size_mb)
+{
+     unsigned int counter;

^
It's kind of strange to name this variable anything else but i.

Will use i instead.

Quoted 7 lines

lib/tst_sync_device.c line 47

Quoted 4 lines
lib/tst_sync_device.c new file +4 -0
+     SAFE_FILE_SCANF(dev_stat_path, "%*s %*s %*s %*s %*s %*s %lu",
+                     &prev_write_sec);
+
+     fd =  SAFE_OPEN(file, O_RDWR|O_CREAT, MODE);
            ^
            Extra space.

Will fix.

Quoted 4 lines

lib/tst_sync_device.c line 49

Quoted 1 line
lib/tst_sync_device.c new file +1 -0
+     /* Filling the test file */

^
Useless comment, it's pretty clear what we do here.

Will remove this comment.

Quoted 25 lines
Quoted 12 lines
lib/tst_sync_device.c new file +12 -0
+     for (counter = 0; counter < size_mb; counter++)
+             SAFE_WRITE(1, fd, buffer, SIZE_MB);
+
+     return fd;
+}
+
+bool tst_sync_device_check(unsigned int size_mb)
+{
+     unsigned long write_sec = 0;
+     bool res = false;
+
+     SAFE_FILE_SCANF(dev_stat_path, "%*s %*s %*s %*s %*s %*s %lu",

lib/tst_sync_device.c line 71

Quoted 10 lines
lib/tst_sync_device.c new file +10 -0
+                     &write_sec);
+
+     if ((write_sec - prev_write_sec) * 512 >=
+         (size_mb * SIZE_MB))
+             res = true;
+
+     SAFE_CLOSE(fd);
+
+     return res;
+}

I do not like that this API is tailored just to this specific usecase.

Quoted 3 lines

I would rather see the code that writes the file separated from the code that measures the bytes written.

Agree. Actually my initial idea was to tailor it for maximal code re-use.

Quoted 15 lines

Maybe we just need a tst_dev_bytes_written() function that would return the bytes written since the last call of the function so that we could do:

        fd = SAFE_OPEN(...);

        tst_dev_blocks_written(tst_device.dev);

        tst_fill_fd(fd, 0, TST_MB, size_mb);

        TEST(fdsync(fd));

        if (TST_RET)
                tst_brk(TFAIL | TTERRNO, "syncfd() failed with %i", TST_RET);
Quoted 9 lines
        written = tst_dev_blocks_written(tst_device.dev);

        SAFE_CLOSE(fd);

        if (written >= size_mb * TST_DEV_BLOCKS_IN_MB)
                tst_res(TPASS, ...);
        else
                tst_res(TFAIL, ...);

Seems to be nicer approach. So rather than new file should I add tst_dev_bytes_written() function in "lib/tst_device.c" file?

Quoted 6 lines

The test a bit longer, but the library functions are more reusable, if you do 'git grep -B 1 SAFE_WRITE' you can see that the tst_fill_fd function that loops over SAFE_WRITE could be used in a few places already.

I am not able to locate tst_fill_fd function. Are you referring to tst_fill_file function? If yes, then we could split that function to create tst_fill_fd function.

-Sumit

Quoted 15 lines
Quoted 11 lines
lib/tst_sync_device.c new file +8 -1
+void tst_sync_device_cleanup(void)
+{
+     if (buffer)
+             free(buffer);
+
+     if (fd > 0)
+             SAFE_CLOSE(fd);
+}
--

2.7.4

--
Cyril Hrubis
[email protected]

#4 lore raw

PATCH v3 1/7 lib: Add library functions for sync related syscalls

Hi!

Quoted 19 lines
Quoted 19 lines

Maybe we just need a tst_dev_bytes_written() function that would return the bytes written since the last call of the function so that we could do:

        fd = SAFE_OPEN(...);

        tst_dev_blocks_written(tst_device.dev);

        tst_fill_fd(fd, 0, TST_MB, size_mb);

        TEST(fdsync(fd));

        if (TST_RET)
                tst_brk(TFAIL | TTERRNO, "syncfd() failed with %i", TST_RET);

        written = tst_dev_blocks_written(tst_device.dev);

        SAFE_CLOSE(fd);
Quoted 8 lines
Quoted 5 lines
        if (written >= size_mb * TST_DEV_BLOCKS_IN_MB)
                tst_res(TPASS, ...);
        else
                tst_res(TFAIL, ...);

Seems to be nicer approach. So rather than new file should I add tst_dev_bytes_written() function in "lib/tst_device.c" file?

Sounds good to me.

Quoted 9 lines
Quoted 5 lines

The test a bit longer, but the library functions are more reusable, if you do 'git grep -B 1 SAFE_WRITE' you can see that the tst_fill_fd function that loops over SAFE_WRITE could be used in a few places already.

I am not able to locate tst_fill_fd function. Are you referring to tst_fill_file function? If yes, then we could split that function to create tst_fill_fd function.

There is none, I was trying to state that there are several places that use the same pattern and that such function would be generally useful.

And yes, buiding tst_fill_file on the top of tst_fill_fd sounds like a good approach.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#5 lore raw

PATCH v3 1/7 lib: Add library functions for sync related syscalls

Quoted 38 lines · Cyril Hrubis

Hi!

Quoted 19 lines
Quoted 19 lines

Maybe we just need a tst_dev_bytes_written() function that would return the bytes written since the last call of the function so that we could do:

        fd = SAFE_OPEN(...);

        tst_dev_blocks_written(tst_device.dev);

        tst_fill_fd(fd, 0, TST_MB, size_mb);

        TEST(fdsync(fd));

        if (TST_RET)
                tst_brk(TFAIL | TTERRNO, "syncfd() failed with %i", TST_RET);

        written = tst_dev_blocks_written(tst_device.dev);

        SAFE_CLOSE(fd);
Quoted 8 lines
Quoted 5 lines
        if (written >= size_mb * TST_DEV_BLOCKS_IN_MB)
                tst_res(TPASS, ...);
        else
                tst_res(TFAIL, ...);

Seems to be nicer approach. So rather than new file should I add tst_dev_bytes_written() function in "lib/tst_device.c" file?

Sounds good to me.

Quoted 6 lines
Quoted 5 lines

The test a bit longer, but the library functions are more reusable, if you do 'git grep -B 1 SAFE_WRITE' you can see that the tst_fill_fd function that loops over SAFE_WRITE could be used in a few places already.

Quoted 7 lines
Quoted 3 lines

I am not able to locate tst_fill_fd function. Are you referring to tst_fill_file function? If yes, then we could split that function to create tst_fill_fd function.

There is none, I was trying to state that there are several places that use the same pattern and that such function would be generally useful.

Ah, ok.

Quoted 3 lines

And yes, buiding tst_fill_file on the top of tst_fill_fd sounds like a good approach.

Will incorporate in v4.

-Sumit

Quoted 3 lines

--
Cyril Hrubis
[email protected]

author
#6 lore raw

PATCH v3 2/7 syscalls: add syncfs() sync device test-case

In reply to Sumit Garg

syncfs01 tests to sync filesystem having large dirty file pages to block device. Also, it tests all supported filesystems on a test block device.

---
 configure.ac                                    |  1 +
 include/lapi/syncfs.h                           | 21 ++++++++
 m4/ltp-syncfs.m4                                | 10 ++++
 runtest/syscalls                                |  2 +
 testcases/kernel/syscalls/syncfs/.gitignore     |  1 +
 testcases/kernel/syscalls/syncfs/Makefile       |  8 ++++
 testcases/kernel/syscalls/syncfs/check_syncfs.h | 19 ++++++++
 testcases/kernel/syscalls/syncfs/syncfs01.c     | 64 +++++++++++++++++++++++++
 8 files changed, 126 insertions(+)
 create mode 100644 include/lapi/syncfs.h
 create mode 100644 m4/ltp-syncfs.m4
 create mode 100644 testcases/kernel/syscalls/syncfs/.gitignore
 create mode 100644 testcases/kernel/syscalls/syncfs/Makefile
 create mode 100644 testcases/kernel/syscalls/syncfs/check_syncfs.h
 create mode 100644 testcases/kernel/syscalls/syncfs/syncfs01.c
configure.ac +1 -0
index caea344..9122b6d 100644
@@ -231,6 +231,7 @@ LTP_CHECK_TPACKET_V3
 LTP_CHECK_RLIMIT64
 LTP_DETECT_HOST_CPU
 LTP_CHECK_PERF_EVENT
+LTP_CHECK_SYNCFS
 
 if test "x$with_numa" = xyes; then
 	LTP_CHECK_SYSCALL_NUMA
include/lapi/syncfs.h new file +21 -0
new file mode 100644
index 0000000..1341c6b
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+#ifndef SYNCFS_H
+#define SYNCFS_H
+
+#include <sys/types.h>
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_SYNCFS)
+int syncfs(int fd)
+{
+	return tst_syscall(__NR_syncfs, fd);
+}
+#endif
+
+#endif /* SYNCFS_H */
m4/ltp-syncfs.m4 new file +10 -0
new file mode 100644
index 0000000..836a055
@@ -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_SYNCFS
+dnl ----------------------------
+dnl
+AC_DEFUN([LTP_CHECK_SYNCFS],[
+AC_CHECK_FUNCS(syncfs,,)
+])
runtest/syscalls +2 -0
index 668c87c..9442740 100644
@@ -1346,6 +1346,8 @@ symlinkat01 symlinkat01
 sync01 sync01
 sync02 sync02
 
+syncfs01 syncfs01
+
 #testcases for sync_file_range
 sync_file_range01 sync_file_range01
 
testcases/kernel/syscalls/syncfs/.gitignore new file +1 -0
new file mode 100644
index 0000000..6066295
@@ -0,0 +1 @@
+syncfs01
testcases/kernel/syscalls/syncfs/Makefile new file +8 -0
new file mode 100644
index 0000000..3e6c2f4
@@ -0,0 +1,8 @@
+# Copyright (c) 2019 - Linaro Limited. All rights reserved.
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir             ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/syncfs/check_syncfs.h new file +19 -0
new file mode 100644
index 0000000..26991d2
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+#ifndef CHECK_SYNCFS_H
+#define CHECK_SYNCFS_H
+
+void check_syncfs(void)
+{
+	int ret;
+
+	ret = syncfs(-1);
+	if (ret == -1 && errno == EINVAL)
+		tst_brk(TCONF, "syncfs() not supported");
+}
+
+#endif /* CHECK_SYNCFS_H */
testcases/kernel/syscalls/syncfs/syncfs01.c new file +64 -0

64 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#7 lore raw

PATCH v3 3/7 syscalls/sync: add sync device test-case

In reply to Sumit Garg

sync03 tests to sync file having large dirty file pages to block device. It tests all supported filesystems on a test block device.

Also define TEST_VOID macro in tst_test.h.

---
 include/tst_test.h                        |  7 ++++
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/sync/.gitignore |  1 +
 testcases/kernel/syscalls/sync/sync03.c   | 59 +++++++++++++++++++++++++++++++
 4 files changed, 68 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sync/sync03.c
include/tst_test.h +7 -0
index 12dda2e..03c88e3 100644
@@ -216,6 +216,13 @@ void tst_reinit(void);
 		TST_ERR = errno; \
 	} while (0)
 
+#define TEST_VOID(SCALL) \
+	do { \
+		errno = 0; \
+		SCALL; \
+		TST_ERR = errno; \
+	} while (0)
+
 extern long TST_RET;
 extern int TST_ERR;
 
runtest/syscalls +1 -0
index 9442740..dba0dee 100644
@@ -1345,6 +1345,7 @@ symlinkat01 symlinkat01
 
 sync01 sync01
 sync02 sync02
+sync03 sync03
 
 syncfs01 syncfs01
 
testcases/kernel/syscalls/sync/.gitignore +1 -0
index d8d304d..04f4710 100644
@@ -1,2 +1,3 @@
 /sync01
 /sync02
+/sync03
testcases/kernel/syscalls/sync/sync03.c new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw

PATCH v3 3/7 syscalls/sync: add sync device test-case

Hi!

Quoted 1 line

Also define TEST_VOID macro in tst_test.h.

This should be in a separate patch, otherwise this all looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#9 lore raw

PATCH v3 3/7 syscalls/sync: add sync device test-case

Quoted 6 lines · Cyril Hrubis

Hi!

Quoted 1 line

Also define TEST_VOID macro in tst_test.h.

This should be in a separate patch, otherwise this all looks good.

Sure, will create separate patch for this.

-Sumit

Quoted 3 lines

--
Cyril Hrubis
[email protected]

author
#10 lore raw

PATCH v3 4/7 syscalls/fsync: add sync device test-case

In reply to Sumit Garg

fsync04 tests to sync file having large dirty file pages to block device. Also, it tests all supported filesystems on a test block device.

---
 runtest/syscalls                           |  1 +
 testcases/kernel/syscalls/fsync/.gitignore |  1 +
 testcases/kernel/syscalls/fsync/fsync04.c  | 61 ++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fsync/fsync04.c
runtest/syscalls +1 -0
index dba0dee..0d09509 100644
@@ -347,6 +347,7 @@ fstatfs02_64 fstatfs02_64
 fsync01 fsync01
 fsync02 fsync02
 fsync03 fsync03
+fsync04 fsync04
 
 ftruncate01 ftruncate01
 ftruncate01_64 ftruncate01_64
testcases/kernel/syscalls/fsync/.gitignore +1 -0
index 3c694a4..4b5ea83 100644
@@ -1,3 +1,4 @@
 /fsync01
 /fsync02
 /fsync03
+/fsync04
testcases/kernel/syscalls/fsync/fsync04.c new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#11 lore raw

PATCH v3 5/7 syscalls/fdatasync: add sync device test-case

In reply to Sumit Garg

fdatasync03 tests to sync file data having large dirty file pages to block device. Also, it tests all supported filesystems on a test block device.

---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/fdatasync/.gitignore    |  1 +
 testcases/kernel/syscalls/fdatasync/fdatasync03.c | 61 +++++++++++++++++++++++
 3 files changed, 63 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fdatasync/fdatasync03.c
runtest/syscalls +1 -0
index 0d09509..aaad651 100644
@@ -291,6 +291,7 @@ fcntl36_64 fcntl36_64
 
 fdatasync01 fdatasync01
 fdatasync02 fdatasync02
+fdatasync03 fdatasync03
 
 fgetxattr01 fgetxattr01
 fgetxattr02 fgetxattr02
testcases/kernel/syscalls/fdatasync/.gitignore +1 -0
index d1d3cba..dc56ad7 100644
@@ -1,2 +1,3 @@
 /fdatasync01
 /fdatasync02
+/fdatasync03
testcases/kernel/syscalls/fdatasync/fdatasync03.c new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#12 lore raw

PATCH v3 6/7 syscalls/sync_file_range: Use C library wrapper if present

In reply to Sumit Garg

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

---
 configure.ac                                       |  1 +
 include/lapi/sync_file_range.h                     | 64 ++++++++++++++++++++++
 m4/ltp-sync_file_range.m4                          | 10 ++++
 .../sync_file_range/check_sync_file_range.h        | 23 ++++++++
 .../syscalls/sync_file_range/sync_file_range01.c   | 62 ++-------------------
 5 files changed, 103 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
configure.ac +1 -0
index 9122b6d..d15bff3 100644
@@ -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
include/lapi/sync_file_range.h new file +64 -0

64 lines not on this page · raw message

m4/ltp-sync_file_range.m4 new file +10 -0
new file mode 100644
index 0000000..b47a091
@@ -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,,)
+])
testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h new file +23 -0
new file mode 100644
index 0000000..3d932f6
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+#ifndef CHECK_SYNC_FILE_RANGE_H
+#define CHECK_SYNC_FILE_RANGE_H
+
+#include <stdbool.h>
+
+bool check_sync_file_range(void)
+{
+	int ret;
+
+	ret = sync_file_range(-1, 0, 0, 0);
+	if (ret == -1 && errno == EINVAL)
+		return false;
+
+	return true;
+}
+
+#endif /* CHECK_SYNC_FILE_RANGE_H */
testcases/kernel/syscalls/sync_file_range/sync_file_range01.c +5 -57

84 lines not on this page · raw message

Signature · 1 line
2.7.4
#13 lore raw

PATCH v3 6/7 syscalls/sync_file_range: Use C library wrapper if present

Hi!

Quoted 50 lines
configure.ac +1 -0
index 9122b6d..d15bff3 100644
@@ -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
include/lapi/sync_file_range.h new file +32 -0
new file mode 100644
index 0000000..7b0ef69
@@ -0,0 +1,64 @@
+// 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)
+{
+/* arm and powerpc */
+#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),

include/lapi/sync_file_range.h line 42

Quoted 10 lines
include/lapi/sync_file_range.h new file +10 -0
+		(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
+
+/* s390 */

Instead of comment like this the usuall way how to make this maze easier to read is to stick spaces after the hash to inner conditions, so this would become:

#if (defined(__arm__) || defined (__powerpc__) || defined(__powerpc64__))

# if (__WORDSIZE == 32)
#  if __BYTE_ORDER == __BIG_ENDIAN
	return ...;
#  elif __BYTE_ORDER == __LITTLE_ENDIAN
	return ...;
#  endif
# else
	return ...;
#endif
Quoted 57 lines
include/lapi/sync_file_range.h new file +21 -0
+#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);
+
+/* mips */
+#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
+
+/* other */
+#else
+	return TST_SYSCALL(__NR_sync_file_range, fd, offset, nbytes, flags);
+#endif
+}
+#endif
 
 
 
+#endif /* SYNC_FILE_RANGE_H */
m4/ltp-sync_file_range.m4 new file +10 -0
new file mode 100644
index 0000000..b47a091
@@ -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,,)
+])
testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h new file +11 -0
new file mode 100644
index 0000000..3d932f6
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+#ifndef CHECK_SYNC_FILE_RANGE_H
+#define CHECK_SYNC_FILE_RANGE_H
+
+#include <stdbool.h>
+

testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h line 21

Quoted 10 lines
testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h new file +10 -0
+bool check_sync_file_range(void)
+{
+	int ret;
+
+	ret = sync_file_range(-1, 0, 0, 0);
+	if (ret == -1 && errno == EINVAL)
+		return false;
+
+	return true;
+}

I would rather stick to return 0 and return 1 instead of including the stdbool, but that is very minor.

Quoted 82 lines
testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h new file +1 -0
+#endif /* CHECK_SYNC_FILE_RANGE_H */
testcases/kernel/syscalls/sync_file_range/sync_file_range01.c +3 -56
index cebb919..3a97183 100644
@@ -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())

testcases/kernel/syscalls/sync_file_range/sync_file_range01.c int main(int ac, char **av) · line 229

Quoted 10 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range01.c +2 -1
+		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,

Other than the minor things, this is great work.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#14 lore raw

PATCH v3 6/7 syscalls/sync_file_range: Use C library wrapper if present

Quoted 68 lines · Cyril Hrubis

Hi!

Quoted 50 lines
configure.ac +1 -0
index 9122b6d..d15bff3 100644
@@ -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
include/lapi/sync_file_range.h new file +32 -0
new file mode 100644
index 0000000..7b0ef69
@@ -0,0 +1,64 @@
+// 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)
+{
+/* arm and powerpc */
+#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),

include/lapi/sync_file_range.h line 42

Quoted 10 lines
include/lapi/sync_file_range.h new file +10 -0
+             (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
+
+/* s390 */

Instead of comment like this the usuall way how to make this maze easier to read is to stick spaces after the hash to inner conditions, so this would become:

#if (defined(__arm__) || defined (__powerpc__) || defined(__powerpc64__))

Quoted 10 lines
# if (__WORDSIZE == 32)
#  if __BYTE_ORDER == __BIG_ENDIAN
        return ...;
#  elif __BYTE_ORDER == __LITTLE_ENDIAN
        return ...;
#  endif
# else
        return ...;
#endif

Sure, will remove comments and insert spaces.

Quoted 63 lines
Quoted 63 lines
include/lapi/sync_file_range.h new file +21 -0
+#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);
+
+/* mips */
+#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
+
+/* other */
+#else
+     return TST_SYSCALL(__NR_sync_file_range, fd, offset, nbytes, flags);
+#endif
+}
+#endif
 
 
 
+#endif /* SYNC_FILE_RANGE_H */
m4/ltp-sync_file_range.m4 new file +10 -0
new file mode 100644
index 0000000..b47a091
@@ -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,,)
+])
testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h new file +16 -0
new file mode 100644
index 0000000..3d932f6
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+#ifndef CHECK_SYNC_FILE_RANGE_H
+#define CHECK_SYNC_FILE_RANGE_H
+
+#include <stdbool.h>
+
+bool check_sync_file_range(void)
+{
+     int ret;
+
+     ret = sync_file_range(-1, 0, 0, 0);
Quoted 9 lines

testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h line 21

Quoted 5 lines
testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h new file +5 -0
+     if (ret == -1 && errno == EINVAL)
+             return false;
+
+     return true;
+}

I would rather stick to return 0 and return 1 instead of including the stdbool, but that is very minor.

Ok will use 0 and 1 then.

Quoted 86 lines
Quoted 86 lines
testcases/kernel/syscalls/sync_file_range/check_sync_file_range.h new file +1 -0
+#endif /* CHECK_SYNC_FILE_RANGE_H */
testcases/kernel/syscalls/sync_file_range/sync_file_range01.c +4 -56
index cebb919..3a97183 100644
@@ -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();
 
Quoted 9 lines

testcases/kernel/syscalls/sync_file_range/sync_file_range01.c int main(int ac, char **av) · line 229

Quoted 6 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range01.c +1 -1
      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,

Other than the minor things, this is great work.

Thanks,
-Sumit

Quoted 3 lines

--
Cyril Hrubis
[email protected]

author
#15 lore raw

PATCH v3 7/7 syscalls/sync_file_range: add sync device test-case

In reply to Sumit Garg

sync_file_range02 tests to sync file data range having large dirty file pages to block device. Also, it tests all supported filesystems on a test block device.

---
 runtest/syscalls                                   |  1 +
 .../kernel/syscalls/sync_file_range/.gitignore     |  1 +
 .../syscalls/sync_file_range/sync_file_range02.c   | 70 ++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
runtest/syscalls +1 -0
index aaad651..70d3561 100644
@@ -1353,6 +1353,7 @@ syncfs01 syncfs01
 
 #testcases for sync_file_range
 sync_file_range01 sync_file_range01
+sync_file_range02 sync_file_range02
 
 syscall01 syscall01
 
testcases/kernel/syscalls/sync_file_range/.gitignore +1 -0
index 3f6bd75..e6485f7 100644
@@ -1 +1,2 @@
 /sync_file_range01
+/sync_file_range02
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.7.4
#16 lore raw

PATCH v3 7/7 syscalls/sync_file_range: add sync device test-case

Hi!

Quoted 84 lines

sync_file_range02 tests to sync file data range having large dirty file pages to block device. Also, it tests all supported filesystems on a test block device.

---
 runtest/syscalls                                   |  1 +
 .../kernel/syscalls/sync_file_range/.gitignore     |  1 +
 .../syscalls/sync_file_range/sync_file_range02.c   | 70 ++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
runtest/syscalls +1 -0
index aaad651..70d3561 100644
@@ -1353,6 +1353,7 @@ syncfs01 syncfs01
 
 #testcases for sync_file_range
 sync_file_range01 sync_file_range01
+sync_file_range02 sync_file_range02
 
 syscall01 syscall01
 
testcases/kernel/syscalls/sync_file_range/.gitignore +1 -0
index 3f6bd75..e6485f7 100644
@@ -1 +1,2 @@
 /sync_file_range01
+/sync_file_range02
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c new file +47 -0
new file mode 100644
index 0000000..fb7a5f7
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+/*
+ * sync_file_range02
+ *
+ * It basically tests sync_file_range() to sync test file range having large
+ * dirty file pages to block device. Also, it tests all supported filesystems
+ * on a test block device.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include "tst_sync_device.h"
+#include "tst_test.h"
+#include "lapi/sync_file_range.h"
+#include "check_sync_file_range.h"
+
+#define MNTPOINT		"mnt_point"
+#define TST_FILE		MNTPOINT"/test"
+#define TST_FILE_SIZE_MB	32
+#define SIZE_MB			(1024*1024)
+
+static void verify_sync_file_range(void)
+{
+	int fd;
+
+	fd = tst_sync_device_write(TST_FILE, TST_FILE_SIZE_MB);
+
+	TEST(sync_file_range(fd, 0, TST_FILE_SIZE_MB * SIZE_MB,
+			     SYNC_FILE_RANGE_WAIT_BEFORE |
+			     SYNC_FILE_RANGE_WRITE |
+			     SYNC_FILE_RANGE_WAIT_AFTER));
+	if (TST_RET != 0)
+		tst_brk(TFAIL | TTERRNO, "sync_file_range() failed");
+
+	if (tst_sync_device_check(TST_FILE_SIZE_MB))
+		tst_res(TPASS, "Test file range synced to device");
+	else
+		tst_res(TFAIL, "Failed to sync test file range to device");
+}

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c line 57

Quoted 10 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c new file +10 -0
+
+static void setup(void)
+{
+	tst_sync_device_init(tst_device->dev);
+}
+
+static void cleanup(void)
+{
+	if (!check_sync_file_range())
+		tst_brk(TCONF, "sync_file_range() not supported");

This check is supposed to be in the test setup, right?

Quoted 15 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c new file +12 -0
+	tst_sync_device_cleanup();
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.mntpoint = MNTPOINT,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_sync_file_range,
+};
Signature · 1 line
2.7.4
Signature · 2 lines
Cyril Hrubis
[email protected]
author
#17 lore raw

PATCH v3 7/7 syscalls/sync_file_range: add sync device test-case

Quoted 90 lines · Cyril Hrubis

Hi!

Quoted 88 lines

sync_file_range02 tests to sync file data range having large dirty file pages to block device. Also, it tests all supported filesystems on a test block device.

---
 runtest/syscalls                                   |  1 +
 .../kernel/syscalls/sync_file_range/.gitignore     |  1 +
 .../syscalls/sync_file_range/sync_file_range02.c   | 70 ++++++++++++++++++++++
 3 files changed, 72 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
runtest/syscalls +1 -0
index aaad651..70d3561 100644
@@ -1353,6 +1353,7 @@ syncfs01 syncfs01
 
 #testcases for sync_file_range
 sync_file_range01 sync_file_range01
+sync_file_range02 sync_file_range02
 
 syscall01 syscall01
 
testcases/kernel/syscalls/sync_file_range/.gitignore +1 -0
index 3f6bd75..e6485f7 100644
@@ -1 +1,2 @@
 /sync_file_range01
+/sync_file_range02
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c new file +51 -0
new file mode 100644
index 0000000..fb7a5f7
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <[email protected]>
+ */
+
+/*
+ * sync_file_range02
+ *
+ * It basically tests sync_file_range() to sync test file range having large
+ * dirty file pages to block device. Also, it tests all supported filesystems
+ * on a test block device.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include "tst_sync_device.h"
+#include "tst_test.h"
+#include "lapi/sync_file_range.h"
+#include "check_sync_file_range.h"
+
+#define MNTPOINT             "mnt_point"
+#define TST_FILE             MNTPOINT"/test"
+#define TST_FILE_SIZE_MB     32
+#define SIZE_MB                      (1024*1024)
+
+static void verify_sync_file_range(void)
+{
+     int fd;
+
+     fd = tst_sync_device_write(TST_FILE, TST_FILE_SIZE_MB);
+
+     TEST(sync_file_range(fd, 0, TST_FILE_SIZE_MB * SIZE_MB,
+                          SYNC_FILE_RANGE_WAIT_BEFORE |
+                          SYNC_FILE_RANGE_WRITE |
+                          SYNC_FILE_RANGE_WAIT_AFTER));
+     if (TST_RET != 0)
+             tst_brk(TFAIL | TTERRNO, "sync_file_range() failed");
+
+     if (tst_sync_device_check(TST_FILE_SIZE_MB))
+             tst_res(TPASS, "Test file range synced to device");
+     else
+             tst_res(TFAIL, "Failed to sync test file range to device");
+}
+
+static void setup(void)
+{
+     tst_sync_device_init(tst_device->dev);
Quoted 9 lines

testcases/kernel/syscalls/sync_file_range/sync_file_range02.c line 57

Quoted 6 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c new file +6 -0
+}
+
+static void cleanup(void)
+{
+     if (!check_sync_file_range())
+             tst_brk(TCONF, "sync_file_range() not supported");

This check is supposed to be in the test setup, right?

Ah, right. I will correct it.

-Sumit

Quoted 19 lines
Quoted 13 lines
testcases/kernel/syscalls/sync_file_range/sync_file_range02.c new file +12 -1
+     tst_sync_device_cleanup();
+}
+
+static struct tst_test test = {
+     .needs_root = 1,
+     .mount_device = 1,
+     .all_filesystems = 1,
+     .mntpoint = MNTPOINT,
+     .setup = setup,
+     .cleanup = cleanup,
+     .test_all = verify_sync_file_range,
+};
--
Quoted 2 lines

2.7.4

--
Cyril Hrubis
[email protected]