diff mbox series

src: fix detached_mounts_propagation compile errors

Message ID 20230419032955.114278-1-hsiangkao@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series src: fix detached_mounts_propagation compile errors | expand

Commit Message

Gao Xiang April 19, 2023, 3:29 a.m. UTC
Newer glibc such as glibc 2.36 also defines 'struct mount_attr'
in addition to <linux/mount.h>.  It will report as below when
compiling with old linux kernel headers (without idmapped mounts,
such as kernel-headers 5.10.134) but with newer glibc (here checked
with glibc 2.36.6):

    [CC]    detached_mounts_propagation
In file included from detached_mounts_propagation.c:29:
vfs/missing.h:115:8: error: redefinition of 'struct mount_attr'
  115 | struct mount_attr {
      |        ^~~~~~~~~~
In file included from detached_mounts_propagation.c:23:
/usr/include/sys/mount.h:210:8: note: originally defined here
  210 | struct mount_attr
      |        ^~~~~~~~~~
gmake[3]: *** [Makefile:102: detached_mounts_propagation] Error 1
gmake[2]: *** [include/buildrules:31: src] Error 2
make[1]: *** [Makefile:51: default] Error 2
make: *** [Makefile:49: default] Error 2

Cc: Christian Brauner <brauner@kernel.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---

Not quite look into that, but at a quick glance of tester reports
it seems the cases.

 configure.ac                      | 5 ++++-
 src/detached_mounts_propagation.c | 1 -
 src/vfs/missing.h                 | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)

Comments

Christian Brauner April 19, 2023, 8:45 a.m. UTC | #1
On Wed, Apr 19, 2023 at 11:29:55AM +0800, Gao Xiang wrote:
> Newer glibc such as glibc 2.36 also defines 'struct mount_attr'
> in addition to <linux/mount.h>.  It will report as below when
> compiling with old linux kernel headers (without idmapped mounts,
> such as kernel-headers 5.10.134) but with newer glibc (here checked
> with glibc 2.36.6):
> 
>     [CC]    detached_mounts_propagation
> In file included from detached_mounts_propagation.c:29:
> vfs/missing.h:115:8: error: redefinition of 'struct mount_attr'
>   115 | struct mount_attr {
>       |        ^~~~~~~~~~
> In file included from detached_mounts_propagation.c:23:
> /usr/include/sys/mount.h:210:8: note: originally defined here
>   210 | struct mount_attr
>       |        ^~~~~~~~~~
> gmake[3]: *** [Makefile:102: detached_mounts_propagation] Error 1
> gmake[2]: *** [include/buildrules:31: src] Error 2
> make[1]: *** [Makefile:51: default] Error 2
> make: *** [Makefile:49: default] Error 2
> 
> Cc: Christian Brauner <brauner@kernel.org>
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
> ---

This header mount.h mess is a neverending nightmare...

> 
> Not quite look into that, but at a quick glance of tester reports
> it seems the cases.
> 
>  configure.ac                      | 5 ++++-
>  src/detached_mounts_propagation.c | 1 -
>  src/vfs/missing.h                 | 1 +
>  3 files changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 4687d8a3..517b4c18 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -74,7 +74,10 @@ AC_HAVE_FIEXCHANGE
>  
>  AC_CHECK_FUNCS([renameat2])
>  AC_CHECK_FUNCS([reallocarray])
> -AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]])
> +AC_CHECK_TYPES([struct mount_attr], [], [], [[
> +#include <linux/mount.h>
> +#include <sys/mount.h>

I think we should only rely on sys/mount.h. linux/mount.h and
sys/mount.h are incompatible because linux/mount.h might have a #define
where sys/mount.h has an enum.
Gao Xiang April 19, 2023, 9:04 a.m. UTC | #2
On 2023/4/19 16:45, Christian Brauner wrote:
> On Wed, Apr 19, 2023 at 11:29:55AM +0800, Gao Xiang wrote:
>> Newer glibc such as glibc 2.36 also defines 'struct mount_attr'
>> in addition to <linux/mount.h>.  It will report as below when
>> compiling with old linux kernel headers (without idmapped mounts,
>> such as kernel-headers 5.10.134) but with newer glibc (here checked
>> with glibc 2.36.6):
>>
>>      [CC]    detached_mounts_propagation
>> In file included from detached_mounts_propagation.c:29:
>> vfs/missing.h:115:8: error: redefinition of 'struct mount_attr'
>>    115 | struct mount_attr {
>>        |        ^~~~~~~~~~
>> In file included from detached_mounts_propagation.c:23:
>> /usr/include/sys/mount.h:210:8: note: originally defined here
>>    210 | struct mount_attr
>>        |        ^~~~~~~~~~
>> gmake[3]: *** [Makefile:102: detached_mounts_propagation] Error 1
>> gmake[2]: *** [include/buildrules:31: src] Error 2
>> make[1]: *** [Makefile:51: default] Error 2
>> make: *** [Makefile:49: default] Error 2
>>
>> Cc: Christian Brauner <brauner@kernel.org>
>> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>> ---
> 
> This header mount.h mess is a neverending nightmare...
> 
>>
>> Not quite look into that, but at a quick glance of tester reports
>> it seems the cases.
>>
>>   configure.ac                      | 5 ++++-
>>   src/detached_mounts_propagation.c | 1 -
>>   src/vfs/missing.h                 | 1 +
>>   3 files changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/configure.ac b/configure.ac
>> index 4687d8a3..517b4c18 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -74,7 +74,10 @@ AC_HAVE_FIEXCHANGE
>>   
>>   AC_CHECK_FUNCS([renameat2])
>>   AC_CHECK_FUNCS([reallocarray])
>> -AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]])
>> +AC_CHECK_TYPES([struct mount_attr], [], [], [[
>> +#include <linux/mount.h>
>> +#include <sys/mount.h>
> 
> I think we should only rely on sys/mount.h. linux/mount.h and
> sys/mount.h are incompatible because linux/mount.h might have a #define
> where sys/mount.h has an enum.

Ok, got it.  Let me play with it later.

Thanks,
Gao Xiang
Yang Xu (Fujitsu) April 19, 2023, 9:08 a.m. UTC | #3
on 2023/04/19 16:45, Christian Brauner wrote:

> On Wed, Apr 19, 2023 at 11:29:55AM +0800, Gao Xiang wrote:
>> Newer glibc such as glibc 2.36 also defines 'struct mount_attr'
>> in addition to <linux/mount.h>.  It will report as below when
>> compiling with old linux kernel headers (without idmapped mounts,
>> such as kernel-headers 5.10.134) but with newer glibc (here checked
>> with glibc 2.36.6):
>>
>>      [CC]    detached_mounts_propagation
>> In file included from detached_mounts_propagation.c:29:
>> vfs/missing.h:115:8: error: redefinition of 'struct mount_attr'
>>    115 | struct mount_attr {
>>        |        ^~~~~~~~~~
>> In file included from detached_mounts_propagation.c:23:
>> /usr/include/sys/mount.h:210:8: note: originally defined here
>>    210 | struct mount_attr
>>        |        ^~~~~~~~~~
>> gmake[3]: *** [Makefile:102: detached_mounts_propagation] Error 1
>> gmake[2]: *** [include/buildrules:31: src] Error 2
>> make[1]: *** [Makefile:51: default] Error 2
>> make: *** [Makefile:49: default] Error 2
>>
>> Cc: Christian Brauner <brauner@kernel.org>
>> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>> ---
> 
> This header mount.h mess is a neverending nightmare...
> 
>>
>> Not quite look into that, but at a quick glance of tester reports
>> it seems the cases.
>>
>>   configure.ac                      | 5 ++++-
>>   src/detached_mounts_propagation.c | 1 -
>>   src/vfs/missing.h                 | 1 +
>>   3 files changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/configure.ac b/configure.ac
>> index 4687d8a3..517b4c18 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -74,7 +74,10 @@ AC_HAVE_FIEXCHANGE
>>   
>>   AC_CHECK_FUNCS([renameat2])
>>   AC_CHECK_FUNCS([reallocarray])
>> -AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]])
>> +AC_CHECK_TYPES([struct mount_attr], [], [], [[
>> +#include <linux/mount.h>
>> +#include <sys/mount.h>
> 
> I think we should only rely on sys/mount.h. linux/mount.h and
> sys/mount.h are incompatible because linux/mount.h might have a #define
> where sys/mount.h has an enum.

In fact, ltp also has this problem, but ltp has fixed this

We check whether mount_setattr() supported, if support, then use 
<sys/mount.h>,otherwise, use <linux/mount.h>

AC_CHECK_TYPES([struct mount_attr],,,[
#ifdef HAVE_MOUNT_SETATTR
# include <sys/mount.h>
#elif HAVE_LINUX_MOUNT_H
# include <linux/mount.h>
#endif

see 
https://github.com/linux-test-project/ltp/commit/30353a1eb3ee8940f38d6a0e8f5f39352fd8a179.

Best Regards
Yang Xu
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index 4687d8a3..517b4c18 100644
--- a/configure.ac
+++ b/configure.ac
@@ -74,7 +74,10 @@  AC_HAVE_FIEXCHANGE
 
 AC_CHECK_FUNCS([renameat2])
 AC_CHECK_FUNCS([reallocarray])
-AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]])
+AC_CHECK_TYPES([struct mount_attr], [], [], [[
+#include <linux/mount.h>
+#include <sys/mount.h>
+]])
 AC_CHECK_TYPES([struct btrfs_qgroup_limit], [], [], [[
 #include <stddef.h>
 #include <linux/btrfs.h>
diff --git a/src/detached_mounts_propagation.c b/src/detached_mounts_propagation.c
index 17db2c02..4041c75f 100644
--- a/src/detached_mounts_propagation.c
+++ b/src/detached_mounts_propagation.c
@@ -20,7 +20,6 @@ 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
diff --git a/src/vfs/missing.h b/src/vfs/missing.h
index 059e742d..04ab33d1 100644
--- a/src/vfs/missing.h
+++ b/src/vfs/missing.h
@@ -18,6 +18,7 @@ 
 #include <sys/types.h>
 #include <syscall.h>
 #include <unistd.h>
+#include <sys/mount.h>
 
 #ifndef __NR_mount_setattr
 	#if defined __alpha__