> selftests/filesystems: add backing file tests for pseudo files

TL;DR:
- Selftest: fuse tests may fail instead of skip without
  CONFIG_FUSE_PASSTHROUGH (-EOPNOTSUPP, not -EPERM)
- Metacopy test may fail without CONFIG_TMPFS_XATTR
- Minor duplicated setup code

> diff --git a/tools/testing/selftests/filesystems/config 
> b/tools/testing/selftests/filesystems/config
> --- a/tools/testing/selftests/filesystems/config
> +++ b/tools/testing/selftests/filesystems/config
> @@ -6,3 +6,19 @@ CONFIG_NET=y
>  CONFIG_NET_NS=y
>  CONFIG_INET=y
>  CONFIG_SYSFS=y
> +CONFIG_BLK_DEV_LOOP=y
> +CONFIG_OVERLAY_FS=y
> +CONFIG_TMPFS=y
> +CONFIG_CONFIGFS_FS=y
[ ... ]

Should CONFIG_TMPFS_XATTR=y be added here as well?

TEST(fuse_passthrough_overlayfs_metacopy_file) mounts a private tmpfs
through setup_tmp() and then does:

    ASSERT_EQ(setxattr("/tmp/lower/file", "trusted.overlay.metacopy",
                       "", 0, 0), 0);

shmem_fill_super() only sets sb->s_xattr under CONFIG_TMPFS_XATTR, which
defaults to n, and CONFIG_TMPFS does not select it.  Without it
setxattr() fails with EOPNOTSUPP, the ASSERT_EQ() aborts, and the run
reports a failure rather than a skip.  tools/testing/selftests/landlock/config
lists CONFIG_TMPFS_XATTR=y next to CONFIG_TMPFS=y.

Alternatively the test could SKIP when setxattr() returns EOPNOTSUPP.

> diff --git a/tools/testing/selftests/filesystems/pseudo_backing_test.c 
> b/tools/testing/selftests/filesystems/pseudo_backing_test.c
> new file mode 100644
> --- /dev/null
> +++ b/tools/testing/selftests/filesystems/pseudo_backing_test.c

[ ... ]

> +TEST(overlayfs_on_sysfs_backing_file)
> +{
> +     if (!can_use_loop())
> +             SKIP(return, "loop devices unavailable");
> +
> +     ASSERT_EQ(unshare(CLONE_NEWNS), 0);
> +     ASSERT_EQ(mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
> +     ASSERT_EQ(mount("tmpfs", "/tmp", "tmpfs", 0, NULL), 0);

this isn't a bug, but could overlayfs_on_sysfs_backing_file() call
ASSERT_EQ(setup_tmp(), 0) like the other tests, instead of repeating its
three steps?  Similarly, usb_mass_storage_backing_file() repeats the
statfs()/CONFIGFS_MAGIC/mount() logic of setup_configfs(), and the comment
"Mounting configfs on top of itself fails with EBUSY." appears twice.

[ ... ]

> +TEST(fuse_passthrough_backing_file)
> +{
> +     int fuse_fd, ret;
> +
[ ... ]
> +     ASSERT_EQ(create_file("/tmp/file"), 0);
> +     ret = fuse_backing_path(fuse_fd, "/tmp/file", O_PATH);
> +     if (ret == -EPERM)
> +             SKIP(return, "no fuse passthrough");
> +     EXPECT_EQ(ret, 0);

Is -EPERM the right errno to key the skip on?  On a kernel with
CONFIG_FUSE_FS=y and CONFIG_FUSE_PASSTHROUGH=n the test filesystem mounts
fine, and then fuse_dev_ioctl_backing_open() returns before any
permission check:

    if (!IS_ENABLED(CONFIG_FUSE_PASSTHROUGH))
        return -EOPNOTSUPP;

-EPERM only comes from fuse_backing_open_file() when fc->passthrough is
clear or CAP_SYS_ADMIN is missing.  So here EXPECT_EQ(ret, 0) and the
later -EINVAL checks see -EOPNOTSUPP and fail, and the harness records
"not ok" for a feature that is not configured.  Kernels that predate
FUSE_DEV_IOC_BACKING_OPEN return -ENOTTY and fail the same way.

Should -EOPNOTSUPP (and possibly -ENOTTY) also lead to the SKIP?

[ ... ]

> +TEST(fuse_passthrough_overlayfs_metacopy_file)
[ ... ]
> +     ASSERT_EQ(create_file("/tmp/lower/file"), 0);
> +     ASSERT_EQ(setxattr("/tmp/lower/file", "trusted.overlay.metacopy",
> +                        "", 0, 0), 0);
> +     ASSERT_EQ(setxattr("/tmp/lower/file", "trusted.overlay.redirect",
> +                        "/missing", strlen("/missing"), 0), 0);

Can these setxattr() calls fail on a kernel without CONFIG_TMPFS_XATTR?

The private tmpfs from setup_tmp() has no xattr handlers in that case, so
setxattr() returns EOPNOTSUPP, the ASSERT_EQ() aborts, and the program
exits with a failure instead of KSFT_SKIP.  The mount of overlayfs just
below already has a SKIP for missing support.  Would a SKIP on
EOPNOTSUPP here, or CONFIG_TMPFS_XATTR=y in the config fragment, avoid
this?

> +     ret = fuse_backing_path(fuse_fd, "/tmp/file", O_PATH);
> +     if (ret == -EPERM)
> +             SKIP(return, "no fuse passthrough");
> +     ASSERT_EQ(ret, 0);

The same -EPERM check as in fuse_passthrough_backing_file() is used here,
so ASSERT_EQ(ret, 0) fails with -EOPNOTSUPP when CONFIG_FUSE_PASSTHROUGH
is off.

[ ... ]

> +TEST(fuse_passthrough_io)
[ ... ]
> +             srv.backing_ids[i] = fuse_backing_open(srv.fd, fd);
> +             EXPECT_EQ(close(fd), 0);
> +             if (srv.backing_ids[i] == -EPERM)
> +                     SKIP(return, "no fuse passthrough");
> +             ASSERT_GT(srv.backing_ids[i], 0);

Does this skip also miss the unconfigured case?  With
CONFIG_FUSE_PASSTHROUGH=n, fuse_backing_open() gets -EOPNOTSUPP from the
ioctl, which is not -EPERM, so ASSERT_GT(srv.backing_ids[i], 0) fails and
run_one() records "not ok" for the whole pseudo_backing_test.  No fuse
server has been started at this point, so nothing hangs.  The config
fragment does list CONFIG_FUSE_PASSTHROUGH=y, but should -EOPNOTSUPP and
-ENOTTY also lead to SKIP(return, "no fuse passthrough") in all three fuse
tests?


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/43858134663

Reply via email to