Skip to contentSkip to conversation

syscalls/newmount: new test case for new mount API

PATCH Superseded Zorro Lang 2 participants 3 messages Dec 8, 2019 – Dec 9, 2019 VFS

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zorro Lang

author
#0 lore raw

PATCH v2 1/1 syscalls/newmount: new test case for new mount API

Linux supports new mount syscalls from 5.2, so add new test cases to cover these new API. This newmount01 case make sure new API - fsopen(), fsconfig(), fsmount() and move_mount() can mount a filesystem, then can be unmounted.

---

Hi,

V2 test passed on ext2/3/4 and xfs[1], on upstream mainline kernel. Thanks all your review points:)
But I have a question, how to test other filesystems, likes nfs, cifs?

Thanks,
Zorro

[1]

# ./newmount01 -i3
tst_device.c:87: INFO: Found free device 0 '/dev/loop0'
tst_supported_fs_types.c:60: INFO: Kernel supports ext2
tst_supported_fs_types.c:44: INFO: mkfs.ext2 does exist
tst_supported_fs_types.c:60: INFO: Kernel supports ext3
tst_supported_fs_types.c:44: INFO: mkfs.ext3 does exist
tst_supported_fs_types.c:60: INFO: Kernel supports ext4
tst_supported_fs_types.c:44: INFO: mkfs.ext4 does exist
tst_supported_fs_types.c:60: INFO: Kernel supports xfs
tst_supported_fs_types.c:44: INFO: mkfs.xfs does exist
tst_supported_fs_types.c:83: INFO: Filesystem btrfs is not supported
tst_supported_fs_types.c:60: INFO: Kernel supports vfat
tst_supported_fs_types.c:40: INFO: mkfs.vfat does not exist
tst_supported_fs_types.c:83: INFO: Filesystem exfat is not supported
tst_supported_fs_types.c:83: INFO: Filesystem ntfs is not supported
tst_test.c:1278: INFO: Testing on ext2
tst_mkfs.c:90: INFO: Formatting /dev/loop0 with ext2 opts='' extra opts=''
mke2fs 1.44.6 (5-Mar-2019)
tst_test.c:1217: INFO: Timeout per run is 0h 05m 00s
newmount01.c:62: PASS: fsopen ext2
newmount01.c:69: PASS: fsconfig set source to /dev/loop0
newmount01.c:77: PASS: fsconfig create superblock
newmount01.c:84: PASS: fsmount  
newmount01.c:92: PASS: move_mount attach to mount point
newmount01.c:96: PASS: new mount works
newmount01.c:62: PASS: fsopen ext2
newmount01.c:69: PASS: fsconfig set source to /dev/loop0
newmount01.c:77: PASS: fsconfig create superblock
newmount01.c:84: PASS: fsmount  
newmount01.c:92: PASS: move_mount attach to mount point
newmount01.c:96: PASS: new mount works
newmount01.c:62: PASS: fsopen ext2
newmount01.c:69: PASS: fsconfig set source to /dev/loop0
newmount01.c:77: PASS: fsconfig create superblock
newmount01.c:84: PASS: fsmount  
newmount01.c:92: PASS: move_mount attach to mount point
newmount01.c:96: PASS: new mount works
tst_test.c:1278: INFO: Testing on ext3
...
newmount01.c:96: PASS: new mount works
tst_test.c:1278: INFO: Testing on ext4
...
newmount01.c:96: PASS: new mount works
tst_test.c:1278: INFO: Testing on xfs
...
newmount01.c:96: PASS: new mount works

Summary:

passed   72
failed   0
skipped  0

warnings 0

 configure.ac                                  |   1 +
 include/lapi/newmount.h                       |  89 ++++++++++++++
 include/lapi/syscalls/aarch64.in              |   4 +
 include/lapi/syscalls/powerpc64.in            |   4 +
 include/lapi/syscalls/s390x.in                |   4 +
 include/lapi/syscalls/x86_64.in               |   4 +
 m4/ltp-newmount.m4                            |  10 ++
 runtest/syscalls                              |   2 +
 testcases/kernel/syscalls/newmount/.gitignore |   1 +
 testcases/kernel/syscalls/newmount/Makefile   |   9 ++
 .../kernel/syscalls/newmount/newmount01.c     | 114 ++++++++++++++++++
 11 files changed, 242 insertions(+)
 create mode 100644 include/lapi/newmount.h
 create mode 100644 m4/ltp-newmount.m4
 create mode 100644 testcases/kernel/syscalls/newmount/.gitignore
 create mode 100644 testcases/kernel/syscalls/newmount/Makefile
 create mode 100644 testcases/kernel/syscalls/newmount/newmount01.c
configure.ac +1 -0
index 50d14967d..28f840c51 100644
@@ -229,6 +229,7 @@ LTP_CHECK_MADVISE
 LTP_CHECK_MKDTEMP
 LTP_CHECK_MMSGHDR
 LTP_CHECK_MREMAP_FIXED
+LTP_CHECK_NEWMOUNT
 LTP_CHECK_NOMMU_LINUX
 LTP_CHECK_PERF_EVENT
 LTP_CHECK_PRCTL_SUPPORT
include/lapi/newmount.h new file +89 -0

89 lines not on this page · raw message

include/lapi/syscalls/aarch64.in +4 -0
index 0e00641bc..5b9e1d9a4 100644
@@ -270,4 +270,8 @@ pkey_mprotect 288
 pkey_alloc 289
 pkey_free 290
 pidfd_send_signal 424
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
 _sysctl 1078
include/lapi/syscalls/powerpc64.in +4 -0
index 660165d7a..3aaed64e0 100644
@@ -359,3 +359,7 @@ pidfd_send_signal 424
 pkey_mprotect 386
 pkey_alloc 384
 pkey_free 385
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
include/lapi/syscalls/s390x.in +4 -0
index 7d632d1dc..bd427555a 100644
@@ -341,3 +341,7 @@ pkey_mprotect 384
 pkey_alloc 385
 pkey_free 386
 pidfd_send_signal 424
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
include/lapi/syscalls/x86_64.in +4 -0
index b1cbd4f2f..94f0b562e 100644
@@ -320,3 +320,7 @@ pkey_alloc 330
 pkey_free 331
 statx 332
 pidfd_send_signal 424
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
m4/ltp-newmount.m4 new file +10 -0
new file mode 100644
index 000000000..e13a6f0b1
@@ -0,0 +1,10 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_NEWMOUNT],[
+AC_CHECK_FUNCS(fsopen,,)
+AC_CHECK_FUNCS(fsconfig,,)
+AC_CHECK_FUNCS(fsmount,,)
+AC_CHECK_FUNCS(move_mount,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
runtest/syscalls +2 -0
index 15dbd9971..fac1c62d2 100644
@@ -794,6 +794,8 @@ nanosleep01 nanosleep01
 nanosleep02 nanosleep02
 nanosleep04 nanosleep04
 
+newmount01 newmount01
+
 nftw01 nftw01
 nftw6401 nftw6401
 
testcases/kernel/syscalls/newmount/.gitignore new file +1 -0
new file mode 100644
index 000000000..dc78edd5b
@@ -0,0 +1 @@
+/newmount01
testcases/kernel/syscalls/newmount/Makefile new file +9 -0
new file mode 100644
index 000000000..7d0920df6
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/newmount/newmount01.c new file +114 -0

114 lines not on this page · raw message

Signature · 1 line
2.20.1
#1 lore raw

Hi Zorro

Quoted 24 lines · Zorro Lang
configure.ac +1 -0
index 50d14967d..28f840c51 100644
@@ -229,6 +229,7 @@ LTP_CHECK_MADVISE
  LTP_CHECK_MKDTEMP
  LTP_CHECK_MMSGHDR
  LTP_CHECK_MREMAP_FIXED
+LTP_CHECK_NEWMOUNT
  LTP_CHECK_NOMMU_LINUX
  LTP_CHECK_PERF_EVENT
  LTP_CHECK_PRCTL_SUPPORT
include/lapi/newmount.h new file +5 -0
new file mode 100644
index 000000000..6b787fe7d
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ * Author: Zorro Lang <[email protected]>
+ */

include/lapi/newmount.h line 15

Quoted 10 lines
include/lapi/newmount.h new file +10 -0
+
+#ifndef NEWMOUNT_H__
+#define NEWMOUNT_H__
+
+#include <stdint.h>
+#include <unistd.h>
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_NEWMOUNT)

Why use HVAE_NEWMOUNT?

Quoted 129 lines
include/lapi/newmount.h new file +74 -0
+static inline int fsopen(const char *fs_name, unsigned int flags)
+{
+	return tst_syscall(__NR_fsopen, fs_name, flags);
+}
+
+/*
+ * fsopen() flags.
+ */
+#define FSOPEN_CLOEXEC		0x00000001
+
+static inline int fsconfig(int fsfd, unsigned int cmd,
+                           const char *key, const void *val, int aux)
+{
+	return tst_syscall(__NR_fsconfig, fsfd, cmd, key, val, aux);
+}
+
+/*
+ * The type of fsconfig() call made.
+ */
+enum fsconfig_command {
+	FSCONFIG_SET_FLAG	= 0,    /* Set parameter, supplying no value */
+	FSCONFIG_SET_STRING	= 1,    /* Set parameter, supplying a string value */
+	FSCONFIG_SET_BINARY	= 2,    /* Set parameter, supplying a binary blob value */
+	FSCONFIG_SET_PATH	= 3,    /* Set parameter, supplying an object by path */
+	FSCONFIG_SET_PATH_EMPTY	= 4,    /* Set parameter, supplying an object by (empty) path */
+	FSCONFIG_SET_FD		= 5,    /* Set parameter, supplying an object by fd */
+	FSCONFIG_CMD_CREATE	= 6,    /* Invoke superblock creation */
+	FSCONFIG_CMD_RECONFIGURE = 7,   /* Invoke superblock reconfiguration */
+};
+
+static inline int fsmount(int fsfd, unsigned int flags, unsigned int ms_flags)
+{
+	return tst_syscall(__NR_fsmount, fsfd, flags, ms_flags);
+}
+
+/*
+ * fsmount() flags.
+ */
+#define FSMOUNT_CLOEXEC		0x00000001
+
+/*
+ * Mount attributes.
+ */
+#define MOUNT_ATTR_RDONLY	0x00000001 /* Mount read-only */
+#define MOUNT_ATTR_NOSUID	0x00000002 /* Ignore suid and sgid bits */
+#define MOUNT_ATTR_NODEV	0x00000004 /* Disallow access to device special files */
+#define MOUNT_ATTR_NOEXEC	0x00000008 /* Disallow program execution */
+#define MOUNT_ATTR__ATIME	0x00000070 /* Setting on how atime should be updated */
+#define MOUNT_ATTR_RELATIME	0x00000000 /* - Update atime relative to mtime/ctime. */
+#define MOUNT_ATTR_NOATIME	0x00000010 /* - Do not update access times. */
+#define MOUNT_ATTR_STRICTATIME	0x00000020 /* - Always perform atime updates */
+#define MOUNT_ATTR_NODIRATIME	0x00000080 /* Do not update directory access times */
+
+static inline int move_mount(int from_dfd, const char *from_pathname,
+                             int to_dfd, const char *to_pathname,
+                             unsigned int flags)
+{
+	return tst_syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd,
+	                   to_pathname, flags);
+}
+
+/*
+ * move_mount() flags.
+ */
+#define MOVE_MOUNT_F_SYMLINKS		0x00000001 /* Follow symlinks on from path */
+#define MOVE_MOUNT_F_AUTOMOUNTS		0x00000002 /* Follow automounts on from path */
+#define MOVE_MOUNT_F_EMPTY_PATH		0x00000004 /* Empty from path permitted */
+#define MOVE_MOUNT_T_SYMLINKS		0x00000010 /* Follow symlinks on to path */
+#define MOVE_MOUNT_T_AUTOMOUNTS		0x00000020 /* Follow automounts on to path */
+#define MOVE_MOUNT_T_EMPTY_PATH		0x00000040 /* Empty to path permitted */
+#define MOVE_MOUNT__MASK		0x00000077
+
+#endif /* HAVE_NEWMOUNT */
+#endif /* NEWMOUNT_H__ */
include/lapi/syscalls/aarch64.in +4 -0
index 0e00641bc..5b9e1d9a4 100644
@@ -270,4 +270,8 @@ pkey_mprotect 288
  pkey_alloc 289
  pkey_free 290
  pidfd_send_signal 424
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
  _sysctl 1078
include/lapi/syscalls/powerpc64.in +4 -0
index 660165d7a..3aaed64e0 100644
@@ -359,3 +359,7 @@ pidfd_send_signal 424
  pkey_mprotect 386
  pkey_alloc 384
  pkey_free 385
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
include/lapi/syscalls/s390x.in +4 -0
index 7d632d1dc..bd427555a 100644
@@ -341,3 +341,7 @@ pkey_mprotect 384
  pkey_alloc 385
  pkey_free 386
  pidfd_send_signal 424
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
include/lapi/syscalls/x86_64.in +4 -0
index b1cbd4f2f..94f0b562e 100644
@@ -320,3 +320,7 @@ pkey_alloc 330
  pkey_free 331
  statx 332
  pidfd_send_signal 424
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
m4/ltp-newmount.m4 new file +0 -0
new file mode 100644
index 000000000..e13a6f0b1

m4/ltp-newmount.m4 line 10

Quoted 10 lines
m4/ltp-newmount.m4 new file +10 -0
@@ -0,0 +1,10 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_NEWMOUNT],[
+AC_CHECK_FUNCS(fsopen,,)
+AC_CHECK_FUNCS(fsconfig,,)
+AC_CHECK_FUNCS(fsmount,,)
+AC_CHECK_FUNCS(move_mount,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])

You use m4 to check them. But it seems that you don't use those macros in your cases.

Quoted 48 lines
runtest/syscalls +2 -0
index 15dbd9971..fac1c62d2 100644
@@ -794,6 +794,8 @@ nanosleep01 nanosleep01
  nanosleep02 nanosleep02
  nanosleep04 nanosleep04
 
+newmount01 newmount01
+
  nftw01 nftw01
  nftw6401 nftw6401
 
testcases/kernel/syscalls/newmount/.gitignore new file +1 -0
new file mode 100644
index 000000000..dc78edd5b
@@ -0,0 +1 @@
+/newmount01
testcases/kernel/syscalls/newmount/Makefile new file +9 -0
new file mode 100644
index 000000000..7d0920df6
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/newmount/newmount01.c new file +7 -0
new file mode 100644
index 000000000..464ecb699
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ * Author: Zorro Lang <[email protected]>
+ *
+ * Use new mount API (fsopen, fsconfig, fsmount, move_mount) to mount
+ * a filesystem without any specified mount options.

testcases/kernel/syscalls/newmount/newmount01.c line 17

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/mount.h>
+
+#include "tst_test.h"
+#include "tst_safe_macros.h"

"tst_test.h" has included "tst_safe_macros.h"

testcases/kernel/syscalls/newmount/newmount01.c line 23

Quoted 6 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +6 -0
+#include "lapi/newmount.h"
+
+#define LINELENGTH 256
+#define MNTPOINT "newmount_point"
+static int sfd, mfd;
+static int is_mounted = 0;

static int sfd, mfd, is_mounted;

Quoted 67 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +67 -0
+
+static int ismount(char *mntpoint)
+{
+	int ret = 0;
+	FILE *file;
+	char line[LINELENGTH];
+
+	file = fopen("/proc/mounts", "r");
+	if (file == NULL)
+		tst_brk(TFAIL | TTERRNO, "Open /proc/mounts failed");
+
+	while (fgets(line, LINELENGTH, file) != NULL) {
+		if (strstr(line, mntpoint) != NULL) {
+			ret = 1;
+			break;
+		}
+	}
+	fclose(file);
+	return ret;
+}
+
+static void cleanup(void)
+{
+	if (is_mounted) {
+		TEST(tst_umount(MNTPOINT));
+		if (TST_RET != 0)
+			tst_brk(TFAIL | TTERRNO, "umount failed in cleanup");
+	}
+}
+
+static void test_newmount(void)
+{
+	TEST(fsopen(tst_device->fs_type, FSOPEN_CLOEXEC));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO,
+		        "fsopen %s", tst_device->fs_type);
+	}
+	sfd = TST_RET;
+	tst_res(TPASS, "fsopen %s", tst_device->fs_type);
+
+	TEST(fsconfig(sfd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO,
+		        "fsconfig set source to %s", tst_device->dev);
+	}
+	tst_res(TPASS, "fsconfig set source to %s", tst_device->dev);
+
+
+	TEST(fsconfig(sfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO,
+		        "fsconfig create superblock");
+	}
+	tst_res(TPASS, "fsconfig create superblock");
+
+	TEST(fsmount(sfd, FSMOUNT_CLOEXEC, 0));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO, "fsmount");
+	}
+	mfd = TST_RET;
+	tst_res(TPASS, "fsmount");
+	SAFE_CLOSE(sfd);
+
+	TEST(move_mount(mfd, "", AT_FDCWD, MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO, "move_mount attach to mount point");
+	}

testcases/kernel/syscalls/newmount/newmount01.c line 100

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+	is_mounted = 1;
+	tst_res(TPASS, "move_mount attach to mount point");
+	SAFE_CLOSE(mfd);
+
+	if (ismount(MNTPOINT)) {
+		tst_res(TPASS, "new mount works");
+		TEST(tst_umount(MNTPOINT));
+		if (TST_RET != 0)
+			tst_brk(TFAIL | TTERRNO, "umount failed");
+		is_mounted = 0;

cleanup also does umount operation. Maybe we can call it in here.

testcases/kernel/syscalls/newmount/newmount01.c line 111

Quoted 11 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +11 -0
+	} else {
+		tst_res(TFAIL, "new mount fails");
+	}
+}
+
+static struct tst_test test = {
+	.test_all	= test_newmount,
+	.cleanup	= cleanup,
+	.needs_root	= 1,
+	.mntpoint	= MNTPOINT,
+	.needs_device	= 1,

In ltp library code, if you sepecify "format_device = 1", it will auto set "needs_device = 1". So remove it.

Quoted 4 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +3 -0
+	.format_device	= 1,
+	.all_filesystems = 1,
+};
#2 lore raw

----- ???? -----

Quoted 37 lines

???: "Yang Xu" <[email protected]>
???: "Zorro Lang" <[email protected]>, [email protected]
??: [email protected]
????: ???, 2019? 12 ? 09? ?? 12:49:32
??: Re: [LTP] [PATCH v2] syscalls/newmount: new test case for new mount API

Hi Zorro

Quoted 27 lines · Zorro Lang
configure.ac +1 -0
index 50d14967d..28f840c51 100644
@@ -229,6 +229,7 @@ LTP_CHECK_MADVISE
  LTP_CHECK_MKDTEMP
  LTP_CHECK_MMSGHDR
  LTP_CHECK_MREMAP_FIXED
+LTP_CHECK_NEWMOUNT
  LTP_CHECK_NOMMU_LINUX
  LTP_CHECK_PERF_EVENT
  LTP_CHECK_PRCTL_SUPPORT
include/lapi/newmount.h new file +8 -0
new file mode 100644
index 000000000..6b787fe7d
@@ -0,0 +1,89 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ * Author: Zorro Lang <[email protected]>
+ */
+
+#ifndef NEWMOUNT_H__
+#define NEWMOUNT_H__
Quoted 8 lines

include/lapi/newmount.h line 15

Quoted 7 lines
include/lapi/newmount.h new file +7 -0
+
+#include <stdint.h>
+#include <unistd.h>
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_NEWMOUNT)

Why use HVAE_NEWMOUNT?

Oh, my mistake. I wrote HAVE_NEWMOUNT with CHECK_NEWMOUNT together. I should use HAVE_FSOPEN, HAVE_FSCONFIG etc.

Thanks,
Zorro

Quoted 329 lines
Quoted 146 lines
include/lapi/newmount.h new file +23 -0
+static inline int fsopen(const char *fs_name, unsigned int flags)
+{
+	return tst_syscall(__NR_fsopen, fs_name, flags);
+}
+
+/*
+ * fsopen() flags.
+ */
+#define FSOPEN_CLOEXEC		0x00000001
+
+static inline int fsconfig(int fsfd, unsigned int cmd,
+                           const char *key, const void *val, int aux)
+{
+	return tst_syscall(__NR_fsconfig, fsfd, cmd, key, val, aux);
+}
+
+/*
+ * The type of fsconfig() call made.
+ */
+enum fsconfig_command {
+	FSCONFIG_SET_FLAG	= 0,    /* Set parameter, supplying no value */
+	FSCONFIG_SET_STRING	= 1,    /* Set parameter, supplying a string value */
+	FSCONFIG_SET_BINARY	= 2,    /* Set parameter, supplying a binary blob

value */

include/lapi/newmount.h new file +1 -0
+	FSCONFIG_SET_PATH	= 3,    /* Set parameter, supplying an object by path

*/

include/lapi/newmount.h new file +1 -0
+	FSCONFIG_SET_PATH_EMPTY	= 4,    /* Set parameter, supplying an object by

(empty) path */

include/lapi/newmount.h new file +6 -0
+	FSCONFIG_SET_FD		= 5,    /* Set parameter, supplying an object by fd */
+	FSCONFIG_CMD_CREATE	= 6,    /* Invoke superblock creation */
+	FSCONFIG_CMD_RECONFIGURE = 7,   /* Invoke superblock reconfiguration */
+};
+
+static inline int fsmount(int fsfd, unsigned int flags, unsigned int

ms_flags)

include/lapi/newmount.h new file +15 -0
+{
+	return tst_syscall(__NR_fsmount, fsfd, flags, ms_flags);
+}
+
+/*
+ * fsmount() flags.
+ */
+#define FSMOUNT_CLOEXEC		0x00000001
+
+/*
+ * Mount attributes.
+ */
+#define MOUNT_ATTR_RDONLY	0x00000001 /* Mount read-only */
+#define MOUNT_ATTR_NOSUID	0x00000002 /* Ignore suid and sgid bits */
+#define MOUNT_ATTR_NODEV	0x00000004 /* Disallow access to device special

files */

include/lapi/newmount.h new file +2 -0
+#define MOUNT_ATTR_NOEXEC	0x00000008 /* Disallow program execution */
+#define MOUNT_ATTR__ATIME	0x00000070 /* Setting on how atime should be

updated */
+#define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to
mtime/ctime. */

include/lapi/newmount.h new file +2 -0
+#define MOUNT_ATTR_NOATIME	0x00000010 /* - Do not update access times. */
+#define MOUNT_ATTR_STRICTATIME	0x00000020 /* - Always perform atime

updates */
+#define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access
times */

include/lapi/newmount.h new file +13 -0
+
+static inline int move_mount(int from_dfd, const char *from_pathname,
+                             int to_dfd, const char *to_pathname,
+                             unsigned int flags)
+{
+	return tst_syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd,
+	                   to_pathname, flags);
+}
+
+/*
+ * move_mount() flags.
+ */
+#define MOVE_MOUNT_F_SYMLINKS		0x00000001 /* Follow symlinks on from path

*/
+#define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from
path */
+#define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted
*/

include/lapi/newmount.h new file +2 -0
+#define MOVE_MOUNT_T_SYMLINKS		0x00000010 /* Follow symlinks on to path */
+#define MOVE_MOUNT_T_AUTOMOUNTS		0x00000020 /* Follow automounts on to

path */

include/lapi/newmount.h new file +5 -0
+#define MOVE_MOUNT_T_EMPTY_PATH		0x00000040 /* Empty to path permitted */
+#define MOVE_MOUNT__MASK		0x00000077
+
+#endif /* HAVE_NEWMOUNT */
+#endif /* NEWMOUNT_H__ */
include/lapi/syscalls/aarch64.in +4 -0
index 0e00641bc..5b9e1d9a4 100644
@@ -270,4 +270,8 @@ pkey_mprotect 288
  pkey_alloc 289
  pkey_free 290
  pidfd_send_signal 424
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
  _sysctl 1078
include/lapi/syscalls/powerpc64.in +4 -0
index 660165d7a..3aaed64e0 100644
@@ -359,3 +359,7 @@ pidfd_send_signal 424
  pkey_mprotect 386
  pkey_alloc 384
  pkey_free 385
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
include/lapi/syscalls/s390x.in +4 -0
index 7d632d1dc..bd427555a 100644
@@ -341,3 +341,7 @@ pkey_mprotect 384
  pkey_alloc 385
  pkey_free 386
  pidfd_send_signal 424
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
include/lapi/syscalls/x86_64.in +4 -0
index b1cbd4f2f..94f0b562e 100644
@@ -320,3 +320,7 @@ pkey_alloc 330
  pkey_free 331
  statx 332
  pidfd_send_signal 424
+move_mount 429
+fsopen 430
+fsconfig 431
+fsmount 432
m4/ltp-newmount.m4 new file +0 -0
new file mode 100644
index 000000000..e13a6f0b1

m4/ltp-newmount.m4 line 10

Quoted 10 lines
m4/ltp-newmount.m4 new file +10 -0
@@ -0,0 +1,10 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_NEWMOUNT],[
+AC_CHECK_FUNCS(fsopen,,)
+AC_CHECK_FUNCS(fsconfig,,)
+AC_CHECK_FUNCS(fsmount,,)
+AC_CHECK_FUNCS(move_mount,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])

You use m4 to check them. But it seems that you don't use those macros in your cases.

Quoted 51 lines
runtest/syscalls +2 -0
index 15dbd9971..fac1c62d2 100644
@@ -794,6 +794,8 @@ nanosleep01 nanosleep01
  nanosleep02 nanosleep02
  nanosleep04 nanosleep04
 
+newmount01 newmount01
+
  nftw01 nftw01
  nftw6401 nftw6401
 
testcases/kernel/syscalls/newmount/.gitignore new file +1 -0
new file mode 100644
index 000000000..dc78edd5b
@@ -0,0 +1 @@
+/newmount01
testcases/kernel/syscalls/newmount/Makefile new file +9 -0
new file mode 100644
index 000000000..7d0920df6
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/newmount/newmount01.c new file +7 -0
new file mode 100644
index 000000000..464ecb699
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ * Author: Zorro Lang <[email protected]>
+ *
+ * Use new mount API (fsopen, fsconfig, fsmount, move_mount) to mount
+ * a filesystem without any specified mount options.

testcases/kernel/syscalls/newmount/newmount01.c line 17

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/mount.h>
+
+#include "tst_test.h"
+#include "tst_safe_macros.h"

"tst_test.h" has included "tst_safe_macros.h"

testcases/kernel/syscalls/newmount/newmount01.c line 23

Quoted 6 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +6 -0
+#include "lapi/newmount.h"
+
+#define LINELENGTH 256
+#define MNTPOINT "newmount_point"
+static int sfd, mfd;
+static int is_mounted = 0;

static int sfd, mfd, is_mounted;

Quoted 67 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +67 -0
+
+static int ismount(char *mntpoint)
+{
+	int ret = 0;
+	FILE *file;
+	char line[LINELENGTH];
+
+	file = fopen("/proc/mounts", "r");
+	if (file == NULL)
+		tst_brk(TFAIL | TTERRNO, "Open /proc/mounts failed");
+
+	while (fgets(line, LINELENGTH, file) != NULL) {
+		if (strstr(line, mntpoint) != NULL) {
+			ret = 1;
+			break;
+		}
+	}
+	fclose(file);
+	return ret;
+}
+
+static void cleanup(void)
+{
+	if (is_mounted) {
+		TEST(tst_umount(MNTPOINT));
+		if (TST_RET != 0)
+			tst_brk(TFAIL | TTERRNO, "umount failed in cleanup");
+	}
+}
+
+static void test_newmount(void)
+{
+	TEST(fsopen(tst_device->fs_type, FSOPEN_CLOEXEC));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO,
+		        "fsopen %s", tst_device->fs_type);
+	}
+	sfd = TST_RET;
+	tst_res(TPASS, "fsopen %s", tst_device->fs_type);
+
+	TEST(fsconfig(sfd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO,
+		        "fsconfig set source to %s", tst_device->dev);
+	}
+	tst_res(TPASS, "fsconfig set source to %s", tst_device->dev);
+
+
+	TEST(fsconfig(sfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO,
+		        "fsconfig create superblock");
+	}
+	tst_res(TPASS, "fsconfig create superblock");
+
+	TEST(fsmount(sfd, FSMOUNT_CLOEXEC, 0));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO, "fsmount");
+	}
+	mfd = TST_RET;
+	tst_res(TPASS, "fsmount");
+	SAFE_CLOSE(sfd);
+
+	TEST(move_mount(mfd, "", AT_FDCWD, MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO, "move_mount attach to mount point");
+	}

testcases/kernel/syscalls/newmount/newmount01.c line 100

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+	is_mounted = 1;
+	tst_res(TPASS, "move_mount attach to mount point");
+	SAFE_CLOSE(mfd);
+
+	if (ismount(MNTPOINT)) {
+		tst_res(TPASS, "new mount works");
+		TEST(tst_umount(MNTPOINT));
+		if (TST_RET != 0)
+			tst_brk(TFAIL | TTERRNO, "umount failed");
+		is_mounted = 0;

cleanup also does umount operation. Maybe we can call it in here.

testcases/kernel/syscalls/newmount/newmount01.c line 111

Quoted 11 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +11 -0
+	} else {
+		tst_res(TFAIL, "new mount fails");
+	}
+}
+
+static struct tst_test test = {
+	.test_all	= test_newmount,
+	.cleanup	= cleanup,
+	.needs_root	= 1,
+	.mntpoint	= MNTPOINT,
+	.needs_device	= 1,

In ltp library code, if you sepecify "format_device = 1", it will auto set "needs_device = 1". So remove it.

Quoted 4 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +3 -0
+	.format_device	= 1,
+	.all_filesystems = 1,
+};