The file_stressor test creates directories in the root filesystem and
performs mount namespace operations that can fail on NFS root filesystems
due to network filesystem restrictions and permission limitations.

Add NFS root filesystem detection using statfs() to check for
NFS_SUPER_MAGIC and skip the test gracefully when running on NFS root,
providing a clear message about why the test was skipped.

This prevents spurious test failures in CI environments that use NFS
root while preserving the test's ability to catch SLAB_TYPESAFE_BY_RCU
related bugs on local filesystems where it can run properly.

Signed-off-by: Anders Roxell <anders.rox...@linaro.org>
---
 tools/testing/selftests/filesystems/file_stressor.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/filesystems/file_stressor.c 
b/tools/testing/selftests/filesystems/file_stressor.c
index 01dd89f8e52f..b9dfe0b6b125 100644
--- a/tools/testing/selftests/filesystems/file_stressor.c
+++ b/tools/testing/selftests/filesystems/file_stressor.c
@@ -10,12 +10,14 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/mount.h>
+#include <sys/vfs.h>
 #include <unistd.h>
 
 #include "../kselftest_harness.h"
 
 #include <linux/types.h>
 #include <linux/mount.h>
+#include <linux/magic.h>
 #include <sys/syscall.h>
 
 static inline int sys_fsopen(const char *fsname, unsigned int flags)
@@ -58,8 +60,13 @@ FIXTURE(file_stressor) {
 
 FIXTURE_SETUP(file_stressor)
 {
+       struct statfs sfs;
        int fd_context;
 
+       /* Skip test if root filesystem is NFS */
+       if (statfs("/", &sfs) == 0 && sfs.f_type == NFS_SUPER_MAGIC)
+               SKIP(return, "Test requires local root filesystem, NFS root 
detected");
+
        ASSERT_EQ(unshare(CLONE_NEWNS), 0);
        ASSERT_EQ(mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL), 0);
        ASSERT_EQ(mkdir("/slab_typesafe_by_rcu", 0755), 0);
-- 
2.50.1


Reply via email to