syscalls/fspick: Set .mount_device to get rid of mounting related code
PATCH 1/2 syscalls/fspick: Set .mount_device to get rid of mounting related code
We don't necessarily need to work with the fsmount() related syscalls to initially mount the device, we can set .mount_device instead and get rid of a lot of code.
--- testcases/kernel/syscalls/fspick/fspick.h | 60 --------------------- testcases/kernel/syscalls/fspick/fspick01.c | 7 ++- testcases/kernel/syscalls/fspick/fspick02.c | 8 +-- 3 files changed, 7 insertions(+), 68 deletions(-) delete mode 100644 testcases/kernel/syscalls/fspick/fspick.h
testcases/kernel/syscalls/fspick/fspick.h deleted +0 -60
@@ -1,60 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-or-later -/* -* Copyright (c) 2020 Viresh Kumar <[email protected]> -*/ - -#ifndef FSPICK_H__ -#define FSPICK_H__ - -#define MNTPOINT "mntpoint" - -static int ismounted; - -static void cleanup (void ) -{ -if (ismounted) -SAFE_UMOUNT (MNTPOINT ); -} - -static void setup (void ) -{ -int fd, fsmfd; - -fsopen_supported_by_kernel (); - -TEST (fd =fsopen (tst_device->fs_type,0 )); -if (fd ==-1 ) -tst_brk (TBROK |TERRNO ,"fsopen() failed" ); - -TEST (fsconfig (fd,FSCONFIG_SET_STRING ,"source" , tst_device->dev,0 )); -if (TST_RET ==-1 ) { -SAFE_CLOSE (fd); -tst_brk (TBROK |TERRNO ,"fsconfig(FSCONFIG_SET_STRING) failed" ); - } - -TEST (fsconfig (fd,FSCONFIG_CMD_CREATE ,NULL ,NULL ,0 )); -if (TST_RET ==-1 ) { -SAFE_CLOSE (fd); -tst_brk (TBROK |TERRNO ,"fsconfig(FSCONFIG_CMD_CREATE) failed" ); - } - -TEST (fsmfd =fsmount (fd,0 ,0 )); -SAFE_CLOSE (fd); - -if (fsmfd ==-1 ) -tst_brk (TBROK |TERRNO ,"fsmount() failed" ); - -TEST (move_mount (fsmfd,"" ,AT_FDCWD ,MNTPOINT , -MOVE_MOUNT_F_EMPTY_PATH )); -SAFE_CLOSE (fsmfd); - -if (TST_RET ==-1 ) -tst_brk (TBROK |TERRNO ,"move_mount() failed" ); - -if (!tst_is_mounted_at_tmpdir (MNTPOINT )) -tst_brk (TBROK |TERRNO ,"device not mounted" ); - - ismounted =1 ; -} - -#endif /* FSPICK_H__ */
testcases/kernel/syscalls/fspick/fspick01.c +3 -4
@@ -6,8 +6,8 @@*/ #include "tst_test.h" #include "lapi/fsmount.h" -#include "fspick.h" +#define MNTPOINT "mntpoint"#define TCASE_ENTRY (_flags) {.name = "Flag " #_flags, .flags = _flags} static struct tcase {
@@ -58,10 +58,9 @@ static void run(unsigned int n)static struct tst_test test = { .tcnt =ARRAY_SIZE (tcases), .test = run, - .setup = setup, - .cleanup = cleanup, + .setup = fsopen_supported_by_kernel, .needs_root =1 , - .format_device =1 , + .mount_device =1 , .mntpoint =MNTPOINT , .all_filesystems =1 , .dev_fs_flags =TST_FS_SKIP_FUSE ,
testcases/kernel/syscalls/fspick/fspick02.c +4 -4
@@ -6,7 +6,8 @@*/ #include "tst_test.h" #include "lapi/fsmount.h" -#include "fspick.h" + +#define MNTPOINT "mntpoint" static struct tcase { char *name;
@@ -44,10 +45,9 @@ static void run(unsigned int n)static struct tst_test test = { .tcnt =ARRAY_SIZE (tcases), .test = run, - .setup = setup, - .cleanup = cleanup, + .setup = fsopen_supported_by_kernel, .needs_root =1 , - .format_device =1 , + .mount_device =1 , .mntpoint =MNTPOINT , .all_filesystems =1 , .dev_fs_flags =TST_FS_SKIP_FUSE ,
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 2/2 syscalls/open_tree: Set .mount_device to get rid of mounting related code
We don't necessarily need to work with the fsmount() related syscalls to initially mount the device, we can set .mount_device instead and get rid of a lot of code.
--- .../kernel/syscalls/open_tree/open_tree01.c | 53 ++---------------- .../kernel/syscalls/open_tree/open_tree02.c | 54 +------------------ 2 files changed, 6 insertions(+), 101 deletions(-)
testcases/kernel/syscalls/open_tree/open_tree01.c +4 -49
@@ -38,54 +38,12 @@ static void setup(void)static void run (unsigned int n) {struct tcase *tc = &tcases[n]; -int fd, fsmfd, otfd; - -TEST (fd =fsopen (tst_device->fs_type,0 )); -if (fd ==-1 ) { -tst_res (TFAIL |TTERRNO ,"fsopen() failed" ); -return ; - } - -TEST (fsconfig (fd,FSCONFIG_SET_STRING ,"source" , tst_device->dev,0 )); -if (TST_RET ==-1 ) { -SAFE_CLOSE (fd); -tst_res (TFAIL |TTERRNO ,"fsconfig(FSCONFIG_SET_STRING) failed" ); -return ; - } - -TEST (fsconfig (fd,FSCONFIG_CMD_CREATE ,NULL ,NULL ,0 )); -if (TST_RET ==-1 ) { -SAFE_CLOSE (fd); -tst_res (TFAIL |TTERRNO ,"fsconfig(FSCONFIG_CMD_CREATE) failed" ); -return ; - } - -TEST (fsmfd =fsmount (fd,0 ,0 )); -SAFE_CLOSE (fd); - -if (fsmfd ==-1 ) { -tst_res (TFAIL |TTERRNO ,"fsmount() failed" ); -return ; - } - -TEST (move_mount (fsmfd,"" ,AT_FDCWD ,MNTPOINT , -MOVE_MOUNT_F_EMPTY_PATH )); -SAFE_CLOSE (fsmfd); - -if (TST_RET ==-1 ) { -tst_res (TFAIL |TTERRNO ,"move_mount() failed" ); -return ; - } - -if (!tst_is_mounted_at_tmpdir (MNTPOINT )) { -tst_res (TFAIL |TTERRNO ,"device not mounted" ); -return ; - } +int otfd;TEST (otfd =open_tree (AT_FDCWD ,MNTPOINT , tc->flags |OPEN_TREE_CLONE ));if (otfd ==-1 ) {tst_res (TFAIL |TTERRNO ,"open_tree() failed" ); - goto out; +return ; } TEST(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT,
@@ -94,16 +52,13 @@ static void run(unsigned int n)if (TST_RET ==-1 ) {tst_res (TFAIL |TTERRNO ,"move_mount() failed" ); - goto out; +return ; }if (tst_is_mounted_at_tmpdir (OT_MNTPOINT )) {SAFE_UMOUNT (OT_MNTPOINT );tst_res (TPASS ,"%s: open_tree() passed" , tc->name); } - -out: -SAFE_UMOUNT (MNTPOINT ); }static struct tst_test test = {
@@ -112,7 +67,7 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .needs_root = 1, - .format_device = 1, + .mount_device = 1, .mntpoint = MNTPOINT, .all_filesystems = 1, .dev_fs_flags = TST_FS_SKIP_FUSE,
testcases/kernel/syscalls/open_tree/open_tree02.c +2 -52
67 lines not on this page · raw message
Signature · 1 line
2.21.0.rc0.269.g1a574e7a288b
PATCH 2/2 syscalls/open_tree: Set .mount_device to get rid of mounting related code
Hi Viresh,
Quoted 3 lines
We don't necessarily need to work with the
fsmount()related syscalls to initially mount the device, we can set .mount_device instead and get rid of a lot of code.
Patchset merged. Thanks!
Kind regards,
Petr