open_tree_attr syscall coverage
v2 cover open_tree_attr syscall coverage
open_tree_attr has been added in kernel 6.15 in the following commit:
https://lore.kernel.org/all/[email protected]/
---
Changes in v2:
- close FD after opening it with open_tree()
- revert style edit in setup()
- use TST_EXP_FD_SILENT()
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (2):
Add open_tree_attr fallback
mount_setattr01: add open_tree_attr variant
configure.ac | 1 + include/lapi/fsmount.h | 8 +++ .../syscalls/mount_setattr/mount_setattr01.c | 68 ++++++++++++++++------ 3 files changed, 60 insertions(+), 17 deletions(-)
---
base-commit: 9691c4b2bea4f772d61ca9e9a93d2087c88f6040
change-id: 20250828-open_tree_attr-4b2ece576c1c
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/2 Add open_tree_attr fallback
From: Andrea Cervesato <[email protected]>
open_tree_attr syscall has been introduced in kernel 6.15 and it's now defined in lapi/fsmount.h.
--- configure.ac | 1 + include/lapi/fsmount.h | 8 ++++++++ 2 files changed, 9 insertions(+)
configure.ac +1 -0
@@ -137,6 +137,7 @@ AC_CHECK_FUNCS_ONCE([ \ move_mount \ name_to_handle_at \ open_tree \ + open_tree_attr \ openat \ openat2 \ pidfd_getfd \
include/lapi/fsmount.h +8 -0
@@ -105,6 +105,14 @@ static inline int open_tree(int dirfd, const char *pathname, unsigned int flags) }#endif /* HAVE_OPEN_TREE */ +#ifndef HAVE_OPEN_TREE_ATTR +static inline int open_tree_attr (int dirfd,const char *pathname,unsigned int flags, +struct mount_attr *attr,size_t size) +{ +return tst_syscall (__NR_open_tree_attr, dirfd, pathname, flags, attr, size); +} +#endif /* HAVE_OPEN_TREE_ATTR */ +#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)
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 1/2] Add open_tree_attr fallback
Hi Andrea,
Obviously correct.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 2/2 mount_setattr01: add open_tree_attr variant
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This patch simply introduces a new variant to the mount_setattr01 test, in order to verify that open_tree_attr() works correctly. The open_tree_attr() syscall has been introduced in the kernel v6.15 by commit "c4a16820d901 - fs: add open_tree_attr()".
--- .../syscalls/mount_setattr/mount_setattr01.c | 68 ++++++++++++++++------ 1 file changed, 51 insertions(+), 17 deletions(-)
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +51 -17
@@ -3,10 +3,11 @@* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved. * Author: Dai Shili <[email protected]> * Author: Chen Hanxiao <[email protected]> +* Copyright (C) 2025 SUSE LLC Andrea Cervesato <[email protected]> */ /*\ -* Basic mount_setattr() test. +* Basic mount_setattr()/open_tree_attr() test. * Test whether the basic mount attributes are set correctly. * * Verify some MOUNT_SETATTR(2) attributes:
@@ -22,7 +23,8 @@* - MOUNT_ATTR_NODIRATIME - prevents updating access time for * directories on this mount * -* The functionality was added in v5.12. +* The mount_setattr functionality was added in v5.12, while the open_tree_attr +* functionality was added in v6.15. */ #define _GNU_SOURCE
@@ -41,6 +43,7 @@ }static int mount_flag, otfd =-1 ; +struct mount_attr *attr; static struct tcase { char *name;
@@ -66,35 +69,61 @@ static void cleanup(void)static void setup (void ) {fsopen_supported_by_kernel (); -struct stat st = {0 }; -if (stat (OT_MNTPOINT , &st) ==-1 ) +if (access (OT_MNTPOINT ,F_OK ) !=0 )SAFE_MKDIR (OT_MNTPOINT ,0777 ); } +static int open_tree_variant1 (struct mount_attr *attr) +{ +tst_res (TINFO ,"Variant using open_tree() + mount_setattr()" ); + + otfd =TST_EXP_FD_SILENT (open_tree (AT_FDCWD ,MNTPOINT , +AT_EMPTY_PATH |OPEN_TREE_CLONE )); +if (otfd ==-1 ) +return -1 ; + +TST_EXP_PASS (mount_setattr (otfd,"" ,AT_EMPTY_PATH , + attr,sizeof (*attr))); +if (TST_RET ==-1 ) { +SAFE_CLOSE (otfd); +return -1 ; + } + +return otfd; +} + +static int open_tree_variant2 (struct mount_attr *attr) +{ +tst_res (TINFO ,"Variant using open_tree_attr()" ); + + otfd =TST_EXP_FD (open_tree_attr (AT_FDCWD ,MNTPOINT , +AT_EMPTY_PATH |OPEN_TREE_CLONE , + attr,sizeof (*attr))); + +return otfd; +} +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 ; +memset (attr,0 ,sizeof (*attr)); + attr->attr_set = tc->mount_attrs; - otfd = (int )TST_RET ; +if (tst_variant) + otfd =open_tree_variant1 (attr); +else + otfd =open_tree_variant2 (attr); -TST_EXP_PASS_SILENT (mount_setattr (otfd,"" ,AT_EMPTY_PATH , &attr,sizeof (attr)), -"%s set" , tc->name); -if (!TST_PASS ) - goto out1; +if (otfd ==-1 ) + goto out2;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);
@@ -123,9 +152,14 @@ static struct tst_test test = { .test = run, .setup = setup, .cleanup = cleanup, + .test_variants = 2, .needs_root = 1, .mount_device = 1, .mntpoint = MNTPOINT, .all_filesystems = 1, - .skip_filesystems = (const char *const []){"fuse", NULL}, + .skip_filesystems = (const char *const []) {"fuse", NULL}, + .bufs = (struct tst_buffers []) { + {&attr, .size =sizeof (struct mount_attr )}, + {} + } };
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] mount_setattr01: add open_tree_attr variant
Hi Andrea,
generally LGTM. But it'd be great (can be a separate effort) if you could write checkers similar to fsopen_supported_by_kernel() for __NR_mount_setattr and __NR_open_tree_attr. That would save time wasted when looping filesystem on the variants which aren't supported.
Also while at it, could you fix older typo: 'sucess' => 'success' ?
...
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c static void cleanup(void) · line 73
Quoted 10 lines
static struct tcase {
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +1
-2char *name;@@ -66,35 +69,61 @@ static void cleanup(void)static void setup (void ) {fsopen_supported_by_kernel (); -struct stat st = {0 }; -if (stat (OT_MNTPOINT , &st) ==-1 ) +if (access (OT_MNTPOINT ,F_OK ) !=0 )
Out of curiosity why this change? Faster?
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c static void cleanup(void) · line 79
Quoted 6 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +3
-0SAFE_MKDIR (OT_MNTPOINT ,0777 ); } +static int open_tree_variant1 (struct mount_attr *attr) +{ +tst_res (TINFO ,"Variant using open_tree() + mount_setattr()" );
nit: I'm not an english speaker, but I would say "Using variant ..."
Quoted 9 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +9
-0+ + otfd =TST_EXP_FD_SILENT (open_tree (AT_FDCWD ,MNTPOINT , +AT_EMPTY_PATH |OPEN_TREE_CLONE )); +if (otfd ==-1 ) +return -1 ; + +TST_EXP_PASS (mount_setattr (otfd,"" ,AT_EMPTY_PATH , + attr,sizeof (*attr))); +if (TST_RET ==-1 ) {
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c static void cleanup(void) · line 98
Quoted 10 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +10
-0+SAFE_CLOSE (otfd); +return -1 ; + } + +return otfd; +} + +static int open_tree_variant2 (struct mount_attr *attr) +{ +tst_res (TINFO ,"Variant using open_tree_attr()" );
And here.
The rest LGTM.
Kind regards,
Petr
Quoted 7 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +7
-0+ + otfd =TST_EXP_FD (open_tree_attr (AT_FDCWD ,MNTPOINT , +AT_EMPTY_PATH |OPEN_TREE_CLONE , + attr,sizeof (*attr))); + +return otfd; +}
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v2 2/2] mount_setattr01: add open_tree_attr variant
Hi Petr,
Quoted 4 lines · Petr Vorel
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c static void cleanup(void) · line 73
Quoted 3 lines
testcases/kernel/syscalls/mount_setattr/mount_setattr01.c +1
-2-struct stat st = {0 }; -if (stat (OT_MNTPOINT , &st) ==-1 ) +if (access (OT_MNTPOINT ,F_OK ) !=0 )Out of curiosity why this change? Faster?
Because in this way there's no need to declare any struct. I will achieve the rest of the review and send v3.
- Andrea
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp