All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases
@ 2019-02-21  9:00 Sumit Garg
  2019-02-21  9:00 ` [LTP] [PATCH v4 1/9] lib/tst_device: add new api tst_dev_bytes_written() Sumit Garg
                   ` (9 more replies)
  0 siblings, 10 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-21  9:00 UTC (permalink / raw)
  To: ltp

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 v4:
1. Update common library functions from reusability perspective.
2. Create separate patch for TEST_VOID macro.
3. Add check for broken /sys/block/<device>/stat file.
4. Miscellaneous fixups.

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.

Fixes: https://github.com/linux-test-project/ltp/issues/294

Sumit Garg (9):
  lib/tst_device: add new api tst_dev_bytes_written()
  lib: split tst_fill_file() to create new tst_fill_fd()
  lib/tst_test: define TEST_VOID() macro
  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                     | 57 +++++++++++++++++
 include/lapi/syncfs.h                              | 21 +++++++
 include/tst_device.h                               |  7 +++
 include/tst_fs.h                                   |  9 +++
 include/tst_test.h                                 |  7 +++
 lib/tst_device.c                                   | 29 +++++++++
 lib/tst_fill_file.c                                | 40 +++++++-----
 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  | 60 ++++++++++++++++++
 testcases/kernel/syscalls/fsync/.gitignore         |  1 +
 testcases/kernel/syscalls/fsync/fsync04.c          | 60 ++++++++++++++++++
 testcases/kernel/syscalls/sync/.gitignore          |  1 +
 testcases/kernel/syscalls/sync/sync03.c            | 60 ++++++++++++++++++
 .../kernel/syscalls/sync_file_range/.gitignore     |  1 +
 .../sync_file_range/check_sync_file_range.h        | 21 +++++++
 .../syscalls/sync_file_range/sync_file_range01.c   | 62 ++-----------------
 .../syscalls/sync_file_range/sync_file_range02.c   | 72 ++++++++++++++++++++++
 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        | 67 ++++++++++++++++++++
 25 files changed, 558 insertions(+), 74 deletions(-)
 create mode 100644 include/lapi/sync_file_range.h
 create mode 100644 include/lapi/syncfs.h
 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

-- 
2.7.4


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 1/9] lib/tst_device: add new api tst_dev_bytes_written()
  2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
@ 2019-02-21  9:00 ` Sumit Garg
  2019-02-25 15:21   ` Cyril Hrubis
  2019-02-21  9:00 ` [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd() Sumit Garg
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 24+ messages in thread
From: Sumit Garg @ 2019-02-21  9:00 UTC (permalink / raw)
  To: ltp

This api reads test block device stat file and returns the bytes written
since the last invocation of this api.

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 include/tst_device.h |  7 +++++++
 lib/tst_device.c     | 29 +++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/include/tst_device.h b/include/tst_device.h
index 7ac2883..61902b7 100644
--- a/include/tst_device.h
+++ b/include/tst_device.h
@@ -44,4 +44,11 @@ int tst_umount(const char *path);
  */
 int tst_clear_device(const char *dev);
 
+/*
+ * Reads test block device stat file and returns the bytes written since the
+ * last call of this function.
+ * @dev: test block device
+ */
+unsigned long tst_dev_bytes_written(const char *dev);
+
 #endif	/* TST_DEVICE_H__ */
diff --git a/lib/tst_device.c b/lib/tst_device.c
index fd4e277..65fcc13 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -45,6 +45,7 @@
 
 static char dev_path[1024];
 static int device_acquired;
+static unsigned long prev_dev_sec_write;
 
 static const char *dev_variants[] = {
 	"/dev/loop%i",
@@ -364,3 +365,31 @@ int tst_umount(const char *path)
 	errno = err;
 	return -1;
 }
+
+unsigned long tst_dev_bytes_written(const char *dev)
+{
+	struct stat st;
+	unsigned long dev_sec_write = 0, dev_bytes_written, io_ticks = 0;
+	char dev_stat_path[1024];
+
+	snprintf(dev_stat_path, sizeof(dev_stat_path), "/sys/block/%s/stat",
+		 strrchr(dev, '/') + 1);
+
+	if (stat(dev_stat_path, &st) != 0)
+		tst_brkm(TCONF, NULL, "Test device stat file: %s not found",
+			 dev_stat_path);
+
+	SAFE_FILE_SCANF(NULL, dev_stat_path,
+			"%*s %*s %*s %*s %*s %*s %lu %*s %*s %lu",
+			&dev_sec_write, &io_ticks);
+
+	if (!io_ticks)
+		tst_brkm(TCONF, NULL, "Test device stat file: %s broken",
+			 dev_stat_path);
+
+	dev_bytes_written = (dev_sec_write - prev_dev_sec_write) * 512;
+
+	prev_dev_sec_write = dev_sec_write;
+
+	return dev_bytes_written;
+}
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd()
  2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
  2019-02-21  9:00 ` [LTP] [PATCH v4 1/9] lib/tst_device: add new api tst_dev_bytes_written() Sumit Garg
@ 2019-02-21  9:00 ` Sumit Garg
  2019-02-21 11:38   ` Daniel Thompson
  2019-02-25 15:22   ` Cyril Hrubis
  2019-02-21  9:00 ` [LTP] [PATCH v4 3/9] lib/tst_test: define TEST_VOID() macro Sumit Garg
                   ` (7 subsequent siblings)
  9 siblings, 2 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-21  9:00 UTC (permalink / raw)
  To: ltp

Split tst_fill_file() api to create new tst_fill_fd() api which could be
used to fill file using fd and allows syscalls tests to operate on fd.

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 include/tst_fs.h    |  9 +++++++++
 lib/tst_fill_file.c | 40 +++++++++++++++++++++++-----------------
 2 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/include/tst_fs.h b/include/tst_fs.h
index 23f139d..b2b19ad 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -139,6 +139,15 @@ int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose);
 int tst_get_path(const char *prog_name, char *buf, size_t buf_len);
 
 /*
+ * Fill a file with specified pattern
+ * @fd: file descriptor
+ * @pattern: pattern
+ * @bs: block size
+ * @bcount: blocks count
+ */
+int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount);
+
+/*
  * Creates/ovewrites a file with specified pattern
  * @path: path to file
  * @pattern: pattern
diff --git a/lib/tst_fill_file.c b/lib/tst_fill_file.c
index 7baead8..f2bc52d 100644
--- a/lib/tst_fill_file.c
+++ b/lib/tst_fill_file.c
@@ -28,40 +28,46 @@
 
 #include "test.h"
 
-int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount)
+int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount)
 {
-	int fd;
-	size_t counter;
+	size_t i;
 	char *buf;
 
-	fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
-	if (fd < 0)
-		return -1;
-
 	/* Filling a memory buffer with provided pattern */
 	buf = malloc(bs);
-	if (buf == NULL) {
-		close(fd);
-
+	if (buf == NULL)
 		return -1;
-	}
 
-	for (counter = 0; counter < bs; counter++)
-		buf[counter] = pattern;
+	for (i = 0; i < bs; i++)
+		buf[i] = pattern;
 
 	/* Filling the file */
-	for (counter = 0; counter < bcount; counter++) {
+	for (i = 0; i < bcount; i++) {
 		if (write(fd, buf, bs) != (ssize_t)bs) {
 			free(buf);
-			close(fd);
-			unlink(path);
-
 			return -1;
 		}
 	}
 
 	free(buf);
 
+	return 0;
+}
+
+int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount)
+{
+	int fd;
+
+	fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
+	if (fd < 0)
+		return -1;
+
+	if (tst_fill_fd(fd, pattern, bs, bcount)) {
+		close(fd);
+		unlink(path);
+		return -1;
+	}
+
 	if (close(fd) < 0) {
 		unlink(path);
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 3/9] lib/tst_test: define TEST_VOID() macro
  2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
  2019-02-21  9:00 ` [LTP] [PATCH v4 1/9] lib/tst_device: add new api tst_dev_bytes_written() Sumit Garg
  2019-02-21  9:00 ` [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd() Sumit Garg
@ 2019-02-21  9:00 ` Sumit Garg
  2019-02-21  9:00 ` [LTP] [PATCH v4 4/9] syscalls: add syncfs() sync device test-case Sumit Garg
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-21  9:00 UTC (permalink / raw)
  To: ltp

Define TEST_VOID() macro for syscalls whose return type is void like
sync() etc.

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 include/tst_test.h | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/include/tst_test.h b/include/tst_test.h
index 12dda2e..03c88e3 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -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;
 
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 4/9] syscalls: add syncfs() sync device test-case
  2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
                   ` (2 preceding siblings ...)
  2019-02-21  9:00 ` [LTP] [PATCH v4 3/9] lib/tst_test: define TEST_VOID() macro Sumit Garg
@ 2019-02-21  9:00 ` Sumit Garg
  2019-02-21  9:00 ` [LTP] [PATCH v4 5/9] syscalls/sync: add " Sumit Garg
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-21  9:00 UTC (permalink / raw)
  To: ltp

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

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 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     | 67 +++++++++++++++++++++++++
 8 files changed, 129 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

diff --git a/configure.ac b/configure.ac
index caea344..9122b6d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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
diff --git a/include/lapi/syncfs.h b/include/lapi/syncfs.h
new file mode 100644
index 0000000..1341c6b
--- /dev/null
+++ b/include/lapi/syncfs.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 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 */
diff --git a/m4/ltp-syncfs.m4 b/m4/ltp-syncfs.m4
new file mode 100644
index 0000000..836a055
--- /dev/null
+++ b/m4/ltp-syncfs.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_SYNCFS
+dnl ----------------------------
+dnl
+AC_DEFUN([LTP_CHECK_SYNCFS],[
+AC_CHECK_FUNCS(syncfs,,)
+])
diff --git a/runtest/syscalls b/runtest/syscalls
index 668c87c..9442740 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1346,6 +1346,8 @@ symlinkat01 symlinkat01
 sync01 sync01
 sync02 sync02
 
+syncfs01 syncfs01
+
 #testcases for sync_file_range
 sync_file_range01 sync_file_range01
 
diff --git a/testcases/kernel/syscalls/syncfs/.gitignore b/testcases/kernel/syscalls/syncfs/.gitignore
new file mode 100644
index 0000000..6066295
--- /dev/null
+++ b/testcases/kernel/syscalls/syncfs/.gitignore
@@ -0,0 +1 @@
+syncfs01
diff --git a/testcases/kernel/syscalls/syncfs/Makefile b/testcases/kernel/syscalls/syncfs/Makefile
new file mode 100644
index 0000000..3e6c2f4
--- /dev/null
+++ b/testcases/kernel/syscalls/syncfs/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/syncfs/check_syncfs.h b/testcases/kernel/syscalls/syncfs/check_syncfs.h
new file mode 100644
index 0000000..26991d2
--- /dev/null
+++ b/testcases/kernel/syscalls/syncfs/check_syncfs.h
@@ -0,0 +1,19 @@
+// 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_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 */
diff --git a/testcases/kernel/syscalls/syncfs/syncfs01.c b/testcases/kernel/syscalls/syncfs/syncfs01.c
new file mode 100644
index 0000000..4382a34
--- /dev/null
+++ b/testcases/kernel/syscalls/syncfs/syncfs01.c
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <sumit.garg@linaro.org>
+ */
+
+/*
+ * Test syncfs
+ *
+ * It basically tests syncfs() to sync filesystem having large dirty file
+ * pages to block device. Also, it tests all supported filesystems on a test
+ * block device.
+ */
+
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include "lapi/syncfs.h"
+#include "tst_test.h"
+#include "check_syncfs.h"
+
+#define MNTPOINT		"mnt_point"
+#define TST_FILE		MNTPOINT"/test"
+#define TST_FILE_SIZE_MB	32
+#define SIZE_MB			(1024*1024)
+#define MODE			0644
+
+static void verify_syncfs(void)
+{
+	int fd;
+	unsigned long written;
+
+	fd = SAFE_OPEN(TST_FILE, O_RDWR|O_CREAT, MODE);
+
+	tst_dev_bytes_written(tst_device->dev);
+
+	tst_fill_fd(fd, 0, SIZE_MB, TST_FILE_SIZE_MB);
+
+	TEST(syncfs(fd));
+
+	if (TST_RET)
+		tst_brk(TFAIL | TTERRNO, "syncfs(fd) failed");
+
+	written = tst_dev_bytes_written(tst_device->dev);
+
+	SAFE_CLOSE(fd);
+
+	if (written >= SIZE_MB * TST_FILE_SIZE_MB)
+		tst_res(TPASS, "Test filesystem synced to device");
+	else
+		tst_res(TFAIL, "Failed to sync test filesystem to device");
+}
+
+static void setup(void)
+{
+	check_syncfs();
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.mntpoint = MNTPOINT,
+	.setup = setup,
+	.test_all = verify_syncfs,
+};
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 5/9] syscalls/sync: add sync device test-case
  2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
                   ` (3 preceding siblings ...)
  2019-02-21  9:00 ` [LTP] [PATCH v4 4/9] syscalls: add syncfs() sync device test-case Sumit Garg
@ 2019-02-21  9:00 ` Sumit Garg
  2019-02-21  9:00 ` [LTP] [PATCH v4 6/9] syscalls/fsync: " Sumit Garg
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-21  9:00 UTC (permalink / raw)
  To: ltp

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

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 runtest/syscalls                          |  1 +
 testcases/kernel/syscalls/sync/.gitignore |  1 +
 testcases/kernel/syscalls/sync/sync03.c   | 60 +++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sync/sync03.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 9442740..dba0dee 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -1345,6 +1345,7 @@ symlinkat01 symlinkat01
 
 sync01 sync01
 sync02 sync02
+sync03 sync03
 
 syncfs01 syncfs01
 
diff --git a/testcases/kernel/syscalls/sync/.gitignore b/testcases/kernel/syscalls/sync/.gitignore
index d8d304d..04f4710 100644
--- a/testcases/kernel/syscalls/sync/.gitignore
+++ b/testcases/kernel/syscalls/sync/.gitignore
@@ -1,2 +1,3 @@
 /sync01
 /sync02
+/sync03
diff --git a/testcases/kernel/syscalls/sync/sync03.c b/testcases/kernel/syscalls/sync/sync03.c
new file mode 100644
index 0000000..4dc2ff6
--- /dev/null
+++ b/testcases/kernel/syscalls/sync/sync03.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <sumit.garg@linaro.org>
+ */
+
+/*
+ * sync03
+ *
+ * It basically tests sync() to sync test file 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_test.h"
+
+#define MNTPOINT		"mnt_point"
+#define TST_FILE		MNTPOINT"/test"
+#define TST_FILE_SIZE_MB	32
+#define SIZE_MB			(1024*1024)
+#define MODE			0644
+
+static void verify_sync(void)
+{
+	int fd;
+	unsigned long written;
+
+	fd = SAFE_OPEN(TST_FILE, O_RDWR|O_CREAT, MODE);
+
+	tst_dev_bytes_written(tst_device->dev);
+
+	tst_fill_fd(fd, 0, SIZE_MB, TST_FILE_SIZE_MB);
+
+	TEST_VOID(sync());
+
+	if (TST_RET)
+		tst_brk(TFAIL | TTERRNO, "sync() failed");
+
+	written = tst_dev_bytes_written(tst_device->dev);
+
+	SAFE_CLOSE(fd);
+
+	if (written >= SIZE_MB * TST_FILE_SIZE_MB)
+		tst_res(TPASS, "Test file synced to device");
+	else
+		tst_res(TFAIL, "Failed to sync test file to device");
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.mntpoint = MNTPOINT,
+	.test_all = verify_sync,
+};
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 6/9] syscalls/fsync: add sync device test-case
  2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
                   ` (4 preceding siblings ...)
  2019-02-21  9:00 ` [LTP] [PATCH v4 5/9] syscalls/sync: add " Sumit Garg
@ 2019-02-21  9:00 ` Sumit Garg
  2019-02-21  9:00 ` [LTP] [PATCH v4 7/9] syscalls/fdatasync: " Sumit Garg
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-21  9:00 UTC (permalink / raw)
  To: ltp

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

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 runtest/syscalls                           |  1 +
 testcases/kernel/syscalls/fsync/.gitignore |  1 +
 testcases/kernel/syscalls/fsync/fsync04.c  | 60 ++++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fsync/fsync04.c

diff --git a/runtest/syscalls b/runtest/syscalls
index dba0dee..0d09509 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -347,6 +347,7 @@ fstatfs02_64 fstatfs02_64
 fsync01 fsync01
 fsync02 fsync02
 fsync03 fsync03
+fsync04 fsync04
 
 ftruncate01 ftruncate01
 ftruncate01_64 ftruncate01_64
diff --git a/testcases/kernel/syscalls/fsync/.gitignore b/testcases/kernel/syscalls/fsync/.gitignore
index 3c694a4..4b5ea83 100644
--- a/testcases/kernel/syscalls/fsync/.gitignore
+++ b/testcases/kernel/syscalls/fsync/.gitignore
@@ -1,3 +1,4 @@
 /fsync01
 /fsync02
 /fsync03
+/fsync04
diff --git a/testcases/kernel/syscalls/fsync/fsync04.c b/testcases/kernel/syscalls/fsync/fsync04.c
new file mode 100644
index 0000000..4b5b586
--- /dev/null
+++ b/testcases/kernel/syscalls/fsync/fsync04.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <sumit.garg@linaro.org>
+ */
+
+/*
+ * fsync04
+ *
+ * It basically tests fsync() to sync test file 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_test.h"
+
+#define MNTPOINT		"mnt_point"
+#define TST_FILE		MNTPOINT"/test"
+#define TST_FILE_SIZE_MB	32
+#define SIZE_MB			(1024*1024)
+#define MODE			0644
+
+static void verify_fsync(void)
+{
+	int fd;
+	unsigned long written;
+
+	fd = SAFE_OPEN(TST_FILE, O_RDWR|O_CREAT, MODE);
+
+	tst_dev_bytes_written(tst_device->dev);
+
+	tst_fill_fd(fd, 0, SIZE_MB, TST_FILE_SIZE_MB);
+
+	TEST(fsync(fd));
+
+	if (TST_RET)
+		tst_brk(TFAIL | TTERRNO, "fsync(fd) failed");
+
+	written = tst_dev_bytes_written(tst_device->dev);
+
+	SAFE_CLOSE(fd);
+
+	if (written >= SIZE_MB * TST_FILE_SIZE_MB)
+		tst_res(TPASS, "Test file synced to device");
+	else
+		tst_res(TFAIL, "Failed to sync test file to device");
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.mntpoint = MNTPOINT,
+	.test_all = verify_fsync,
+};
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 7/9] syscalls/fdatasync: add sync device test-case
  2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
                   ` (5 preceding siblings ...)
  2019-02-21  9:00 ` [LTP] [PATCH v4 6/9] syscalls/fsync: " Sumit Garg
@ 2019-02-21  9:00 ` Sumit Garg
  2019-02-21  9:00 ` [LTP] [PATCH v4 8/9] syscalls/sync_file_range: Use C library wrapper if present Sumit Garg
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-21  9:00 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 runtest/syscalls                                  |  1 +
 testcases/kernel/syscalls/fdatasync/.gitignore    |  1 +
 testcases/kernel/syscalls/fdatasync/fdatasync03.c | 60 +++++++++++++++++++++++
 3 files changed, 62 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fdatasync/fdatasync03.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 0d09509..aaad651 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -291,6 +291,7 @@ fcntl36_64 fcntl36_64
 
 fdatasync01 fdatasync01
 fdatasync02 fdatasync02
+fdatasync03 fdatasync03
 
 fgetxattr01 fgetxattr01
 fgetxattr02 fgetxattr02
diff --git a/testcases/kernel/syscalls/fdatasync/.gitignore b/testcases/kernel/syscalls/fdatasync/.gitignore
index d1d3cba..dc56ad7 100644
--- a/testcases/kernel/syscalls/fdatasync/.gitignore
+++ b/testcases/kernel/syscalls/fdatasync/.gitignore
@@ -1,2 +1,3 @@
 /fdatasync01
 /fdatasync02
+/fdatasync03
diff --git a/testcases/kernel/syscalls/fdatasync/fdatasync03.c b/testcases/kernel/syscalls/fdatasync/fdatasync03.c
new file mode 100644
index 0000000..d5c8ea9
--- /dev/null
+++ b/testcases/kernel/syscalls/fdatasync/fdatasync03.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <sumit.garg@linaro.org>
+ */
+
+/*
+ * fdatasync03
+ *
+ * It basically tests fdatasync() to sync test file data 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_test.h"
+
+#define MNTPOINT		"mnt_point"
+#define TST_FILE		MNTPOINT"/test"
+#define TST_FILE_SIZE_MB	32
+#define SIZE_MB			(1024*1024)
+#define MODE			0644
+
+static void verify_fdatasync(void)
+{
+	int fd;
+	unsigned long written;
+
+	fd = SAFE_OPEN(TST_FILE, O_RDWR|O_CREAT, MODE);
+
+	tst_dev_bytes_written(tst_device->dev);
+
+	tst_fill_fd(fd, 0, SIZE_MB, TST_FILE_SIZE_MB);
+
+	TEST(fdatasync(fd));
+
+	if (TST_RET)
+		tst_brk(TFAIL | TTERRNO, "fdatasync(fd) failed");
+
+	written = tst_dev_bytes_written(tst_device->dev);
+
+	SAFE_CLOSE(fd);
+
+	if (written >= SIZE_MB * TST_FILE_SIZE_MB)
+		tst_res(TPASS, "Test file data synced to device");
+	else
+		tst_res(TFAIL, "Failed to sync test file data to device");
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.mntpoint = MNTPOINT,
+	.test_all = verify_fdatasync,
+};
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 8/9] syscalls/sync_file_range: Use C library wrapper if present
  2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
                   ` (6 preceding siblings ...)
  2019-02-21  9:00 ` [LTP] [PATCH v4 7/9] syscalls/fdatasync: " Sumit Garg
@ 2019-02-21  9:00 ` Sumit Garg
  2019-02-21  9:00 ` [LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case Sumit Garg
  2019-02-25 15:19 ` [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Cyril Hrubis
  9 siblings, 0 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-21  9:00 UTC (permalink / raw)
  To: ltp

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 --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,
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case
  2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
                   ` (7 preceding siblings ...)
  2019-02-21  9:00 ` [LTP] [PATCH v4 8/9] syscalls/sync_file_range: Use C library wrapper if present Sumit Garg
@ 2019-02-21  9:00 ` Sumit Garg
  2019-02-25 15:26   ` Cyril Hrubis
  2019-02-25 15:19 ` [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Cyril Hrubis
  9 siblings, 1 reply; 24+ messages in thread
From: Sumit Garg @ 2019-02-21  9:00 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
---
 runtest/syscalls                                   |  1 +
 .../kernel/syscalls/sync_file_range/.gitignore     |  1 +
 .../syscalls/sync_file_range/sync_file_range02.c   | 72 ++++++++++++++++++++++
 3 files changed, 74 insertions(+)
 create mode 100644 testcases/kernel/syscalls/sync_file_range/sync_file_range02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index aaad651..70d3561 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -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
 
diff --git a/testcases/kernel/syscalls/sync_file_range/.gitignore b/testcases/kernel/syscalls/sync_file_range/.gitignore
index 3f6bd75..e6485f7 100644
--- a/testcases/kernel/syscalls/sync_file_range/.gitignore
+++ b/testcases/kernel/syscalls/sync_file_range/.gitignore
@@ -1 +1,2 @@
 /sync_file_range01
+/sync_file_range02
diff --git a/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
new file mode 100644
index 0000000..37ea68a
--- /dev/null
+++ b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 Linaro Limited. All rights reserved.
+ * Author: Sumit Garg <sumit.garg@linaro.org>
+ */
+
+/*
+ * 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_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)
+#define MODE			0644
+
+static void verify_sync_file_range(void)
+{
+	int fd;
+	unsigned long written;
+
+	fd = SAFE_OPEN(TST_FILE, O_RDWR|O_CREAT, MODE);
+
+	tst_dev_bytes_written(tst_device->dev);
+
+	tst_fill_fd(fd, 0, SIZE_MB, 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)
+		tst_brk(TFAIL | TTERRNO, "sync_file_range() failed");
+
+	written = tst_dev_bytes_written(tst_device->dev);
+
+	SAFE_CLOSE(fd);
+
+	if (written >= SIZE_MB * 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)
+{
+	if (!check_sync_file_range())
+		tst_brk(TCONF, "sync_file_range() not supported");
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.mntpoint = MNTPOINT,
+	.setup = setup,
+	.test_all = verify_sync_file_range,
+};
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd()
  2019-02-21  9:00 ` [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd() Sumit Garg
@ 2019-02-21 11:38   ` Daniel Thompson
  2019-02-21 12:04     ` Cyril Hrubis
  2019-02-25 15:22   ` Cyril Hrubis
  1 sibling, 1 reply; 24+ messages in thread
From: Daniel Thompson @ 2019-02-21 11:38 UTC (permalink / raw)
  To: ltp

On Thu, Feb 21, 2019 at 02:30:09PM +0530, Sumit Garg wrote:
> Split tst_fill_file() api to create new tst_fill_fd() api which could be
> used to fill file using fd and allows syscalls tests to operate on fd.
> 
> Signed-off-by: Sumit Garg <sumit.garg@linaro.org>
> ---
>  include/tst_fs.h    |  9 +++++++++
>  lib/tst_fill_file.c | 40 +++++++++++++++++++++++-----------------
>  2 files changed, 32 insertions(+), 17 deletions(-)
> 
> diff --git a/include/tst_fs.h b/include/tst_fs.h
> index 23f139d..b2b19ad 100644
> --- a/include/tst_fs.h
> +++ b/include/tst_fs.h
> @@ -139,6 +139,15 @@ int tst_dir_is_empty_(void (*cleanup)(void), const char *name, int verbose);
>  int tst_get_path(const char *prog_name, char *buf, size_t buf_len);
>  
>  /*
> + * Fill a file with specified pattern
> + * @fd: file descriptor
> + * @pattern: pattern
> + * @bs: block size
> + * @bcount: blocks count
> + */
> +int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount);
> +
> +/*
>   * Creates/ovewrites a file with specified pattern
>   * @path: path to file
>   * @pattern: pattern
> diff --git a/lib/tst_fill_file.c b/lib/tst_fill_file.c
> index 7baead8..f2bc52d 100644
> --- a/lib/tst_fill_file.c
> +++ b/lib/tst_fill_file.c
> @@ -28,40 +28,46 @@
>  
>  #include "test.h"
>  
> -int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount)
> +int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount)
>  {
> -	int fd;
> -	size_t counter;
> +	size_t i;

Nitpicking perhaps but gratuitous variable renames don't make patches
containing other changes easier to read. Nor, to be honest, does 
"counter" seem any more descriptive then i (since i is more idiomatic
and therefore quicker to read).


Daniel.



>  	char *buf;
>  
> -	fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
> -	if (fd < 0)
> -		return -1;
> -
>  	/* Filling a memory buffer with provided pattern */
>  	buf = malloc(bs);
> -	if (buf == NULL) {
> -		close(fd);
> -
> +	if (buf == NULL)
>  		return -1;
> -	}
>  
> -	for (counter = 0; counter < bs; counter++)
> -		buf[counter] = pattern;
> +	for (i = 0; i < bs; i++)
> +		buf[i] = pattern;
>  
>  	/* Filling the file */
> -	for (counter = 0; counter < bcount; counter++) {
> +	for (i = 0; i < bcount; i++) {
>  		if (write(fd, buf, bs) != (ssize_t)bs) {
>  			free(buf);
> -			close(fd);
> -			unlink(path);
> -
>  			return -1;
>  		}
>  	}
>  
>  	free(buf);
>  
> +	return 0;
> +}
> +
> +int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount)
> +{
> +	int fd;
> +
> +	fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, S_IRUSR|S_IWUSR);
> +	if (fd < 0)
> +		return -1;
> +
> +	if (tst_fill_fd(fd, pattern, bs, bcount)) {
> +		close(fd);
> +		unlink(path);
> +		return -1;
> +	}
> +
>  	if (close(fd) < 0) {
>  		unlink(path);
>  
> -- 
> 2.7.4
> 

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd()
  2019-02-21 11:38   ` Daniel Thompson
@ 2019-02-21 12:04     ` Cyril Hrubis
  2019-02-21 13:36       ` Daniel Thompson
  0 siblings, 1 reply; 24+ messages in thread
From: Cyril Hrubis @ 2019-02-21 12:04 UTC (permalink / raw)
  To: ltp

Hi!
> > -int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount)
> > +int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount)
> >  {
> > -	int fd;
> > -	size_t counter;
> > +	size_t i;
> 
> Nitpicking perhaps but gratuitous variable renames don't make patches
> containing other changes easier to read. Nor, to be honest, does 
> "counter" seem any more descriptive then i (since i is more idiomatic
> and therefore quicker to read).

It seems you misread the patch as we are replacing the counter with i
here and I asked for that since i is the idiomatic way of naming loop
variables, so all the blame for this change goes to me :-).

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd()
  2019-02-21 12:04     ` Cyril Hrubis
@ 2019-02-21 13:36       ` Daniel Thompson
  0 siblings, 0 replies; 24+ messages in thread
From: Daniel Thompson @ 2019-02-21 13:36 UTC (permalink / raw)
  To: ltp

On Thu, Feb 21, 2019 at 01:04:42PM +0100, Cyril Hrubis wrote:
> Hi!
> > > -int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount)
> > > +int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount)
> > >  {
> > > -	int fd;
> > > -	size_t counter;
> > > +	size_t i;
> > 
> > Nitpicking perhaps but gratuitous variable renames don't make patches
> > containing other changes easier to read. Nor, to be honest, does 
> > "counter" seem any more descriptive then i (since i is more idiomatic
> > and therefore quicker to read).
> 
> It seems you misread the patch as we are replacing the counter with i
> here and I asked for that since i is the idiomatic way of naming loop
> variables, so all the blame for this change goes to me :-).

Quite right. I misread it. Sorry for the noise.


Daniel.

> 
> -- 
> Cyril Hrubis
> chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases
  2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
                   ` (8 preceding siblings ...)
  2019-02-21  9:00 ` [LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case Sumit Garg
@ 2019-02-25 15:19 ` Cyril Hrubis
  2019-02-26  5:59   ` Sumit Garg
  9 siblings, 1 reply; 24+ messages in thread
From: Cyril Hrubis @ 2019-02-25 15:19 UTC (permalink / raw)
  To: ltp

Hi!
> 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.

Pushed with minor changes, good work, thanks.

I've changed the tests to print how much data was synced in a case of a
failure and also removed the TST_ prefix from the macros defined in the
tests as the TST_ prefix is reserved for the test library.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 1/9] lib/tst_device: add new api tst_dev_bytes_written()
  2019-02-21  9:00 ` [LTP] [PATCH v4 1/9] lib/tst_device: add new api tst_dev_bytes_written() Sumit Garg
@ 2019-02-25 15:21   ` Cyril Hrubis
  2019-02-26  6:01     ` Sumit Garg
  0 siblings, 1 reply; 24+ messages in thread
From: Cyril Hrubis @ 2019-02-25 15:21 UTC (permalink / raw)
  To: ltp

Hi!
This should get documented in the doc/test-writing-guidelines.txt
probably under the 2.2.14 paragraph.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd()
  2019-02-21  9:00 ` [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd() Sumit Garg
  2019-02-21 11:38   ` Daniel Thompson
@ 2019-02-25 15:22   ` Cyril Hrubis
  2019-02-26  6:04     ` Sumit Garg
  1 sibling, 1 reply; 24+ messages in thread
From: Cyril Hrubis @ 2019-02-25 15:22 UTC (permalink / raw)
  To: ltp

Hi!
Ideally these two functions should be noted in the
test-writing-guidelines.txt as well.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case
  2019-02-21  9:00 ` [LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case Sumit Garg
@ 2019-02-25 15:26   ` Cyril Hrubis
  2019-02-26  9:02     ` Sumit Garg
  0 siblings, 1 reply; 24+ messages in thread
From: Cyril Hrubis @ 2019-02-25 15:26 UTC (permalink / raw)
  To: ltp

Hi!
This tests fails for me for fuse based filesystems, the call returns 0
but does not write anything, the questions is if this is desired
behavior or not.

Also we should as well add a second test here that sync only a middle of
a written region of a file and expects that the data written are
somewhere between a few percents of the synced size.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases
  2019-02-25 15:19 ` [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Cyril Hrubis
@ 2019-02-26  5:59   ` Sumit Garg
  0 siblings, 0 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-26  5:59 UTC (permalink / raw)
  To: ltp

On Mon, 25 Feb 2019 at 20:49, Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> > 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.
>
> Pushed with minor changes, good work, thanks.
>
> I've changed the tests to print how much data was synced in a case of a
> failure and also removed the TST_ prefix from the macros defined in the
> tests as the TST_ prefix is reserved for the test library.
>

Thanks for these changes and merging this patch-set.

-Sumit

> --
> Cyril Hrubis
> chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 1/9] lib/tst_device: add new api tst_dev_bytes_written()
  2019-02-25 15:21   ` Cyril Hrubis
@ 2019-02-26  6:01     ` Sumit Garg
  0 siblings, 0 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-26  6:01 UTC (permalink / raw)
  To: ltp

On Mon, 25 Feb 2019 at 20:52, Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> This should get documented in the doc/test-writing-guidelines.txt
> probably under the 2.2.14 paragraph.
>

Sure, will document it.

-Sumit

> --
> Cyril Hrubis
> chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd()
  2019-02-25 15:22   ` Cyril Hrubis
@ 2019-02-26  6:04     ` Sumit Garg
  0 siblings, 0 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-26  6:04 UTC (permalink / raw)
  To: ltp

On Mon, 25 Feb 2019 at 20:53, Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> Ideally these two functions should be noted in the
> test-writing-guidelines.txt as well.
>

Agree, will document them.

-Sumit

> --
> Cyril Hrubis
> chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case
  2019-02-25 15:26   ` Cyril Hrubis
@ 2019-02-26  9:02     ` Sumit Garg
  2019-02-26 10:57       ` Cyril Hrubis
  0 siblings, 1 reply; 24+ messages in thread
From: Sumit Garg @ 2019-02-26  9:02 UTC (permalink / raw)
  To: ltp

On Mon, 25 Feb 2019 at 20:57, Cyril Hrubis <chrubis@suse.cz> wrote:
>
> Hi!
> This tests fails for me for fuse based filesystems, the call returns 0
> but does not write anything, the questions is if this is desired
> behavior or not.
>

Interesting case. Do you see similar behaviour with other sync related syscalls?

AFAIK, fuse file-system operations are implemented in user-space
daemons exported to kernel as callbacks via libfuse. Maybe we need to
check fsync() callback operation [1] implementation?

[1] https://libfuse.github.io/doxygen/structfuse__operations.html

> Also we should as well add a second test here that sync only a middle of
> a written region of a file and expects that the data written are
> somewhere between a few percents of the synced size.
>

Sure, will add a test for this.

-Sumit

> --
> Cyril Hrubis
> chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case
  2019-02-26  9:02     ` Sumit Garg
@ 2019-02-26 10:57       ` Cyril Hrubis
  2019-02-26 11:48         ` Daniel Thompson
  0 siblings, 1 reply; 24+ messages in thread
From: Cyril Hrubis @ 2019-02-26 10:57 UTC (permalink / raw)
  To: ltp

Hi!
> > This tests fails for me for fuse based filesystems, the call returns 0
> > but does not write anything, the questions is if this is desired
> > behavior or not.
> >
> 
> Interesting case. Do you see similar behaviour with other sync related syscalls?

Just this one, I would have expected that the new syscall is not wired
into fuse yet hence it does nothing silently instead of returning
EOPNOTSUPP which could break applications...

> AFAIK, fuse file-system operations are implemented in user-space
> daemons exported to kernel as callbacks via libfuse. Maybe we need to
> check fsync() callback operation [1] implementation?
> 
> [1] https://libfuse.github.io/doxygen/structfuse__operations.html
> 
> > Also we should as well add a second test here that sync only a middle of
> > a written region of a file and expects that the data written are
> > somewhere between a few percents of the synced size.
> >
> 
> Sure, will add a test for this.

Ideally this should be put into the existing test in order to spare time
needed to format the devices etc.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case
  2019-02-26 10:57       ` Cyril Hrubis
@ 2019-02-26 11:48         ` Daniel Thompson
  2019-02-26 13:34           ` Sumit Garg
  0 siblings, 1 reply; 24+ messages in thread
From: Daniel Thompson @ 2019-02-26 11:48 UTC (permalink / raw)
  To: ltp

On Tue, Feb 26, 2019 at 11:57:11AM +0100, Cyril Hrubis wrote:
> Hi!
> > > This tests fails for me for fuse based filesystems, the call returns 0
> > > but does not write anything, the questions is if this is desired
> > > behavior or not.
> > >
> > 
> > Interesting case. Do you see similar behaviour with other sync related syscalls?
> 
> Just this one, I would have expected that the new syscall is not wired
> into fuse yet hence it does nothing silently instead of returning
> EOPNOTSUPP which could break applications...
> 
> > AFAIK, fuse file-system operations are implemented in user-space
> > daemons exported to kernel as callbacks via libfuse. Maybe we need to
> > check fsync() callback operation [1] implementation?
> > 
> > [1] https://libfuse.github.io/doxygen/structfuse__operations.html

For file syncs I think (admitedly without having much VFS experience)
that the writeback will end up being requested via the writepages VFS op;
since we are writing back data from a single fd then the kernel doesn't
need much help from the filesystem to find out which pages are
affected so the "big" sync API in fuse is probably not needed here.


Daniel.


> > 
> > > Also we should as well add a second test here that sync only a middle of
> > > a written region of a file and expects that the data written are
> > > somewhere between a few percents of the synced size.
> > >
> > 
> > Sure, will add a test for this.
> 
> Ideally this should be put into the existing test in order to spare time
> needed to format the devices etc.
> 
> -- 
> Cyril Hrubis
> chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case
  2019-02-26 11:48         ` Daniel Thompson
@ 2019-02-26 13:34           ` Sumit Garg
  0 siblings, 0 replies; 24+ messages in thread
From: Sumit Garg @ 2019-02-26 13:34 UTC (permalink / raw)
  To: ltp

On Tue, 26 Feb 2019 at 17:18, Daniel Thompson
<daniel.thompson@linaro.org> wrote:
>
> On Tue, Feb 26, 2019 at 11:57:11AM +0100, Cyril Hrubis wrote:
> > Hi!
> > > > This tests fails for me for fuse based filesystems, the call returns 0
> > > > but does not write anything, the questions is if this is desired
> > > > behavior or not.
> > > >
> > >
> > > Interesting case. Do you see similar behaviour with other sync related syscalls?
> >
> > Just this one, I would have expected that the new syscall is not wired
> > into fuse yet hence it does nothing silently instead of returning
> > EOPNOTSUPP which could break applications...
> >
> > > AFAIK, fuse file-system operations are implemented in user-space
> > > daemons exported to kernel as callbacks via libfuse. Maybe we need to
> > > check fsync() callback operation [1] implementation?
> > >
> > > [1] https://libfuse.github.io/doxygen/structfuse__operations.html
>
> For file syncs I think (admitedly without having much VFS experience)
> that the writeback will end up being requested via the writepages VFS op;
> since we are writing back data from a single fd then the kernel doesn't
> need much help from the filesystem to find out which pages are
> affected so the "big" sync API in fuse is probably not needed here.
>

Hmm, I see in case of sync_file_range(), its handled via writepages
VFS op. And fuse fsync() callback is used for fsync() and fdatasync()
syscalls.

>
> Daniel.
>
>
> > >
> > > > Also we should as well add a second test here that sync only a middle of
> > > > a written region of a file and expects that the data written are
> > > > somewhere between a few percents of the synced size.
> > > >
> > >
> > > Sure, will add a test for this.
> >
> > Ideally this should be put into the existing test in order to spare time
> > needed to format the devices etc.
> >

Agree.


-Sumit

> > --
> > Cyril Hrubis
> > chrubis@suse.cz

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2019-02-26 13:34 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-21  9:00 [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Sumit Garg
2019-02-21  9:00 ` [LTP] [PATCH v4 1/9] lib/tst_device: add new api tst_dev_bytes_written() Sumit Garg
2019-02-25 15:21   ` Cyril Hrubis
2019-02-26  6:01     ` Sumit Garg
2019-02-21  9:00 ` [LTP] [PATCH v4 2/9] lib: split tst_fill_file() to create new tst_fill_fd() Sumit Garg
2019-02-21 11:38   ` Daniel Thompson
2019-02-21 12:04     ` Cyril Hrubis
2019-02-21 13:36       ` Daniel Thompson
2019-02-25 15:22   ` Cyril Hrubis
2019-02-26  6:04     ` Sumit Garg
2019-02-21  9:00 ` [LTP] [PATCH v4 3/9] lib/tst_test: define TEST_VOID() macro Sumit Garg
2019-02-21  9:00 ` [LTP] [PATCH v4 4/9] syscalls: add syncfs() sync device test-case Sumit Garg
2019-02-21  9:00 ` [LTP] [PATCH v4 5/9] syscalls/sync: add " Sumit Garg
2019-02-21  9:00 ` [LTP] [PATCH v4 6/9] syscalls/fsync: " Sumit Garg
2019-02-21  9:00 ` [LTP] [PATCH v4 7/9] syscalls/fdatasync: " Sumit Garg
2019-02-21  9:00 ` [LTP] [PATCH v4 8/9] syscalls/sync_file_range: Use C library wrapper if present Sumit Garg
2019-02-21  9:00 ` [LTP] [PATCH v4 9/9] syscalls/sync_file_range: add sync device test-case Sumit Garg
2019-02-25 15:26   ` Cyril Hrubis
2019-02-26  9:02     ` Sumit Garg
2019-02-26 10:57       ` Cyril Hrubis
2019-02-26 11:48         ` Daniel Thompson
2019-02-26 13:34           ` Sumit Garg
2019-02-25 15:19 ` [LTP] [PATCH v4 0/9] syscalls: add sync device test-cases Cyril Hrubis
2019-02-26  5:59   ` Sumit Garg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.