mount_setattr02.c: Check mount_setattr attr.propagation
PATCH 1/1 mount_setattr02.c: Check mount_setattr attr.propagation
--- runtest/syscalls | 1 + .../kernel/syscalls/mount_setattr/.gitignore | 1 + .../syscalls/mount_setattr/mount_setattr02.c | 102 ++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 testcases/kernel/syscalls/mount_setattr/mount_setattr02.c
runtest/syscalls +1 -0
@@ -856,6 +856,7 @@ mount06 mount06 mount07 mount07 mount_setattr01 mount_setattr01 +mount_setattr02 mount_setattr02 move_mount01 move_mount01 move_mount02 move_mount02
testcases/kernel/syscalls/mount_setattr/.gitignore +1 -0
@@ -1 +1,2 @@ /mount_setattr01 +/mount_setattr02
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +102 -0
102 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
nit: I guess you want to replace dot with space in subject.
Quoted 12 lines
+++
b/testcases/kernel/syscalls/mount_setattr/mount_setattr02.ctestcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +10
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2025 SUSE LLC Wei Gao <[email protected]> +*/ + +/*\ +* [Description] +* +* Basic mount_setattr() test. +* Test basic propagation mount attributes are set correctly.
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 20
Quoted 10 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +10
-0+*/ + +#define _GNU_SOURCE + +#include <sys/statvfs.h> +#include "tst_test.h" +#include "lapi/fsmount.h" +#include "tst_safe_stdio.h" + +#define DIRA "/DIRA_PROPAGATION_CHECK"
Is it necessary to to use directory under root?
...
Review line 22
Quoted 2 lines
(quoted diff) +2
-0+static void cleanup(void) +{
I guess this is due result of:SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0); There should be either a proper detection whether this works or
../../../../include/lapi/fsmount.h:113: TCONF: syscall(442) __NR_mount_setattr not supported on your arch mount_setattr02.c:52: TWARN: rmdir(/DIRA_PROPAGATION_CHECK) failed: EBUSY (16)
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 52
Quoted 1 line
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +1
-0+SAFE_RMDIR (DIRA );
When running on old kernel (e.g. SLES based 4.12) it fails due TCONF:
../../../../include/lapi/fsmount.h:197: TCONF: Test not supported on kernel version < v5.2 mount_setattr02.c:52: TWARN: rmdir(/DIRA_PROPAGATION_CHECK) failed: ENOENT (2)
There should be a flag to remove dir only when it was created.
Review line 24
Quoted 1 line
(quoted diff) +1
-0+
nit: please remove this new line (I have to keep asking this :( ).
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 58
Quoted 5 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +5
-0+} + +static void setup (void ) +{ +fsopen_supported_by_kernel ();
I wonder if this needed for detecting new mount API support. Because second SAFE_MOUNT also runs code which detects code unsupported:
../../../../include/lapi/fsmount.h:113: TCONF: syscall(442) __NR_mount_setattr not supported on your arch mount_setattr02.c:52: TWARN: rmdir(/DIRA_PROPAGATION_CHECK) failed: EBUSY (16)
But I have no idea what would be needed to be done to cleanup result of the first SAFE_MOUNT().
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 65
Quoted 7 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +7
-0+ +SAFE_MKDIR (DIRA ,0777 ); +} + +static void run (void ) +{ +
and here new line.
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 68
Quoted 3 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +3
-0+SAFE_UNSHARE (CLONE_NEWNS ); +SAFE_MOUNT (NULL ,"/" ,NULL ,MS_REC |MS_PRIVATE ,0 ); +SAFE_MOUNT ("testing" ,DIRA ,"tmpfs" ,MS_NOATIME |MS_NODEV ,"" );
Do these 2 needs to be in the run()? How about move them to setup()?
static int dir_created, mounted;
static void setup(void)
{
fsopen_supported_by_kernel();
SAFE_MKDIR(DIRA, 0777);
dir_created = 1;
SAFE_UNSHARE(CLONE_NEWNS);
SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
SAFE_MOUNT("testing", DIRA, "tmpfs", MS_NOATIME | MS_NODEV, "");
mounted = 1;
}static void cleanup(void)
{
if (mounted)
SAFE_UMOUNT(DIRA);
if (dir_created)
SAFE_RMDIR(DIRA);
}+ I later create generic helper from is_shared_mount().
Kind regards,
Petr
Quoted 34 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +34
-0+ +struct mount_attr attr = { + .attr_set =MOUNT_ATTR_RDONLY |MOUNT_ATTR_NOEXEC |MOUNT_ATTR_RELATIME , + .attr_clr =MOUNT_ATTR__ATIME , + }; + +TST_EXP_PASS_SILENT (mount_setattr (-1 ,DIRA ,0 , &attr,sizeof (attr))); +TST_EXP_EQ_LI (is_shared_mount (DIRA ),0 ); + + attr.propagation =-1 ; +TST_EXP_FAIL_SILENT (mount_setattr (-1 ,DIRA ,0 , &attr,sizeof (attr)),EINVAL ); +TST_EXP_EQ_LI (is_shared_mount (DIRA ),0 ); + + attr.propagation =MS_SHARED ; +TST_EXP_PASS_SILENT (mount_setattr (-1 ,DIRA ,0 , &attr,sizeof (attr))); +TST_EXP_EQ_LI (is_shared_mount (DIRA ),1 ); + + attr.propagation =MS_PRIVATE ; +TST_EXP_PASS_SILENT (mount_setattr (-1 ,DIRA ,0 , &attr,sizeof (attr))); +TST_EXP_EQ_LI (is_shared_mount (DIRA ),0 ); + + attr.propagation =MS_SLAVE ; +TST_EXP_PASS_SILENT (mount_setattr (-1 ,DIRA ,0 , &attr,sizeof (attr))); +TST_EXP_EQ_LI (is_shared_mount (DIRA ),0 ); + +SAFE_UMOUNT (DIRA ); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , +};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 3 lines · Petr Vorel
Hi Wei,
nit: I guess you want to replace dot with space in subject.
You mean i s/attr.propagation/attr propagation ?
Quoted 17 lines
Quoted 17 lines
+++
b/testcases/kernel/syscalls/mount_setattr/mount_setattr02.ctestcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +14
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2025 SUSE LLC Wei Gao <[email protected]> +*/ + +/*\ +* [Description] +* +* Basic mount_setattr() test. +* Test basic propagation mount attributes are set correctly. +*/ + +#define _GNU_SOURCE +
Quoted 8 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 20
Quoted 6 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +6
-0+#include <sys/statvfs.h> +#include "tst_test.h" +#include "lapi/fsmount.h" +#include "tst_safe_stdio.h" + +#define DIRA "/DIRA_PROPAGATION_CHECK"Is it necessary to to use directory under root?
Yes. Otherwise failed will happen during mount_setattr. But i have not check for detail.
Quoted 17 lines
...
Review
Quoted 2 lines
(quoted diff) +2
-0+static void cleanup(void) +{I guess this is due result of:
SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0); There should be either a proper detection whether this works or
../../../../include/lapi/fsmount.h:113: TCONF: syscall(442)__NR_mount_setattrnot supported on your arch mount_setattr02.c:52: TWARN:rmdir(/DIRA_PROPAGATION_CHECK)failed: EBUSY (16)testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 52
Quoted 1 line
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +1
-0+SAFE_RMDIR (DIRA );When running on old kernel (e.g. SLES based 4.12) it fails due TCONF:
Quoted 7 lines
../../../../include/lapi/fsmount.h:197: TCONF: Test not supported on kernel version < v5.2 mount_setattr02.c:52: TWARN:rmdir(/DIRA_PROPAGATION_CHECK)failed: ENOENT (2)There should be a flag to remove dir only when it was created.
Quoted 1 line
+
nit: please remove this new line (I have to keep asking this :( ).
Sorry, i need pay attention, thanks for point this out with great patient :).
Quoted 50 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 58
Quoted 5 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +5
-0+} + +static void setup (void ) +{ +fsopen_supported_by_kernel ();I wonder if this needed for detecting new mount API support. Because second
SAFE_MOUNTalso runs code which detects code unsupported:
../../../../include/lapi/fsmount.h:113: TCONF: syscall(442)__NR_mount_setattrnot supported on your arch mount_setattr02.c:52: TWARN:rmdir(/DIRA_PROPAGATION_CHECK)failed: EBUSY (16)But I have no idea what would be needed to be done to cleanup result of the first
SAFE_MOUNT().testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 65
Quoted 7 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +7
-0+ +SAFE_MKDIR (DIRA ,0777 ); +} + +static void run (void ) +{ +and here new line.
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 68
Quoted 3 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +3
-0+SAFE_UNSHARE (CLONE_NEWNS ); +SAFE_MOUNT (NULL ,"/" ,NULL ,MS_REC |MS_PRIVATE ,0 ); +SAFE_MOUNT ("testing" ,DIRA ,"tmpfs" ,MS_NOATIME |MS_NODEV ,"" );Do these 2 needs to be in the
run()? How about move them tosetup()?static int
dir_created, mounted;static void setup(void)
{ fsopen_supported_by_kernel(); SAFE_MKDIR(DIRA, 0777); dir_created = 1; SAFE_UNSHARE(CLONE_NEWNS); SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0); SAFE_MOUNT("testing", DIRA, "tmpfs", MS_NOATIME | MS_NODEV, ""); mounted = 1; }static void cleanup(void)
{ if (mounted) SAFE_UMOUNT(DIRA); if (dir_created) SAFE_RMDIR(DIRA); }
Quoted 1 line
+ I later create generic helper from
is_shared_mount().
I sent v2 patch now, once your create generic helper i can do another patch together with your generic helper.
Quoted 4 lines
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 5 lines · Petr Vorel
Quoted 3 lines
Hi Wei,
nit: I guess you want to replace dot with space in subject.
You mean i s/attr.propagation/attr propagation ?
Yes.
...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+#define DIRA "/DIRA_PROPAGATION_CHECK"
Is it necessary to to use directory under root?
Yes. Otherwise failed will happen during
mount_setattr. But i have not check for detail.
Ideally we would create files in TMPDIR. Specially if bug in the code leave /DIRA_PROPAGATION_CHECK kept.
Quoted 16 lines
Quoted 15 lines
...
Review
Quoted 2 lines
(quoted diff) +2
-0+static void cleanup(void) +{I guess this is due result of:
SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0); There should be either a proper detection whether this works or
../../../../include/lapi/fsmount.h:113: TCONF: syscall(442)__NR_mount_setattrnot supported on your arch mount_setattr02.c:52: TWARN:rmdir(/DIRA_PROPAGATION_CHECK)failed: EBUSY (16)testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 52
Quoted 1 line
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +1
-0+SAFE_RMDIR (DIRA );When running on old kernel (e.g. SLES based 4.12) it fails due TCONF:
Quoted 8 lines
Quoted 7 lines
../../../../include/lapi/fsmount.h:197: TCONF: Test not supported on kernel version < v5.2 mount_setattr02.c:52: TWARN:rmdir(/DIRA_PROPAGATION_CHECK)failed: ENOENT (2)There should be a flag to remove dir only when it was created.
Quoted 1 line
+
nit: please remove this new line (I have to keep asking this :( ).
Sorry, i need pay attention, thanks for point this out with great patient :).
Thank you, not a big deal :).
...
Quoted 3 lines
Quoted 1 line
+ I later create generic helper from
is_shared_mount().I sent v2 patch now, once your create generic helper i can do another patch together with your generic helper.
Sure, it should not block your work on the test.
Kind regards,
Petr
Quoted 2 lines
Quoted 2 lines
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 7 lines · Petr Vorel
Quoted 5 lines · Petr Vorel
Quoted 3 lines
Hi Wei,
nit: I guess you want to replace dot with space in subject.
You mean i s/attr.propagation/attr propagation ?
Yes.
Will update it in v3
Quoted 10 lines
...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+#define DIRA "/DIRA_PROPAGATION_CHECK"
Is it necessary to to use directory under root?
Yes. Otherwise failed will happen during
mount_setattr. But i have not check for detail.Ideally we would create files in TMPDIR. Specially if bug in the code leave /DIRA_PROPAGATION_CHECK kept.
Got it, will try using TMPDIR and investigate why it report error.
Quoted 9 lines
Quoted 2 lines
Quoted 2 lines
...
Sure, it should not block your work on the test.
Kind regards,
PetrQuoted 2 lines
Quoted 2 lines
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 9 lines · Petr Vorel
Quoted 7 lines
Quoted 5 lines · Petr Vorel
Quoted 3 lines
Hi Wei,
nit: I guess you want to replace dot with space in subject.
You mean i s/attr.propagation/attr propagation ?
Yes.
Will update it in v3
This is not important (the code matters), but IMHO something like:
"mount_setattr02: Add test to check mount attributes propagation"
would be more readable for me than "mount_setattr02.c: Check mount_setattr attr.propagation" you provided. From your subject it's not even obvious it's a new test and not a change in the existing test.
Quoted 10 lines
Quoted 9 lines
...
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+#define DIRA "/DIRA_PROPAGATION_CHECK"
Is it necessary to to use directory under root?
Yes. Otherwise failed will happen during
mount_setattr. But i have not check for detail.Ideally we would create files in TMPDIR. Specially if bug in the code leave /DIRA_PROPAGATION_CHECK kept.
Got it, will try using TMPDIR and investigate why it report error.
Thank you!
Kind regards,
Petr
Quoted 8 lines
Quoted 8 lines
Quoted 1 line
Quoted 1 line
...
Sure, it should not block your work on the test.
Kind regards,
PetrQuoted 2 lines
Quoted 2 lines
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 mount_setattr02.c: Check mount_setattr attr.propagation
In reply to Wei Gao via ltp--- runtest/syscalls | 1 + .../kernel/syscalls/mount_setattr/.gitignore | 1 + .../syscalls/mount_setattr/mount_setattr02.c | 103 ++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 testcases/kernel/syscalls/mount_setattr/mount_setattr02.c
runtest/syscalls +1 -0
@@ -856,6 +856,7 @@ mount06 mount06 mount07 mount07 mount_setattr01 mount_setattr01 +mount_setattr02 mount_setattr02 move_mount01 move_mount01 move_mount02 move_mount02
testcases/kernel/syscalls/mount_setattr/.gitignore +1 -0
@@ -1 +1,2 @@ /mount_setattr01 +/mount_setattr02
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +103 -0
103 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
nit: You did not change commit message subject (we talked about it).
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 7
Quoted 10 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +7
-0@@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2025 SUSE LLC Wei Gao <[email protected]> +*/ + +/*\ +* [Description]
NOTE: this '[Description]' should no longer be added.
See:
https://github.com/linux-test-project/ltp/commit/a3e27df34d6cb49477c9bd6f9bbaa1ce4de155f9
(it updated also examples in doc)
and follow ups
https://github.com/linux-test-project/ltp/commit/63eceaa2a83bca41997edcd649eb62272622a100
https://github.com/linux-test-project/ltp/commit/824f66ca72fc7505a31c30792334905b646c9d37
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 9
Quoted 2 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +2
-0+* +* Basic mount_setattr() test.
nit: here is better a blank line.
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 20
Quoted 11 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +11
-0+* Test basic propagation mount attributes are set correctly. +*/ + +#define _GNU_SOURCE + +#include <sys/statvfs.h> +#include "tst_test.h" +#include "lapi/fsmount.h" +#include "tst_safe_stdio.h" + +#define DIRA "/DIRA_PROPAGATION_CHECK"
Also, I found a way to test into TMPDIR. There is no need to touch a real root. It works even on separate /tmp.
If you agree, I merge with following diff.
https://github.com/pevik/ltp/blob/wei/mount_setattr02.v2.fixes/testcases/kernel/syscalls/mount_setattr/mount_setattr02.c
With changes below.
Kind regards,
Petr
+++ testcases/kernel/syscalls/mount_setattr/mount_setattr02.c @@ -4,9 +4,8 @@
*/
/*\
- * [Description]
- *
* Basic mount_setattr() test.
+ *
* Test basic propagation mount attributes are set correctly. */
@@ -17,9 +16,9 @@
#include "lapi/fsmount.h"
#include "tst_safe_stdio.h"
-#define DIRA "/DIRA_PROPAGATION_CHECK"
+static char *tmpdir;
-static int dir_created, mounted;
+static int mounted;
static bool is_shared_mount(const char *path)
{
@@ -52,19 +51,15 @@ static bool is_shared_mount(const char *path)
static void cleanup(void)
{
if (mounted)
- SAFE_UMOUNT(DIRA);
-
- if (dir_created)
- SAFE_RMDIR(DIRA);
+ SAFE_UMOUNT(tmpdir);
}
static void setup(void)
{
- SAFE_MKDIR(DIRA, 0777);
+ tmpdir = tst_tmpdir_path();
SAFE_UNSHARE(CLONE_NEWNS);
- dir_created = 1;
SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0);
- SAFE_MOUNT("testing", DIRA, "tmpfs", MS_NOATIME | MS_NODEV, "");
+ SAFE_MOUNT("testing", tmpdir, "tmpfs", MS_NOATIME | MS_NODEV, "");
mounted = 1;
}
@@ -75,24 +70,24 @@ static void run(void)
.attr_clr = MOUNT_ATTR__ATIME,
};
- TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)));
- TST_EXP_EQ_LI(is_shared_mount(DIRA), 0);
+ TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)));
+ TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0);
attr.propagation = -1;
- TST_EXP_FAIL_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)), EINVAL);
- TST_EXP_EQ_LI(is_shared_mount(DIRA), 0);
+ TST_EXP_FAIL_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)), EINVAL);
+ TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0);
attr.propagation = MS_SHARED;
- TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)));
- TST_EXP_EQ_LI(is_shared_mount(DIRA), 1);
+ TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)));
+ TST_EXP_EQ_LI(is_shared_mount(tmpdir), 1);
attr.propagation = MS_PRIVATE;
- TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)));
- TST_EXP_EQ_LI(is_shared_mount(DIRA), 0);
+ TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)));
+ TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0);
attr.propagation = MS_SLAVE;
- TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)));
- TST_EXP_EQ_LI(is_shared_mount(DIRA), 0);
+ TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)));
+ TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0);
}
static struct tst_test test = {
@@ -100,4 +95,5 @@ static struct tst_test test = {
.setup = setup,
.cleanup = cleanup,
.needs_root = 1,
+ .needs_tmpdir = 1,
};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 3 lines · Petr Vorel
Hi Wei,
nit: You did not change commit message subject (we talked about it).
Oh, if you check time of message, i sent v2 patch before we talked about this :)
Quoted 13 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 7
Quoted 11 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +7
-0@@ -0,0 +1,103 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2025 SUSE LLC Wei Gao <[email protected]> +*/ + +/*\ +* [Description] NOTE: this '[Description]' should no longer be added.
Quoted 7 lines
See:
https://github.com/linux-test-project/ltp/commit/a3e27df34d6cb49477c9bd6f9bbaa1ce4de155f9
(it updated also examples in doc)and follow ups
https://github.com/linux-test-project/ltp/commit/63eceaa2a83bca41997edcd649eb62272622a100
https://github.com/linux-test-project/ltp/commit/824f66ca72fc7505a31c30792334905b646c9d37
Got it, thanks your information.
Quoted 18 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 9
Quoted 2 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +2
-0+* +* Basic mount_setattr() test. nit: here is better a blank line.
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 20
Quoted 11 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +11
-0+* Test basic propagation mount attributes are set correctly. +*/ + +#define _GNU_SOURCE + +#include <sys/statvfs.h> +#include "tst_test.h" +#include "lapi/fsmount.h" +#include "tst_safe_stdio.h" + +#define DIRA "/DIRA_PROPAGATION_CHECK"Also, I found a way to test into TMPDIR. There is no need to touch a real root. It works even on separate /tmp.
Quoted 2 lines
If you agree, I merge with following diff.
https://github.com/pevik/ltp/blob/wei/mount_setattr02.v2.fixes/testcases/kernel/syscalls/mount_setattr/mount_setattr02.c
I agree. Great!
Quoted 95 lines
With changes below.
Reviewed-by Petr Vorel <[email protected]>Kind regards,
Petr+++
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c(quoted diff) +17
-21@@ -4,9 +4,8 @@ */ /*\ - * [Description] - * * Basic mount_setattr() test. + * * Test basic propagation mount attributes are set correctly. */@@ -17,9 +16,9 @@ #include "lapi/fsmount.h" #include "tst_safe_stdio.h" -#define DIRA "/DIRA_PROPAGATION_CHECK" +static char *tmpdir; -static int dir_created, mounted; +static int mounted; static bool is_shared_mount(const char *path) {@@ -52,19 +51,15 @@ static bool is_shared_mount(const char *path) static void cleanup(void) { if (mounted) - SAFE_UMOUNT(DIRA); - - if (dir_created) - SAFE_RMDIR(DIRA); + SAFE_UMOUNT(tmpdir); } static void setup(void) { - SAFE_MKDIR(DIRA, 0777); + tmpdir = tst_tmpdir_path(); SAFE_UNSHARE(CLONE_NEWNS); - dir_created = 1; SAFE_MOUNT(NULL, "/", NULL, MS_REC | MS_PRIVATE, 0); - SAFE_MOUNT("testing", DIRA, "tmpfs", MS_NOATIME | MS_NODEV, ""); + SAFE_MOUNT("testing", tmpdir, "tmpfs", MS_NOATIME | MS_NODEV, ""); mounted = 1; }@@ -75,24 +70,24 @@ static void run(void) .attr_clr = MOUNT_ATTR__ATIME, }; - TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr))); - TST_EXP_EQ_LI(is_shared_mount(DIRA), 0); + TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr))); + TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0); attr.propagation = -1; - TST_EXP_FAIL_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr)), EINVAL); - TST_EXP_EQ_LI(is_shared_mount(DIRA), 0); + TST_EXP_FAIL_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr)), EINVAL); + TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0); attr.propagation = MS_SHARED; - TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr))); - TST_EXP_EQ_LI(is_shared_mount(DIRA), 1); + TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr))); + TST_EXP_EQ_LI(is_shared_mount(tmpdir), 1); attr.propagation = MS_PRIVATE; - TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr))); - TST_EXP_EQ_LI(is_shared_mount(DIRA), 0); + TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr))); + TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0); attr.propagation = MS_SLAVE; - TST_EXP_PASS_SILENT(mount_setattr(-1, DIRA, 0, &attr, sizeof(attr))); - TST_EXP_EQ_LI(is_shared_mount(DIRA), 0); + TST_EXP_PASS_SILENT(mount_setattr(-1, tmpdir, 0, &attr, sizeof(attr))); + TST_EXP_EQ_LI(is_shared_mount(tmpdir), 0); } static struct tst_test test = {@@ -100,4 +95,5 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .needs_root = 1, + .needs_tmpdir = 1, };
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 mount_setattr02.c: Check mount_setattr attr propagation
In reply to Wei Gao via ltp--- runtest/syscalls | 1 + .../kernel/syscalls/mount_setattr/.gitignore | 1 + .../syscalls/mount_setattr/mount_setattr02.c | 99 +++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 testcases/kernel/syscalls/mount_setattr/mount_setattr02.c
runtest/syscalls +1 -0
@@ -858,6 +858,7 @@ mount06 mount06 mount07 mount07 mount_setattr01 mount_setattr01 +mount_setattr02 mount_setattr02 move_mount01 move_mount01 move_mount02 move_mount02
testcases/kernel/syscalls/mount_setattr/.gitignore +1 -0
@@ -1 +1,2 @@ /mount_setattr01 +/mount_setattr02
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +99 -0
99 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v3] mount_setattr02.c: Check mount_setattr attr propagation
Hi!
Quoted 15 lines
move_mount01move_mount01
move_mount02move_mount02testcases/kernel/syscalls/mount_setattr/.gitignore +1
-0@@ -1 +1,2 @@ /mount_setattr01 +/mount_setattr02testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +0
-0
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 9
Quoted 9 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +9
-0@@ -0,0 +1,99 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2025 SUSE LLC Wei Gao <[email protected]> +*/ + +/*\ +* Basic mount_setattr() test. +* +* Test basic propagation mount attributes are set correctly.
This is too sparse. We should at least write here which parameters we are testing, obviously the test is checking if the propagation field of the structure is handled properly.
And then we should list what we are trying to test
- When propagation is set to 0 it's not changed
- EINVAL with propagation set to -1
- MS_SHARED turns propagation on
- MS_PRIVATE turns propagation off
...
Quoted 43 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +43
-0+*/ + +#define _GNU_SOURCE + +#include <sys/statvfs.h> +#include "tst_test.h" +#include "lapi/fsmount.h" +#include "tst_safe_stdio.h" + +static char *tmpdir; + +static int mounted; + +static bool is_shared_mount (const char *path) +{ +FILE *file =SAFE_FOPEN ("/proc/self/mountinfo" ,"r" ); + +char line[PATH_MAX ]; +bool found = false; + +while (fgets (line,sizeof (line), file)) { +char mntpoint[PATH_MAX ]; +char opts[256 ]; + +if (sscanf (line,"%*d %*d %*d:%*d %*s %255s %*s %255s" , + mntpoint, opts) !=2 ) +continue ; + +if (strcmp (mntpoint, path) !=0 ) +continue ; + +if (strstr (opts,"shared:" ) !=NULL ) { + found = true; +break ; + } + } + +fclose (file); +return found; +} + +static void cleanup (void ) +{
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 62
Quoted 10 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +10
-0+if (mounted) +SAFE_UMOUNT (tmpdir); +} + +static void setup (void ) +{ + tmpdir =tst_tmpdir_path (); +SAFE_UNSHARE (CLONE_NEWNS ); +SAFE_MOUNT (NULL ,"/" ,NULL ,MS_REC |MS_PRIVATE ,0 ); +SAFE_MOUNT ("testing" , tmpdir,"tmpfs" ,MS_NOATIME |MS_NODEV ,"" );
^
We tend to include ltp in names that are visible on the system so that's clear where they came from.
It would be a bit better if the name of the mount was "ltp-mount_setattr" or something that makes it clear which test was mounting it.
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 70
Quoted 8 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +8
-0+ mounted =1 ; +} + +static void run (void ) +{ +struct mount_attr attr = { + .attr_set =MOUNT_ATTR_RDONLY |MOUNT_ATTR_NOEXEC |MOUNT_ATTR_RELATIME , + .attr_clr =MOUNT_ATTR__ATIME ,
I suppose that we can as well set these to zero as we are trying to test only the propagation part. Or is there a reason why we are specifying any attributes here?
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 82
Quoted 12 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +12
-0+ }; + +TST_EXP_PASS_SILENT (mount_setattr (-1 , tmpdir,0 , &attr,sizeof (attr))); +TST_EXP_EQ_LI (is_shared_mount (tmpdir),0 ); + + attr.propagation =-1 ; +TST_EXP_FAIL_SILENT (mount_setattr (-1 , tmpdir,0 , &attr,sizeof (attr)),EINVAL ); +TST_EXP_EQ_LI (is_shared_mount (tmpdir),0 ); + + attr.propagation =MS_SHARED ; +TST_EXP_PASS_SILENT (mount_setattr (-1 , tmpdir,0 , &attr,sizeof (attr))); +TST_EXP_EQ_LI (is_shared_mount (tmpdir),1 );
Here we should once more check with propagation = 0 and expect that the mount is shared after that call.
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c line 90
Quoted 7 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +7
-0+ attr.propagation =MS_PRIVATE ; +TST_EXP_PASS_SILENT (mount_setattr (-1 , tmpdir,0 , &attr,sizeof (attr))); +TST_EXP_EQ_LI (is_shared_mount (tmpdir),0 ); + + attr.propagation =MS_SLAVE ; +TST_EXP_PASS_SILENT (mount_setattr (-1 , tmpdir,0 , &attr,sizeof (attr))); +TST_EXP_EQ_LI (is_shared_mount (tmpdir),0 );
Can we figure out slave mount from the mountinfo? I suppose there will be slave in in the opts.
Quoted 15 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +9
-0+} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root =1 , + .needs_tmpdir =1 , +};Signature · 5 lines
2.35.3 -- 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
PATCH v4 1/1 mount_setattr02.c: Check mount_setattr attr propagation
In reply to Wei Gao via ltp--- runtest/syscalls | 1 + .../kernel/syscalls/mount_setattr/.gitignore | 1 + .../syscalls/mount_setattr/mount_setattr02.c | 127 ++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 testcases/kernel/syscalls/mount_setattr/mount_setattr02.c
runtest/syscalls +1 -0
@@ -866,6 +866,7 @@ mount06 mount06 mount07 mount07 mount_setattr01 mount_setattr01 +mount_setattr02 mount_setattr02 move_mount01 move_mount01 move_mount02 move_mount02
testcases/kernel/syscalls/mount_setattr/.gitignore +1 -0
@@ -1 +1,2 @@ /mount_setattr01 +/mount_setattr02
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c new file +127 -0
127 lines not on this page · raw message
Signature · 5 lines
2.49.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v4] mount_setattr02.c: Check mount_setattr attr propagation
Hi!
Pushed with some changes, thanks.
- We have to move the SAFE_UMOUNT(tmpdir) to the run() otherwise the test fails to cleanup() with -i 2
- Make sure that the slavedir was mounted shared before making it slave
- Minor adjustenment to the test description
testcases/kernel/syscalls/mount_setattr/mount_setattr02.c +4 -4
@@ -5,7 +5,7 @@/*\ * This test is checking if the propagation field of the -* structure is handled properly. +* mount_attr structure is handled properly. * * - EINVAL with propagation set to -1 * - When propagation is set to 0 it's not changed
@@ -68,10 +68,8 @@ static bool check_mount_type(const char *path, enum mount_type type_to_check)static void cleanup (void ) { -if (mounted) { -SAFE_UMOUNT (slavedir); +if (mounted)SAFE_UMOUNT (tmpdir); - } }static void setup (void )
@@ -109,9 +107,11 @@ static void run(void) attr.propagation =MS_SLAVE ;SAFE_MOUNT (tmpdir, slavedir,"none" ,MS_BIND ,NULL ); +TST_EXP_EQ_LI (check_mount_type (slavedir,MOUNT_TYPE_SHARED ),1 );TST_EXP_PASS_SILENT (mount_setattr (-1 , slavedir,0 , &attr,sizeof (attr)));TST_EXP_EQ_LI (check_mount_type (slavedir,MOUNT_TYPE_MASTER ),1 );TST_EXP_EQ_LI (check_mount_type (slavedir,MOUNT_TYPE_SHARED ),0 ); +SAFE_UMOUNT (slavedir); attr.propagation =MS_PRIVATE ;TST_EXP_PASS_SILENT (mount_setattr (-1 , tmpdir,0 , &attr,sizeof (attr)));
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp