Skip to contentSkip to conversation

syscalls/newmount: new test case for new mount API

PATCH Superseded Zorro Lang 4 participants 9 messages Nov 28, 2019 – Dec 6, 2019 VFS

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Zorro Lang

author
#0 lore raw

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

This's the 1st case for LTP to test current new mount API. So I have to add lots of new things to include/lapi/* and m4/ltp-*(as below), I'm not familiar with LTP code, so please help to review. There might be lot of things need to be improved.

I'll try to add more test if this 1st case can be merged. I've tested this patch on latest upstream xfs-linux for-next branch, due to xfs supports the new mount API now.

# ./runltp -B xfs -f newmount
...
...
Running tests.......
<<<test_start>>>
tag=newmount01 stime=1574961655
cmdline="newmount01"
contacts=""
analysis=exit
<<<test_output>>>
incrementing stop
tst_device.c:238: INFO: Using test device LTP_DEV='/dev/loop1'
tst_test.c:1217: INFO: Timeout per run is 0h 05m 00s
tst_mkfs.c:90: INFO: Formatting /dev/loop1 with xfs opts='' extra opts=''
newmount01.c:87: PASS: fsopen xfs
newmount01.c:96: PASS: fsconfig set source to /dev/loop1
newmount01.c:105: PASS: fsconfig create superblock
newmount01.c:113: PASS: fsmount
newmount01.c:121: PASS: move_mount attach to mount point
newmount01.c:124: PASS: new mount works

Summary:

passed   6
failed   0
skipped  0

warnings 0
<<<execution_status>>>
initiation_status="ok"
duration=4 termination_type=exited termination_id=0 corefile=no cutime=0 cstime=8
<<<test_end>>>

Thanks,
Zorro

 configure.ac                                  |   4 +
 include/lapi/newmount.h                       | 106 +++++++++++++
 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-fsconfig.m4                            |   7 +
 m4/ltp-fsmount.m4                             |   7 +
 m4/ltp-fsopen.m4                              |   7 +
 m4/ltp-move_mount.m4                          |   7 +
 runtest/syscalls                              |   2 +
 testcases/kernel/syscalls/newmount/.gitignore |   1 +
 testcases/kernel/syscalls/newmount/Makefile   |  29 ++++
 .../kernel/syscalls/newmount/newmount01.c     | 150 ++++++++++++++++++
 14 files changed, 336 insertions(+)
 create mode 100644 include/lapi/newmount.h
 create mode 100644 m4/ltp-fsconfig.m4
 create mode 100644 m4/ltp-fsmount.m4
 create mode 100644 m4/ltp-fsopen.m4
 create mode 100644 m4/ltp-move_mount.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 +4 -0
index 50d14967d..f17ab2e96 100644
@@ -217,6 +217,9 @@ LTP_CHECK_CRYPTO
 LTP_CHECK_FANOTIFY
 LTP_CHECK_FIDEDUPE
 LTP_CHECK_FORTIFY_SOURCE
+LTP_CHECK_FSOPEN
+LTP_CHECK_FSCONFIG
+LTP_CHECK_FSMOUNT
 LTP_CHECK_FTS_H
 LTP_CHECK_IF_LINK
 LTP_CHECK_IOVEC
@@ -228,6 +231,7 @@ LTP_CHECK_LINUXRANDOM
 LTP_CHECK_MADVISE
 LTP_CHECK_MKDTEMP
 LTP_CHECK_MMSGHDR
+LTP_CHECK_MOVE_MOUNT
 LTP_CHECK_MREMAP_FIXED
 LTP_CHECK_NOMMU_LINUX
 LTP_CHECK_PERF_EVENT
include/lapi/newmount.h new file +106 -0

106 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-fsconfig.m4 new file +7 -0
new file mode 100644
index 000000000..397027f1b
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSCONFIG],[
+AC_CHECK_FUNCS(fsconfig,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-fsmount.m4 new file +7 -0
new file mode 100644
index 000000000..ee32ef713
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSMOUNT],[
+AC_CHECK_FUNCS(fsmount,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-fsopen.m4 new file +7 -0
new file mode 100644
index 000000000..6e23d437d
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSOPEN],[
+AC_CHECK_FUNCS(fsopen,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-move_mount.m4 new file +7 -0
new file mode 100644
index 000000000..d6bfd82e9
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_MOVE_MOUNT],[
+AC_CHECK_FUNCS(move_mount,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
runtest/syscalls +2 -0
index 15dbd9971..d11a87dd9 100644
@@ -716,6 +716,8 @@ mount04 mount04
 mount05 mount05
 mount06 mount06
 
+newmount01 newmount01
+
 move_pages01 move_pages01
 move_pages02 move_pages02
 move_pages03 move_pages03
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 +29 -0
new file mode 100644
index 000000000..8b0a60332
@@ -0,0 +1,29 @@
+#
+#  Copyright (C) 2017 Red Hat, Inc.  All rights reserved.
+#
+#  This program is free software;  you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+#  the GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# HISTORY:
+#  27/11/2019 [email protected]  Create newmount01.c
+#
+#############################################################################
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CFLAGS			+= -D_GNU_SOURCE
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/newmount/newmount01.c new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Zorro,

Quoted 4 lines

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.

Thanks for writing test for recently added kernel functionality. This is important.
Test itself looks ok to me.
There are few code style differences (note below), but that's not important.

BTW I thought it'd be nice to use more filesystems via .all_filesystems = 1 [1] but at least it breaks nfs. And IMHO we don't have blacklist support for .all_filesystems.

Quoted 6 lines
 configure.ac                                  |   4 +
 include/lapi/newmount.h                       | 106 +++++++++++++
 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 +

In final version we'd want to add syscall numbers for all archs.

...

Quoted 9 lines

+++ b/include/lapi/newmount.h

include/lapi/newmount.h new file +7 -0
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.

include/lapi/newmount.h line 17

Quoted 10 lines
include/lapi/newmount.h new file +10 -0
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */

Use SPDX license identifier instead of verbose GPL everywhere (including headers and makefiles; we don't want any HISTORY: text, but feel free to add Author:
your name).

include/lapi/newmount.h line 20

Quoted 3 lines
include/lapi/newmount.h new file +3 -0
+
+#ifndef __NEWMOUNT_H__
+#define __NEWMOUNT_H__

Double underscore at the beginning and end (__FOO_H__) is IMHO reserved for library (use NEWMOUNT_H__).
...

Quoted 45 lines
m4/ltp-fsconfig.m4 new file +7 -0
new file mode 100644
index 000000000..397027f1b
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSCONFIG],[
+AC_CHECK_FUNCS(fsconfig,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-fsmount.m4 new file +7 -0
new file mode 100644
index 000000000..ee32ef713
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSMOUNT],[
+AC_CHECK_FUNCS(fsmount,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-fsopen.m4 new file +7 -0
new file mode 100644
index 000000000..6e23d437d
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSOPEN],[
+AC_CHECK_FUNCS(fsopen,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-move_mount.m4 new file +0 -0
new file mode 100644
index 000000000..d6bfd82e9

m4/ltp-move_mount.m4 line 7

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

As all of these require <sys/mount.h>, I'd add them into single file
m4/ltp-newmount.m4.
BTW it might take a time before it get into <sys/mount.h>, they're now just <linux/mount.h> (even in musl, which is unlike glic fast with porting new things).

...

Quoted 1 line

+++ b/testcases/kernel/syscalls/newmount/Makefile

...

m4/ltp-move_mount.m4

Quoted 6 lines
m4/ltp-move_mount.m4 new file +6 -0
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CFLAGS			+= -D_GNU_SOURCE

Is _GNU_SOURCE needed?

m4/ltp-move_mount.m4

Quoted 2 lines
m4/ltp-move_mount.m4 new file +2 -0
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk

Kind regards,
Petr

[1] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#2215-testing-with-a-block-device

author
#2 lore raw
Quoted 10 lines · Petr Vorel

Hi Zorro,

Quoted 4 lines

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.

Thanks for writing test for recently added kernel functionality. This is important.
Test itself looks ok to me.
There are few code style differences (note below), but that's not important.

Quoted 5 lines

BTW I thought it'd be nice to use more filesystems via .all_filesystems = 1 [1] but at least it breaks nfs. And IMHO we don't have blacklist support for .all_filesystems.

I(or with my colleagues) would like to add more filesystem specified test later, to make sure filesystem specified mount options still works well with new mount syscalls.

Quoted 8 lines
Quoted 7 lines
 configure.ac                                  |   4 +
 include/lapi/newmount.h                       | 106 +++++++++++++
 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 +

In final version we'd want to add syscall numbers for all archs.

Yeah, I tried to find a .in file for all archs, but didn't find, so had to add these __NR_ definition separately.

Quoted 16 lines

...

Quoted 14 lines

+++ b/include/lapi/newmount.h

include/lapi/newmount.h new file +12 -0
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
Quoted 8 lines

include/lapi/newmount.h line 17

Quoted 5 lines
include/lapi/newmount.h new file +5 -0
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */

Use SPDX license identifier instead of verbose GPL everywhere (including headers and makefiles; we don't want any HISTORY: text, but feel free to add Author:
your name).

Wow, sorry I don't learn about the license things so much, just copy from other file:) I'll search how to use the SPDX license.

Quoted 5 lines

include/lapi/newmount.h line 20

Quoted 3 lines
include/lapi/newmount.h new file +3 -0
+
+#ifndef __NEWMOUNT_H__
+#define __NEWMOUNT_H__

Double underscore at the beginning and end (__FOO_H__) is IMHO reserved for library (use NEWMOUNT_H__).

Sure, I'll change it to a proper one.

Quoted 48 lines

...

Quoted 46 lines
m4/ltp-fsconfig.m4 new file +7 -0
new file mode 100644
index 000000000..397027f1b
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSCONFIG],[
+AC_CHECK_FUNCS(fsconfig,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-fsmount.m4 new file +7 -0
new file mode 100644
index 000000000..ee32ef713
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSMOUNT],[
+AC_CHECK_FUNCS(fsmount,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-fsopen.m4 new file +7 -0
new file mode 100644
index 000000000..6e23d437d
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSOPEN],[
+AC_CHECK_FUNCS(fsopen,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-move_mount.m4 new file +1 -0
new file mode 100644
index 000000000..d6bfd82e9
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
Quoted 8 lines

m4/ltp-move_mount.m4 line 7

Quoted 6 lines
m4/ltp-move_mount.m4 new file +6 -0
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_MOVE_MOUNT],[
+AC_CHECK_FUNCS(move_mount,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])

As all of these require <sys/mount.h>, I'd add them into single file m4/ltp-newmount.m4.

OK, I'll do that.

Quoted 1 line

BTW it might take a time before it get into <sys/mount.h>, they're now just <linux/mount.h> (even in musl, which is unlike glic fast with porting new things).

Yes, there're still in kernel-headers, glibc doesn't have patch for that. Maybe they're waiting. I don't know if there'll be more newmount syscalls (e.g fsinfo or something else), or fsdevel might would like to disconnect umount() in the feature:)

Quoted 11 lines

...

Quoted 1 line

+++ b/testcases/kernel/syscalls/newmount/Makefile

...

m4/ltp-move_mount.m4

Quoted 6 lines
m4/ltp-move_mount.m4 new file +6 -0
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CFLAGS			+= -D_GNU_SOURCE

Is _GNU_SOURCE needed?

Hmm... I'm not sure, just copy this Makefile from syscalls/mount/Makefile ;) I think the new mount API might not be POSIX defined?

Thanks for your review so much, I'll send V2 patch soon.

Thanks,
Zorro

Quoted 8 lines

m4/ltp-move_mount.m4

Quoted 2 lines
m4/ltp-move_mount.m4 new file +2 -0
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk

Kind regards,
Petr

[1] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#2215-testing-with-a-block-device

#3 lore raw

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

In reply to Zorro Lang
Quoted 4 lines · Zorro Lang

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 Zorro

?This patch looks good to me. Only a few comments as below:

Quoted 21 lines

---

Hi,

This's the 1st case for LTP to test current new mount API. So I have to add lots of new things to include/lapi/* and m4/ltp-*(as below), I'm not familiar with LTP code, so please help to review. There might be lot of things need to be improved.

I'll try to add more test if this 1st case can be merged. I've tested this patch on latest upstream xfs-linux for-next branch, due to xfs supports the new mount API now.

configure.ac +0 -0
index 50d14967d..f17ab2e96 100644

configure.ac LTP_CHECK_CRYPTO · line 222

Quoted 6 lines
configure.ac +3 -0
@@ -217,6 +217,9 @@ LTP_CHECK_CRYPTO
  LTP_CHECK_FANOTIFY
  LTP_CHECK_FIDEDUPE
  LTP_CHECK_FORTIFY_SOURCE
+LTP_CHECK_FSOPEN
+LTP_CHECK_FSCONFIG
+LTP_CHECK_FSMOUNT

sort alphabetically.
+LTP_CHECK_FSCONFIG
+LTP_CHECK_FSMOUNT
+LTP_CHECK_FSOPEN

Quoted 217 lines
configure.ac +1 -0
  LTP_CHECK_FTS_H
  LTP_CHECK_IF_LINK
  LTP_CHECK_IOVEC
@@ -228,6 +231,7 @@ LTP_CHECK_LINUXRANDOM
  LTP_CHECK_MADVISE
  LTP_CHECK_MKDTEMP
  LTP_CHECK_MMSGHDR
+LTP_CHECK_MOVE_MOUNT
  LTP_CHECK_MREMAP_FIXED
  LTP_CHECK_NOMMU_LINUX
  LTP_CHECK_PERF_EVENT
include/lapi/newmount.h new file +106 -0
new file mode 100644
index 000000000..07d57ff96
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __NEWMOUNT_H__
+#define __NEWMOUNT_H__
+
+#include <stdint.h>
+#include <unistd.h>
+#include "lapi/syscalls.h"
+
+#if !defined(HAVE_FSOPEN)
+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
+#endif
+
+#if !defined(HAVE_FSCONFIG)
+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 */
+};
+#endif
+
+#if !defined(HAVE_FSMOUNT)
+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 */
+#endif
+
+#if !defined(HAVE_MOVE_MOUNT)
+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
+
+#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-fsconfig.m4 new file +7 -0
new file mode 100644
index 000000000..397027f1b
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSCONFIG],[
+AC_CHECK_FUNCS(fsconfig,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-fsmount.m4 new file +7 -0
new file mode 100644
index 000000000..ee32ef713
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSMOUNT],[
+AC_CHECK_FUNCS(fsmount,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-fsopen.m4 new file +7 -0
new file mode 100644
index 000000000..6e23d437d
@@ -0,0 +1,7 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (C) 2019 Red Hat, Inc. All Rights Reserved.
+
+AC_DEFUN([LTP_CHECK_FSOPEN],[
+AC_CHECK_FUNCS(fsopen,,)
+AC_CHECK_HEADER(sys/mount.h,,,)
+])
m4/ltp-move_mount.m4 new file +0 -0
new file mode 100644
index 000000000..d6bfd82e9

m4/ltp-move_mount.m4 line 7

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

IMHO, we don't need to add these m4 files. I think you can move fsopen,fsconfig,fsmount,move_mount , sys/mount.h into configure.ac. We usually do it since commit 8fd49cebd5("configure.ac: Simplify the check for libc function implementations")

Or, you will add more info on the comming patches to test new mount api.

runtest/syscalls mount04 mount04 · line 719

Quoted 9 lines
runtest/syscalls +1 -0
index 15dbd9971..d11a87dd9 100644
@@ -716,6 +716,8 @@ mount04 mount04
  mount05 mount05
  mount06 mount06
 
+newmount01 newmount01

In runtest/syscalls file, we should sort alphabetically. We should put it before newuname01.

Quoted 72 lines
runtest/syscalls +1 -0
+
  move_pages01 move_pages01
  move_pages02 move_pages02
  move_pages03 move_pages03
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 +29 -0
new file mode 100644
index 000000000..8b0a60332
@@ -0,0 +1,29 @@
+#
+#  Copyright (C) 2017 Red Hat, Inc.  All rights reserved.
+#
+#  This program is free software;  you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+#  the GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program;  if not, write to the Free Software
+#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#
+# HISTORY:
+#  27/11/2019 [email protected]  Create newmount01.c
+#
+#############################################################################
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CFLAGS			+= -D_GNU_SOURCE
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/newmount/newmount01.c new file +20 -0
new file mode 100644
index 000000000..35e355506
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ * Author: Zorro Lang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+/*
+ *  DESCRIPTION

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

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+ *	Use new mount API (fsopen, fsconfig, fsmount, move_mount) to mount
+ *	a filesystem.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/prctl.h>

I don't see you use prctl and fcntl . Remove it.

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

Quoted 1 line
testcases/kernel/syscalls/newmount/newmount01.c new file +1 -0
+#include <sys/wait.h>

It also can be removed.

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

Quoted 4 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +4 -0
+#include <sys/mount.h>
+
+#include "tst_test.h"
+#include "tst_safe_macros.h"

"tst_test.h" has include this header filer. Remove it.

Quoted 16 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +16 -0
+#include "lapi/newmount.h"
+
+#define LINELENGTH 256
+#define MNTPOINT "newmount_point"
+static int sfd, mfd;
+static int mount_flag = 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");

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

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+
+	while (fgets(line, LINELENGTH, file) != NULL) {
+		if (strstr(line, mntpoint) != NULL) {
+			ret = 1;
+			break;
+		}
+	}
+	fclose(file);
+	return ret;
+}

I think grep command is a simple way by using tst_run_cmd.

Quoted 57 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +57 -0
+
+static void setup(void)
+{
+	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
+}
+
+static void cleanup(void)
+{
+	if (mount_flag == 1) {
+		TEST(tst_umount(MNTPOINT));
+		if (TST_RET != 0)
+			tst_brk(TBROK | TTERRNO, "umount failed");
+	}
+}
+
+
+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);
+	} else {
+		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);
+	} else {
+		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");
+	} else {
+		tst_res(TPASS,
+			"fsconfig create superblock");
+	}
+
+	TEST(fsmount(sfd, FSMOUNT_CLOEXEC, 0));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO, "fsmount");
+	} else {
+		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) {

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

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+		tst_brk(TFAIL | TTERRNO, "move_mount attach to mount point");
+	} else {
+		tst_res(TPASS, "move_mount attach to mount point");
+		mount_flag = 1;
+		if (ismount(MNTPOINT))
+			tst_res(TPASS, "new mount works");
+		else
+			tst_res(TFAIL, "new mount fails");
+	}
+	SAFE_CLOSE(mfd);

Here,? I think you should umount. Otherwise, I will get an error when I run in a loop fail as below:

[root@localhost newmount]# ./newmount01 -i 2
tst_device.c:87: INFO: Found free device 2 '/dev/loop2' tst_test.c:1217: INFO: Timeout per run is 0h 05m 00s tst_mkfs.c:90: INFO: Formatting /dev/loop2 with ext2 opts='' extra opts='' mke2fs 1.44.6 (5-Mar-2019)
newmount01.c:87: PASS: fsopen ext2
newmount01.c:96: PASS: fsconfig set source to /dev/loop2 newmount01.c:105: PASS: fsconfig create superblock newmount01.c:113: PASS: fsmount
newmount01.c:121: PASS: move_mount attach to mount point newmount01.c:124: PASS: new mount works
newmount01.c:87: PASS: fsopen ext2
newmount01.c:96: PASS: fsconfig set source to /dev/loop2 newmount01.c:105: PASS: fsconfig create superblock newmount01.c:113: PASS: fsmount
newmount01.c:121: PASS: move_mount attach to mount point newmount01.c:124: PASS: new mount works

Summary:

passed   12
failed   0
skipped  0

warnings 0
tst_device.c:221: WARN: ioctl(/dev/loop2, LOOP_CLR_FD, 0) no ENXIO for too long
tst_tmpdir.c:330: WARN: tst_rmdir: rmobj(/tmp/RjSYWS) failed: remove(/tmp/RjSYWS/newmount_point) failed; errno=16: EBUSY

we can fix this by calling cleanup and setting mount_flag to 0 when umount succeed

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

Quoted 12 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +12 -0
+}
+
+struct test_cases {
+	void (*tfunc)(void);
+} tcases[] = {
+	{&test_newmount},
+};
+
+static void run(unsigned int i)
+{
+	tcases[i].tfunc();
+}

Why not use test_newmount directly? You can use .test_all= test_newmount in struct tst_test
and doesn't need tcnt [1].
[1]https://github.com/linux-test-project/ltp/blob/master/doc/test-writing-guidelines.txt

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

Quoted 2 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +2 -0
+
+static struct tst_test test = {

As Petr said, using .all_filesysystem is a better way. we can test more filesystems.

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

Quoted 8 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +8 -0
+	.test		= run,
+	.tcnt		= ARRAY_SIZE(tcases),
+	.setup		= setup,
+	.cleanup	= cleanup,
+	 .needs_root	= 1,
+	.mntpoint	= MNTPOINT,
+	.needs_device	= 1,
+};

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20191129/0b1d8b9f/attachment-0001.htm>

#4 lore raw
Quoted 19 lines · Yang Xu
include/lapi/newmount.h new file +16 -0
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

include/lapi/newmount.h line 26

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

When we run make autotools and ./configure, this macro is in "include/config.h". You should include this header file like other lapi files.

Quoted 2 lines
include/lapi/newmount.h new file +2 -0
+static inline int fsopen(const char *fs_name, unsigned int flags)
+{
author
#5 lore raw
Quoted 27 lines · Yang Xu
Quoted 24 lines · Yang Xu
include/lapi/newmount.h new file +21 -0
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef __NEWMOUNT_H__
+#define __NEWMOUNT_H__
+
Quoted 8 lines

include/lapi/newmount.h line 26

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

When we run make autotools and ./configure, this macro is in "include/config.h". You should include this header file like other lapi files.

Oh, thanks, I refered to the include/lapi/stat.h file, it doesn't include config.h, I don't know if it's needed.

Thanks,
Zorro

Quoted 4 lines
Quoted 2 lines
include/lapi/newmount.h new file +2 -0
+static inline int fsopen(const char *fs_name, unsigned int flags)
+{
#6 lore raw
In reply to Zorro Lang

Hi!

Quoted 58 lines
testcases/kernel/syscalls/newmount/Makefile new file +1 -0
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/newmount/newmount01.c new file +51 -0
new file mode 100644
index 000000000..35e355506
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ * Author: Zorro Lang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+/*
+ *  DESCRIPTION
+ *	Use new mount API (fsopen, fsconfig, fsmount, move_mount) to mount
+ *	a filesystem.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/prctl.h>
+#include <sys/wait.h>
+#include <sys/mount.h>
+
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+#include "lapi/newmount.h"
+
+#define LINELENGTH 256
+#define MNTPOINT "newmount_point"
+static int sfd, mfd;
+static int mount_flag = 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");

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

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+
+	while (fgets(line, LINELENGTH, file) != NULL) {
+		if (strstr(line, mntpoint) != NULL) {
+			ret = 1;
+			break;
+		}
+	}
+	fclose(file);
+	return ret;
+}

Hmm, this is very similar to file_lines_scanf(), maybe we need a library function that would iterate over file lines to call a callback on each of them as well. I will think about this.

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

Quoted 3 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +3 -0
+static void setup(void)
+{
+	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);

Why aren't we just setting .format_device in the test structure?

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

Quoted 8 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +8 -0
+}
+
+static void cleanup(void)
+{
+	if (mount_flag == 1) {
+		TEST(tst_umount(MNTPOINT));
+		if (TST_RET != 0)
+			tst_brk(TBROK | TTERRNO, "umount failed");

The library already produces TWARN if we fail to umount the device, so I would say that there is no need to TBROK here, the TBROK will be converted to TWARN anyways since it's in the cleanup...

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

Quoted 11 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +11 -0
+	}
+}
+
+
+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);
+	} else {

There is no need for else branches after tst_brk(), the test will exit if we reach the tst_brk().

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

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+		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);
+	} else {

Here as well.

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

Quoted 8 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +8 -0
+		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");

And here.

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

Quoted 9 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +9 -0
+	} else {
+		tst_res(TPASS,
+			"fsconfig create superblock");
+	}
+
+	TEST(fsmount(sfd, FSMOUNT_CLOEXEC, 0));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO, "fsmount");
+	} else {

And here.

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

Quoted 9 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +9 -0
+		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");
+	} else {

And here.

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

Quoted 8 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +8 -0
+		tst_res(TPASS, "move_mount attach to mount point");
+		mount_flag = 1;
+		if (ismount(MNTPOINT))
+			tst_res(TPASS, "new mount works");
+		else
+			tst_res(TFAIL, "new mount fails");
+	}
+	SAFE_CLOSE(mfd);

We have to umount the device here, otherwise it would be mounted for each test iteration with -i.

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

Quoted 7 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +7 -0
+}
+
+struct test_cases {
+	void (*tfunc)(void);
+} tcases[] = {
+	{&test_newmount},
+};

Unless you plan to add more tests here, there is no point in declaring the structure with function pointers.

Quoted 4 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +4 -0
+static void run(unsigned int i)
+{
+	tcases[i].tfunc();
+}

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

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+
+static struct tst_test test = {
+	.test		= run,
+	.tcnt		= ARRAY_SIZE(tcases),
+	.setup		= setup,
+	.cleanup	= cleanup,
+	.needs_root	= 1,
+	.mntpoint	= MNTPOINT,
+	.needs_device	= 1,
+};

Otherwise it looks good.

Signature · 2 lines
Cyril Hrubis
[email protected]
author
#7 lore raw
Quoted 93 lines · Cyril Hrubis

Hi!

Quoted 58 lines
testcases/kernel/syscalls/newmount/Makefile new file +1 -0
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/newmount/newmount01.c new file +51 -0
new file mode 100644
index 000000000..35e355506
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2019 Red Hat, Inc.  All rights reserved.
+ * Author: Zorro Lang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+/*
+ *  DESCRIPTION
+ *	Use new mount API (fsopen, fsconfig, fsmount, move_mount) to mount
+ *	a filesystem.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <sys/prctl.h>
+#include <sys/wait.h>
+#include <sys/mount.h>
+
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+#include "lapi/newmount.h"
+
+#define LINELENGTH 256
+#define MNTPOINT "newmount_point"
+static int sfd, mfd;
+static int mount_flag = 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");

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

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+
+	while (fgets(line, LINELENGTH, file) != NULL) {
+		if (strstr(line, mntpoint) != NULL) {
+			ret = 1;
+			break;
+		}
+	}
+	fclose(file);
+	return ret;
+}

Hmm, this is very similar to file_lines_scanf(), maybe we need a library function that would iterate over file lines to call a callback on each of them as well. I will think about this.

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

Quoted 3 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +3 -0
+static void setup(void)
+{
+	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);

Why aren't we just setting .format_device in the test structure?

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

Quoted 8 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +8 -0
+}
+
+static void cleanup(void)
+{
+	if (mount_flag == 1) {
+		TEST(tst_umount(MNTPOINT));
+		if (TST_RET != 0)
+			tst_brk(TBROK | TTERRNO, "umount failed");

The library already produces TWARN if we fail to umount the device, so I would say that there is no need to TBROK here, the TBROK will be converted to TWARN anyways since it's in the cleanup...

Quoted 14 lines

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

Quoted 11 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +11 -0
+	}
+}
+
+
+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);
+	} else {

There is no need for else branches after tst_brk(), the test will exit if we reach the tst_brk().

Sorry I can't be 100% sure what you mean at here. Do you mean as this:
--
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);
--

Quoted 49 lines

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

Quoted 11 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+		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);
+	} else {

Here as well.

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

Quoted 8 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +8 -0
+		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");

And here.

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

Quoted 9 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +9 -0
+	} else {
+		tst_res(TPASS,
+			"fsconfig create superblock");
+	}
+
+	TEST(fsmount(sfd, FSMOUNT_CLOEXEC, 0));
+	if (TST_RET < 0) {
+		tst_brk(TFAIL | TTERRNO, "fsmount");
+	} else {

And here.

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

Quoted 9 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +9 -0
+		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");
+	} else {

And here.

Quoted 11 lines

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

Quoted 8 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +8 -0
+		tst_res(TPASS, "move_mount attach to mount point");
+		mount_flag = 1;
+		if (ismount(MNTPOINT))
+			tst_res(TPASS, "new mount works");
+		else
+			tst_res(TFAIL, "new mount fails");
+	}
+	SAFE_CLOSE(mfd);

We have to umount the device here, otherwise it would be mounted for each test iteration with -i.

OK, should I keep the 'umount' operation in cleanup() too?

Thanks,
Zorro

Quoted 33 lines

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

Quoted 8 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +7 -0
+}
+
+struct test_cases {
+	void (*tfunc)(void);
+} tcases[] = {
+	{&test_newmount},
+};

Unless you plan to add more tests here, there is no point in declaring the structure with function pointers.

Quoted 4 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +4 -0
+static void run(unsigned int i)
+{
+	tcases[i].tfunc();
+}

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

Quoted 10 lines
testcases/kernel/syscalls/newmount/newmount01.c new file +10 -0
+
+static struct tst_test test = {
+	.test		= run,
+	.tcnt		= ARRAY_SIZE(tcases),
+	.setup		= setup,
+	.cleanup	= cleanup,
+	.needs_root	= 1,
+	.mntpoint	= MNTPOINT,
+	.needs_device	= 1,
+};

Otherwise it looks good.

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

Hi!

Quoted 9 lines

Sorry I can't be 100% sure what you mean at here. Do you mean as this:
--
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);

Yes, indeed. The tst_brk() calls exit() so it never returns back to the caller.

Signature · 2 lines
Cyril Hrubis
[email protected]