syscalls: Add tests for name_to_handle_at()
PATCH v2 1/2 syscalls: Add tests for name_to_handle_at()
This adds basic success and failure tests for name_to_handle_at() syscall.
---V1->V2:
- Separate directories for both the syscalls.
- Added common header file.
- Use tst_alloc() instead of malloc().
- Use proper format for description.
- Minor other cleanups.
include/lapi/name_to_handle_at.h | 54 +++++++++ runtest/syscalls | 3 + .../syscalls/name_to_handle_at/.gitignore | 2 + .../syscalls/name_to_handle_at/Makefile | 7 ++ .../name_to_handle_at/name_to_handle_at01.c | 113 ++++++++++++++++++ .../name_to_handle_at/name_to_handle_at02.c | 82 +++++++++++++ 6 files changed, 261 insertions(+) create mode 100644 include/lapi/name_to_handle_at.h create mode 100644 testcases/kernel/syscalls/name_to_handle_at/.gitignore create mode 100644 testcases/kernel/syscalls/name_to_handle_at/Makefile create mode 100644 testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at01.c create mode 100644 testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at02.c
include/lapi/name_to_handle_at.h new file +54 -0
@@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Linaro Limited. All rights reserved. +* Author: Viresh Kumar <[email protected]> +*/ + +#ifndef NAME_TO_HANDLE_AT_H__ +#define NAME_TO_HANDLE_AT_H__ + +#include <sys/syscall.h> +#include "config.h" +#include "tst_buffers.h" +#include "tst_test.h" + +#ifndef HAVE_NAME_TO_HANDLE_AT +struct file_handle { +unsigned int handle_bytes; +int handle_type; +/* File identifier. */ +unsigned char f_handle[0 ]; +}; + +int name_to_handle_at (int dfd,const char *pathname,struct file_handle *handle, +int *mount_id,int flags); +int open_by_handle_at (int mount_fd,struct file_handle *handle,int flags); +#endif + +/* Returns a valid pointer on success, NULL on errors */ +static inline struct file_handle * +allocate_file_handle (int dfd,const char *pathname) +{ +struct file_handle fh = {}, *fhp; +int mount_id; + +/* +* Make an initial call to name_to_handle_at() to discover the size +* required for the file handle. +*/ +TEST (name_to_handle_at (dfd, pathname, &fh, &mount_id,0 )); +if (TST_RET !=-1 ||TST_ERR !=EOVERFLOW ) { +tst_res (TFAIL |TTERRNO , +"name_to_handle_at() should fail with EOVERFLOW" ); +return NULL ; + } + +/* Valid file handle */ + fhp =tst_alloc (sizeof (*fhp) + fh.handle_bytes); + fhp->handle_type = fh.handle_type; + fhp->handle_bytes = fh.handle_bytes; + +return fhp; +} + +#endif /* NAME_TO_HANDLE_AT_H__ */
runtest/syscalls +3 -0
@@ -846,6 +846,9 @@ nanosleep01 nanosleep01 nanosleep02 nanosleep02 nanosleep04 nanosleep04 +name_to_handle_at01 name_to_handle_at01 +name_to_handle_at02 name_to_handle_at02 + nftw01 nftw01 nftw6401 nftw6401
testcases/kernel/syscalls/name_to_handle_at/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +name_to_handle_at01 +name_to_handle_at02
testcases/kernel/syscalls/name_to_handle_at/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# 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/name_to_handle_at/name_to_handle_at01.c new file +113 -0
113 lines not on this page · raw message
testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at02.c new file +82 -0
82 lines not on this page · raw message
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v2 2/2 syscalls: Add tests for open_by_handle_at()
This adds basic success and failure tests for open_by_handle_at() syscall.
--- runtest/syscalls | 3 + .../syscalls/open_by_handle_at/.gitignore | 2 + .../syscalls/open_by_handle_at/Makefile | 7 ++ .../open_by_handle_at/open_by_handle_at01.c | 112 ++++++++++++++++++ .../open_by_handle_at/open_by_handle_at02.c | 109 +++++++++++++++++ 5 files changed, 233 insertions(+) create mode 100644 testcases/kernel/syscalls/open_by_handle_at/.gitignore create mode 100644 testcases/kernel/syscalls/open_by_handle_at/Makefile create mode 100644 testcases/kernel/syscalls/open_by_handle_at/open_by_handle_at01.c create mode 100644 testcases/kernel/syscalls/open_by_handle_at/open_by_handle_at02.c
runtest/syscalls +3 -0
@@ -882,6 +882,9 @@ openat201 openat201 openat202 openat202 openat203 openat203 +open_by_handle_at01 open_by_handle_at01 +open_by_handle_at02 open_by_handle_at02 + open_tree01 open_tree01 open_tree02 open_tree02
testcases/kernel/syscalls/open_by_handle_at/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +open_by_handle_at01 +open_by_handle_at02
testcases/kernel/syscalls/open_by_handle_at/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# 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/open_by_handle_at/open_by_handle_at01.c new file +112 -0
112 lines not on this page · raw message
testcases/kernel/syscalls/open_by_handle_at/open_by_handle_at02.c new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.25.0.rc1.19.g042ed3e048af
PATCH v2 1/2 syscalls: Add tests for name_to_handle_at()
In reply to Viresh KumarHi!
Quoted 21 lines
include/lapi/name_to_handle_at.h new file +15
-0@@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Linaro Limited. All rights reserved. +* Author: Viresh Kumar <[email protected]> +*/ + +#ifndef NAME_TO_HANDLE_AT_H__ +#define NAME_TO_HANDLE_AT_H__ + +#include <sys/syscall.h> +#include "config.h" +#include "tst_buffers.h" +#include "tst_test.h" + +#ifndef HAVE_NAME_TO_HANDLE_AT
include/lapi/name_to_handle_at.h line 25
Quoted 10 lines
include/lapi/name_to_handle_at.h new file +10
-0+struct file_handle { +unsigned int handle_bytes; +int handle_type; +/* File identifier. */ +unsigned char f_handle[0 ]; +}; + +int name_to_handle_at (int dfd,const char *pathname,struct file_handle *handle, +int *mount_id,int flags); +int open_by_handle_at (int mount_fd,struct file_handle *handle,int flags);
This still is not complete solution. As far as I can tell this will fail to link on machine where libc does not implement these, so we have to make them static inline functions that actually call the tst_syscall().
Eitherway these functions were added to glibc 2.14 which is 2011 which seems to be old enough, but I'm not sure about musl libc support. Does anyone have an idea?
Quoted 119 lines
include/lapi/name_to_handle_at.h new file +29
-0+#endif + +/* Returns a valid pointer on success, NULL on errors */ +static inline struct file_handle * +allocate_file_handle (int dfd,const char *pathname) +{ +struct file_handle fh = {}, *fhp; +int mount_id; + +/* +* Make an initial call to name_to_handle_at() to discover the size +* required for the file handle. +*/ +TEST (name_to_handle_at (dfd, pathname, &fh, &mount_id,0 )); +if (TST_RET !=-1 ||TST_ERR !=EOVERFLOW ) { +tst_res (TFAIL |TTERRNO , +"name_to_handle_at() should fail with EOVERFLOW" ); +return NULL ; + } + +/* Valid file handle */ + fhp =tst_alloc (sizeof (*fhp) + fh.handle_bytes); + fhp->handle_type = fh.handle_type; + fhp->handle_bytes = fh.handle_bytes; + +return fhp; +} + +#endif /* NAME_TO_HANDLE_AT_H__ */ runtest/syscalls +3
-0@@ -846,6 +846,9 @@ nanosleep01 nanosleep01 nanosleep02 nanosleep02 nanosleep04 nanosleep04 +name_to_handle_at01 name_to_handle_at01 +name_to_handle_at02 name_to_handle_at02 + nftw01 nftw01 nftw6401 nftw6401testcases/kernel/syscalls/name_to_handle_at/.gitignore new file +2
-0@@ -0,0 +1,2 @@ +name_to_handle_at01 +name_to_handle_at02testcases/kernel/syscalls/name_to_handle_at/Makefile new file +7
-0@@ -0,0 +1,7 @@ +# 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/name_to_handle_at/name_to_handle_at01.c new file +49
-0@@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Viresh Kumar <[email protected]> +*/ + +/*\ +* [DESCRIPTION] +* +* Basic name_to_handle_at() tests. +* +* [ALGORITHM] +* - Check that EOVERFLOW is returned as expected by name_to_handle_at(). +* - Check that we were able to access a file's stat with name_to_handle_at() +* and open_by_handle_at(). +\*/ +#define _GNU_SOURCE +#include <fcntl.h> +#include <sys/stat.h> +#include "lapi/name_to_handle_at.h" + +#define TEST_FILE "test_file" +#define TEST_DIR "test_dir" + +static int dir_fd, fd_atcwd =AT_FDCWD ; +static struct file_handle *fhp; + +static struct tcase { +int *dfd; +const char *pathname; +int name_flags; +int flags; +} tcases[] = { + {&dir_fd,TEST_FILE ,0 ,O_RDWR }, + {&dir_fd,TEST_FILE ,0 ,O_RDONLY }, + {&dir_fd,TEST_FILE ,0 ,O_WRONLY }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH ,O_RDWR }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH ,O_RDONLY }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH ,O_WRONLY }, + {&dir_fd,TEST_FILE ,AT_SYMLINK_FOLLOW ,O_RDWR }, + {&dir_fd,TEST_FILE ,AT_SYMLINK_FOLLOW ,O_RDONLY }, + {&dir_fd,TEST_FILE ,AT_SYMLINK_FOLLOW ,O_WRONLY }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH |AT_SYMLINK_FOLLOW ,O_RDWR }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH |AT_SYMLINK_FOLLOW ,O_RDONLY }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH |AT_SYMLINK_FOLLOW ,O_WRONLY }, + {&dir_fd,"" ,AT_EMPTY_PATH ,O_RDONLY }, + + {&fd_atcwd,TEST_FILE ,0 ,O_RDWR }, + {&fd_atcwd,TEST_FILE ,0 ,O_RDONLY }, + {&fd_atcwd,TEST_FILE ,0 ,O_WRONLY },
testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at01.c line 59
Quoted 10 lines
testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at01.c new file +10
-0+ {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH, O_RDWR}, + {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH, O_RDONLY}, + {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH, O_WRONLY}, + {&fd_atcwd, TEST_FILE, AT_SYMLINK_FOLLOW, O_RDWR}, + {&fd_atcwd, TEST_FILE, AT_SYMLINK_FOLLOW, O_RDONLY}, + {&fd_atcwd, TEST_FILE, AT_SYMLINK_FOLLOW, O_WRONLY}, + {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH | AT_SYMLINK_FOLLOW, O_RDWR}, + {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH | AT_SYMLINK_FOLLOW, O_RDONLY}, + {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH | AT_SYMLINK_FOLLOW, O_WRONLY}, + {&fd_atcwd, "", AT_EMPTY_PATH, O_RDONLY},
Reading manual we can supposedly pass a dirfd reffering to a file with AT_EMPTY_PATH, so we may as well add that test here as well.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/2 syscalls: Add tests for name_to_handle_at()
Hi Cyril, Viresh
Quoted 28 lines
Hi!
Quoted 27 lines
include/lapi/name_to_handle_at.h new file +21
-0@@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Linaro Limited. All rights reserved. +* Author: Viresh Kumar<[email protected]> +*/ + +#ifndef NAME_TO_HANDLE_AT_H__ +#define NAME_TO_HANDLE_AT_H__ + +#include <sys/syscall.h> +#include "config.h" +#include "tst_buffers.h" +#include "tst_test.h" + +#ifndef HAVE_NAME_TO_HANDLE_AT +struct file_handle { +unsigned int handle_bytes; +int handle_type; +/* File identifier. */ +unsigned char f_handle[0 ]; +};
Quoted 9 lines
include/lapi/name_to_handle_at.h line 25
Quoted 4 lines
include/lapi/name_to_handle_at.h new file +4
-0+ +int name_to_handle_at (int dfd,const char *pathname,struct file_handle *handle, +int *mount_id,int flags); +int open_by_handle_at (int mount_fd,struct file_handle *handle,int flags);This still is not complete solution. As far as I can tell this will fail to link on machine where libc does not implement these, so we have to make them static inline functions that actually call the
tst_syscall().
Agree.
Quoted 4 lines
Eitherway these functions were added to glibc 2.14 which is 2011 which seems to be old enough, but I'm not sure about musl libc support. Does anyone have an idea?
musl libc supports them since 2018.9 after this patch[1] and it is about 2 year ago. We should add a fallback for it like setns.h.
[1]https://git.musl-libc.org/cgit/musl/commit/?id=3e14bbcd1979376b188bfabb816ff828608fb5d7
Quoted 134 lines
Quoted 119 lines
include/lapi/name_to_handle_at.h new file +29
-0+#endif + +/* Returns a valid pointer on success, NULL on errors */ +static inline struct file_handle * +allocate_file_handle (int dfd,const char *pathname) +{ +struct file_handle fh = {}, *fhp; +int mount_id; + +/* +* Make an initial call to name_to_handle_at() to discover the size +* required for the file handle. +*/ +TEST (name_to_handle_at (dfd, pathname,&fh,&mount_id,0 )); +if (TST_RET !=-1 ||TST_ERR !=EOVERFLOW ) { +tst_res (TFAIL |TTERRNO , +"name_to_handle_at() should fail with EOVERFLOW" ); +return NULL ; + } + +/* Valid file handle */ + fhp =tst_alloc (sizeof (*fhp) + fh.handle_bytes); + fhp->handle_type = fh.handle_type; + fhp->handle_bytes = fh.handle_bytes; + +return fhp; +} + +#endif /* NAME_TO_HANDLE_AT_H__ */ runtest/syscalls +3
-0@@ -846,6 +846,9 @@ nanosleep01 nanosleep01 nanosleep02 nanosleep02 nanosleep04 nanosleep04 +name_to_handle_at01 name_to_handle_at01 +name_to_handle_at02 name_to_handle_at02 + nftw01 nftw01 nftw6401 nftw6401testcases/kernel/syscalls/name_to_handle_at/.gitignore new file +2
-0@@ -0,0 +1,2 @@ +name_to_handle_at01 +name_to_handle_at02testcases/kernel/syscalls/name_to_handle_at/Makefile new file +7
-0@@ -0,0 +1,7 @@ +# 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/name_to_handle_at/name_to_handle_at01.c new file +49
-0@@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Viresh Kumar<[email protected]> +*/ + +/*\ +* [DESCRIPTION] +* +* Basic name_to_handle_at() tests. +* +* [ALGORITHM] +* - Check that EOVERFLOW is returned as expected by name_to_handle_at(). +* - Check that we were able to access a file's stat with name_to_handle_at() +* and open_by_handle_at(). +\*/ +#define _GNU_SOURCE +#include <fcntl.h> +#include <sys/stat.h> +#include "lapi/name_to_handle_at.h" + +#define TEST_FILE "test_file" +#define TEST_DIR "test_dir" + +static int dir_fd, fd_atcwd =AT_FDCWD ; +static struct file_handle *fhp; + +static struct tcase { +int *dfd; +const char *pathname; +int name_flags; +int flags; +} tcases[] = { + {&dir_fd,TEST_FILE ,0 ,O_RDWR }, + {&dir_fd,TEST_FILE ,0 ,O_RDONLY }, + {&dir_fd,TEST_FILE ,0 ,O_WRONLY }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH ,O_RDWR }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH ,O_RDONLY }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH ,O_WRONLY }, + {&dir_fd,TEST_FILE ,AT_SYMLINK_FOLLOW ,O_RDWR }, + {&dir_fd,TEST_FILE ,AT_SYMLINK_FOLLOW ,O_RDONLY }, + {&dir_fd,TEST_FILE ,AT_SYMLINK_FOLLOW ,O_WRONLY }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH |AT_SYMLINK_FOLLOW ,O_RDWR }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH |AT_SYMLINK_FOLLOW ,O_RDONLY }, + {&dir_fd,TEST_FILE ,AT_EMPTY_PATH |AT_SYMLINK_FOLLOW ,O_WRONLY }, + {&dir_fd,"" ,AT_EMPTY_PATH ,O_RDONLY }, + + {&fd_atcwd,TEST_FILE ,0 ,O_RDWR }, + {&fd_atcwd,TEST_FILE ,0 ,O_RDONLY }, + {&fd_atcwd,TEST_FILE ,0 ,O_WRONLY },testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at01.c line 59
Quoted 10 lines
testcases/kernel/syscalls/name_to_handle_at/name_to_handle_at01.c new file +10
-0+ {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH, O_RDWR}, + {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH, O_RDONLY}, + {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH, O_WRONLY}, + {&fd_atcwd, TEST_FILE, AT_SYMLINK_FOLLOW, O_RDWR}, + {&fd_atcwd, TEST_FILE, AT_SYMLINK_FOLLOW, O_RDONLY}, + {&fd_atcwd, TEST_FILE, AT_SYMLINK_FOLLOW, O_WRONLY}, + {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH | AT_SYMLINK_FOLLOW, O_RDWR}, + {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH | AT_SYMLINK_FOLLOW, O_RDONLY}, + {&fd_atcwd, TEST_FILE, AT_EMPTY_PATH | AT_SYMLINK_FOLLOW, O_WRONLY}, + {&fd_atcwd, "", AT_EMPTY_PATH, O_RDONLY},Reading manual we can supposedly pass a dirfd reffering to a file with
AT_EMPTY_PATH, so we may as well add that test here as well.
PATCH v2 1/2 syscalls: Add tests for name_to_handle_at()
In reply to Cyril HrubisQuoted 28 lines · Cyril Hrubis
Hi!
Quoted 27 lines
include/lapi/name_to_handle_at.h new file +21
-0@@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2020 Linaro Limited. All rights reserved. +* Author: Viresh Kumar <[email protected]> +*/ + +#ifndef NAME_TO_HANDLE_AT_H__ +#define NAME_TO_HANDLE_AT_H__ + +#include <sys/syscall.h> +#include "config.h" +#include "tst_buffers.h" +#include "tst_test.h" + +#ifndef HAVE_NAME_TO_HANDLE_AT +struct file_handle { +unsigned int handle_bytes; +int handle_type; +/* File identifier. */ +unsigned char f_handle[0 ]; +};
Quoted 8 lines
include/lapi/name_to_handle_at.h line 25
Quoted 4 lines
include/lapi/name_to_handle_at.h new file +4
-0+ +int name_to_handle_at (int dfd,const char *pathname,struct file_handle *handle, +int *mount_id,int flags); +int open_by_handle_at (int mount_fd,struct file_handle *handle,int flags);This still is not complete solution. As far as I can tell this will fail to link on machine where libc does not implement these, so we have to make them static inline functions that actually call the
tst_syscall().
This is embarrassing. Not that I was doing this for the first time, I just completely forgot to update this path, damn. Sorry about that.
Signature · 1 line
viresh