Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/filesystems:fix build error in overlayfs

One build issue comes up due to both mount.h included dev_in_maps.c

In file included from dev_in_maps.c:10:
/usr/include/sys/mount.h:35:3: error: expected identifier before numeric constant
35 | MS_RDONLY = 1, /* Mount read-only. */
| ^~~~~~~~~
In file included from dev_in_maps.c:13:

Remove one of them to solve conflict, another error comes up:

dev_in_maps.c:170:6: error: implicit declaration of function ‘mount’ [-Werror=implicit-function-declaration]
170 | if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) == -1) {
| ^~~~~
cc1: all warnings being treated as errors

and then , add sys_mount definition to solve it
After both above, dev_in_maps.c can be built correctly on my mache(gcc 10.2,glibc-2.32,kernel-5.10)

Signed-off-by: Hu Yadi <hu.yadi@h3c.com>
Link: https://lore.kernel.org/r/20240112074059.29673-1-hu.yadi@h3c.com
Acked-by: Andrei Vagin <avagin@google.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>

authored by

Hu Yadi and committed by
Christian Brauner
0f05ee44 8b3d8381

+6 -4
+6 -4
tools/testing/selftests/filesystems/overlayfs/dev_in_maps.c
··· 10 10 #include <linux/mount.h> 11 11 #include <sys/syscall.h> 12 12 #include <sys/stat.h> 13 - #include <sys/mount.h> 14 13 #include <sys/mman.h> 15 14 #include <sched.h> 16 15 #include <fcntl.h> ··· 31 32 { 32 33 return syscall(__NR_fsmount, fd, flags, attr_flags); 33 34 } 34 - 35 + static int sys_mount(const char *src, const char *tgt, const char *fst, 36 + unsigned long flags, const void *data) 37 + { 38 + return syscall(__NR_mount, src, tgt, fst, flags, data); 39 + } 35 40 static int sys_move_mount(int from_dfd, const char *from_pathname, 36 41 int to_dfd, const char *to_pathname, 37 42 unsigned int flags) ··· 169 166 ksft_test_result_skip("unable to create a new mount namespace\n"); 170 167 return 1; 171 168 } 172 - 173 - if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) == -1) { 169 + if (sys_mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) == -1) { 174 170 pr_perror("mount"); 175 171 return 1; 176 172 }