selftests: filesystems: Add functional test for the abort file in fusectl
Subsystems (3)
PATCH RESEND v3 1/1 selftests: filesystems: Add functional test for the abort file in fusectl
This patch add a simple functional test for the "abort" file in fusectlfs (/sys/fs/fuse/connections/ID/about).
A simple fuse daemon is added for testing.
Related discussion can be found in the link below.
---
Changes in v3:
- Apply changes suggested by Amir Goldstein
- Rename the test subdir to filesystems/fuse
- Verify errno when connection is aborted
- Apply changes suggested by Shuah Khan
- Update commit message
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Apply changes suggested by Amir Goldstein
- Check errno
- Link to v1: https://lore.kernel.org/all/[email protected]/
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + .../selftests/filesystems/fuse/.gitignore | 3 + .../selftests/filesystems/fuse/Makefile | 21 +++ .../selftests/filesystems/fuse/fuse_mnt.c | 146 ++++++++++++++++++ .../selftests/filesystems/fuse/fusectl_test.c | 116 ++++++++++++++ 6 files changed, 288 insertions(+) create mode 100644 tools/testing/selftests/filesystems/fuse/.gitignore create mode 100644 tools/testing/selftests/filesystems/fuse/Makefile create mode 100644 tools/testing/selftests/filesystems/fuse/fuse_mnt.c create mode 100644 tools/testing/selftests/filesystems/fuse/fusectl_test.c
MAINTAINERS +1 -0
@@ -9901,6 +9901,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse.git F: Documentation/filesystems/fuse* F: fs/fuse/ F: include/uapi/linux/fuse.h +F: tools/testing/selftests/filesystems/fuse/ FUTEX SUBSYSTEM M: Thomas Gleixner <[email protected]>
tools/testing/selftests/Makefile +1 -0
@@ -36,6 +36,7 @@ TARGETS += filesystems/fat TARGETS += filesystems/overlayfs TARGETS += filesystems/statmount TARGETS += filesystems/mount-notify +TARGETS += filesystems/fuse TARGETS += firmware TARGETS += fpu TARGETS += ftrace
tools/testing/selftests/filesystems/fuse/.gitignore new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only +fuse_mnt +fusectl_test
tools/testing/selftests/filesystems/fuse/Makefile new file +21 -0
@@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) + +TEST_GEN_PROGS := fusectl_test +TEST_GEN_FILES := fuse_mnt + +include ../../lib.mk + +VAR_CFLAGS := $(shell pkg-config fuse --cflags 2>/dev/null) +ifeq ($(VAR_CFLAGS),) +VAR_CFLAGS := -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse +endif + +VAR_LDLIBS := $(shell pkg-config fuse --libs 2>/dev/null) +ifeq ($(VAR_LDLIBS),) +VAR_LDLIBS := -lfuse -pthread +endif + +$(OUTPUT)/fuse_mnt: CFLAGS += $(VAR_CFLAGS) +$(OUTPUT)/fuse_mnt: LDLIBS += $(VAR_LDLIBS)
tools/testing/selftests/filesystems/fuse/fuse_mnt.c new file +146 -0
146 lines not on this page · raw message
tools/testing/selftests/filesystems/fuse/fusectl_test.c new file +116 -0
116 lines not on this page · raw message
Signature · 1 line
2.43.0
Miklos Szeredi
maintainerQuoted 4 lines · Chen Linxuan
This patch add a simple functional test for the "abort" file in fusectlfs (
/sys/fs/fuse/connections/ID/about).
Quoted 8 lines
A simple fuse daemon is added for testing.
Related discussion can be found in the link below.
Thanks.
I suggest setting up a userns environment, see attached patch (also fixes a EBUSY on umount/rmdir).
Thanks,
Miklos
tools/testing/selftests/filesystems/fuse/fusectl_test.c +25 -1
@@ -14,6 +14,7 @@#include <sys/wait.h> #include <unistd.h> #include <dirent.h> +#include <sched.h> #include <linux/limits.h> #include "../../kselftest_harness.h"
@@ -23,6 +24,17 @@#define FUSE_DEVICE "/dev/fuse"#define FUSECTL_TEST_VALUE "1" +static void write_file (struct __test_metadata *const _metadata, +const char *path,const char *val) +{ +int fd =open (path,O_WRONLY ); +size_t len =strlen (val); + +ASSERT_GE (fd,0 ); +ASSERT_EQ (write (fd, val, len), len); +ASSERT_EQ (close (fd),0 ); +} +FIXTURE (fusectl){char fuse_mountpoint[sizeof (FUSE_MOUNTPOINT )];int connection;
@@ -33,6 +45,18 @@ FIXTURE_SETUP(fusectl)const char *fuse_mnt_prog ="./fuse_mnt" ;int status, pid;struct stat statbuf; +uid_t uid =getuid (); +gid_t gid =getgid (); +char buf[32 ]; + +/* Setup userns */ +ASSERT_EQ (unshare (CLONE_NEWNS |CLONE_NEWUSER ),0 ); +sprintf (buf,"0 %d 1" , uid); +write_file (_metadata,"/proc/self/uid_map" , buf); +write_file (_metadata,"/proc/self/setgroups" ,"deny" ); +sprintf (buf,"0 %d 1" , gid); +write_file (_metadata,"/proc/self/gid_map" , buf); +ASSERT_EQ (mount ("" ,"/" ,NULL ,MS_REC |MS_PRIVATE ,NULL ),0 );strcpy (self->fuse_mountpoint,FUSE_MOUNTPOINT );
@@ -73,7 +97,7 @@ FIXTURE_SETUP(fusectl)FIXTURE_TEARDOWN (fusectl) { -umount (self->fuse_mountpoint); +umount2 (self->fuse_mountpoint,MNT_DETACH );rmdir (self->fuse_mountpoint); }
Quoted 15 lines · Miklos Szeredi
Quoted 4 lines · Chen Linxuan
This patch add a simple functional test for the "abort" file in fusectlfs (
/sys/fs/fuse/connections/ID/about).Quoted 8 lines
A simple fuse daemon is added for testing.
Related discussion can be found in the link below.
Quoted 4 lines
Thanks.
I suggest setting up a userns environment, see attached patch (also fixes a EBUSY on umount/rmdir).
The v4 patch series has been sent with your suggested changes applied:
https://lore.kernel.org/all/[email protected]/
However, I have some concerns about creating a user namespace. Some downstream distributions (such as Ubuntu?) may disable unprivileged user namespaces by default.
If we create the user namespace before mounting FUSE, these tests would require privileges.
Quoted 3 lines
Thanks,
Miklos