From: "Yang Xu (Fujitsu)" <xuyang2018.jy@fujitsu.com>
To: Zorro Lang <zlang@redhat.com>,
Ziyang Zhang <ZiyangZhang@linux.alibaba.com>
Cc: Gao Xiang <hsiangkao@linux.alibaba.com>,
"fstests@vger.kernel.org" <fstests@vger.kernel.org>,
Christian Brauner <brauner@kernel.org>
Subject: Re: [PATCH v2] src: fix detached_mounts_propagation compile errors
Date: Tue, 25 Apr 2023 01:28:43 +0000 [thread overview]
Message-ID: <5cd6f60e-b725-6aa0-733b-ce92434694c8@fujitsu.com> (raw)
In-Reply-To: <20230424210648.53l3k2xmuj53nusa@zlang-mailbox>
on 2023/04/25 5:06, Zorro Lang wrote:
> On Mon, Apr 24, 2023 at 06:17:55PM +0800, Ziyang Zhang wrote:
>> On 2023/4/22 21:54, Zorro Lang wrote:
>>> On Thu, Apr 20, 2023 at 10:11:06AM +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
>>>>
>>>> Let's get rid of <linux/mount.h> as Christian suggested to avoid
>>>> potential incompatibility between these two headers.
>>>>
>>>> Cc: Christian Brauner <brauner@kernel.org>
>>>> Cc: "Yang Xu (Fujitsu)" <xuyang2018.jy@fujitsu.com>
>>>> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
>>>> ---
>>>
>>> This patch works on latest fedora, but it cause fstests can't be built on
>>> RHEL-8 [1] and RHEL-9 [2], please check this incompatible problem.
>>>
>>> Thanks,
>>> Zorro
>>>
>>> [1]
>>> ...
>>> Building include
>>> Building lib
>>> Building ltp
>>> Building src
>>> [CC] feature
>>> In file included from /usr/include/linux/fs.h:18,
>>> from /usr/include/xfs/linux.h:30,
>>> from /usr/include/xfs/xfs.h:9,
>>> from global.h:13,
>>> from feature.c:29:
>>> /usr/include/sys/mount.h:35:3: error: expected identifier before numeric constant
>>> MS_RDONLY = 1, /* Mount read-only. */
>>> ^~~~~~~~~
>>> gmake[2]: *** [Makefile:112: feature] Error 1
>>> gmake[1]: *** [include/buildrules:31: src] Error 2
>>> make: *** [Makefile:51: default] Error 2
>>>
>>> [2]
>>> ...
>>> Building include
>>> Building lib
>>> Building ltp
>>> Building src
>>> [CC] feature
>>> In file included from /usr/include/linux/fs.h:19,
>>> from /usr/include/xfs/linux.h:36,
>>> from /usr/include/xfs/xfs.h:9,
>>> from global.h:13,
>>> from feature.c:29:
>>> /usr/include/sys/mount.h:35:3: error: expected identifier before numeric constant
>>> 35 | MS_RDONLY = 1, /* Mount read-only. */
>>> | ^~~~~~~~~
>>> In file included from feature.c:49:
>>> vfs/missing.h:116:8: error: redefinition of 'struct mount_attr'
>>> 116 | struct mount_attr {
>>> | ^~~~~~~~~~
>>> In file included from /usr/include/linux/fs.h:19,
>>> from /usr/include/xfs/linux.h:36,
>>> from /usr/include/xfs/xfs.h:9,
>>> from global.h:13,
>>> from feature.c:29:
>>> /usr/include/linux/mount.h:128:8: note: originally defined here
>>> 128 | struct mount_attr {
>>> | ^~~~~~~~~~
>>> gmake[2]: *** [Makefile:112: feature] Error 1
>>> gmake[1]: *** [include/buildrules:31: src] Error 2
>>> make: *** [Makefile:51: default] Error 2
>>>
>>>
>>>> configure.ac | 2 +-
>>>> src/detached_mounts_propagation.c | 1 -
>>>> src/vfs/missing.h | 1 +
>>>> 3 files changed, 2 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/configure.ac b/configure.ac
>>>> index 4687d8a3..bb29f37e 100644
>>>> --- a/configure.ac
>>>> +++ b/configure.ac
>>>> @@ -74,7 +74,7 @@ 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 <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__
>>>> --
>>>> 2.24.4
>>>>
>>
>> Hi Zorro,
>>
>> Can you try this patch, which is inspired by Yang Xu[1].
>>
>> [1]https://lore.kernel.org/fstests/ed0bb9f0-c255-10d7-d711-36a464cd6512@fujitsu.com/T/#me981ae064b3ecb151b3321a4ee77f5d916cb017c
>>
>> Regards,
>> Zhang
>>
>>
>> Patch:
>
> Looks like not help [1]. The src/feature.c through global.h -> xfs/xfs.h
> -> xfs/linux.h -> linux/fs.h to include linux/mount.h, then it include
> "vfs/missing.h" manually. As you add "<sys/mount.h>" to vfs/missing.h,
> so there's a conflict.
Yes, here is a complex problem than ltp because global.h includes
<linux/mount.h>. We don't include <sys/mount.h> or <linux/mount.h>
together on older glibc(glibc 2.36.6). Newer glibc(glibc-2.37-1)[1]
seems has sloved this problem.
[1]https://sourceware.org/git/?p=glibc.git;a=commit;h=774058d72942249f71d74e7f2b639f77184160a6
I guess we can not use <sys/mount.h> header,
then compile info as below:
detached_mounts_propagation.c: In function 'main':
detached_mounts_propagation.c:129:15: warning: implicit declaration of
function 'mount' [-Wimplicit-function-declaration]
129 | ret = mount(NULL, base_dir, NULL, MS_REC | MS_SHARED,
NULL);
| ^~~~~
detached_mounts_propagation.c:176:23: warning: implicit declaration of
function 'umount2'; did you mean 'sys_umount2'?
[-Wimplicit-function-declaration]
176 | ret = umount2(target, MNT_DETACH);
| ^~~~~~~
| sys_umount2
then we can use syscall wrapper directly instead of glibc wrapper
--- 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>
@@ -127,7 +126,7 @@ int main(int argc, char *argv[])
if (ret < 0)
exit_log("%m - Failed to create new mount namespace");
- ret = mount(NULL, base_dir, NULL, MS_REC | MS_SHARED, NULL);
+ ret = sys_mount(NULL, base_dir, NULL, MS_REC | MS_SHARED, NULL);
if (ret < 0)
exit_log("%m - Failed to make base_dir shared mountpoint");
@@ -174,7 +173,7 @@ int main(int argc, char *argv[])
}
close(fd_tree);
- ret = umount2(target, MNT_DETACH);
+ ret = sys_umount2(target, MNT_DETACH);
if (ret < 0) {
fprintf(stderr, "%m - Failed to unmount %s",
target);
exit_code = EXIT_FAILURE;
Best Regards
Yang Xu
>
> Thanks,
> Zorro
>
> [1]
> # make
> Building include
> Building lib
> Building ltp
> Building src
> [CC] feature
> In file included from /usr/include/linux/fs.h:18,
> from /usr/include/xfs/linux.h:30,
> from /usr/include/xfs/xfs.h:9,
> from global.h:13,
> from feature.c:29:
> /usr/include/sys/mount.h:35:3: error: expected identifier before numeric constant
> MS_RDONLY = 1, /* Mount read-only. */
> ^~~~~~~~~
> gmake[2]: *** [Makefile:112: feature] Error 1
> gmake[1]: *** [include/buildrules:31: src] Error 2
> make: *** [Makefile:51: default] Error 2
>
>>
>> diff --git a/configure.ac b/configure.ac
>> index cbf83779..060c0a5d 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -16,6 +16,7 @@ AC_CHECK_HEADERS([ assert.h \
>> sys/uuid.h \
>> sys/file.h \
>> sys/fcntl.h \
>> + sys/mount.h \
>> sys/syssgi.h \
>> sys/param.h \
>> sys/stat.h \
>> @@ -27,6 +28,7 @@ AC_CHECK_HEADERS([ assert.h \
>> strings.h \
>> err.h \
>> linux/falloc.h \
>> + linux/mount.h \
>> sys/fs/xfs_fsops.h \
>> sys/fs/xfs_itable.h \
>> xfs/platform_defs.h \
>> @@ -35,6 +37,10 @@ AC_CHECK_HEADERS([ assert.h \
>> sys/mman.h \
>> ])
>>
>> +AC_CHECK_FUNCS_ONCE([
>> + mount_setattr
>> +])
>> +
>> AC_CHECK_HEADERS([xfs/xfs_log_format.h],,,[
>> #define _GNU_SOURCE
>> #include <xfs/libxfs.h>])
>> @@ -68,7 +74,13 @@ AC_PACKAGE_WANT_LIBBTRFSUTIL
>> AC_HAVE_COPY_FILE_RANGE
>> AC_CHECK_FUNCS([renameat2])
>> AC_CHECK_FUNCS([reallocarray])
>> -AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <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
>> +]])
>> AC_CHECK_TYPES([struct btrfs_qgroup_limit], [], [], [[
>> #include <stddef.h>
>> #include <linux/btrfs.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__
>>
>
next prev parent reply other threads:[~2023-04-25 1:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-19 3:29 [PATCH] src: fix detached_mounts_propagation compile errors Gao Xiang
2023-04-19 8:45 ` Christian Brauner
2023-04-19 9:04 ` Gao Xiang
2023-04-19 9:08 ` Yang Xu (Fujitsu)
2023-04-20 2:11 ` [PATCH v2] " Gao Xiang
2023-04-20 8:42 ` Christian Brauner
2023-04-22 13:54 ` Zorro Lang
2023-04-24 3:13 ` Gao Xiang
2023-04-24 10:17 ` Ziyang Zhang
2023-04-24 21:06 ` Zorro Lang
2023-04-25 1:28 ` Yang Xu (Fujitsu) [this message]
2023-04-25 1:59 ` Ziyang Zhang
2023-04-25 2:07 ` Yang Xu (Fujitsu)
2023-04-25 3:18 ` Ziyang Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5cd6f60e-b725-6aa0-733b-ce92434694c8@fujitsu.com \
--to=xuyang2018.jy@fujitsu.com \
--cc=ZiyangZhang@linux.alibaba.com \
--cc=brauner@kernel.org \
--cc=fstests@vger.kernel.org \
--cc=hsiangkao@linux.alibaba.com \
--cc=zlang@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox