syscalls/mount_setattr01: Add basic functional test
PATCH v4 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.
---
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
@@ -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
@@ -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
@@ -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 +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
Hi!
Quoted 15 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +15
-0+// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +* Author: Chen Hanxiao <[email protected]> +*/ + +/*\ +* [Description] +* +* Basic mount_setattr() test. +* Test whether the basic mount attributes are set correctly. +* +* Verify some MOUNT_SETATTR(2) attributes: +*
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 25
Quoted 10 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +10
-0+* - 1) MOUNT_ATTR_RDONLY - makes the mount read-only +* - 2) MOUNT_ATTR_NOSUID - causes the mount not to honor the +* set-user-ID and set-group-ID mode bits and file capabilities +* when executing programs. +* - 3) MOUNT_ATTR_NODEV - prevents access to devices on this mount +* - 4) MOUNT_ATTR_NOEXEC - prevents executing programs on this mount +* - 5) MOUNT_ATTR_NOSYMFOLLOW - prevents following symbolic links +* on this mount +* - 6) MOUNT_ATTR_NODIRATIME - prevents updating access time for +* directories on this mount
The numbers here are useless and confusing I bet that it renders strangely in asciidoc too.
Quoted 82 lines
+ * The functionality was added in v5.12.
+ */testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +80
-0+ +#define _GNU_SOURCE + +#include <sys/statvfs.h> +#include "tst_test.h" +#include "lapi/fsmount.h" +#include "lapi/stat.h" + +#define MNTPOINT "mntpoint" +#define OT_MNTPOINT "ot_mntpoint" +#define TCASE_ENTRY (attrs, exp_attrs) \ + { \ + .name = #attrs, \ + .mount_attrs = attrs, \ + .expect_attrs = exp_attrs \ + } + +static int mount_flag, otfd =-1 ; + +static struct tcase { +char *name; +unsigned int mount_attrs; +unsigned int expect_attrs; +} tcases[] = { +TCASE_ENTRY (MOUNT_ATTR_RDONLY ,ST_RDONLY ), +TCASE_ENTRY (MOUNT_ATTR_NOSUID ,ST_NOSUID ), +TCASE_ENTRY (MOUNT_ATTR_NODEV ,ST_NODEV ), +TCASE_ENTRY (MOUNT_ATTR_NOEXEC ,ST_NOEXEC ), +TCASE_ENTRY (MOUNT_ATTR_NOSYMFOLLOW ,ST_NOSYMFOLLOW ), +TCASE_ENTRY (MOUNT_ATTR_NODIRATIME ,ST_NODIRATIME ), +}; + +static void cleanup (void ) +{ +if (otfd >-1 ) +SAFE_CLOSE (otfd); +if (mount_flag) +SAFE_UMOUNT (OT_MNTPOINT ); +} + +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 out; + +TST_EXP_PASS_SILENT (move_mount (otfd,"" ,AT_FDCWD ,OT_MNTPOINT ,MOVE_MOUNT_F_EMPTY_PATH )); +if (!TST_PASS ) + goto out; + mount_flag =1 ; + +TST_EXP_PASS_SILENT (statvfs (OT_MNTPOINT , &buf),"statvfs sucess" ); +if (!TST_PASS ) + goto out; + +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 118
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); + +out: +if (otfd >-1 ) +SAFE_CLOSE (otfd); +if (tst_is_mounted_at_tmpdir (OT_MNTPOINT )) { + mount_flag =0 ; +SAFE_UMOUNT (OT_MNTPOINT ); + }
Can we instead of the ifs just jump to a right label as I asked in the previous review?
Quoted 18 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +13
-0+} + +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 · 1 line
2.35.1
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 19 lines
Quoted 10 lines
+/*\
+ * [Description]
+ *
+ * Basicmount_setattr()test.
+ * Test whether the basic mount attributes are set correctly.
+ *
+ * Verify someMOUNT_SETATTR(2)attributes:
+ *
+ * - 1)MOUNT_ATTR_RDONLY- makes the mount read-only
+ * - 2)MOUNT_ATTR_NOSUID- causes the mount not to honor theQuoted 8 lines
+ * set-user-ID and set-group-ID mode bits and file capabilities
+ * when executing programs.
+ * - 3)MOUNT_ATTR_NODEV- prevents access to devices on this mount
+ * - 4)MOUNT_ATTR_NOEXEC- prevents executing programs on this mount
+ * - 5)MOUNT_ATTR_NOSYMFOLLOW- prevents following symbolic links
+ * on this mount
+ * - 6)MOUNT_ATTR_NODIRATIME- prevents updating access time for
+ * directories on this mount
Quoted 2 lines
The numbers here are useless and confusing I bet that it renders strangely in asciidoc too.
+1. Simple bullets done with "-" are good enough.
Some people used numbers in our docs, but I don't think it's necessary and I'd be for removing it.
BTW if we want to use it, it'd have to be with dot (i.e. 1.).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi,all
Quoted 28 lines
-----邮件原件-----
发件人: Cyril Hrubis <[email protected]>
发送时间: 2022年4月27日 22:05
收件人: Chen, Hanxiao/陈 晗霄 <[email protected]>
抄送: [email protected]; [email protected]; Dai, Shili/戴 世丽 <[email protected]>
主题: Re: [PATCH v4] syscalls/mount_setattr01: Add basic functional testHi!
Quoted 19 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +19
-0+// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. +* Author: Dai Shili <[email protected]> +* Author: Chen Hanxiao <[email protected]> */ + +/*\ +* [Description] +* +* Basic mount_setattr() test. +* Test whether the basic mount attributes are set correctly. +* +* Verify some MOUNT_SETATTR(2) attributes: +* +* - 1) MOUNT_ATTR_RDONLY - makes the mount read-only +* - 2) MOUNT_ATTR_NOSUID - causes the mount not to honor the +* set-user-ID and set-group-ID mode bits and file capabilities +* when executing programs. +* - 3) MOUNT_ATTR_NODEV - prevents access to devices on this mount
Quoted 9 lines
Quoted 5 lines
+ * - 4)
MOUNT_ATTR_NOEXEC- prevents executing programs on this mount
+ * - 5)MOUNT_ATTR_NOSYMFOLLOW- prevents following symbolic links
+ * on this mount
+ * - 6)MOUNT_ATTR_NODIRATIME- prevents updating access time for
+ * directories on this mountThe numbers here are useless and confusing I bet that it renders strangely in asciidoc too.
OK.
Quoted 1 line
Quoted 1 line
+ * The functionality was added in v5.12.
...
Quoted 9 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c line 118
Quoted 6 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +6
-0+if (otfd >-1 ) +SAFE_CLOSE (otfd); +if (tst_is_mounted_at_tmpdir (OT_MNTPOINT )) { + mount_flag =0 ; +SAFE_UMOUNT (OT_MNTPOINT ); + }Can we instead of the ifs just jump to a right label as I asked in the previous review?
Sure.
Regards,
- Chen
Quoted 22 lines
Quoted 14 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c new file +12
-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 }, }; --Quoted 4 lines
2.35.1
--
Cyril Hrubis
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp