All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls
@ 2020-03-12 12:01 Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 01/10] tst_device: Add tst_is_mounted() and tst_is_mounted_at_tmpdir() helpers Viresh Kumar
                   ` (9 more replies)
  0 siblings, 10 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

Hello,

Here is the sixth version of these patches.  This is tested on both ARM
and X86 platforms now and no more errors are seen with it.

V5->V6:
- A new implementation of tst_is_mounted() and a new helper
  tst_is_mounted_at_tmpdir().
- Add cleanup() callback in fsconfig01.c
- Call umount() only if tst_is_mounted_at_tmpdir() passes.
- Call close() in fsopen_supported_by_kernel().
- Use /dev/foo instead of /dev/sda1

V4->V5:
- s/TBROK/TFAIL/ in run(int n) callbacks.
- Many conversions like TEST(fd = fsopen());
- A new implementation of tst_is_mounted().
- fspick.h created to take care of duplicate code.
- tmp directory not removed from code as that will be auto done anyway.
- Other minor improvements.

V3->V4:
- Only the first patch was resent after fixing git log and minor code
  modifications.

V2->V3:
- Fix errors with xfs.
- Add macros to define test names.
- Continue with multiple iteration tests on failures, instead of
  returning early.
- Set value of is_mounted in open_tree patch.
- Rename tst_ismount() and make it return 1 on success.
- Fix various formatting issues.
- Add all reviewed/ack tags.

V1->V2:
- Lots of changes, really :)
- Rebased over Zorro's work with fsmount.
- The success tests are modified to test all possible flags, attributes
  as well.
- Create tst_ismount() and fsopen_supported_by_kernel() helpers.
- Verify if mount is successful or not using tst_ismount().
- Remove min_kver and instead check if older kernels have patches
  backported or not.
- Test on multiple filesystems.
- Better handling of failures during setup/run callbacks.
- One of the patches around fsmount.h is already merged, dropped it now.
- Other minor cleanups.


Viresh Kumar (10):
  tst_device: Add tst_is_mounted() and tst_is_mounted_at_tmpdir()
    helpers
  lapi/fsmount.h: Add fsopen_supported_by_kernel()
  lapi/fsmount.h: Include "lapi/fcntl.h"
  syscalls/fsopen: New tests
  syscalls/fsconfig: New tests
  syscalls/fsmount: Improve fsmount01 test
  syscalls/fsmount: Add failure tests
  syscalls/move_mount: New tests
  syscalls/fspick: New tests
  syscalls/open_tree: New tests

 include/lapi/fsmount.h                        |  13 +-
 include/tst_device.h                          |   7 +
 lib/tst_device.c                              |  44 +++++++
 runtest/syscalls                              |  16 +++
 testcases/kernel/syscalls/fsconfig/.gitignore |   2 +
 testcases/kernel/syscalls/fsconfig/Makefile   |   6 +
 .../kernel/syscalls/fsconfig/fsconfig01.c     |  91 +++++++++++++
 .../kernel/syscalls/fsconfig/fsconfig02.c     |  99 ++++++++++++++
 testcases/kernel/syscalls/fsmount/.gitignore  |   1 +
 testcases/kernel/syscalls/fsmount/fsmount01.c | 121 +++++++++---------
 testcases/kernel/syscalls/fsmount/fsmount02.c |  80 ++++++++++++
 testcases/kernel/syscalls/fsopen/.gitignore   |   2 +
 testcases/kernel/syscalls/fsopen/Makefile     |   6 +
 testcases/kernel/syscalls/fsopen/fsopen01.c   |  80 ++++++++++++
 testcases/kernel/syscalls/fsopen/fsopen02.c   |  58 +++++++++
 testcases/kernel/syscalls/fspick/.gitignore   |   2 +
 testcases/kernel/syscalls/fspick/Makefile     |   6 +
 testcases/kernel/syscalls/fspick/fspick.h     |  60 +++++++++
 testcases/kernel/syscalls/fspick/fspick01.c   |  62 +++++++++
 testcases/kernel/syscalls/fspick/fspick02.c   |  54 ++++++++
 .../kernel/syscalls/move_mount/.gitignore     |   2 +
 testcases/kernel/syscalls/move_mount/Makefile |   6 +
 .../kernel/syscalls/move_mount/move_mount01.c |  83 ++++++++++++
 .../kernel/syscalls/move_mount/move_mount02.c |  92 +++++++++++++
 .../kernel/syscalls/open_tree/.gitignore      |   2 +
 testcases/kernel/syscalls/open_tree/Makefile  |   6 +
 .../kernel/syscalls/open_tree/open_tree01.c   | 109 ++++++++++++++++
 .../kernel/syscalls/open_tree/open_tree02.c   | 105 +++++++++++++++
 28 files changed, 1155 insertions(+), 60 deletions(-)
 create mode 100644 testcases/kernel/syscalls/fsconfig/.gitignore
 create mode 100644 testcases/kernel/syscalls/fsconfig/Makefile
 create mode 100644 testcases/kernel/syscalls/fsconfig/fsconfig01.c
 create mode 100644 testcases/kernel/syscalls/fsconfig/fsconfig02.c
 create mode 100644 testcases/kernel/syscalls/fsmount/fsmount02.c
 create mode 100644 testcases/kernel/syscalls/fsopen/.gitignore
 create mode 100644 testcases/kernel/syscalls/fsopen/Makefile
 create mode 100644 testcases/kernel/syscalls/fsopen/fsopen01.c
 create mode 100644 testcases/kernel/syscalls/fsopen/fsopen02.c
 create mode 100644 testcases/kernel/syscalls/fspick/.gitignore
 create mode 100644 testcases/kernel/syscalls/fspick/Makefile
 create mode 100644 testcases/kernel/syscalls/fspick/fspick.h
 create mode 100644 testcases/kernel/syscalls/fspick/fspick01.c
 create mode 100644 testcases/kernel/syscalls/fspick/fspick02.c
 create mode 100644 testcases/kernel/syscalls/move_mount/.gitignore
 create mode 100644 testcases/kernel/syscalls/move_mount/Makefile
 create mode 100644 testcases/kernel/syscalls/move_mount/move_mount01.c
 create mode 100644 testcases/kernel/syscalls/move_mount/move_mount02.c
 create mode 100644 testcases/kernel/syscalls/open_tree/.gitignore
 create mode 100644 testcases/kernel/syscalls/open_tree/Makefile
 create mode 100644 testcases/kernel/syscalls/open_tree/open_tree01.c
 create mode 100644 testcases/kernel/syscalls/open_tree/open_tree02.c

-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 01/10] tst_device: Add tst_is_mounted() and tst_is_mounted_at_tmpdir() helpers
  2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
@ 2020-03-12 12:01 ` Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 02/10] lapi/fsmount.h: Add fsopen_supported_by_kernel() Viresh Kumar
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

This patch moves the ismount() helper added to the fsmount syscall tests
to the standard library and renames it to tst_is_mounted() and also adds
a new helper tst_is_mounted_at_tmpdir(). These helpers can be used
across different files now.

Minor modifications are also done to the helper.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 include/tst_device.h                          |  7 +++
 lib/tst_device.c                              | 44 +++++++++++++++++++
 testcases/kernel/syscalls/fsmount/fsmount01.c | 25 +----------
 3 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/include/tst_device.h b/include/tst_device.h
index 04577eb1ac55..950cfe1edcba 100644
--- a/include/tst_device.h
+++ b/include/tst_device.h
@@ -24,6 +24,13 @@ extern struct tst_device *tst_device;
  */
 int tst_umount(const char *path);
 
+/*
+ * Verifies if an earlier mount is successful or not.
+ * @path: Mount path to verify
+ */
+int tst_is_mounted(const char *path);
+int tst_is_mounted_at_tmpdir(const char *path);
+
 /*
  * Clears a first few blocks of the device. This is needed when device has
  * already been formatted with a filesystems, subset of mkfs.foo utils aborts
diff --git a/lib/tst_device.c b/lib/tst_device.c
index 8b5459def1cb..a703512d2aeb 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -386,6 +386,50 @@ int tst_umount(const char *path)
 	return -1;
 }
 
+int tst_is_mounted(const char *path)
+{
+	char line[PATH_MAX];
+	FILE *file;
+	int ret = 0;
+
+	file = SAFE_FOPEN(NULL, "/proc/mounts", "r");
+
+	while (fgets(line, sizeof(line), file)) {
+		if (strstr(line, path) != NULL) {
+			ret = 1;
+			break;
+		}
+	}
+
+	SAFE_FCLOSE(NULL, file);
+
+	if (!ret)
+		tst_resm(TINFO, "No device is mounted at %s", path);
+
+	return ret;
+}
+
+int tst_is_mounted_at_tmpdir(const char *path)
+{
+	char cdir[PATH_MAX], mpath[PATH_MAX];
+	int ret;
+
+	if (!getcwd(cdir, PATH_MAX)) {
+		tst_resm(TWARN | TERRNO, "Failed to find current directory");
+		return 0;
+	}
+
+	ret = snprintf(mpath, PATH_MAX, "%s/%s", cdir, path);
+	if (ret < 0 || ret >= PATH_MAX) {
+		tst_resm(TWARN | TERRNO,
+			 "snprintf() should have returned %d instead of %d",
+			 PATH_MAX, ret);
+		return 0;
+	}
+
+	return tst_is_mounted(mpath);
+}
+
 int find_stat_file(const char *dev, char *path, size_t path_len)
 {
 	const char *devname = strrchr(dev, '/') + 1;
diff --git a/testcases/kernel/syscalls/fsmount/fsmount01.c b/testcases/kernel/syscalls/fsmount/fsmount01.c
index 83185b48aedd..530a794647c1 100644
--- a/testcases/kernel/syscalls/fsmount/fsmount01.c
+++ b/testcases/kernel/syscalls/fsmount/fsmount01.c
@@ -12,30 +12,10 @@
 #include "tst_test.h"
 #include "lapi/fcntl.h"
 #include "lapi/fsmount.h"
-#include "tst_safe_stdio.h"
 
-#define LINELENGTH 256
 #define MNTPOINT "newmount_point"
 static int sfd, mfd, is_mounted;
 
-static int ismount(char *mntpoint)
-{
-	int ret = 0;
-	FILE *file;
-	char line[LINELENGTH];
-
-	file = SAFE_FOPEN("/proc/mounts", "r");
-
-	while (fgets(line, sizeof(line), file)) {
-		if (strstr(line, mntpoint) != NULL) {
-			ret = 1;
-			break;
-		}
-	}
-	SAFE_FCLOSE(file);
-	return ret;
-}
-
 static void cleanup(void)
 {
 	if (is_mounted)
@@ -76,12 +56,9 @@ static void test_fsmount(void)
 	tst_res(TPASS, "move_mount() attached to the mount point");
 	SAFE_CLOSE(mfd);
 
-	if (ismount(MNTPOINT)) {
-		tst_res(TPASS, "device mounted");
+	if (tst_is_mounted_at_tmpdir(MNTPOINT)) {
 		SAFE_UMOUNT(MNTPOINT);
 		is_mounted = 0;
-	} else {
-		tst_res(TFAIL, "device not mounted");
 	}
 }
 
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 02/10] lapi/fsmount.h: Add fsopen_supported_by_kernel()
  2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 01/10] tst_device: Add tst_is_mounted() and tst_is_mounted_at_tmpdir() helpers Viresh Kumar
@ 2020-03-12 12:01 ` Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 03/10] lapi/fsmount.h: Include "lapi/fcntl.h" Viresh Kumar
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

Add a helper to check if the fsmount() related syscalls are supported by
the kernel or not.

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Acked-by: Li Wang <liwang@redhat.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 include/lapi/fsmount.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/lapi/fsmount.h b/include/lapi/fsmount.h
index 87f2f229c371..94adec2fb609 100644
--- a/include/lapi/fsmount.h
+++ b/include/lapi/fsmount.h
@@ -130,5 +130,16 @@ enum fsconfig_command {
 
 #endif /* OPEN_TREE_CLONE */
 
+void fsopen_supported_by_kernel(void)
+{
+	if ((tst_kvercmp(5, 2, 0)) < 0) {
+		/* Check if the syscall is backported on an older kernel */
+		TEST(syscall(__NR_fsopen, NULL, 0));
+		if (TST_RET != -1)
+			SAFE_CLOSE(TST_RET);
+		else if (TST_ERR == ENOSYS)
+			tst_brk(TCONF, "Test not supported on kernel version < v5.2");
+	}
+}
 
 #endif /* FSMOUNT_H__ */
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 03/10] lapi/fsmount.h: Include "lapi/fcntl.h"
  2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 01/10] tst_device: Add tst_is_mounted() and tst_is_mounted_at_tmpdir() helpers Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 02/10] lapi/fsmount.h: Add fsopen_supported_by_kernel() Viresh Kumar
@ 2020-03-12 12:01 ` Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 04/10] syscalls/fsopen: New tests Viresh Kumar
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

All the files that include (and that will include it in future) are most
probably going to need the definitions from "lapi/fcntl.h", include it
directly instead of <fcntl.h>, which will break it for old RHL distros.

Acked-by: Petr Vorel <pvorel@suse.cz>
Acked-by: Li Wang <liwang@redhat.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 include/lapi/fsmount.h                        | 2 +-
 testcases/kernel/syscalls/fsmount/fsmount01.c | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/lapi/fsmount.h b/include/lapi/fsmount.h
index 94adec2fb609..09a2c1611866 100644
--- a/include/lapi/fsmount.h
+++ b/include/lapi/fsmount.h
@@ -7,12 +7,12 @@
 #ifndef FSMOUNT_H__
 #define FSMOUNT_H__
 
-#include <fcntl.h>
 #include <sys/mount.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
 
 #include "config.h"
+#include "lapi/fcntl.h"
 #include "lapi/syscalls.h"
 
 #ifndef HAVE_FSOPEN
diff --git a/testcases/kernel/syscalls/fsmount/fsmount01.c b/testcases/kernel/syscalls/fsmount/fsmount01.c
index 530a794647c1..43337e22e224 100644
--- a/testcases/kernel/syscalls/fsmount/fsmount01.c
+++ b/testcases/kernel/syscalls/fsmount/fsmount01.c
@@ -10,7 +10,6 @@
 #include <sys/mount.h>
 
 #include "tst_test.h"
-#include "lapi/fcntl.h"
 #include "lapi/fsmount.h"
 
 #define MNTPOINT "newmount_point"
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 04/10] syscalls/fsopen: New tests
  2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
                   ` (2 preceding siblings ...)
  2020-03-12 12:01 ` [LTP] [PATCH V6 03/10] lapi/fsmount.h: Include "lapi/fcntl.h" Viresh Kumar
@ 2020-03-12 12:01 ` Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 05/10] syscalls/fsconfig: " Viresh Kumar
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

Add tests to check working of fsopen() syscall.

Acked-by: Li Wang <liwang@redhat.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 runtest/syscalls                            |  3 +
 testcases/kernel/syscalls/fsopen/.gitignore |  2 +
 testcases/kernel/syscalls/fsopen/Makefile   |  6 ++
 testcases/kernel/syscalls/fsopen/fsopen01.c | 80 +++++++++++++++++++++
 testcases/kernel/syscalls/fsopen/fsopen02.c | 58 +++++++++++++++
 5 files changed, 149 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fsopen/.gitignore
 create mode 100644 testcases/kernel/syscalls/fsopen/Makefile
 create mode 100644 testcases/kernel/syscalls/fsopen/fsopen01.c
 create mode 100644 testcases/kernel/syscalls/fsopen/fsopen02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 30ea8be21ec1..ce752f12ec55 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -344,6 +344,9 @@ fremovexattr02 fremovexattr02
 
 fsmount01 fsmount01
 
+fsopen01 fsopen01
+fsopen02 fsopen02
+
 fstat02 fstat02
 fstat02_64 fstat02_64
 fstat03 fstat03
diff --git a/testcases/kernel/syscalls/fsopen/.gitignore b/testcases/kernel/syscalls/fsopen/.gitignore
new file mode 100644
index 000000000000..5da868621883
--- /dev/null
+++ b/testcases/kernel/syscalls/fsopen/.gitignore
@@ -0,0 +1,2 @@
+/fsopen01
+/fsopen02
diff --git a/testcases/kernel/syscalls/fsopen/Makefile b/testcases/kernel/syscalls/fsopen/Makefile
new file mode 100644
index 000000000000..5ea7d67db123
--- /dev/null
+++ b/testcases/kernel/syscalls/fsopen/Makefile
@@ -0,0 +1,6 @@
+# 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/fsopen/fsopen01.c b/testcases/kernel/syscalls/fsopen/fsopen01.c
new file mode 100644
index 000000000000..d486361dcf01
--- /dev/null
+++ b/testcases/kernel/syscalls/fsopen/fsopen01.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic fsopen() test which tries to configure and mount the filesystem as
+ * well.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+#define MNTPOINT	"mntpoint"
+
+#define TCASE_ENTRY(_flags)	{.name = "Flag " #_flags, .flags = _flags}
+
+static struct tcase {
+	char *name;
+	unsigned int flags;
+} tcases[] = {
+	TCASE_ENTRY(0),
+	TCASE_ENTRY(FSOPEN_CLOEXEC),
+};
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int fd, fsmfd;
+
+	TEST(fd = fsopen(tst_device->fs_type, tc->flags));
+	if (fd == -1) {
+		tst_res(TFAIL | TERRNO, "fsopen() failed");
+		return;
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		goto out;
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		goto out;
+	}
+
+	TEST(fsmfd = fsmount(fd, 0, 0));
+	if (fsmfd == -1) {
+		tst_res(TFAIL | TERRNO, "fsmount() failed");
+		goto out;
+	}
+
+	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
+			MOVE_MOUNT_F_EMPTY_PATH));
+
+	SAFE_CLOSE(fsmfd);
+
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TERRNO, "move_mount() failed");
+		goto out;
+	}
+
+	if (tst_is_mounted_at_tmpdir(MNTPOINT)) {
+		SAFE_UMOUNT(MNTPOINT);
+		tst_res(TPASS, "%s: fsopen() passed", tc->name);
+	}
+
+out:
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = fsopen_supported_by_kernel,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
diff --git a/testcases/kernel/syscalls/fsopen/fsopen02.c b/testcases/kernel/syscalls/fsopen/fsopen02.c
new file mode 100644
index 000000000000..3f287bf2962b
--- /dev/null
+++ b/testcases/kernel/syscalls/fsopen/fsopen02.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic fsopen() failure tests.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+const char *invalid_fs = "invalid";
+const char *valid_fs;
+
+static struct tcase {
+	char *name;
+	const char **fs;
+	unsigned int flags;
+	int exp_errno;
+} tcases[] = {
+	{"invalid-fs", &invalid_fs, 0, ENODEV},
+	{"invalid-flags", &valid_fs, 0x10, EINVAL},
+};
+
+static void setup(void)
+{
+	fsopen_supported_by_kernel();
+
+	valid_fs = tst_device->fs_type;
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(fsopen(*tc->fs, tc->flags));
+
+	if (TST_RET != -1) {
+		SAFE_CLOSE(TST_RET);
+		tst_res(TFAIL, "%s: fsopen() succeeded unexpectedly (index: %d)",
+			tc->name, n);
+		return;
+	}
+
+	if (tc->exp_errno != TST_ERR) {
+		tst_res(TFAIL | TTERRNO, "%s: fsopen() should fail with %s",
+			tc->name, tst_strerrno(tc->exp_errno));
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "%s: fsopen() failed as expected", tc->name);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_device = 1,
+};
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 05/10] syscalls/fsconfig: New tests
  2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
                   ` (3 preceding siblings ...)
  2020-03-12 12:01 ` [LTP] [PATCH V6 04/10] syscalls/fsopen: New tests Viresh Kumar
@ 2020-03-12 12:01 ` Viresh Kumar
  2020-03-12 19:10   ` Cyril Hrubis
  2020-03-17 21:33   ` Petr Vorel
  2020-03-12 12:01 ` [LTP] [PATCH V6 06/10] syscalls/fsmount: Improve fsmount01 test Viresh Kumar
                   ` (4 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

Add tests to check working of fsconfig() syscall.

Acked-by: Li Wang <liwang@redhat.com>
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 runtest/syscalls                              |  3 +
 testcases/kernel/syscalls/fsconfig/.gitignore |  2 +
 testcases/kernel/syscalls/fsconfig/Makefile   |  6 ++
 .../kernel/syscalls/fsconfig/fsconfig01.c     | 91 +++++++++++++++++
 .../kernel/syscalls/fsconfig/fsconfig02.c     | 99 +++++++++++++++++++
 5 files changed, 201 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fsconfig/.gitignore
 create mode 100644 testcases/kernel/syscalls/fsconfig/Makefile
 create mode 100644 testcases/kernel/syscalls/fsconfig/fsconfig01.c
 create mode 100644 testcases/kernel/syscalls/fsconfig/fsconfig02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index ce752f12ec55..72e59059f98a 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -342,6 +342,9 @@ fpathconf01 fpathconf01
 fremovexattr01 fremovexattr01
 fremovexattr02 fremovexattr02
 
+fsconfig01 fsconfig01
+fsconfig02 fsconfig02
+
 fsmount01 fsmount01
 
 fsopen01 fsopen01
diff --git a/testcases/kernel/syscalls/fsconfig/.gitignore b/testcases/kernel/syscalls/fsconfig/.gitignore
new file mode 100644
index 000000000000..2bc54b82751b
--- /dev/null
+++ b/testcases/kernel/syscalls/fsconfig/.gitignore
@@ -0,0 +1,2 @@
+/fsconfig01
+/fsconfig02
diff --git a/testcases/kernel/syscalls/fsconfig/Makefile b/testcases/kernel/syscalls/fsconfig/Makefile
new file mode 100644
index 000000000000..5ea7d67db123
--- /dev/null
+++ b/testcases/kernel/syscalls/fsconfig/Makefile
@@ -0,0 +1,6 @@
+# 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/fsconfig/fsconfig01.c b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
new file mode 100644
index 000000000000..d05350ce214e
--- /dev/null
+++ b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic fsconfig() test which tries to configure and mount the filesystem as
+ * well.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+#define MNTPOINT	"mntpoint"
+
+static int fd;
+
+static void cleanup(void)
+{
+	if (fd != -1)
+		SAFE_CLOSE(fd);
+}
+
+static void run(void)
+{
+	int fsmfd;
+
+	TEST(fd = fsopen(tst_device->fs_type, 0));
+	if (fd == -1)
+		tst_brk(TBROK | TERRNO, "fsopen() failed");
+
+	TEST(fsconfig(fd, FSCONFIG_SET_FLAG, "rw", NULL, 0));
+	if (TST_RET == -1)
+		tst_brk(TFAIL | TERRNO, "fsconfig() failed");
+
+	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET == -1)
+		tst_brk(TFAIL | TERRNO, "fsconfig() failed");
+
+	TEST(fsconfig(fd, FSCONFIG_SET_PATH, "sync", tst_device->dev, 0));
+	if (TST_RET == -1) {
+		if (TST_ERR == EOPNOTSUPP)
+			tst_res(TCONF, "fsconfig(): FSCONFIG_SET_PATH not supported");
+		else
+			tst_brk(TFAIL | TERRNO, "fsconfig() failed");
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_SET_PATH_EMPTY, "sync", tst_device->dev, 0));
+	if (TST_RET == -1) {
+		if (TST_ERR == EOPNOTSUPP)
+			tst_res(TCONF, "fsconfig(): FSCONFIG_SET_PATH_EMPTY not supported");
+		else
+			tst_brk(TFAIL | TERRNO, "fsconfig() failed");
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_SET_FD, "sync", NULL, 0));
+	if (TST_RET == -1) {
+		if (TST_ERR == EOPNOTSUPP)
+			tst_res(TCONF, "fsconfig(): FSCONFIG_SET_FD not supported");
+		else
+			tst_brk(TFAIL | TERRNO, "fsconfig() failed");
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET == -1)
+		tst_brk(TFAIL | TERRNO, "fsconfig() failed");
+
+	TEST(fsmfd = fsmount(fd, 0, 0));
+	if (fsmfd == -1)
+		tst_brk(TBROK | TERRNO, "fsmount() failed");
+
+	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
+			MOVE_MOUNT_F_EMPTY_PATH));
+	SAFE_CLOSE(fsmfd);
+
+	if (TST_RET == -1)
+		tst_brk(TBROK | TERRNO, "move_mount() failed");
+
+	if (tst_is_mounted_at_tmpdir(MNTPOINT)) {
+		SAFE_UMOUNT(MNTPOINT);
+		tst_res(TPASS, "fsconfig() passed");
+	}
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = fsopen_supported_by_kernel,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig02.c b/testcases/kernel/syscalls/fsconfig/fsconfig02.c
new file mode 100644
index 000000000000..b07a5f3ab82f
--- /dev/null
+++ b/testcases/kernel/syscalls/fsconfig/fsconfig02.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic fsconfig() failure tests.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+static int fd = -1, temp_fd = -1, invalid_fd = -1;
+static int aux_0 = 0, aux_1 = 1, aux_fdcwd = AT_FDCWD, aux_minus1 = -1;
+
+static struct tcase {
+	char *name;
+	int *fd;
+	unsigned int cmd;
+	const char *key;
+	const void *value;
+	int *aux;
+	int exp_errno;
+} tcases[] = {
+	{"invalid-fd", &invalid_fd, FSCONFIG_SET_FLAG, "user_xattr", NULL, &aux_0, EINVAL},
+	{"invalid-cmd", &fd, 100, "rw", NULL, &aux_0, EOPNOTSUPP},
+	{"set-flag-key", &fd, FSCONFIG_SET_FLAG, NULL, NULL, &aux_0, EINVAL},
+	{"set-flag-value", &fd, FSCONFIG_SET_FLAG, "rw", "foo", &aux_0, EINVAL},
+	{"set-flag-aux", &fd, FSCONFIG_SET_FLAG, "rw", NULL, &aux_1, EINVAL},
+	{"set-string-key", &fd, FSCONFIG_SET_STRING, NULL, "#grand.central.org:root.cell.", &aux_0, EINVAL},
+	{"set-string-value", &fd, FSCONFIG_SET_STRING, "source", NULL, &aux_0, EINVAL},
+	{"set-string-aux", &fd, FSCONFIG_SET_STRING, "source", "#grand.central.org:root.cell.", &aux_1, EINVAL},
+	{"set-binary-key", &fd, FSCONFIG_SET_BINARY, NULL, "foo", &aux_1, EINVAL},
+	{"set-binary-value", &fd, FSCONFIG_SET_BINARY, "sync", NULL, &aux_1, EINVAL},
+	{"set-binary-aux", &fd, FSCONFIG_SET_BINARY, "sync", "foo", &aux_0, EINVAL},
+	{"set-path-key", &fd, FSCONFIG_SET_PATH, NULL, "/dev/foo", &aux_fdcwd, EINVAL},
+	{"set-path-value", &fd, FSCONFIG_SET_PATH, "sync", NULL, &aux_fdcwd, EINVAL},
+	{"set-path-aux", &fd, FSCONFIG_SET_PATH, "sync", "/dev/foo", &aux_minus1, EINVAL},
+	{"set-path-empty-key", &fd, FSCONFIG_SET_PATH_EMPTY, NULL, "/dev/foo", &aux_fdcwd, EINVAL},
+	{"set-path-empty-value", &fd, FSCONFIG_SET_PATH_EMPTY, "sync", NULL, &aux_fdcwd, EINVAL},
+	{"set-path-empty-aux", &fd, FSCONFIG_SET_PATH_EMPTY, "sync", "/dev/foo", &aux_minus1, EINVAL},
+	{"set-fd-key", &fd, FSCONFIG_SET_FD, NULL, NULL, &temp_fd, EINVAL},
+	{"set-fd-value", &fd, FSCONFIG_SET_FD, "sync", "foo", &temp_fd, EINVAL},
+	{"set-fd-aux", &fd, FSCONFIG_SET_FD, "sync", NULL, &aux_minus1, EINVAL},
+	{"cmd-create-key", &fd, FSCONFIG_CMD_CREATE, "foo", NULL, &aux_0, EINVAL},
+	{"cmd-create-value", &fd, FSCONFIG_CMD_CREATE, NULL, "foo", &aux_0, EINVAL},
+	{"cmd-create-aux", &fd, FSCONFIG_CMD_CREATE, NULL, NULL, &aux_1, EINVAL},
+	{"cmd-reconfigure-key", &fd, FSCONFIG_CMD_RECONFIGURE, "foo", NULL, &aux_0, EINVAL},
+	{"cmd-reconfigure-value", &fd, FSCONFIG_CMD_RECONFIGURE, NULL, "foo", &aux_0, EINVAL},
+	{"cmd-reconfigure-aux", &fd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, &aux_1, EINVAL},
+};
+
+static void setup(void)
+{
+	fsopen_supported_by_kernel();
+
+	TEST(fd = fsopen(tst_device->fs_type, 0));
+	if (fd == -1)
+		tst_brk(TBROK | TERRNO, "fsopen() failed");
+
+	temp_fd = open("testfile", O_RDWR | O_CREAT, 01444);
+	if (temp_fd == -1)
+		tst_brk(TBROK, "Can't obtain temp_fd, open() failed");
+}
+
+static void cleanup(void)
+{
+	if (temp_fd != -1)
+		SAFE_CLOSE(temp_fd);
+	if (fd != -1)
+		SAFE_CLOSE(fd);
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(fsconfig(*tc->fd, tc->cmd, tc->key, tc->value, *tc->aux));
+
+	if (TST_RET != -1) {
+		tst_res(TFAIL, "%s: fsconfig() succeeded unexpectedly (index: %d)",
+			tc->name, n);
+		return;
+	}
+
+	if (tc->exp_errno != TST_ERR) {
+		tst_res(TFAIL | TTERRNO, "%s: fsconfig() should fail with %s",
+			tc->name, tst_strerrno(tc->exp_errno));
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "%s: fsconfig() failed as expected", tc->name);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.needs_device = 1,
+};
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 06/10] syscalls/fsmount: Improve fsmount01 test
  2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
                   ` (4 preceding siblings ...)
  2020-03-12 12:01 ` [LTP] [PATCH V6 05/10] syscalls/fsconfig: " Viresh Kumar
@ 2020-03-12 12:01 ` Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 07/10] syscalls/fsmount: Add failure tests Viresh Kumar
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

This patch updates the fsmount01.c file to make it look similar to all
other fsmount related syscall tests and here is the list of all changes:

- Test all fsmount flags and mount attributes
- Remove extra PASS messages as all we want to test here is fsmount()
  and not other syscalls.
- On the same lines, print TFAIL for fsmount() syscall and TBROK for
  other calls.
- close sfd on failures
- Make the file look similar to other fsmount related tests
- General cleanup

Acked-by: Li Wang <liwang@redhat.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 testcases/kernel/syscalls/fsmount/fsmount01.c | 99 ++++++++++++-------
 1 file changed, 63 insertions(+), 36 deletions(-)

diff --git a/testcases/kernel/syscalls/fsmount/fsmount01.c b/testcases/kernel/syscalls/fsmount/fsmount01.c
index 43337e22e224..34d9365d4680 100644
--- a/testcases/kernel/syscalls/fsmount/fsmount01.c
+++ b/testcases/kernel/syscalls/fsmount/fsmount01.c
@@ -3,67 +3,94 @@
  * Copyright (C) 2020 Red Hat, Inc.  All rights reserved.
  * Author: Zorro Lang <zlang@redhat.com>
  *
- * Use new mount API from v5.2 (fsopen(), fsconfig(), fsmount(), move_mount())
- * to mount a filesystem without any specified mount options.
+ * Basic fsmount() test.
  */
 
-#include <sys/mount.h>
-
 #include "tst_test.h"
 #include "lapi/fsmount.h"
 
-#define MNTPOINT "newmount_point"
-static int sfd, mfd, is_mounted;
+#define MNTPOINT	"mntpoint"
 
-static void cleanup(void)
-{
-	if (is_mounted)
-		SAFE_UMOUNT(MNTPOINT);
-}
+#define TCASE_ENTRY(_flags, _attrs)	{.name = "Flag " #_flags ", Attr " #_attrs, .flags = _flags, .attrs = _attrs}
 
-static void test_fsmount(void)
+static struct tcase {
+	char *name;
+	unsigned int flags;
+	unsigned int attrs;
+} tcases[] = {
+	TCASE_ENTRY(0, MOUNT_ATTR_RDONLY),
+	TCASE_ENTRY(0, MOUNT_ATTR_NOSUID),
+	TCASE_ENTRY(0, MOUNT_ATTR_NODEV),
+	TCASE_ENTRY(0, MOUNT_ATTR_NOEXEC),
+	TCASE_ENTRY(0, MOUNT_ATTR_RELATIME),
+	TCASE_ENTRY(0, MOUNT_ATTR_NOATIME),
+	TCASE_ENTRY(0, MOUNT_ATTR_STRICTATIME),
+	TCASE_ENTRY(0, MOUNT_ATTR_NODIRATIME),
+	TCASE_ENTRY(FSMOUNT_CLOEXEC, MOUNT_ATTR_RDONLY),
+	TCASE_ENTRY(FSMOUNT_CLOEXEC, MOUNT_ATTR_NOSUID),
+	TCASE_ENTRY(FSMOUNT_CLOEXEC, MOUNT_ATTR_NODEV),
+	TCASE_ENTRY(FSMOUNT_CLOEXEC, MOUNT_ATTR_NOEXEC),
+	TCASE_ENTRY(FSMOUNT_CLOEXEC, MOUNT_ATTR_RELATIME),
+	TCASE_ENTRY(FSMOUNT_CLOEXEC, MOUNT_ATTR_NOATIME),
+	TCASE_ENTRY(FSMOUNT_CLOEXEC, MOUNT_ATTR_STRICTATIME),
+	TCASE_ENTRY(FSMOUNT_CLOEXEC, MOUNT_ATTR_NODIRATIME),
+};
+
+static void run(unsigned int n)
 {
-	TEST(fsopen(tst_device->fs_type, FSOPEN_CLOEXEC));
-	if (TST_RET < 0)
-		tst_brk(TBROK | TTERRNO, "fsopen() on %s failed", tst_device->fs_type);
-	sfd = TST_RET;
-	tst_res(TPASS, "fsopen() on %s", tst_device->fs_type);
+	struct tcase *tc = &tcases[n];
+	int sfd, mfd;
+
+	TEST(sfd = fsopen(tst_device->fs_type, FSOPEN_CLOEXEC));
+	if (sfd == -1) {
+		tst_res(TFAIL | TTERRNO, "fsopen() on %s failed",
+			tst_device->fs_type);
+		return;
+	}
 
 	TEST(fsconfig(sfd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
-	if (TST_RET < 0)
-		tst_brk(TBROK | TTERRNO,
+	if (TST_RET == -1) {
+		SAFE_CLOSE(sfd);
+		tst_res(TFAIL | TTERRNO,
 			"fsconfig() failed to set source to %s", tst_device->dev);
-	tst_res(TPASS, "fsconfig() set source to %s", tst_device->dev);
-
+		return;
+	}
 
 	TEST(fsconfig(sfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
-	if (TST_RET < 0)
-		tst_brk(TBROK | TTERRNO, "fsconfig() created superblock");
-	tst_res(TPASS, "fsconfig() created superblock");
+	if (TST_RET == -1) {
+		SAFE_CLOSE(sfd);
+		tst_res(TFAIL | TTERRNO, "fsconfig() created superblock");
+		return;
+	}
 
-	TEST(fsmount(sfd, FSMOUNT_CLOEXEC, 0));
-	if (TST_RET < 0)
-		tst_brk(TBROK | TTERRNO, "fsmount() failed to create a mount object");
-	mfd = TST_RET;
-	tst_res(TPASS, "fsmount() created a mount object");
+	TEST(mfd = fsmount(sfd, tc->flags, tc->attrs));
 	SAFE_CLOSE(sfd);
 
+	if (mfd == -1) {
+		tst_res(TFAIL | TTERRNO,
+			"fsmount() failed to create a mount object");
+		return;
+	}
+
 	TEST(move_mount(mfd, "", AT_FDCWD, MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH));
-	if (TST_RET < 0)
-		tst_brk(TBROK | TTERRNO, "move_mount() failed to attach to the mount point");
-	is_mounted = 1;
-	tst_res(TPASS, "move_mount() attached to the mount point");
 	SAFE_CLOSE(mfd);
 
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO,
+			"move_mount() failed to attach to the mount point");
+		return;
+	}
+
 	if (tst_is_mounted_at_tmpdir(MNTPOINT)) {
 		SAFE_UMOUNT(MNTPOINT);
-		is_mounted = 0;
+		tst_res(TPASS, "%s: fsmount() passed", tc->name);
 	}
 }
 
 static struct tst_test test = {
-	.test_all = test_fsmount,
-	.cleanup = cleanup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = fsopen_supported_by_kernel,
 	.needs_root = 1,
 	.mntpoint = MNTPOINT,
 	.format_device = 1,
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 07/10] syscalls/fsmount: Add failure tests
  2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
                   ` (5 preceding siblings ...)
  2020-03-12 12:01 ` [LTP] [PATCH V6 06/10] syscalls/fsmount: Improve fsmount01 test Viresh Kumar
@ 2020-03-12 12:01 ` Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 08/10] syscalls/move_mount: New tests Viresh Kumar
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

This adds fsmount02.c tests to verify all the errors returned on
failures.

Acked-by: Li Wang <liwang@redhat.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 runtest/syscalls                              |  1 +
 testcases/kernel/syscalls/fsmount/.gitignore  |  1 +
 testcases/kernel/syscalls/fsmount/fsmount02.c | 80 +++++++++++++++++++
 3 files changed, 82 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fsmount/fsmount02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 72e59059f98a..41d824562dde 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -346,6 +346,7 @@ fsconfig01 fsconfig01
 fsconfig02 fsconfig02
 
 fsmount01 fsmount01
+fsmount02 fsmount02
 
 fsopen01 fsopen01
 fsopen02 fsopen02
diff --git a/testcases/kernel/syscalls/fsmount/.gitignore b/testcases/kernel/syscalls/fsmount/.gitignore
index e2f01ea17a40..7b77c5e33ee6 100644
--- a/testcases/kernel/syscalls/fsmount/.gitignore
+++ b/testcases/kernel/syscalls/fsmount/.gitignore
@@ -1 +1,2 @@
 /fsmount01
+/fsmount02
diff --git a/testcases/kernel/syscalls/fsmount/fsmount02.c b/testcases/kernel/syscalls/fsmount/fsmount02.c
new file mode 100644
index 000000000000..e3419200961c
--- /dev/null
+++ b/testcases/kernel/syscalls/fsmount/fsmount02.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic fsmount() failure tests.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+int fd = -1, invalid_fd = -1;
+
+#define MNTPOINT	"mntpoint"
+
+static struct tcase {
+	char *name;
+	int *fd;
+	unsigned int flags;
+	unsigned int mount_attrs;
+	int exp_errno;
+} tcases[] = {
+	{"invalid-fd", &invalid_fd, FSMOUNT_CLOEXEC, 0, EBADF},
+	{"invalid-flags", &fd, 0x02, 0, EINVAL},
+	{"invalid-attrs", &fd, FSMOUNT_CLOEXEC, 0x100, EINVAL},
+};
+
+static void cleanup(void)
+{
+	if (fd != -1)
+		SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+	fsopen_supported_by_kernel();
+
+	TEST(fd = fsopen(tst_device->fs_type, 0));
+	if (fd == -1)
+		tst_brk(TBROK | TERRNO, "fsopen() failed");
+
+	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TERRNO, "fsconfig() failed");
+
+	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TERRNO, "fsconfig() failed");
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(fsmount(*tc->fd, tc->flags, tc->mount_attrs));
+	if (TST_RET != -1) {
+		SAFE_CLOSE(TST_RET);
+		tst_res(TFAIL, "%s: fsmount() succeeded unexpectedly (index: %d)",
+			tc->name, n);
+		return;
+	}
+
+	if (tc->exp_errno != TST_ERR) {
+		tst_res(TFAIL | TTERRNO, "%s: fsmount() should fail with %s",
+			tc->name, tst_strerrno(tc->exp_errno));
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "%s: fsmount() failed as expected", tc->name);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.format_device = 1,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 08/10] syscalls/move_mount: New tests
  2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
                   ` (6 preceding siblings ...)
  2020-03-12 12:01 ` [LTP] [PATCH V6 07/10] syscalls/fsmount: Add failure tests Viresh Kumar
@ 2020-03-12 12:01 ` Viresh Kumar
  2020-03-12 19:07   ` Cyril Hrubis
  2020-03-12 12:01 ` [LTP] [PATCH V6 09/10] syscalls/fspick: " Viresh Kumar
  2020-03-12 12:01 ` [LTP] [PATCH V6 10/10] syscalls/open_tree: " Viresh Kumar
  9 siblings, 1 reply; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

Add tests to check working of move_mount() syscall.

Acked-by: Li Wang <liwang@redhat.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 runtest/syscalls                              |  3 +
 .../kernel/syscalls/move_mount/.gitignore     |  2 +
 testcases/kernel/syscalls/move_mount/Makefile |  6 ++
 .../kernel/syscalls/move_mount/move_mount01.c | 83 +++++++++++++++++
 .../kernel/syscalls/move_mount/move_mount02.c | 92 +++++++++++++++++++
 5 files changed, 186 insertions(+)
 create mode 100644 testcases/kernel/syscalls/move_mount/.gitignore
 create mode 100644 testcases/kernel/syscalls/move_mount/Makefile
 create mode 100644 testcases/kernel/syscalls/move_mount/move_mount01.c
 create mode 100644 testcases/kernel/syscalls/move_mount/move_mount02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 41d824562dde..077e724b62e4 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -734,6 +734,9 @@ mount04 mount04
 mount05 mount05
 mount06 mount06
 
+move_mount01 move_mount01
+move_mount02 move_mount02
+
 move_pages01 move_pages01
 move_pages02 move_pages02
 move_pages03 move_pages03
diff --git a/testcases/kernel/syscalls/move_mount/.gitignore b/testcases/kernel/syscalls/move_mount/.gitignore
new file mode 100644
index 000000000000..83ae40145dff
--- /dev/null
+++ b/testcases/kernel/syscalls/move_mount/.gitignore
@@ -0,0 +1,2 @@
+/move_mount01
+/move_mount02
diff --git a/testcases/kernel/syscalls/move_mount/Makefile b/testcases/kernel/syscalls/move_mount/Makefile
new file mode 100644
index 000000000000..5ea7d67db123
--- /dev/null
+++ b/testcases/kernel/syscalls/move_mount/Makefile
@@ -0,0 +1,6 @@
+# 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/move_mount/move_mount01.c b/testcases/kernel/syscalls/move_mount/move_mount01.c
new file mode 100644
index 000000000000..abd73d132491
--- /dev/null
+++ b/testcases/kernel/syscalls/move_mount/move_mount01.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic move_mount() test.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+#define MNTPOINT	"mntpoint"
+
+#define TCASE_ENTRY(_flags)	{.name = "Flag " #_flags, .flags = _flags}
+
+static struct tcase {
+	char *name;
+	unsigned int flags;
+} tcases[] = {
+	TCASE_ENTRY(MOVE_MOUNT_F_SYMLINKS),
+	TCASE_ENTRY(MOVE_MOUNT_F_AUTOMOUNTS),
+	TCASE_ENTRY(MOVE_MOUNT_F_EMPTY_PATH),
+	TCASE_ENTRY(MOVE_MOUNT_T_SYMLINKS),
+	TCASE_ENTRY(MOVE_MOUNT_T_AUTOMOUNTS),
+	TCASE_ENTRY(MOVE_MOUNT_T_EMPTY_PATH),
+};
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int fsmfd, fd;
+
+	TEST(fd = fsopen(tst_device->fs_type, 0));
+	if (fd == -1) {
+		tst_res(TFAIL | TERRNO, "fsopen() failed");
+		return;
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		return;
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		return;
+	}
+
+	TEST(fsmfd = fsmount(fd, 0, 0));
+	SAFE_CLOSE(fd);
+
+	if (fsmfd == -1) {
+		tst_res(TFAIL | TERRNO, "fsmount() failed");
+		return;
+	}
+
+	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
+			tc->flags | MOVE_MOUNT_F_EMPTY_PATH));
+	SAFE_CLOSE(fsmfd);
+
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TERRNO, "move_mount() failed");
+		return;
+	}
+
+	if (tst_is_mounted_at_tmpdir(MNTPOINT)) {
+		SAFE_UMOUNT(MNTPOINT);
+		tst_res(TPASS, "%s: move_mount() passed", tc->name);
+	}
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = fsopen_supported_by_kernel,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
diff --git a/testcases/kernel/syscalls/move_mount/move_mount02.c b/testcases/kernel/syscalls/move_mount/move_mount02.c
new file mode 100644
index 000000000000..dfb48a1b3dc6
--- /dev/null
+++ b/testcases/kernel/syscalls/move_mount/move_mount02.c
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic move_mount() failure tests.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+#define MNTPOINT	"mntpoint"
+
+int invalid_fd = -1, fsmfd;
+
+static struct tcase {
+	char *name;
+	int *from_dirfd;
+	const char *from_pathname;
+	int to_dirfd;
+	const char *to_pathname;
+	unsigned int flags;
+	int exp_errno;
+} tcases[] = {
+	{"invalid-from-fd", &invalid_fd, "", AT_FDCWD, MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH, EBADF},
+	{"invalid-from-path", &fsmfd, "invalid", AT_FDCWD, MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH, ENOENT},
+	{"invalid-to-fd", &fsmfd, "", -1, MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH, EBADF},
+	{"invalid-to-path", &fsmfd, "", AT_FDCWD, "invalid", MOVE_MOUNT_F_EMPTY_PATH, ENOENT},
+	{"invalid-flags", &fsmfd, "", AT_FDCWD, MNTPOINT, 0x08, EINVAL},
+};
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int fd;
+
+	TEST(fd = fsopen(tst_device->fs_type, 0));
+	if (fd == -1) {
+		tst_res(TFAIL | TERRNO, "fsopen() failed");
+		return;
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		return;
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		return;
+	}
+
+	TEST(fsmfd = fsmount(fd, 0, 0));
+	SAFE_CLOSE(fd);
+
+	if (fsmfd == -1) {
+		tst_res(TFAIL | TERRNO, "fsmount() failed");
+		return;
+	}
+
+	TEST(move_mount(*tc->from_dirfd, tc->from_pathname, tc->to_dirfd,
+			tc->to_pathname, tc->flags));
+	SAFE_CLOSE(fsmfd);
+
+	if (TST_RET != -1) {
+		SAFE_UMOUNT(MNTPOINT);
+		tst_res(TFAIL, "%s: move_mount() succeeded unexpectedly (index: %d)",
+			tc->name, n);
+		return;
+	}
+
+	if (tc->exp_errno != TST_ERR) {
+		tst_res(TFAIL | TTERRNO, "%s: move_mount() should fail with %s",
+			tc->name, tst_strerrno(tc->exp_errno));
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "%s: move_mount() failed as expected", tc->name);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = fsopen_supported_by_kernel,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 09/10] syscalls/fspick: New tests
  2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
                   ` (7 preceding siblings ...)
  2020-03-12 12:01 ` [LTP] [PATCH V6 08/10] syscalls/move_mount: New tests Viresh Kumar
@ 2020-03-12 12:01 ` Viresh Kumar
  2020-03-13  7:04   ` Petr Vorel
  2020-03-13 12:35   ` Cyril Hrubis
  2020-03-12 12:01 ` [LTP] [PATCH V6 10/10] syscalls/open_tree: " Viresh Kumar
  9 siblings, 2 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

Add tests to check working of fspick() syscall.

Acked-by: Li Wang <liwang@redhat.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 runtest/syscalls                            |  3 +
 testcases/kernel/syscalls/fspick/.gitignore |  2 +
 testcases/kernel/syscalls/fspick/Makefile   |  6 ++
 testcases/kernel/syscalls/fspick/fspick.h   | 60 ++++++++++++++++++++
 testcases/kernel/syscalls/fspick/fspick01.c | 62 +++++++++++++++++++++
 testcases/kernel/syscalls/fspick/fspick02.c | 54 ++++++++++++++++++
 6 files changed, 187 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fspick/.gitignore
 create mode 100644 testcases/kernel/syscalls/fspick/Makefile
 create mode 100644 testcases/kernel/syscalls/fspick/fspick.h
 create mode 100644 testcases/kernel/syscalls/fspick/fspick01.c
 create mode 100644 testcases/kernel/syscalls/fspick/fspick02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 077e724b62e4..32f11f4bc9ab 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -351,6 +351,9 @@ fsmount02 fsmount02
 fsopen01 fsopen01
 fsopen02 fsopen02
 
+fspick01 fspick01
+fspick02 fspick02
+
 fstat02 fstat02
 fstat02_64 fstat02_64
 fstat03 fstat03
diff --git a/testcases/kernel/syscalls/fspick/.gitignore b/testcases/kernel/syscalls/fspick/.gitignore
new file mode 100644
index 000000000000..a8aa61dce18b
--- /dev/null
+++ b/testcases/kernel/syscalls/fspick/.gitignore
@@ -0,0 +1,2 @@
+/fspick01
+/fspick02
diff --git a/testcases/kernel/syscalls/fspick/Makefile b/testcases/kernel/syscalls/fspick/Makefile
new file mode 100644
index 000000000000..5ea7d67db123
--- /dev/null
+++ b/testcases/kernel/syscalls/fspick/Makefile
@@ -0,0 +1,6 @@
+# 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/fspick/fspick.h b/testcases/kernel/syscalls/fspick/fspick.h
new file mode 100644
index 000000000000..ca84269ee7a9
--- /dev/null
+++ b/testcases/kernel/syscalls/fspick/fspick.h
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef FSPICK_H__
+#define FSPICK_H__
+
+#define MNTPOINT	"mntpoint"
+
+static int ismounted;
+
+static void cleanup(void)
+{
+	if (ismounted)
+		SAFE_UMOUNT(MNTPOINT);
+}
+
+static void setup(void)
+{
+	int fd, fsmfd;
+
+	fsopen_supported_by_kernel();
+
+	TEST(fd = fsopen(tst_device->fs_type, 0));
+	if (fd == -1)
+		tst_brk(TBROK | TERRNO, "fsopen() failed");
+
+	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_brk(TBROK | TERRNO, "fsconfig() failed");
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_brk(TBROK | TERRNO, "fsconfig() failed");
+	}
+
+	TEST(fsmfd = fsmount(fd, 0, 0));
+	SAFE_CLOSE(fd);
+
+	if (fsmfd == -1)
+		tst_brk(TBROK | TERRNO, "fsmount() failed");
+
+	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
+			MOVE_MOUNT_F_EMPTY_PATH));
+	SAFE_CLOSE(fsmfd);
+
+	if (TST_RET == -1)
+		tst_brk(TBROK | TERRNO, "move_mount() failed");
+
+	if (!tst_is_mounted_at_tmpdir(MNTPOINT))
+		tst_brk(TBROK | TERRNO, "device not mounted");
+
+	ismounted = 1;
+}
+
+#endif /* FSPICK_H__ */
diff --git a/testcases/kernel/syscalls/fspick/fspick01.c b/testcases/kernel/syscalls/fspick/fspick01.c
new file mode 100644
index 000000000000..4e1daeaee14a
--- /dev/null
+++ b/testcases/kernel/syscalls/fspick/fspick01.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic fspick() test.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+#include "fspick.h"
+
+#define TCASE_ENTRY(_flags)	{.name = "Flag " #_flags, .flags = _flags}
+
+static struct tcase {
+	char *name;
+	unsigned int flags;
+} tcases[] = {
+	TCASE_ENTRY(FSPICK_CLOEXEC),
+	TCASE_ENTRY(FSPICK_SYMLINK_NOFOLLOW),
+	TCASE_ENTRY(FSPICK_NO_AUTOMOUNT),
+	TCASE_ENTRY(FSPICK_EMPTY_PATH),
+};
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int fspick_fd;
+
+	TEST(fspick_fd = fspick(AT_FDCWD, MNTPOINT, tc->flags));
+	if (fspick_fd == -1) {
+		tst_res(TFAIL | TERRNO, "fspick() failed");
+		return;
+	}
+
+	TEST(fsconfig(fspick_fd, FSCONFIG_SET_STRING, "sync", "false", 0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		goto out;
+	}
+
+	TEST(fsconfig(fspick_fd, FSCONFIG_SET_FLAG, "ro", NULL, 0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		goto out;
+	}
+
+	tst_res(TPASS, "%s: fspick() passed", tc->name);
+
+out:
+	SAFE_CLOSE(fspick_fd);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
diff --git a/testcases/kernel/syscalls/fspick/fspick02.c b/testcases/kernel/syscalls/fspick/fspick02.c
new file mode 100644
index 000000000000..dc8f153ccc48
--- /dev/null
+++ b/testcases/kernel/syscalls/fspick/fspick02.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic fspick() failure tests.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+#include "fspick.h"
+
+static struct tcase {
+	char *name;
+	int dirfd;
+	const char *pathname;
+	unsigned int flags;
+	int exp_errno;
+} tcases[] = {
+	{"invalid-fd", -1, MNTPOINT, FSPICK_NO_AUTOMOUNT | FSPICK_CLOEXEC, EBADF},
+	{"invalid-path", AT_FDCWD, "invalid", FSPICK_NO_AUTOMOUNT | FSPICK_CLOEXEC, ENOENT},
+	{"invalid-flags", AT_FDCWD, MNTPOINT, 0x10, EINVAL},
+};
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(fspick(tc->dirfd, tc->pathname, tc->flags));
+	if (TST_RET != -1) {
+		SAFE_CLOSE(TST_RET);
+		tst_res(TFAIL, "%s: fspick() succeeded unexpectedly (index: %d)",
+			tc->name, n);
+		return;
+	}
+
+	if (tc->exp_errno != TST_ERR) {
+		tst_res(TFAIL | TTERRNO, "%s: fspick() should fail with %s",
+			tc->name, tst_strerrno(tc->exp_errno));
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "%s: fspick() failed as expected", tc->name);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 10/10] syscalls/open_tree: New tests
  2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
                   ` (8 preceding siblings ...)
  2020-03-12 12:01 ` [LTP] [PATCH V6 09/10] syscalls/fspick: " Viresh Kumar
@ 2020-03-12 12:01 ` Viresh Kumar
  2020-03-13  8:48   ` Petr Vorel
  2020-03-13  9:03   ` [LTP] [PATCH V7 " Viresh Kumar
  9 siblings, 2 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-12 12:01 UTC (permalink / raw)
  To: ltp

Add tests to check working of open_tree() syscall.

Acked-by: Li Wang <liwang@redhat.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 runtest/syscalls                              |   3 +
 .../kernel/syscalls/open_tree/.gitignore      |   2 +
 testcases/kernel/syscalls/open_tree/Makefile  |   6 +
 .../kernel/syscalls/open_tree/open_tree01.c   | 109 ++++++++++++++++++
 .../kernel/syscalls/open_tree/open_tree02.c   | 105 +++++++++++++++++
 5 files changed, 225 insertions(+)
 create mode 100644 testcases/kernel/syscalls/open_tree/.gitignore
 create mode 100644 testcases/kernel/syscalls/open_tree/Makefile
 create mode 100644 testcases/kernel/syscalls/open_tree/open_tree01.c
 create mode 100644 testcases/kernel/syscalls/open_tree/open_tree02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 32f11f4bc9ab..224de8c9b609 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -847,6 +847,9 @@ openat01 openat01
 openat02 openat02
 openat03 openat03
 
+open_tree01 open_tree01
+open_tree02 open_tree02
+
 mincore01 mincore01
 mincore02 mincore02
 
diff --git a/testcases/kernel/syscalls/open_tree/.gitignore b/testcases/kernel/syscalls/open_tree/.gitignore
new file mode 100644
index 000000000000..2f732b44518e
--- /dev/null
+++ b/testcases/kernel/syscalls/open_tree/.gitignore
@@ -0,0 +1,2 @@
+/open_tree01
+/open_tree02
diff --git a/testcases/kernel/syscalls/open_tree/Makefile b/testcases/kernel/syscalls/open_tree/Makefile
new file mode 100644
index 000000000000..5ea7d67db123
--- /dev/null
+++ b/testcases/kernel/syscalls/open_tree/Makefile
@@ -0,0 +1,6 @@
+# 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/open_tree/open_tree01.c b/testcases/kernel/syscalls/open_tree/open_tree01.c
new file mode 100644
index 000000000000..d52e8c26afae
--- /dev/null
+++ b/testcases/kernel/syscalls/open_tree/open_tree01.c
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic open_tree() test.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+#define MNTPOINT	"mntpoint"
+#define OT_MNTPOINT	"ot_mntpoint"
+
+#define TCASE_ENTRY(_flags)	{.name = "Flag " #_flags, .flags = _flags}
+
+static struct tcase {
+	char *name;
+	unsigned int flags;
+} tcases[] = {
+	TCASE_ENTRY(OPEN_TREE_CLONE),
+	TCASE_ENTRY(OPEN_TREE_CLOEXEC)
+};
+
+static void setup(void)
+{
+	fsopen_supported_by_kernel();
+	SAFE_MKDIR(OT_MNTPOINT, 0777);
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int fd, fsmfd, otfd;
+
+	TEST(fd = fsopen(tst_device->fs_type, 0));
+	if (fd == -1) {
+		tst_res(TFAIL | TERRNO, "fsopen() failed");
+		return;
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		return;
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		return;
+	}
+
+	TEST(fsmfd = fsmount(fd, 0, 0));
+	SAFE_CLOSE(fd);
+
+	if (fsmfd == -1) {
+		tst_res(TFAIL | TERRNO, "fsmount() failed");
+		return;
+	}
+
+	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
+			MOVE_MOUNT_F_EMPTY_PATH));
+	SAFE_CLOSE(fsmfd);
+
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TERRNO, "move_mount() failed");
+		return;
+	}
+
+	if (!tst_is_mounted_at_tmpdir(MNTPOINT)) {
+		tst_res(TFAIL | TERRNO, "device not mounted");
+		return;
+	}
+
+	TEST(otfd = open_tree(AT_FDCWD, MNTPOINT, tc->flags | OPEN_TREE_CLONE));
+	if (otfd == -1) {
+		tst_res(TFAIL | TERRNO, "open_tree() failed");
+		goto out;
+	}
+
+	TEST(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT,
+			MOVE_MOUNT_F_EMPTY_PATH));
+	SAFE_CLOSE(otfd);
+
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TERRNO, "move_mount() failed");
+		goto out;
+	}
+
+	if (tst_is_mounted_at_tmpdir(OT_MNTPOINT)) {
+		SAFE_UMOUNT(OT_MNTPOINT);
+		tst_res(TPASS, "%s: open_tree() passed", tc->name);
+	}
+
+out:
+	SAFE_UMOUNT(MNTPOINT);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
diff --git a/testcases/kernel/syscalls/open_tree/open_tree02.c b/testcases/kernel/syscalls/open_tree/open_tree02.c
new file mode 100644
index 000000000000..6911693837e9
--- /dev/null
+++ b/testcases/kernel/syscalls/open_tree/open_tree02.c
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic open_tree() failure tests.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+#define MNTPOINT	"mntpoint"
+
+static struct tcase {
+	char *name;
+	int dirfd;
+	const char *pathname;
+	unsigned int flags;
+	int exp_errno;
+} tcases[] = {
+	{"invalid-fd", -1, MNTPOINT, OPEN_TREE_CLONE, EBADF},
+	{"invalid-path", AT_FDCWD, "invalid", OPEN_TREE_CLONE, ENOENT},
+	{"invalid-flags", AT_FDCWD, MNTPOINT, 0xFFFFFFFF, EINVAL},
+};
+
+static int ismounted;
+
+static void cleanup(void)
+{
+	if (ismounted)
+		SAFE_UMOUNT(MNTPOINT);
+}
+
+static void setup(void)
+{
+	int fd, fsmfd;
+
+	fsopen_supported_by_kernel();
+
+	TEST(fd = fsopen(tst_device->fs_type, 0));
+	if (fd == -1)
+		tst_brk(TBROK | TERRNO, "fsopen() failed");
+
+	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_brk(TBROK | TERRNO, "fsconfig() failed");
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_brk(TBROK | TERRNO, "fsconfig() failed");
+	}
+
+	TEST(fsmfd = fsmount(fd, 0, 0));
+	SAFE_CLOSE(fd);
+
+	if (fsmfd == -1)
+		tst_brk(TBROK | TERRNO, "fsmount() failed");
+
+	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
+			MOVE_MOUNT_F_EMPTY_PATH));
+	SAFE_CLOSE(fsmfd);
+
+	if (TST_RET == -1)
+		tst_brk(TBROK | TERRNO, "move_mount() failed");
+
+	if (!tst_is_mounted_at_tmpdir(MNTPOINT))
+		tst_brk(TBROK | TERRNO, "device not mounted");
+
+	ismounted = 1;
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(open_tree(tc->dirfd, tc->pathname, tc->flags));
+	if (TST_RET != -1) {
+		SAFE_CLOSE(TST_RET);
+		tst_res(TFAIL, "%s: open_tree() succeeded unexpectedly (index: %d)",
+			tc->name, n);
+		return;
+	}
+
+	if (tc->exp_errno != TST_ERR) {
+		tst_res(TFAIL | TTERRNO, "%s: open_tree() should fail with %s",
+			tc->name, tst_strerrno(tc->exp_errno));
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "%s: open_tree() failed as expected",
+		tc->name);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 08/10] syscalls/move_mount: New tests
  2020-03-12 12:01 ` [LTP] [PATCH V6 08/10] syscalls/move_mount: New tests Viresh Kumar
@ 2020-03-12 19:07   ` Cyril Hrubis
  0 siblings, 0 replies; 30+ messages in thread
From: Cyril Hrubis @ 2020-03-12 19:07 UTC (permalink / raw)
  To: ltp

Hi!
I've reviewed and pushed the patchset up to this patch, I will finish
the remaning ones tomorrow.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH V6 05/10] syscalls/fsconfig: New tests
  2020-03-12 12:01 ` [LTP] [PATCH V6 05/10] syscalls/fsconfig: " Viresh Kumar
@ 2020-03-12 19:10   ` Cyril Hrubis
  2020-03-13  4:00     ` Viresh Kumar
  2020-03-17 21:33   ` Petr Vorel
  1 sibling, 1 reply; 30+ messages in thread
From: Cyril Hrubis @ 2020-03-12 19:10 UTC (permalink / raw)
  To: ltp

Hi!
Pushed with two minor changes:

diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig01.c b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
index d05350ce2..aea6db822 100644
--- a/testcases/kernel/syscalls/fsconfig/fsconfig01.c
+++ b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
@@ -77,6 +77,8 @@ static void run(void)
                SAFE_UMOUNT(MNTPOINT);
                tst_res(TPASS, "fsconfig() passed");
        }
+
+       SAFE_CLOSE(fd);
 }

We need to close the fd here, because the test will run out of file
descriptors for large enough -i parameter, since cleanup is executed
only at the test end. Also note that SAFE_CLOSE() sets the fd to -1 so
that cleanup is no-op unless we trigger some of the tst_brk()
statements.

 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig02.c b/testcases/kernel/syscalls/fsconfig/fsconfig02.c
index b07a5f3ab..586524f14 100644
--- a/testcases/kernel/syscalls/fsconfig/fsconfig02.c
+++ b/testcases/kernel/syscalls/fsconfig/fsconfig02.c
@@ -94,6 +94,7 @@ static struct tst_test test = {
        .test = run,
        .setup = setup,
        .cleanup = cleanup,
+       .needs_tmpdir = 1,
        .needs_root = 1,
        .needs_device = 1,
 };

The test creates a file hence it has to request temporary directory.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH V6 05/10] syscalls/fsconfig: New tests
  2020-03-12 19:10   ` Cyril Hrubis
@ 2020-03-13  4:00     ` Viresh Kumar
  2020-03-13  7:22       ` Petr Vorel
  2020-03-13  8:03       ` Cyril Hrubis
  0 siblings, 2 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-13  4:00 UTC (permalink / raw)
  To: ltp

On 12-03-20, 20:10, Cyril Hrubis wrote:
> Hi!
> Pushed with two minor changes:
> 
> diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig01.c b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> index d05350ce2..aea6db822 100644
> --- a/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> +++ b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> @@ -77,6 +77,8 @@ static void run(void)
>                 SAFE_UMOUNT(MNTPOINT);
>                 tst_res(TPASS, "fsconfig() passed");
>         }
> +
> +       SAFE_CLOSE(fd);

This isn't required as cleanup() routine is taking care of it and this
is a test_all type test.

>  }
> 
> We need to close the fd here, because the test will run out of file
> descriptors for large enough -i parameter, since cleanup is executed
> only at the test end. Also note that SAFE_CLOSE() sets the fd to -1 so
> that cleanup is no-op unless we trigger some of the tst_brk()
> statements.
> 
>  static struct tst_test test = {
> diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig02.c b/testcases/kernel/syscalls/fsconfig/fsconfig02.c
> index b07a5f3ab..586524f14 100644
> --- a/testcases/kernel/syscalls/fsconfig/fsconfig02.c
> +++ b/testcases/kernel/syscalls/fsconfig/fsconfig02.c
> @@ -94,6 +94,7 @@ static struct tst_test test = {
>         .test = run,
>         .setup = setup,
>         .cleanup = cleanup,
> +       .needs_tmpdir = 1,

I probably didn't add this as we weren't mounting anything here.

>         .needs_root = 1,
>         .needs_device = 1,
>  };
> 
> The test creates a file hence it has to request temporary directory.
> 
> -- 
> Cyril Hrubis
> chrubis@suse.cz

-- 
viresh

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

* [LTP] [PATCH V6 09/10] syscalls/fspick: New tests
  2020-03-12 12:01 ` [LTP] [PATCH V6 09/10] syscalls/fspick: " Viresh Kumar
@ 2020-03-13  7:04   ` Petr Vorel
  2020-03-13 12:35   ` Cyril Hrubis
  1 sibling, 0 replies; 30+ messages in thread
From: Petr Vorel @ 2020-03-13  7:04 UTC (permalink / raw)
  To: ltp

Hi,

> Add tests to check working of fspick() syscall.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

* [LTP] [PATCH V6 05/10] syscalls/fsconfig: New tests
  2020-03-13  4:00     ` Viresh Kumar
@ 2020-03-13  7:22       ` Petr Vorel
  2020-03-13  8:03       ` Cyril Hrubis
  1 sibling, 0 replies; 30+ messages in thread
From: Petr Vorel @ 2020-03-13  7:22 UTC (permalink / raw)
  To: ltp

Hi,

> On 12-03-20, 20:10, Cyril Hrubis wrote:
> > Hi!
> > Pushed with two minor changes:

> > diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig01.c b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> > index d05350ce2..aea6db822 100644
> > --- a/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> > +++ b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> > @@ -77,6 +77,8 @@ static void run(void)
> >                 SAFE_UMOUNT(MNTPOINT);
> >                 tst_res(TPASS, "fsconfig() passed");
> >         }
> > +
> > +       SAFE_CLOSE(fd);

> This isn't required as cleanup() routine is taking care of it and this
> is a test_all type test.
+1.

> >  }

> > We need to close the fd here, because the test will run out of file
> > descriptors for large enough -i parameter, since cleanup is executed
> > only at the test end. Also note that SAFE_CLOSE() sets the fd to -1 so
> > that cleanup is no-op unless we trigger some of the tst_brk()
> > statements.

> >  static struct tst_test test = {
> > diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig02.c b/testcases/kernel/syscalls/fsconfig/fsconfig02.c
> > index b07a5f3ab..586524f14 100644
> > --- a/testcases/kernel/syscalls/fsconfig/fsconfig02.c
> > +++ b/testcases/kernel/syscalls/fsconfig/fsconfig02.c
> > @@ -94,6 +94,7 @@ static struct tst_test test = {
> >         .test = run,
> >         .setup = setup,
> >         .cleanup = cleanup,
> > +       .needs_tmpdir = 1,

> I probably didn't add this as we weren't mounting anything here.

> >         .needs_root = 1,
> >         .needs_device = 1,
> >  };

> > The test creates a file hence it has to request temporary directory.

Well, tmp dir would be created anyway due .needs_device, see lib/tst_test.c
static int needs_tmpdir(void)
{
	return tst_test->needs_tmpdir ||
	       tst_test->needs_device ||
	       tst_test->mntpoint ||
	       tst_test->resource_files ||
	       tst_test->needs_checkpoints;
}

But true it not required to be added as .needs_device implies needs_tmpdir,
see dae842774 ("Remove duplicated ".needs_tmpdir=1" when using equivalent flags").
But just a minor detail.

Kind regards,
Petr

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

* [LTP] [PATCH V6 05/10] syscalls/fsconfig: New tests
  2020-03-13  4:00     ` Viresh Kumar
  2020-03-13  7:22       ` Petr Vorel
@ 2020-03-13  8:03       ` Cyril Hrubis
  2020-03-13  8:48         ` Viresh Kumar
  1 sibling, 1 reply; 30+ messages in thread
From: Cyril Hrubis @ 2020-03-13  8:03 UTC (permalink / raw)
  To: ltp

Hi!
> > diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig01.c b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> > index d05350ce2..aea6db822 100644
> > --- a/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> > +++ b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> > @@ -77,6 +77,8 @@ static void run(void)
> >                 SAFE_UMOUNT(MNTPOINT);
> >                 tst_res(TPASS, "fsconfig() passed");
> >         }
> > +
> > +       SAFE_CLOSE(fd);
> 
> This isn't required as cleanup() routine is taking care of it and this
> is a test_all type test.

It _is_, I've tried top explain in the paragraph below, just run the
test with large enough -i, sooner or late the test will run out of file
descriptiors and then it will fail.

The key here is that the run() function can be called repeatedly but
setup() and cleanup() are called only once at the start and at the end
of the test.

> > We need to close the fd here, because the test will run out of file
> > descriptors for large enough -i parameter, since cleanup is executed
> > only at the test end. Also note that SAFE_CLOSE() sets the fd to -1 so
> > that cleanup is no-op unless we trigger some of the tst_brk()
> > statements.

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH V6 10/10] syscalls/open_tree: New tests
  2020-03-12 12:01 ` [LTP] [PATCH V6 10/10] syscalls/open_tree: " Viresh Kumar
@ 2020-03-13  8:48   ` Petr Vorel
  2020-03-13  9:03   ` [LTP] [PATCH V7 " Viresh Kumar
  1 sibling, 0 replies; 30+ messages in thread
From: Petr Vorel @ 2020-03-13  8:48 UTC (permalink / raw)
  To: ltp

Hi Viresh,

> diff --git a/testcases/kernel/syscalls/open_tree/open_tree01.c b/testcases/kernel/syscalls/open_tree/open_tree01.c
...
> +static void setup(void)
> +{
> +	fsopen_supported_by_kernel();
> +	SAFE_MKDIR(OT_MNTPOINT, 0777);
This fails, because setup (and cleanup) is run fo each filesystem. Therefore it
needs to be created just once.
safe_macros.c:172: BROK: open_tree01.c:27: mkdir(ot_mntpoint,0777) failed: EEXIST (17)

Kind regards,
Petr

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

* [LTP] [PATCH V6 05/10] syscalls/fsconfig: New tests
  2020-03-13  8:03       ` Cyril Hrubis
@ 2020-03-13  8:48         ` Viresh Kumar
  2020-03-13 12:09           ` Petr Vorel
  0 siblings, 1 reply; 30+ messages in thread
From: Viresh Kumar @ 2020-03-13  8:48 UTC (permalink / raw)
  To: ltp

On 13-03-20, 09:03, Cyril Hrubis wrote:
> Hi!
> > > diff --git a/testcases/kernel/syscalls/fsconfig/fsconfig01.c b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> > > index d05350ce2..aea6db822 100644
> > > --- a/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> > > +++ b/testcases/kernel/syscalls/fsconfig/fsconfig01.c
> > > @@ -77,6 +77,8 @@ static void run(void)
> > >                 SAFE_UMOUNT(MNTPOINT);
> > >                 tst_res(TPASS, "fsconfig() passed");
> > >         }
> > > +
> > > +       SAFE_CLOSE(fd);
> > 
> > This isn't required as cleanup() routine is taking care of it and this
> > is a test_all type test.
> 
> It _is_, I've tried top explain in the paragraph below, just run the
> test with large enough -i, sooner or late the test will run out of file
> descriptiors and then it will fail.
> 
> The key here is that the run() function can be called repeatedly but
> setup() and cleanup() are called only once at the start and at the end
> of the test.

I didn't knew about the -i option, yeah your change makes sense now :)

-- 
viresh

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

* [LTP] [PATCH V7 10/10] syscalls/open_tree: New tests
  2020-03-12 12:01 ` [LTP] [PATCH V6 10/10] syscalls/open_tree: " Viresh Kumar
  2020-03-13  8:48   ` Petr Vorel
@ 2020-03-13  9:03   ` Viresh Kumar
  2020-03-13 12:27     ` Petr Vorel
  2020-03-13 12:49     ` Cyril Hrubis
  1 sibling, 2 replies; 30+ messages in thread
From: Viresh Kumar @ 2020-03-13  9:03 UTC (permalink / raw)
  To: ltp

Add tests to check working of open_tree() syscall.

Acked-by: Li Wang <liwang@redhat.com>
Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
V6->V7:
- Remove the temporary directory from cleanup routine to avoid test
  failure.

 runtest/syscalls                              |   3 +
 .../kernel/syscalls/open_tree/.gitignore      |   2 +
 testcases/kernel/syscalls/open_tree/Makefile  |   6 +
 .../kernel/syscalls/open_tree/open_tree01.c   | 119 ++++++++++++++++++
 .../kernel/syscalls/open_tree/open_tree02.c   | 105 ++++++++++++++++
 5 files changed, 235 insertions(+)
 create mode 100644 testcases/kernel/syscalls/open_tree/.gitignore
 create mode 100644 testcases/kernel/syscalls/open_tree/Makefile
 create mode 100644 testcases/kernel/syscalls/open_tree/open_tree01.c
 create mode 100644 testcases/kernel/syscalls/open_tree/open_tree02.c

diff --git a/runtest/syscalls b/runtest/syscalls
index 32f11f4bc9ab..224de8c9b609 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -847,6 +847,9 @@ openat01 openat01
 openat02 openat02
 openat03 openat03
 
+open_tree01 open_tree01
+open_tree02 open_tree02
+
 mincore01 mincore01
 mincore02 mincore02
 
diff --git a/testcases/kernel/syscalls/open_tree/.gitignore b/testcases/kernel/syscalls/open_tree/.gitignore
new file mode 100644
index 000000000000..2f732b44518e
--- /dev/null
+++ b/testcases/kernel/syscalls/open_tree/.gitignore
@@ -0,0 +1,2 @@
+/open_tree01
+/open_tree02
diff --git a/testcases/kernel/syscalls/open_tree/Makefile b/testcases/kernel/syscalls/open_tree/Makefile
new file mode 100644
index 000000000000..5ea7d67db123
--- /dev/null
+++ b/testcases/kernel/syscalls/open_tree/Makefile
@@ -0,0 +1,6 @@
+# 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/open_tree/open_tree01.c b/testcases/kernel/syscalls/open_tree/open_tree01.c
new file mode 100644
index 000000000000..5fd8b9b7c438
--- /dev/null
+++ b/testcases/kernel/syscalls/open_tree/open_tree01.c
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic open_tree() test.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+#define MNTPOINT	"mntpoint"
+#define OT_MNTPOINT	"ot_mntpoint"
+
+#define TCASE_ENTRY(_flags)	{.name = "Flag " #_flags, .flags = _flags}
+
+static struct tcase {
+	char *name;
+	unsigned int flags;
+} tcases[] = {
+	TCASE_ENTRY(OPEN_TREE_CLONE),
+	TCASE_ENTRY(OPEN_TREE_CLOEXEC)
+};
+
+static int dir_created;
+
+static void cleanup(void)
+{
+	if (dir_created)
+		SAFE_RMDIR(OT_MNTPOINT);
+}
+
+static void setup(void)
+{
+	fsopen_supported_by_kernel();
+	SAFE_MKDIR(OT_MNTPOINT, 0777);
+	dir_created = 1;
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int fd, fsmfd, otfd;
+
+	TEST(fd = fsopen(tst_device->fs_type, 0));
+	if (fd == -1) {
+		tst_res(TFAIL | TERRNO, "fsopen() failed");
+		return;
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		return;
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_res(TFAIL | TERRNO, "fsconfig() failed");
+		return;
+	}
+
+	TEST(fsmfd = fsmount(fd, 0, 0));
+	SAFE_CLOSE(fd);
+
+	if (fsmfd == -1) {
+		tst_res(TFAIL | TERRNO, "fsmount() failed");
+		return;
+	}
+
+	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
+			MOVE_MOUNT_F_EMPTY_PATH));
+	SAFE_CLOSE(fsmfd);
+
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TERRNO, "move_mount() failed");
+		return;
+	}
+
+	if (!tst_is_mounted_at_tmpdir(MNTPOINT)) {
+		tst_res(TFAIL | TERRNO, "device not mounted");
+		return;
+	}
+
+	TEST(otfd = open_tree(AT_FDCWD, MNTPOINT, tc->flags | OPEN_TREE_CLONE));
+	if (otfd == -1) {
+		tst_res(TFAIL | TERRNO, "open_tree() failed");
+		goto out;
+	}
+
+	TEST(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT,
+			MOVE_MOUNT_F_EMPTY_PATH));
+	SAFE_CLOSE(otfd);
+
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TERRNO, "move_mount() failed");
+		goto out;
+	}
+
+	if (tst_is_mounted_at_tmpdir(OT_MNTPOINT)) {
+		SAFE_UMOUNT(OT_MNTPOINT);
+		tst_res(TPASS, "%s: open_tree() passed", tc->name);
+	}
+
+out:
+	SAFE_UMOUNT(MNTPOINT);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
diff --git a/testcases/kernel/syscalls/open_tree/open_tree02.c b/testcases/kernel/syscalls/open_tree/open_tree02.c
new file mode 100644
index 000000000000..6911693837e9
--- /dev/null
+++ b/testcases/kernel/syscalls/open_tree/open_tree02.c
@@ -0,0 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ *
+ * Basic open_tree() failure tests.
+ */
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+#define MNTPOINT	"mntpoint"
+
+static struct tcase {
+	char *name;
+	int dirfd;
+	const char *pathname;
+	unsigned int flags;
+	int exp_errno;
+} tcases[] = {
+	{"invalid-fd", -1, MNTPOINT, OPEN_TREE_CLONE, EBADF},
+	{"invalid-path", AT_FDCWD, "invalid", OPEN_TREE_CLONE, ENOENT},
+	{"invalid-flags", AT_FDCWD, MNTPOINT, 0xFFFFFFFF, EINVAL},
+};
+
+static int ismounted;
+
+static void cleanup(void)
+{
+	if (ismounted)
+		SAFE_UMOUNT(MNTPOINT);
+}
+
+static void setup(void)
+{
+	int fd, fsmfd;
+
+	fsopen_supported_by_kernel();
+
+	TEST(fd = fsopen(tst_device->fs_type, 0));
+	if (fd == -1)
+		tst_brk(TBROK | TERRNO, "fsopen() failed");
+
+	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_brk(TBROK | TERRNO, "fsconfig() failed");
+	}
+
+	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
+	if (TST_RET == -1) {
+		SAFE_CLOSE(fd);
+		tst_brk(TBROK | TERRNO, "fsconfig() failed");
+	}
+
+	TEST(fsmfd = fsmount(fd, 0, 0));
+	SAFE_CLOSE(fd);
+
+	if (fsmfd == -1)
+		tst_brk(TBROK | TERRNO, "fsmount() failed");
+
+	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
+			MOVE_MOUNT_F_EMPTY_PATH));
+	SAFE_CLOSE(fsmfd);
+
+	if (TST_RET == -1)
+		tst_brk(TBROK | TERRNO, "move_mount() failed");
+
+	if (!tst_is_mounted_at_tmpdir(MNTPOINT))
+		tst_brk(TBROK | TERRNO, "device not mounted");
+
+	ismounted = 1;
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	TEST(open_tree(tc->dirfd, tc->pathname, tc->flags));
+	if (TST_RET != -1) {
+		SAFE_CLOSE(TST_RET);
+		tst_res(TFAIL, "%s: open_tree() succeeded unexpectedly (index: %d)",
+			tc->name, n);
+		return;
+	}
+
+	if (tc->exp_errno != TST_ERR) {
+		tst_res(TFAIL | TTERRNO, "%s: open_tree() should fail with %s",
+			tc->name, tst_strerrno(tc->exp_errno));
+		return;
+	}
+
+	tst_res(TPASS | TTERRNO, "%s: open_tree() failed as expected",
+		tc->name);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.dev_fs_flags = TST_FS_SKIP_FUSE,
+};
-- 
2.21.0.rc0.269.g1a574e7a288b


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

* [LTP] [PATCH V6 05/10] syscalls/fsconfig: New tests
  2020-03-13  8:48         ` Viresh Kumar
@ 2020-03-13 12:09           ` Petr Vorel
  2020-03-16  6:09             ` Viresh Kumar
  0 siblings, 1 reply; 30+ messages in thread
From: Petr Vorel @ 2020-03-13 12:09 UTC (permalink / raw)
  To: ltp

Hi Viresh,

> I didn't knew about the -i option, yeah your change makes sense now :)
NOTE: all test (both C and shell) should support -h (inherited from the
library), to display options.

Kind regards,
Petr

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

* [LTP] [PATCH V7 10/10] syscalls/open_tree: New tests
  2020-03-13  9:03   ` [LTP] [PATCH V7 " Viresh Kumar
@ 2020-03-13 12:27     ` Petr Vorel
  2020-03-13 12:49     ` Cyril Hrubis
  1 sibling, 0 replies; 30+ messages in thread
From: Petr Vorel @ 2020-03-13 12:27 UTC (permalink / raw)
  To: ltp

Hi Viresh,

> V6->V7:
> - Remove the temporary directory from cleanup routine to avoid test
>   failure.
Thanks for a quick fix, merged these 2 remaining tests.

Kind regards,
Petr

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

* [LTP] [PATCH V6 09/10] syscalls/fspick: New tests
  2020-03-12 12:01 ` [LTP] [PATCH V6 09/10] syscalls/fspick: " Viresh Kumar
  2020-03-13  7:04   ` Petr Vorel
@ 2020-03-13 12:35   ` Cyril Hrubis
  1 sibling, 0 replies; 30+ messages in thread
From: Cyril Hrubis @ 2020-03-13 12:35 UTC (permalink / raw)
  To: ltp

Hi!
> Acked-by: Li Wang <liwang@redhat.com>
> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
> ---
>  runtest/syscalls                            |  3 +
>  testcases/kernel/syscalls/fspick/.gitignore |  2 +
>  testcases/kernel/syscalls/fspick/Makefile   |  6 ++
>  testcases/kernel/syscalls/fspick/fspick.h   | 60 ++++++++++++++++++++
>  testcases/kernel/syscalls/fspick/fspick01.c | 62 +++++++++++++++++++++
>  testcases/kernel/syscalls/fspick/fspick02.c | 54 ++++++++++++++++++
>  6 files changed, 187 insertions(+)
>  create mode 100644 testcases/kernel/syscalls/fspick/.gitignore
>  create mode 100644 testcases/kernel/syscalls/fspick/Makefile
>  create mode 100644 testcases/kernel/syscalls/fspick/fspick.h
>  create mode 100644 testcases/kernel/syscalls/fspick/fspick01.c
>  create mode 100644 testcases/kernel/syscalls/fspick/fspick02.c
> 
> diff --git a/runtest/syscalls b/runtest/syscalls
> index 077e724b62e4..32f11f4bc9ab 100644
> --- a/runtest/syscalls
> +++ b/runtest/syscalls
> @@ -351,6 +351,9 @@ fsmount02 fsmount02
>  fsopen01 fsopen01
>  fsopen02 fsopen02
>  
> +fspick01 fspick01
> +fspick02 fspick02
> +
>  fstat02 fstat02
>  fstat02_64 fstat02_64
>  fstat03 fstat03
> diff --git a/testcases/kernel/syscalls/fspick/.gitignore b/testcases/kernel/syscalls/fspick/.gitignore
> new file mode 100644
> index 000000000000..a8aa61dce18b
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fspick/.gitignore
> @@ -0,0 +1,2 @@
> +/fspick01
> +/fspick02
> diff --git a/testcases/kernel/syscalls/fspick/Makefile b/testcases/kernel/syscalls/fspick/Makefile
> new file mode 100644
> index 000000000000..5ea7d67db123
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fspick/Makefile
> @@ -0,0 +1,6 @@
> +# 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/fspick/fspick.h b/testcases/kernel/syscalls/fspick/fspick.h
> new file mode 100644
> index 000000000000..ca84269ee7a9
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fspick/fspick.h
> @@ -0,0 +1,60 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
> + */
> +
> +#ifndef FSPICK_H__
> +#define FSPICK_H__
> +
> +#define MNTPOINT	"mntpoint"
> +
> +static int ismounted;
> +
> +static void cleanup(void)
> +{
> +	if (ismounted)
> +		SAFE_UMOUNT(MNTPOINT);
> +}
> +
> +static void setup(void)
> +{
> +	int fd, fsmfd;
> +
> +	fsopen_supported_by_kernel();
> +
> +	TEST(fd = fsopen(tst_device->fs_type, 0));
> +	if (fd == -1)
> +		tst_brk(TBROK | TERRNO, "fsopen() failed");
> +
> +	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
> +	if (TST_RET == -1) {
> +		SAFE_CLOSE(fd);
> +		tst_brk(TBROK | TERRNO, "fsconfig() failed");
> +	}
> +
> +	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
> +	if (TST_RET == -1) {
> +		SAFE_CLOSE(fd);
> +		tst_brk(TBROK | TERRNO, "fsconfig() failed");
> +	}
> +
> +	TEST(fsmfd = fsmount(fd, 0, 0));
> +	SAFE_CLOSE(fd);
> +
> +	if (fsmfd == -1)
> +		tst_brk(TBROK | TERRNO, "fsmount() failed");
> +
> +	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
> +			MOVE_MOUNT_F_EMPTY_PATH));
> +	SAFE_CLOSE(fsmfd);
> +
> +	if (TST_RET == -1)
> +		tst_brk(TBROK | TERRNO, "move_mount() failed");
> +
> +	if (!tst_is_mounted_at_tmpdir(MNTPOINT))
> +		tst_brk(TBROK | TERRNO, "device not mounted");
> +
> +	ismounted = 1;

I just wonder if we can set the .mount_device = 1 flag instead and omit
the setup and cleanup.

> +}
> +
> +#endif /* FSPICK_H__ */
> diff --git a/testcases/kernel/syscalls/fspick/fspick01.c b/testcases/kernel/syscalls/fspick/fspick01.c
> new file mode 100644
> index 000000000000..4e1daeaee14a
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fspick/fspick01.c
> @@ -0,0 +1,62 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
> + *
> + * Basic fspick() test.
> + */
> +#include "tst_test.h"
> +#include "lapi/fsmount.h"
> +#include "fspick.h"
> +
> +#define TCASE_ENTRY(_flags)	{.name = "Flag " #_flags, .flags = _flags}
> +
> +static struct tcase {
> +	char *name;
> +	unsigned int flags;
> +} tcases[] = {
> +	TCASE_ENTRY(FSPICK_CLOEXEC),
> +	TCASE_ENTRY(FSPICK_SYMLINK_NOFOLLOW),
> +	TCASE_ENTRY(FSPICK_NO_AUTOMOUNT),
> +	TCASE_ENTRY(FSPICK_EMPTY_PATH),
> +};
> +
> +static void run(unsigned int n)
> +{
> +	struct tcase *tc = &tcases[n];
> +	int fspick_fd;
> +
> +	TEST(fspick_fd = fspick(AT_FDCWD, MNTPOINT, tc->flags));
> +	if (fspick_fd == -1) {
> +		tst_res(TFAIL | TERRNO, "fspick() failed");
> +		return;
> +	}
> +
> +	TEST(fsconfig(fspick_fd, FSCONFIG_SET_STRING, "sync", "false", 0));
> +	if (TST_RET == -1) {
> +		tst_res(TFAIL | TERRNO, "fsconfig() failed");
> +		goto out;
> +	}
> +
> +	TEST(fsconfig(fspick_fd, FSCONFIG_SET_FLAG, "ro", NULL, 0));
> +	if (TST_RET == -1) {
> +		tst_res(TFAIL | TERRNO, "fsconfig() failed");
> +		goto out;
> +	}

I guess that we should as well call the FSCONFIG_CMD_RECONFIGURE and
check that the MNTPOINT is read only, right?

> +	tst_res(TPASS, "%s: fspick() passed", tc->name);
> +
> +out:
> +	SAFE_CLOSE(fspick_fd);
> +}
> +
> +static struct tst_test test = {
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.test = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.needs_root = 1,
> +	.format_device = 1,
> +	.mntpoint = MNTPOINT,
> +	.all_filesystems = 1,
> +	.dev_fs_flags = TST_FS_SKIP_FUSE,
> +};
> diff --git a/testcases/kernel/syscalls/fspick/fspick02.c b/testcases/kernel/syscalls/fspick/fspick02.c
> new file mode 100644
> index 000000000000..dc8f153ccc48
> --- /dev/null
> +++ b/testcases/kernel/syscalls/fspick/fspick02.c
> @@ -0,0 +1,54 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
> + *
> + * Basic fspick() failure tests.
> + */
> +#include "tst_test.h"
> +#include "lapi/fsmount.h"
> +#include "fspick.h"
> +
> +static struct tcase {
> +	char *name;
> +	int dirfd;
> +	const char *pathname;
> +	unsigned int flags;
> +	int exp_errno;
> +} tcases[] = {
> +	{"invalid-fd", -1, MNTPOINT, FSPICK_NO_AUTOMOUNT | FSPICK_CLOEXEC, EBADF},
> +	{"invalid-path", AT_FDCWD, "invalid", FSPICK_NO_AUTOMOUNT | FSPICK_CLOEXEC, ENOENT},
> +	{"invalid-flags", AT_FDCWD, MNTPOINT, 0x10, EINVAL},
> +};
> +
> +static void run(unsigned int n)
> +{
> +	struct tcase *tc = &tcases[n];
> +
> +	TEST(fspick(tc->dirfd, tc->pathname, tc->flags));
> +	if (TST_RET != -1) {
> +		SAFE_CLOSE(TST_RET);
> +		tst_res(TFAIL, "%s: fspick() succeeded unexpectedly (index: %d)",
> +			tc->name, n);
> +		return;
> +	}
> +
> +	if (tc->exp_errno != TST_ERR) {
> +		tst_res(TFAIL | TTERRNO, "%s: fspick() should fail with %s",
> +			tc->name, tst_strerrno(tc->exp_errno));
> +		return;
> +	}
> +
> +	tst_res(TPASS | TTERRNO, "%s: fspick() failed as expected", tc->name);
> +}
> +
> +static struct tst_test test = {
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.test = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.needs_root = 1,
> +	.format_device = 1,
> +	.mntpoint = MNTPOINT,
> +	.all_filesystems = 1,
> +	.dev_fs_flags = TST_FS_SKIP_FUSE,
> +};
> -- 
> 2.21.0.rc0.269.g1a574e7a288b
> 

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH V7 10/10] syscalls/open_tree: New tests
  2020-03-13  9:03   ` [LTP] [PATCH V7 " Viresh Kumar
  2020-03-13 12:27     ` Petr Vorel
@ 2020-03-13 12:49     ` Cyril Hrubis
  2020-03-13 12:50       ` Petr Vorel
  2020-03-20  4:35       ` Viresh Kumar
  1 sibling, 2 replies; 30+ messages in thread
From: Cyril Hrubis @ 2020-03-13 12:49 UTC (permalink / raw)
  To: ltp

Hi!
> +include $(top_srcdir)/include/mk/testcases.mk
> +include $(top_srcdir)/include/mk/generic_leaf_target.mk
> diff --git a/testcases/kernel/syscalls/open_tree/open_tree01.c b/testcases/kernel/syscalls/open_tree/open_tree01.c
> new file mode 100644
> index 000000000000..5fd8b9b7c438
> --- /dev/null
> +++ b/testcases/kernel/syscalls/open_tree/open_tree01.c
> @@ -0,0 +1,119 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
> + *
> + * Basic open_tree() test.
> + */
> +#include "tst_test.h"
> +#include "lapi/fsmount.h"
> +
> +#define MNTPOINT	"mntpoint"
> +#define OT_MNTPOINT	"ot_mntpoint"
> +
> +#define TCASE_ENTRY(_flags)	{.name = "Flag " #_flags, .flags = _flags}
> +
> +static struct tcase {
> +	char *name;
> +	unsigned int flags;
> +} tcases[] = {
> +	TCASE_ENTRY(OPEN_TREE_CLONE),
> +	TCASE_ENTRY(OPEN_TREE_CLOEXEC)
> +};
> +
> +static int dir_created;
> +
> +static void cleanup(void)
> +{
> +	if (dir_created)
> +		SAFE_RMDIR(OT_MNTPOINT);
> +}
> +
> +static void setup(void)
> +{
> +	fsopen_supported_by_kernel();
> +	SAFE_MKDIR(OT_MNTPOINT, 0777);
> +	dir_created = 1;
> +}
> +
> +static void run(unsigned int n)
> +{
> +	struct tcase *tc = &tcases[n];
> +	int fd, fsmfd, otfd;
> +
> +	TEST(fd = fsopen(tst_device->fs_type, 0));
> +	if (fd == -1) {
> +		tst_res(TFAIL | TERRNO, "fsopen() failed");
> +		return;
> +	}
> +
> +	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
> +	if (TST_RET == -1) {
> +		SAFE_CLOSE(fd);
> +		tst_res(TFAIL | TERRNO, "fsconfig() failed");
> +		return;
> +	}
> +
> +	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
> +	if (TST_RET == -1) {
> +		SAFE_CLOSE(fd);
> +		tst_res(TFAIL | TERRNO, "fsconfig() failed");
> +		return;
> +	}
> +
> +	TEST(fsmfd = fsmount(fd, 0, 0));
> +	SAFE_CLOSE(fd);
> +
> +	if (fsmfd == -1) {
> +		tst_res(TFAIL | TERRNO, "fsmount() failed");
> +		return;
> +	}
> +
> +	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
> +			MOVE_MOUNT_F_EMPTY_PATH));
> +	SAFE_CLOSE(fsmfd);

Here as well, shouldn't we just set the .mount_device flag instead?

> +	if (TST_RET == -1) {
> +		tst_res(TFAIL | TERRNO, "move_mount() failed");
> +		return;
> +	}
> +
> +	if (!tst_is_mounted_at_tmpdir(MNTPOINT)) {
> +		tst_res(TFAIL | TERRNO, "device not mounted");
> +		return;
> +	}
> +
> +	TEST(otfd = open_tree(AT_FDCWD, MNTPOINT, tc->flags | OPEN_TREE_CLONE));
> +	if (otfd == -1) {
> +		tst_res(TFAIL | TERRNO, "open_tree() failed");
> +		goto out;
> +	}
> +
> +	TEST(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT,
> +			MOVE_MOUNT_F_EMPTY_PATH));
> +	SAFE_CLOSE(otfd);
> +
> +	if (TST_RET == -1) {
> +		tst_res(TFAIL | TERRNO, "move_mount() failed");
> +		goto out;
> +	}
> +
> +	if (tst_is_mounted_at_tmpdir(OT_MNTPOINT)) {
> +		SAFE_UMOUNT(OT_MNTPOINT);
> +		tst_res(TPASS, "%s: open_tree() passed", tc->name);
> +	}
> +
> +out:
> +	SAFE_UMOUNT(MNTPOINT);
> +}
> +
> +static struct tst_test test = {
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.test = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +	.needs_root = 1,
> +	.format_device = 1,
> +	.mntpoint = MNTPOINT,
> +	.all_filesystems = 1,
> +	.dev_fs_flags = TST_FS_SKIP_FUSE,
> +};

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH V7 10/10] syscalls/open_tree: New tests
  2020-03-13 12:49     ` Cyril Hrubis
@ 2020-03-13 12:50       ` Petr Vorel
  2020-03-20  4:35       ` Viresh Kumar
  1 sibling, 0 replies; 30+ messages in thread
From: Petr Vorel @ 2020-03-13 12:50 UTC (permalink / raw)
  To: ltp

Hi,

> > +	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
> > +			MOVE_MOUNT_F_EMPTY_PATH));
> > +	SAFE_CLOSE(fsmfd);

> Here as well, shouldn't we just set the .mount_device flag instead?
Sorry for overlooking these. I was too quick.
I guess metan will fix it himself.

Kind regards,
Petr

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

* [LTP] [PATCH V6 05/10] syscalls/fsconfig: New tests
  2020-03-13 12:09           ` Petr Vorel
@ 2020-03-16  6:09             ` Viresh Kumar
  2020-03-16  6:22               ` Petr Vorel
  0 siblings, 1 reply; 30+ messages in thread
From: Viresh Kumar @ 2020-03-16  6:09 UTC (permalink / raw)
  To: ltp

On 13-03-20, 13:09, Petr Vorel wrote:
> Hi Viresh,
> 
> > I didn't knew about the -i option, yeah your change makes sense now :)
> NOTE: all test (both C and shell) should support -h (inherited from the
> library), to display options.

I didn't thought about that as well earlier, but then tried -h option
with the executable earlier before your mail came and it worked. So I
assume I don't have to do anything special to support the -h option as
it is already working fine right now ?

-- 
viresh

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

* [LTP] [PATCH V6 05/10] syscalls/fsconfig: New tests
  2020-03-16  6:09             ` Viresh Kumar
@ 2020-03-16  6:22               ` Petr Vorel
  0 siblings, 0 replies; 30+ messages in thread
From: Petr Vorel @ 2020-03-16  6:22 UTC (permalink / raw)
  To: ltp

Hi Viresh,

> > > I didn't knew about the -i option, yeah your change makes sense now :)
> > NOTE: all test (both C and shell) should support -h (inherited from the
> > library), to display options.

> I didn't thought about that as well earlier, but then tried -h option
> with the executable earlier before your mail came and it worked. So I
> assume I don't have to do anything special to support the -h option as
> it is already working fine right now ?
Yes, that's automatically done by library (a nice feature of new C library API).
See parse_opts() in lib/tst_test.c. And even better: you can very easily extend
it, see 2.2.5 Test specific command line options [1].

Cyril also recently described LTP library model in his blog [3].

We were thinking to separate the library so it can be reused in other projects
(similarly like kernel's kconfig is used in other projects). But it'd be good
first to rewrite all tests which uses legacy API, which allows remove legacy API
itself.

BTW We also try to keep shell API to be similar to C API (when possible),
therefore getopt support it's there as well, see 2.3.3 Optional command line
parameters [2].

Kind regards,
Petr

[1] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#225-test-specific-command-line-options
[2] https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#233-optional-command-line-parameters
[3] https://people.kernel.org/metan/the-ltp-test-driver-model

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

* [LTP] [PATCH V6 05/10] syscalls/fsconfig: New tests
  2020-03-12 12:01 ` [LTP] [PATCH V6 05/10] syscalls/fsconfig: " Viresh Kumar
  2020-03-12 19:10   ` Cyril Hrubis
@ 2020-03-17 21:33   ` Petr Vorel
  1 sibling, 0 replies; 30+ messages in thread
From: Petr Vorel @ 2020-03-17 21:33 UTC (permalink / raw)
  To: ltp

Hi Viresh,

> +	TEST(fd = fsopen(tst_device->fs_type, 0));
> +	if (fd == -1)
> +		tst_brk(TBROK | TERRNO, "fsopen() failed");
Just a note all these tst_brk/tst_res after TEST() should use TTERRNO, not TERRNO.
Although TERRNO will probably work in this case as well, it'd be better to use
TTERRNO (see lib/tst_res.c).

Kind regards,
Petr

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

* [LTP] [PATCH V7 10/10] syscalls/open_tree: New tests
  2020-03-13 12:49     ` Cyril Hrubis
  2020-03-13 12:50       ` Petr Vorel
@ 2020-03-20  4:35       ` Viresh Kumar
  2020-03-20 19:59         ` Cyril Hrubis
  1 sibling, 1 reply; 30+ messages in thread
From: Viresh Kumar @ 2020-03-20  4:35 UTC (permalink / raw)
  To: ltp

On 13-03-20, 13:49, Cyril Hrubis wrote:
> > +static void run(unsigned int n)
> > +{
> > +	struct tcase *tc = &tcases[n];
> > +	int fd, fsmfd, otfd;
> > +
> > +	TEST(fd = fsopen(tst_device->fs_type, 0));
> > +	if (fd == -1) {
> > +		tst_res(TFAIL | TERRNO, "fsopen() failed");
> > +		return;
> > +	}
> > +
> > +	TEST(fsconfig(fd, FSCONFIG_SET_STRING, "source", tst_device->dev, 0));
> > +	if (TST_RET == -1) {
> > +		SAFE_CLOSE(fd);
> > +		tst_res(TFAIL | TERRNO, "fsconfig() failed");
> > +		return;
> > +	}
> > +
> > +	TEST(fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0));
> > +	if (TST_RET == -1) {
> > +		SAFE_CLOSE(fd);
> > +		tst_res(TFAIL | TERRNO, "fsconfig() failed");
> > +		return;
> > +	}
> > +
> > +	TEST(fsmfd = fsmount(fd, 0, 0));
> > +	SAFE_CLOSE(fd);
> > +
> > +	if (fsmfd == -1) {
> > +		tst_res(TFAIL | TERRNO, "fsmount() failed");
> > +		return;
> > +	}
> > +
> > +	TEST(move_mount(fsmfd, "", AT_FDCWD, MNTPOINT,
> > +			MOVE_MOUNT_F_EMPTY_PATH));
> > +	SAFE_CLOSE(fsmfd);
> 
> Here as well, shouldn't we just set the .mount_device flag instead?

Hi,

Sorry but I am not sure what will happen by .mount_device here. From
what I see from tst_test.c, that flag will end up calling SAFE_MOUNT()
automatically, but what we are calling here is fsmount() and
move_mount() instead.

Can you please elaborate a bit on that ? Thanks.

-- 
viresh

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

* [LTP] [PATCH V7 10/10] syscalls/open_tree: New tests
  2020-03-20  4:35       ` Viresh Kumar
@ 2020-03-20 19:59         ` Cyril Hrubis
  0 siblings, 0 replies; 30+ messages in thread
From: Cyril Hrubis @ 2020-03-20 19:59 UTC (permalink / raw)
  To: ltp

Hi!
> > Here as well, shouldn't we just set the .mount_device flag instead?
> 
> Hi,
> 
> Sorry but I am not sure what will happen by .mount_device here. From
> what I see from tst_test.c, that flag will end up calling SAFE_MOUNT()
> automatically, but what we are calling here is fsmount() and
> move_mount() instead.
> 
> Can you please elaborate a bit on that ? Thanks.

My point here is that most of the code just mounts the device and since
we are testing open_tree() there is no point in mounting the device with
the new mount API in the first half of the run() function, it should
work fine with the device mounted with the plain old mount(). Also we do
OPEN_TREE_CLONE here, so there is no point in mounting the filesystem in
the run() fucntion, moreover it will probably fail with the -i
parameter.

So I'm suggesting to remove the part that mounts the device in the first
half of the test and set the .mount_device flag instead.

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2020-03-20 19:59 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-12 12:01 [LTP] [PATCH V6 00/10] Add new LTP tests related to fsmount family of syscalls Viresh Kumar
2020-03-12 12:01 ` [LTP] [PATCH V6 01/10] tst_device: Add tst_is_mounted() and tst_is_mounted_at_tmpdir() helpers Viresh Kumar
2020-03-12 12:01 ` [LTP] [PATCH V6 02/10] lapi/fsmount.h: Add fsopen_supported_by_kernel() Viresh Kumar
2020-03-12 12:01 ` [LTP] [PATCH V6 03/10] lapi/fsmount.h: Include "lapi/fcntl.h" Viresh Kumar
2020-03-12 12:01 ` [LTP] [PATCH V6 04/10] syscalls/fsopen: New tests Viresh Kumar
2020-03-12 12:01 ` [LTP] [PATCH V6 05/10] syscalls/fsconfig: " Viresh Kumar
2020-03-12 19:10   ` Cyril Hrubis
2020-03-13  4:00     ` Viresh Kumar
2020-03-13  7:22       ` Petr Vorel
2020-03-13  8:03       ` Cyril Hrubis
2020-03-13  8:48         ` Viresh Kumar
2020-03-13 12:09           ` Petr Vorel
2020-03-16  6:09             ` Viresh Kumar
2020-03-16  6:22               ` Petr Vorel
2020-03-17 21:33   ` Petr Vorel
2020-03-12 12:01 ` [LTP] [PATCH V6 06/10] syscalls/fsmount: Improve fsmount01 test Viresh Kumar
2020-03-12 12:01 ` [LTP] [PATCH V6 07/10] syscalls/fsmount: Add failure tests Viresh Kumar
2020-03-12 12:01 ` [LTP] [PATCH V6 08/10] syscalls/move_mount: New tests Viresh Kumar
2020-03-12 19:07   ` Cyril Hrubis
2020-03-12 12:01 ` [LTP] [PATCH V6 09/10] syscalls/fspick: " Viresh Kumar
2020-03-13  7:04   ` Petr Vorel
2020-03-13 12:35   ` Cyril Hrubis
2020-03-12 12:01 ` [LTP] [PATCH V6 10/10] syscalls/open_tree: " Viresh Kumar
2020-03-13  8:48   ` Petr Vorel
2020-03-13  9:03   ` [LTP] [PATCH V7 " Viresh Kumar
2020-03-13 12:27     ` Petr Vorel
2020-03-13 12:49     ` Cyril Hrubis
2020-03-13 12:50       ` Petr Vorel
2020-03-20  4:35       ` Viresh Kumar
2020-03-20 19:59         ` Cyril Hrubis

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.