Skip to contentSkip to conversation

syscalls/mount_setattr01: Add basic functional test

PATCH In review Chen Hanxiao 3 participants 7 messages Apr 28, 2022 – May 27, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 syscalls/mount_setattr01: Add basic functional test

The mount_setattr() system call changes the mount properties of a mount or an entire mount tree. Here we check whether the mount attributes are set correctly.

---
v5:
1. remove numbers from doc
2. modify cleanup labels
v4:
1) add AC_CHECK_TYPES for mount_attr
2) fix cleanup issues
v3:
1) fix doc issue
2) fix bugs according to Petr's comments
v2:
1) fix bugs according to Cyril's comments
2) just set and test mount attributes, remove attr_clr section.

 configure.ac                                  |   7 +
 include/lapi/fsmount.h                        |  47 +++++++
 runtest/syscalls                              |   2 +
 .../kernel/syscalls/mount_setattr/.gitignore  |   1 +
 .../kernel/syscalls/mount_setattr/Makefile    |   6 +
 .../syscalls/mount_setattr/mount_setattr01.c  | 132 ++++++++++++++++++
 6 files changed, 195 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mount_setattr/.gitignore
 create mode 100644 testcases/kernel/syscalls/mount_setattr/Makefile
 create mode 100644 testcases/kernel/syscalls/mount_setattr/mount_setattr01.c
configure.ac +7 -0
index 81cba98c2..816ebf820 100644
@@ -220,6 +220,13 @@ AC_CHECK_TYPES([struct __kernel_old_timeval, struct __kernel_old_timespec, struc
                 struct __kernel_old_itimerspec, struct __kernel_itimerspec],,,[#include <sys/socket.h>])
 
 AC_CHECK_TYPES([struct futex_waitv],,,[#include <linux/futex.h>])
+AC_CHECK_TYPES([struct mount_attr],,,[
+#ifdef HAVE_LINUX_MOUNT_H
+# include <linux/mount.h>
+#else
+# include <sys/mount.h>
+#endif
+])
 
 # Tools knobs
 
include/lapi/fsmount.h +47 -0

59 lines not on this page · raw message

runtest/syscalls +2 -0
index 24d0f955d..3b26d19e6 100644
@@ -803,6 +803,8 @@ mount04 mount04
 mount05 mount05
 mount06 mount06
 
+mount_setattr01 mount_setattr01
+
 move_mount01 move_mount01
 move_mount02 move_mount02
 
testcases/kernel/syscalls/mount_setattr/.gitignore new file +1 -0
new file mode 100644
index 000000000..52a77b9ca
@@ -0,0 +1 @@
+/mount_setattr01
testcases/kernel/syscalls/mount_setattr/Makefile new file +6 -0
new file mode 100644
index 000000000..5ea7d67db
@@ -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
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +132 -0

132 lines not on this page · raw message

Signature · 7 lines
2.35.1




-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v5 1/1
#1 lore raw

Hi Dai, Chen,

LGTM, waiting for Cyril's final ack before merging.

Quoted 1 line
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +0 -0

...

testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 44

Quoted 8 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +8 -0
+#define MNTPOINT        "mntpoint"
+#define OT_MNTPOINT     "ot_mntpoint"
+#define TCASE_ENTRY(attrs, exp_attrs)   \
+	{                                \
+		.name = #attrs,                 \
+		.mount_attrs = attrs,           \
+		.expect_attrs = exp_attrs       \
+	}

nit: This is absolutely ok, but I'd personally use the version from v2, which set only .name and .mount_attrs (the only point for macros are to reduce duplicity, which is not in passing .expect_attrs).

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
Quoted 8 lines

-----邮件原件-----
发件人: Petr Vorel <[email protected]>
发送时间: 2022年4月28日 20:24
<[email protected]>
主题: Re: [PATCH v5] syscalls/mount_setattr01: Add basic functional test

Quoted 4 lines

Hi Dai, Chen,

before merging.

Hi, Cyril

Any comments?

Regards,
- Chen

Quoted 18 lines
Quoted 3 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +0 -0

...

testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 44

Quoted 8 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +8 -0
+#define MNTPOINT        "mntpoint"
+#define OT_MNTPOINT     "ot_mntpoint"
+#define TCASE_ENTRY(attrs, exp_attrs)   \
+	{                                \
+		.name = #attrs,                 \
+		.mount_attrs = attrs,           \
+		.expect_attrs = exp_attrs       \
+	}

nit: This is absolutely ok, but I'd personally use the version from v2, which set only .name and .mount_attrs (the only point for macros are to reduce duplicity, which is not in passing .expect_attrs).

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw
In reply to Chen Hanxiao

Hi Chen, Dai,

...

Quoted 41 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +41 -0
+static void setup(void)
+{
+	fsopen_supported_by_kernel();
+	struct stat st = {0};
+
+	if (stat(OT_MNTPOINT, &st) == -1)
+		SAFE_MKDIR(OT_MNTPOINT, 0777);
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	struct mount_attr attr = {
+		.attr_set = tc->mount_attrs,
+	};
+	struct statvfs buf;
+
+	TST_EXP_FD_SILENT(open_tree(AT_FDCWD, MNTPOINT, AT_EMPTY_PATH |
+		AT_SYMLINK_NOFOLLOW | OPEN_TREE_CLOEXEC | OPEN_TREE_CLONE));
+	if (!TST_PASS)
+		return;
+
+	otfd = (int)TST_RET;
+
+	TST_EXP_PASS_SILENT(mount_setattr(otfd, "", AT_EMPTY_PATH, &attr, sizeof(attr)),
+		"%s set", tc->name);
+	if (!TST_PASS)
+		goto out1;
+
+	TST_EXP_PASS_SILENT(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH));
+	if (!TST_PASS)
+		goto out1;
+	mount_flag = 1;
+	SAFE_CLOSE(otfd);
+
+	TST_EXP_PASS_SILENT(statvfs(OT_MNTPOINT, &buf), "statvfs sucess");
+	if (!TST_PASS)
+		goto out2;
+
+	if (buf.f_flag & tc->expect_attrs)
+		tst_res(TPASS, "%s is actually set as expected", tc->name);

testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 119

Quoted 10 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +10 -0
+	else
+		tst_res(TFAIL, "%s is not actually set as expected", tc->name);
+
+	goto out2;
+
+out1:
+	SAFE_CLOSE(otfd);
+out2:
+	mount_flag = 0;
+	SAFE_UMOUNT(OT_MNTPOINT);

mount_flag needs to be checked before otherwise if it fails on:
TST_EXP_PASS_SILENT(mount_setattr(otfd, "", AT_EMPTY_PATH, &attr, sizeof(attr)),

		"%s set", tc->name);

It tries to umount() not yet mounted filesystem:

mount_setattr01.c:109: TPASS: MOUNT_ATTR_RDONLY is actually set as expected mount_setattr01.c:109: TPASS: MOUNT_ATTR_NOSUID is actually set as expected mount_setattr01.c:109: TPASS: MOUNT_ATTR_NODEV is actually set as expected mount_setattr01.c:109: TPASS: MOUNT_ATTR_NOEXEC is actually set as expected mount_setattr01.c:93: TFAIL: MOUNT_ATTR_NOSYMFOLLOW set failed: EINVAL (22) tst_device.c:394: TWARN: umount('ot_mntpoint') failed with EINVAL mount_setattr01.c:119: TBROK: umount(ot_mntpoint) failed: EINVAL (22)

Because we mount later than opening otfd with open_tree() but need to close otfd before umount() we cannot depend only on labels.

Thus I suggest to have this cleanup code:

out1:

	SAFE_CLOSE(otfd);
out2:
	if (mount_flag)
		SAFE_UMOUNT(OT_MNTPOINT);

	mount_flag = 0;

If Cyril is ok with this I'd merge it before release. (I tested it on various systems, found only this issue.)

Kind regards,
Petr

+++ testcases/kernel/syscalls/mount_setattr/mount_setattr01.c @@ -115,8 +115,10 @@ static void run(unsigned int n)
out1:
SAFE_CLOSE(otfd);
out2:
+ if (mount_flag)
+ SAFE_UMOUNT(OT_MNTPOINT);
+
mount_flag = 0;
- SAFE_UMOUNT(OT_MNTPOINT);
}

static struct tst_test test = {

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi Petr

Quoted 81 lines

Hi Chen, Dai,

...

Quoted 41 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +41 -0
+static void setup(void)
+{
+	fsopen_supported_by_kernel();
+	struct stat st = {0};
+
+	if (stat(OT_MNTPOINT,&st) == -1)
+		SAFE_MKDIR(OT_MNTPOINT, 0777);
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc =&tcases[n];
+	struct mount_attr attr = {
+		.attr_set = tc->mount_attrs,
+	};
+	struct statvfs buf;
+
+	TST_EXP_FD_SILENT(open_tree(AT_FDCWD, MNTPOINT, AT_EMPTY_PATH |
+		AT_SYMLINK_NOFOLLOW | OPEN_TREE_CLOEXEC | OPEN_TREE_CLONE));
+	if (!TST_PASS)
+		return;
+
+	otfd = (int)TST_RET;
+
+	TST_EXP_PASS_SILENT(mount_setattr(otfd, "", AT_EMPTY_PATH,&attr, sizeof(attr)),
+		"%s set", tc->name);
+	if (!TST_PASS)
+		goto out1;
+
+	TST_EXP_PASS_SILENT(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH));
+	if (!TST_PASS)
+		goto out1;
+	mount_flag = 1;
+	SAFE_CLOSE(otfd);
+
+	TST_EXP_PASS_SILENT(statvfs(OT_MNTPOINT,&buf), "statvfs sucess");
+	if (!TST_PASS)
+		goto out2;
+
+	if (buf.f_flag&  tc->expect_attrs)
+		tst_res(TPASS, "%s is actually set as expected", tc->name);

testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 119

Quoted 10 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +10 -0
+	else
+		tst_res(TFAIL, "%s is not actually set as expected", tc->name);
+
+	goto out2;
+
+out1:
+	SAFE_CLOSE(otfd);
+out2:
+	mount_flag = 0;
+	SAFE_UMOUNT(OT_MNTPOINT);

mount_flag needs to be checked before otherwise if it fails on:
TST_EXP_PASS_SILENT(mount_setattr(otfd, "", AT_EMPTY_PATH,&attr, sizeof(attr)),

		"%s set", tc->name);

It tries to umount() not yet mounted filesystem:

mount_setattr01.c:109: TPASS: MOUNT_ATTR_RDONLY is actually set as expected mount_setattr01.c:109: TPASS: MOUNT_ATTR_NOSUID is actually set as expected mount_setattr01.c:109: TPASS: MOUNT_ATTR_NODEV is actually set as expected mount_setattr01.c:109: TPASS: MOUNT_ATTR_NOEXEC is actually set as expected mount_setattr01.c:93: TFAIL: MOUNT_ATTR_NOSYMFOLLOW set failed: EINVAL (22) tst_device.c:394: TWARN: umount('ot_mntpoint') failed with EINVAL mount_setattr01.c:119: TBROK: umount(ot_mntpoint) failed: EINVAL (22)

Because we mount later than opening otfd with open_tree() but need to close otfd before umount() we cannot depend only on labels.

Thus I suggest to have this cleanup code:

out1:

	SAFE_CLOSE(otfd);
out2:
	if (mount_flag)
		SAFE_UMOUNT(OT_MNTPOINT);

	mount_flag = 0;
Quoted 2 lines

If Cyril is ok with this I'd merge it before release. (I tested it on various systems, found only this issue.)

This fix is obviously correct. Since I have reviewed this patch in internal, you can also add my reviewed-by for this patch.

ps: I think we should also check functionality like mount03 did instead of just check flag.

Best Regards
Yang Xu

Quoted 18 lines

Kind regards,
Petr

+++ testcases/kernel/syscalls/mount_setattr/mount_setattr01.c

(quoted diff) +3 -1
@@ -115,8 +115,10 @@ static void run(unsigned int n)
  out1:
  	SAFE_CLOSE(otfd);
  out2:
+	if (mount_flag)
+		SAFE_UMOUNT(OT_MNTPOINT);
+
  	mount_flag = 0;
-	SAFE_UMOUNT(OT_MNTPOINT);
  }
 
  static struct tst_test test = {
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by Yang Xu
#5 lore raw

Hi Xu, all,

Quoted 8 lines
Quoted 7 lines

Thus I suggest to have this cleanup code:

out1:

	SAFE_CLOSE(otfd);
out2:
	if (mount_flag)
		SAFE_UMOUNT(OT_MNTPOINT);
Quoted 6 lines
Quoted 4 lines
	mount_flag = 0;

If Cyril is ok with this I'd merge it before release. (I tested it on various systems, found only this issue.)

This fix is obviously correct. Since I have reviewed this patch in internal, you can also add my reviewed-by for this patch.

Adding it (I'm lazy thus want patchwork to take this patch.

Quoted 2 lines

ps: I think we should also check functionality like mount03 did instead of just check flag.

+1. Although test_rwflag() is a bit complex.

Kind regards,
Petr

Quoted 2 lines

Best Regards
Yang Xu

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Hi all,

merged.

I'm sorry Xu, I have forgotten to add your Reviewed-by.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp