syscalls/mount_setattr01: Add basic functional test
PATCH 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 and cleared correctly.
--- include/lapi/fsmount.h | 29 ++++++ runtest/syscalls | 2 + testcases/kernel/syscalls/mount_setattr/.gitignore | 1 + testcases/kernel/syscalls/mount_setattr/Makefile | 6 ++ .../syscalls/mount_setattr/mount_setattr01.c | 104 +++++++++++++++++++++ 5 files changed, 142 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
include/lapi/fsmount.h +29 -0
@@ -15,6 +15,26 @@#include "lapi/fcntl.h" #include "lapi/syscalls.h" +/* +* Mount attributes. +*/ +#define MOUNT_ATTR_RDONLY 0x00000001/* Mount read-only */ +#define MOUNT_ATTR_NOSUID 0x00000002/* Ignore suid and sgid bits */ +#define MOUNT_ATTR_NODEV 0x00000004/* Disallow access to device special files */ +#define MOUNT_ATTR_NOEXEC 0x00000008/* Disallow program execution */ +#define MOUNT_ATTR_NODIRATIME 0x00000080/* Do not update directory access times */ +#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000/* Do not follow symlinks */ + +/* +* mount_setattr() +*/ +struct mount_attr { +__u64 attr_set; +__u64 attr_clr; +__u64 propagation; +__u64 userns_fd; +}; +#ifndef HAVE_FSOPEN static inline int fsopen (const char *fsname,unsigned int flags) {
@@ -61,6 +81,15 @@ static inline int open_tree(int dirfd, const char *pathname, unsigned int flags) }#endif /* HAVE_OPEN_TREE */ +#ifndef HAVE_MOUNT_SETATTR +static inline int mount_setattr (int dirfd,const char *from_pathname,unsigned int flags, +struct mount_attr *attr,size_t size) +{ +return tst_syscall (__NR_mount_setattr, dirfd, from_pathname, flags, + attr, size); +} +#endif /* HAVE_MOUNT_SETATTR */ +/* * New headers added in kernel after 5.2 release, create them for old userspace. */
runtest/syscalls +2 -0
@@ -800,6 +800,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
@@ -0,0 +1 @@ +/mount_setattr01
testcases/kernel/syscalls/mount_setattr/Makefile new file +6 -0
@@ -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 +104 -0
104 lines not on this page · raw message
Signature · 5 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 7 lines
include/lapi/fsmount.h +0
-0@@ -15,6 +15,26 @@#include "lapi/fcntl.h" #include "lapi/syscalls.h"
include/lapi/fsmount.h line 26
Quoted 10 lines
include/lapi/fsmount.h +9
-0+/* +* Mount attributes. +*/ +#define MOUNT_ATTR_RDONLY 0x00000001/* Mount read-only */ +#define MOUNT_ATTR_NOSUID 0x00000002/* Ignore suid and sgid bits */ +#define MOUNT_ATTR_NODEV 0x00000004/* Disallow access to device special files */ +#define MOUNT_ATTR_NOEXEC 0x00000008/* Disallow program execution */ +#define MOUNT_ATTR_NODIRATIME 0x00000080/* Do not update directory access times */ +#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000/* Do not follow symlinks */
These have to be defined only if they are missing, otherwise we will end up with redefition warnings once glibc add these constants, i.e.
#ifndef MOUNT_ATTR_RDONLY
# define MOUNT_ATTR_RDONLY 0x00000001 #endif
...
include/lapi/fsmount.h line 35
Quoted 8 lines
include/lapi/fsmount.h +8
-0+/* +* mount_setattr() +*/ +struct mount_attr { +__u64 attr_set; +__u64 attr_clr; +__u64 propagation; +__u64 userns_fd;
These should be uint64_t, we cannot use the kernel types in userspace.
Quoted 71 lines
include/lapi/fsmount.h +11
-0+}; +#ifndef HAVE_FSOPEN static inline int fsopen (const char *fsname,unsigned int flags) {@@ -61,6 +81,15 @@ static inline int open_tree(int dirfd, const char *pathname, unsigned int flags) }#endif /* HAVE_OPEN_TREE */ +#ifndef HAVE_MOUNT_SETATTR +static inline int mount_setattr (int dirfd,const char *from_pathname,unsigned int flags, +struct mount_attr *attr,size_t size) +{ +return tst_syscall (__NR_mount_setattr, dirfd, from_pathname, flags, + attr, size); +} +#endif /* HAVE_MOUNT_SETATTR */ +/* * New headers added in kernel after 5.2 release, create them for old userspace. */ runtest/syscalls +2
-0@@ -800,6 +800,8 @@ mount04 mount04 mount05 mount05 mount06 mount06 +mount_setattr01 mount_setattr01 + move_mount01 move_mount01 move_mount02 move_mount02testcases/kernel/syscalls/mount_setattr/.gitignore new file +1
-0@@ -0,0 +1 @@ +/mount_setattr01testcases/kernel/syscalls/mount_setattr/Makefile new file +6
-0@@ -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.mktestcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +12
-0@@ -0,0 +1,104 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +*/ + +/*\ +* [Description] +* +* Basic mount_setattr() test. +* Test whether the basic mount attributes are set and cleared correctly. +*
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 22
Quoted 10 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +10
-0+* Minimum Linux version required is v5.12. +*/ + +#include "tst_test.h" +#include "lapi/fsmount.h" +#include "lapi/stat.h" + +#define MNTPOINT "mntpoint" +#define OT_MNTPOINT "ot_mntpoint" +#define TCASE_ENTRY (_mount_attrs) {.name = #_mount_attrs, .mount_attrs = _mount_attrs}
^
Please do not use identifiers starting with underscore, these are reserved for kernel and libc.
Quoted 9 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +9
-0+ +static int dir_created; + +static struct tcase { +char *name; +unsigned int mount_attrs; +} tcases[] = { +TCASE_ENTRY (MOUNT_ATTR_RDONLY ), +TCASE_ENTRY (MOUNT_ATTR_NOSUID ),
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 41
Quoted 10 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +10
-0+TCASE_ENTRY (MOUNT_ATTR_NODEV ), +TCASE_ENTRY (MOUNT_ATTR_NOEXEC ), +TCASE_ENTRY (MOUNT_ATTR_NOSYMFOLLOW ), + TCASE_ENTRY(MOUNT_ATTR_NODIRATIME), +}; + +static void cleanup (void ) +{ +if (dir_created) +SAFE_RMDIR (OT_MNTPOINT );
No need to rmdir anything, it will be removed by the test library along with the test temporary directory.
Quoted 13 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +13
-0+} + +static void setup (void ) +{ +fsopen_supported_by_kernel (); +SAFE_MKDIR (OT_MNTPOINT ,0777 ); + dir_created =1 ; +} + +static void run (unsigned int n) +{ +int otfd; +struct tcase *tc = &tcases[n];
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 64
Quoted 10 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +10
-0+struct mount_attr attr = { + .attr_set = tc->mount_attrs, + }; + +TEST (otfd =open_tree (AT_FDCWD ,MNTPOINT ,AT_EMPTY_PATH | +AT_SYMLINK_NOFOLLOW |OPEN_TREE_CLOEXEC |OPEN_TREE_CLONE )); +if (otfd ==-1 ) { +tst_res (TFAIL |TTERRNO ,"open_tree() failed" ); +return ; + }
This can be just TST_EXP_FD()
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 70
Quoted 5 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +5
-0+TEST (mount_setattr (otfd,"" ,AT_EMPTY_PATH , &attr,sizeof (attr))); +if (TST_RET ==-1 ) { +tst_res (TFAIL |TTERRNO ,"mount_setattr() set attr %s failed." , tc->name); +return ; + }
and this can be TST_EXP_PASS()
And here we should check if the attribute was really changed.
I guess that we can add functions to verify most of the attributes, e.g. for RDONLY we can add a function that tries to open file for writing and expects that it fails with EROFS if the attribute has been set.
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 72
Quoted 1 line
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +1
-0+ attr.attr_clr = tc->mount_attrs;
This does not have any efect at all unless we also reset attr_set. Accordinlgy to the manual page kernel first clears attributes then sets them, so as long as the attr_set remains set to tc->mount_attrs the following mount_setattr() is no-op.
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 78
Quoted 5 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +5
-0+TEST (mount_setattr (otfd,"" ,AT_EMPTY_PATH , &attr,sizeof (attr))); +if (TST_RET ==-1 ) { +tst_res (TFAIL |TTERRNO ,"mount_setattr() clear attr %s failed." , tc->name); +return ; + }
This can be just TST_EXP_PASS()
And here we should check that the attribute has been reset, e.g. for RDONLY attribute we should check that files can be opened for writing again.
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 84
Quoted 5 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +5
-0+TEST (move_mount (otfd,"" ,AT_FDCWD ,OT_MNTPOINT ,MOVE_MOUNT_F_EMPTY_PATH )); +if (TST_RET ==-1 ) { +tst_res (TFAIL |TTERRNO ,"move_mount() failed" ); +return ; + }
I do not get why we do move the mount at all, this is supposed to be a simple test for mount_setattr().
Quoted 25 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +19
-0+SAFE_CLOSE (otfd); + +if (tst_is_mounted_at_tmpdir (OT_MNTPOINT )) { +SAFE_UMOUNT (OT_MNTPOINT ); +tst_res (TPASS ,"mount_setattr() set and clear attr %s passed." , tc->name); + } +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .test = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .mount_device =1 , + .mntpoint =MNTPOINT , + .all_filesystems =1 , + .skip_filesystems = (const char *const []){"fuse" ,NULL }, +};Signature · 5 lines
1.8.3.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi
Quoted 32 lines
-----邮件原件-----
发件人: ltp <[email protected]> 代表 Cyril Hrubis
发送时间: 2022年3月10日 21:06
收件人: Dai, Shili <[email protected]>
抄送: [email protected]
主题: Re: [LTP] [PATCH] syscalls/mount_setattr01: Add basic functional testHi!
include/lapi/fsmount.h line 22
Quoted 13 lines
include/lapi/fsmount.h index renamed from include/lapi/fsmount.h +0
-0fa25306..99d0a0a 100644
include/lapi/fsmount.h +5
-0@@ -15,6 +15,26 @@#include "lapi/fcntl.h" #include "lapi/syscalls.h" +/* +* Mount attributes. +*/ +#define MOUNT_ATTR_RDONLY 0x00000001/* Mount read-only */ +#define MOUNT_ATTR_NOSUID 0x00000002/* Ignore suid and sgid bits */
include/lapi/fsmount.h line 23
Quoted 1 line
include/lapi/fsmount.h +1
-0+#define MOUNT_ATTR_NODEV 0x00000004/* Disallow access to device special files */
include/lapi/fsmount.h line 24
Quoted 1 line
include/lapi/fsmount.h +1
-0+#define MOUNT_ATTR_NOEXEC 0x00000008/* Disallow program execution */
include/lapi/fsmount.h line 25
Quoted 1 line
include/lapi/fsmount.h +1
-0+#define MOUNT_ATTR_NODIRATIME 0x00000080/* Do not update directory access times */
include/lapi/fsmount.h line 26
Quoted 1 line
include/lapi/fsmount.h +1
-0+#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000/* Do not follow symlinks
Quoted 9 lines
include/lapi/fsmount.h line 27
Quoted 1 line
include/lapi/fsmount.h +1
-0+*/ These have to be defined only if they are missing, otherwise we will end up with redefition warnings once glibc add these constants, i.e.
#ifndef
MOUNT_ATTR_RDONLY# define MOUNT_ATTR_RDONLY 0x00000001 #endif
Get it.
Quoted 13 lines
...
include/lapi/fsmount.h line 35
Quoted 8 lines
include/lapi/fsmount.h +8
-0+/* +* mount_setattr() +*/ +struct mount_attr { +__u64 attr_set; +__u64 attr_clr; +__u64 propagation; +__u64 userns_fd;These should be
uint64_t, we cannot use the kernel types in userspace.
OK.
Quoted 1 line
Quoted 1 line
+};
...
Quoted 8 lines
include/lapi/fsmount.h
Quoted 3 lines
include/lapi/fsmount.h +3
-0+#define MNTPOINT "mntpoint" +#define OT_MNTPOINT "ot_mntpoint" +#define TCASE_ENTRY (_mount_attrs) {.name =#_mount_attrs, .mount_attrs =
_mount_attrs}^Please do not use identifiers starting with underscore, these are reserved for kernel and libc.
Sure.
Quoted 14 lines
Quoted 14 lines
include/lapi/fsmount.h +14
-0+ +static int dir_created; + +static struct tcase { +char *name; +unsigned int mount_attrs; +} tcases[] = { +TCASE_ENTRY (MOUNT_ATTR_RDONLY ), +TCASE_ENTRY (MOUNT_ATTR_NOSUID ), +TCASE_ENTRY (MOUNT_ATTR_NODEV ), +TCASE_ENTRY (MOUNT_ATTR_NOEXEC ), +TCASE_ENTRY (MOUNT_ATTR_NOSYMFOLLOW ), +TCASE_ENTRY (MOUNT_ATTR_NODIRATIME ), +};
Quoted 9 lines
include/lapi/fsmount.h
Quoted 5 lines
include/lapi/fsmount.h +5
-0+ +static void cleanup (void ) +{ +if (dir_created) +SAFE_RMDIR (OT_MNTPOINT );No need to rmdir anything, it will be removed by the test library along with the test temporary directory.
There are several file systems to be tested. If we do not rmdir, it will be error(dir is EEXIST) when testing the second file system.
Quoted 20 lines
Quoted 9 lines
include/lapi/fsmount.h +9
-0+} + +static void setup (void ) +{ +fsopen_supported_by_kernel (); +SAFE_MKDIR (OT_MNTPOINT ,0777 ); + dir_created =1 ; +} +include/lapi/fsmount.h
Quoted 10 lines
include/lapi/fsmount.h +10
-0+static void run(unsigned int n) +{ + int otfd; + struct tcase *tc = &tcases[n]; + struct mount_attr attr = { + .attr_set = tc->mount_attrs, + }; + + TEST(otfd = open_tree(AT_FDCWD, MNTPOINT, AT_EMPTY_PATH | + AT_SYMLINK_NOFOLLOW | OPEN_TREE_CLOEXEC |
OPEN_TREE_CLONE));
Quoted 6 lines
include/lapi/fsmount.h
Quoted 4 lines
include/lapi/fsmount.h +4
-0+if (otfd ==-1 ) { +tst_res (TFAIL |TTERRNO ,"open_tree() failed" ); +return ; + }This can be just
TST_EXP_FD()
OK.
Quoted 10 lines
include/lapi/fsmount.h
Quoted 4 lines
include/lapi/fsmount.h +3
-0+TEST (mount_setattr (otfd,"" ,AT_EMPTY_PATH , &attr,sizeof (attr))); +if (TST_RET ==-1 ) { + tst_res(TFAIL | TTERRNO, "mount_setattr() set attr %s failed.",
tc->name);include/lapi/fsmount.h
Quoted 2 lines
include/lapi/fsmount.h +2
-0+return ; + }and this can be
TST_EXP_PASS()
OK.
Quoted 7 lines
And here we should check if the attribute was really changed.
I guess that we can add functions to verify most of the attributes, e.g. for RDONLY we can add a function that tries to open file for writing and expects that it fails with EROFS if the attribute has been set.
Guess statvfs(3) may help.
Quoted 8 lines
include/lapi/fsmount.h
Quoted 1 line
include/lapi/fsmount.h +1
-0+ attr.attr_clr = tc->mount_attrs;This does not have any efect at all unless we also reset
attr_set. Accordinlgy to the manual page kernel first clears attributes then sets them, so as long as theattr_setremains set totc->mount_attrsthe followingmount_setattr()is no-op.
Will be deleted in v2.
Quoted 16 lines
include/lapi/fsmount.h
Quoted 3 lines
include/lapi/fsmount.h +3
-0+TEST (mount_setattr (otfd,"" ,AT_EMPTY_PATH , &attr,sizeof (attr))); +if (TST_RET ==-1 ) { + tst_res(TFAIL | TTERRNO, "mount_setattr() clear attr %s failed.",
tc->name);include/lapi/fsmount.h
Quoted 2 lines
include/lapi/fsmount.h +2
-0+return ; + }This can be just
TST_EXP_PASS()And here we should check that the attribute has been reset, e.g. for RDONLY attribute we should check that files can be opened for writing again.
include/lapi/fsmount.h
Quoted 1 line
include/lapi/fsmount.h +1
-0+ TEST(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT,
MOVE_MOUNT_F_EMPTY_PATH));
Quoted 7 lines
include/lapi/fsmount.h
Quoted 4 lines
include/lapi/fsmount.h +4
-0+if (TST_RET ==-1 ) { +tst_res (TFAIL |TTERRNO ,"move_mount() failed" ); +return ; + }I do not get why we do move the mount at all, this is supposed to be a simple test for
mount_setattr().
move_mount place the filesystem into a mount namespace and then it will be visible to users.
I'll post a v2 patch soon.
Regards,
- Chen
Quoted 33 lines
include/lapi/fsmount.h
Quoted 6 lines
include/lapi/fsmount.h +5
-0+SAFE_CLOSE (otfd); + +if (tst_is_mounted_at_tmpdir (OT_MNTPOINT )) { +SAFE_UMOUNT (OT_MNTPOINT ); + tst_res(TPASS, "mount_setattr() set and clear attr %s passed.",
tc->name);Quoted 17 lines
include/lapi/fsmount.h +13
-1+ } +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .test = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .mount_device =1 , + .mntpoint =MNTPOINT , + .all_filesystems =1 , + .skip_filesystems = (const char *const []){"fuse" ,NULL }, }; --1.8.3.1
Quoted 2 lines
--
Mailing list info: https://lists.linux.it/listinfo/ltp--
Cyril Hrubis
[email protected]--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi
Quoted 31 lines
-----邮件原件-----
发件人: ltp <[email protected]> 代表 Cyril Hrubis
发送时间: 2022年3月10日 21:06
收件人: Dai, Shili <[email protected]>
抄送: [email protected]
主题: Re: [LTP] [PATCH] syscalls/mount_setattr01: Add basic functional testHi!
include/lapi/fsmount.h line 22
Quoted 13 lines
include/lapi/fsmount.h index renamed from include/lapi/fsmount.h +0
-0fa25306..99d0a0a 100644
include/lapi/fsmount.h +5
-0@@ -15,6 +15,26 @@#include "lapi/fcntl.h" #include "lapi/syscalls.h" +/* +* Mount attributes. +*/ +#define MOUNT_ATTR_RDONLY 0x00000001/* Mount read-only */ +#define MOUNT_ATTR_NOSUID 0x00000002/* Ignore suid and sgid bits */
include/lapi/fsmount.h line 23
Quoted 1 line
include/lapi/fsmount.h +1
-0+#define MOUNT_ATTR_NODEV 0x00000004/* Disallow access to device special files */
include/lapi/fsmount.h line 24
Quoted 1 line
include/lapi/fsmount.h +1
-0+#define MOUNT_ATTR_NOEXEC 0x00000008/* Disallow program execution */
include/lapi/fsmount.h line 25
Quoted 1 line
include/lapi/fsmount.h +1
-0+#define MOUNT_ATTR_NODIRATIME 0x00000080/* Do not update directory access times */
include/lapi/fsmount.h line 26
Quoted 1 line
include/lapi/fsmount.h +1
-0+#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000/* Do not follow symlinks
Quoted 9 lines
include/lapi/fsmount.h line 27
Quoted 1 line
include/lapi/fsmount.h +1
-0+*/ These have to be defined only if they are missing, otherwise we will end up with redefition warnings once glibc add these constants, i.e.
#ifndef
MOUNT_ATTR_RDONLY# define MOUNT_ATTR_RDONLY 0x00000001 #endif
Get it.
Quoted 13 lines
...
include/lapi/fsmount.h line 35
Quoted 8 lines
include/lapi/fsmount.h +8
-0+/* +* mount_setattr() +*/ +struct mount_attr { +__u64 attr_set; +__u64 attr_clr; +__u64 propagation; +__u64 userns_fd;These should be
uint64_t, we cannot use the kernel types in userspace.
OK.
Quoted 1 line
Quoted 1 line
+};
...
Quoted 8 lines
include/lapi/fsmount.h
Quoted 3 lines
include/lapi/fsmount.h +3
-0+#define MNTPOINT "mntpoint" +#define OT_MNTPOINT "ot_mntpoint" +#define TCASE_ENTRY (_mount_attrs) {.name =#_mount_attrs, .mount_attrs =
_mount_attrs}^Please do not use identifiers starting with underscore, these are reserved for kernel and libc.
Sure.
Quoted 14 lines
Quoted 14 lines
include/lapi/fsmount.h +14
-0+ +static int dir_created; + +static struct tcase { +char *name; +unsigned int mount_attrs; +} tcases[] = { +TCASE_ENTRY (MOUNT_ATTR_RDONLY ), +TCASE_ENTRY (MOUNT_ATTR_NOSUID ), +TCASE_ENTRY (MOUNT_ATTR_NODEV ), +TCASE_ENTRY (MOUNT_ATTR_NOEXEC ), +TCASE_ENTRY (MOUNT_ATTR_NOSYMFOLLOW ), +TCASE_ENTRY (MOUNT_ATTR_NODIRATIME ), +};
Quoted 9 lines
include/lapi/fsmount.h
Quoted 5 lines
include/lapi/fsmount.h +5
-0+ +static void cleanup (void ) +{ +if (dir_created) +SAFE_RMDIR (OT_MNTPOINT );No need to rmdir anything, it will be removed by the test library along with the test temporary directory.
There are several file systems to be tested. If we do not rmdir, it will be error(dir is EEXIST) when testing the second file system.
Quoted 20 lines
Quoted 9 lines
include/lapi/fsmount.h +9
-0+} + +static void setup (void ) +{ +fsopen_supported_by_kernel (); +SAFE_MKDIR (OT_MNTPOINT ,0777 ); + dir_created =1 ; +} +include/lapi/fsmount.h
Quoted 10 lines
include/lapi/fsmount.h +10
-0+static void run(unsigned int n) +{ + int otfd; + struct tcase *tc = &tcases[n]; + struct mount_attr attr = { + .attr_set = tc->mount_attrs, + }; + + TEST(otfd = open_tree(AT_FDCWD, MNTPOINT, AT_EMPTY_PATH | + AT_SYMLINK_NOFOLLOW | OPEN_TREE_CLOEXEC |
OPEN_TREE_CLONE));
Quoted 6 lines
include/lapi/fsmount.h
Quoted 4 lines
include/lapi/fsmount.h +4
-0+if (otfd ==-1 ) { +tst_res (TFAIL |TTERRNO ,"open_tree() failed" ); +return ; + }This can be just
TST_EXP_FD()
OK.
Quoted 10 lines
include/lapi/fsmount.h
Quoted 4 lines
include/lapi/fsmount.h +3
-0+TEST (mount_setattr (otfd,"" ,AT_EMPTY_PATH , &attr,sizeof (attr))); +if (TST_RET ==-1 ) { + tst_res(TFAIL | TTERRNO, "mount_setattr() set attr %s failed.",
tc->name);include/lapi/fsmount.h
Quoted 2 lines
include/lapi/fsmount.h +2
-0+return ; + }and this can be
TST_EXP_PASS()
OK.
Quoted 7 lines
And here we should check if the attribute was really changed.
I guess that we can add functions to verify most of the attributes, e.g. for RDONLY we can add a function that tries to open file for writing and expects that it fails with EROFS if the attribute has been set.
Guess statvfs(3) may help.
Quoted 7 lines
include/lapi/fsmount.h
Quoted 1 line
include/lapi/fsmount.h +1
-0+ attr.attr_clr = tc->mount_attrs;This does not have any efect at all unless we also reset
attr_set. Accordinlgy to the manual page kernel first clears attributes then sets them, so as long as theattr_setremains set totc->mount_attrsthe followingmount_setattr()is no-op.
Will be deleted in v2.
Quoted 16 lines
include/lapi/fsmount.h
Quoted 3 lines
include/lapi/fsmount.h +3
-0+TEST (mount_setattr (otfd,"" ,AT_EMPTY_PATH , &attr,sizeof (attr))); +if (TST_RET ==-1 ) { + tst_res(TFAIL | TTERRNO, "mount_setattr() clear attr %s failed.",
tc->name);include/lapi/fsmount.h
Quoted 2 lines
include/lapi/fsmount.h +2
-0+return ; + }This can be just
TST_EXP_PASS()And here we should check that the attribute has been reset, e.g. for RDONLY attribute we should check that files can be opened for writing again.
include/lapi/fsmount.h
Quoted 1 line
include/lapi/fsmount.h +1
-0+ TEST(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT,
MOVE_MOUNT_F_EMPTY_PATH));
Quoted 7 lines
include/lapi/fsmount.h
Quoted 4 lines
include/lapi/fsmount.h +4
-0+if (TST_RET ==-1 ) { +tst_res (TFAIL |TTERRNO ,"move_mount() failed" ); +return ; + }I do not get why we do move the mount at all, this is supposed to be a simple test for
mount_setattr().
move_mount place the filesystem into a mount namespace and then it will be visible to users.
I'll post a v2 patch soon.
Regards,
- Chen
Quoted 33 lines
include/lapi/fsmount.h
Quoted 6 lines
include/lapi/fsmount.h +5
-0+SAFE_CLOSE (otfd); + +if (tst_is_mounted_at_tmpdir (OT_MNTPOINT )) { +SAFE_UMOUNT (OT_MNTPOINT ); + tst_res(TPASS, "mount_setattr() set and clear attr %s passed.",
tc->name);Quoted 17 lines
include/lapi/fsmount.h +13
-1+ } +} + +static struct tst_test test = { + .tcnt =ARRAY_SIZE (tcases), + .test = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .mount_device =1 , + .mntpoint =MNTPOINT , + .all_filesystems =1 , + .skip_filesystems = (const char *const []){"fuse" ,NULL }, }; --1.8.3.1
Quoted 2 lines
--
Mailing list info: https://lists.linux.it/listinfo/ltp--
Cyril Hrubis
[email protected]--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp