sys_open_tree is once defined in filesystems/overlayfs/wrappers.h so
before we define it in mount_setattr_test.c we should check if has been
previously defined or not. Otherwise it results in the following build
error:

make[1]: Nothing to be done for 'all'.
  CC       mount_setattr_test
mount_setattr_test.c:176:19: error: redefinition of ‘sys_open_tree’
  176 | static inline int sys_open_tree(int dfd, const char *filename, unsigned 
int flags)
      |                   ^~~~~~~~~~~~~
In file included from mount_setattr_test.c:23:
../filesystems/overlayfs/wrappers.h:59:19: note: previous definition of
                ‘sys_open_tree’ with type ‘int(int,  const char *, unsigned 
int)’
   59 | static inline int sys_open_tree(int dfd, const char *filename, unsigned 
int flags)
      |                   ^~~~~~~~~~~~~
make[1]: *** [../lib.mk:222: 
/home/listout/linux/tools/testing/selftests/mount_setattr/mount_setattr_test]
                Error 1

Signed-off-by: Brahmajit Das <list...@listout.xyz>
---
 tools/testing/selftests/mount_setattr/mount_setattr_test.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tools/testing/selftests/mount_setattr/mount_setattr_test.c 
b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
index 48a000cabc97..b0798777b822 100644
--- a/tools/testing/selftests/mount_setattr/mount_setattr_test.c
+++ b/tools/testing/selftests/mount_setattr/mount_setattr_test.c
@@ -173,10 +173,13 @@ static inline int sys_mount_setattr(int dfd, const char 
*path, unsigned int flag
 #define AT_RECURSIVE 0x8000 /* Apply to the entire subtree */
 #endif
 
+/* Do not define sys_open_tree if it's already defined in overlayfs/wrappers.h 
*/
+#if !defined(__SELFTEST_OVERLAYFS_WRAPPERS_H__)
 static inline int sys_open_tree(int dfd, const char *filename, unsigned int 
flags)
 {
        return syscall(__NR_open_tree, dfd, filename, flags);
 }
+#endif
 
 static ssize_t write_nointr(int fd, const void *buf, size_t count)
 {
-- 
2.49.0


Reply via email to