@@ -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
new file mode 100644
@@ -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 */
new file mode 100644
@@ -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,,)
+])
@@ -1346,6 +1346,8 @@ symlinkat01 symlinkat01
sync01 sync01
sync02 sync02
+syncfs01 syncfs01
+
#testcases for sync_file_range
sync_file_range01 sync_file_range01
new file mode 100644
@@ -0,0 +1 @@
+syncfs01
new file mode 100644
@@ -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
new file mode 100644
@@ -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 */
new file mode 100644
@@ -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,
+};
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