Blame 0011-linux-user-fix-compat-with-glibc-2.36-sys-mount.h.patch

Daniel P. Berrangé 342547
From a7f14aae85022007a4c77e0792a1abb0509a08eb Mon Sep 17 00:00:00 2001
Daniel P. Berrangé 342547
From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= <berrange@redhat.com>
Daniel P. Berrangé 342547
Date: Tue, 2 Aug 2022 12:34:23 -0400
Daniel P. Berrangé 342547
Subject: [PATCH] linux-user: fix compat with glibc >= 2.36 sys/mount.h
Daniel P. Berrangé 342547
MIME-Version: 1.0
Daniel P. Berrangé 342547
Content-Type: text/plain; charset=UTF-8
Daniel P. Berrangé 342547
Content-Transfer-Encoding: 8bit
Daniel P. Berrangé 342547
Daniel P. Berrangé 342547
The latest glibc 2.36 has extended sys/mount.h so that it
Daniel P. Berrangé 342547
defines the FSCONFIG_* enum constants. These are historically
Daniel P. Berrangé 342547
defined in linux/mount.h, and thus if you include both headers
Daniel P. Berrangé 342547
the compiler complains:
Daniel P. Berrangé 342547
Daniel P. Berrangé 342547
In file included from /usr/include/linux/fs.h:19,
Daniel P. Berrangé 342547
                 from ../linux-user/syscall.c:98:
Daniel P. Berrangé 342547
/usr/include/linux/mount.h:95:6: error: redeclaration of 'enum fsconfig_command'
Daniel P. Berrangé 342547
   95 | enum fsconfig_command {
Daniel P. Berrangé 342547
      |      ^~~~~~~~~~~~~~~~
Daniel P. Berrangé 342547
In file included from ../linux-user/syscall.c:31:
Daniel P. Berrangé 342547
/usr/include/sys/mount.h:189:6: note: originally defined here
Daniel P. Berrangé 342547
  189 | enum fsconfig_command
Daniel P. Berrangé 342547
      |      ^~~~~~~~~~~~~~~~
Daniel P. Berrangé 342547
/usr/include/linux/mount.h:96:9: error: redeclaration of enumerator 'FSCONFIG_SET_FLAG'
Daniel P. Berrangé 342547
   96 |         FSCONFIG_SET_FLAG       = 0,    /* Set parameter, supplying no value */
Daniel P. Berrangé 342547
      |         ^~~~~~~~~~~~~~~~~
Daniel P. Berrangé 342547
/usr/include/sys/mount.h:191:3: note: previous definition of 'FSCONFIG_SET_FLAG' with type 'enum fsconfig_command'
Daniel P. Berrangé 342547
  191 |   FSCONFIG_SET_FLAG       = 0,    /* Set parameter, supplying no value */
Daniel P. Berrangé 342547
      |   ^~~~~~~~~~~~~~~~~
Daniel P. Berrangé 342547
...snip...
Daniel P. Berrangé 342547
Daniel P. Berrangé 342547
QEMU doesn't include linux/mount.h, but it does use
Daniel P. Berrangé 342547
linux/fs.h and thus gets linux/mount.h indirectly.
Daniel P. Berrangé 342547
Daniel P. Berrangé 342547
glibc acknowledges this problem but does not appear to
Daniel P. Berrangé 342547
be intending to fix it in the forseeable future, simply
Daniel P. Berrangé 342547
documenting it as a known incompatibility with no
Daniel P. Berrangé 342547
workaround:
Daniel P. Berrangé 342547
Daniel P. Berrangé 342547
  https://sourceware.org/glibc/wiki/Release/2.36#Usage_of_.3Clinux.2Fmount.h.3E_and_.3Csys.2Fmount.h.3E
Daniel P. Berrangé 342547
  https://sourceware.org/glibc/wiki/Synchronizing_Headers
Daniel P. Berrangé 342547
Daniel P. Berrangé 342547
To address this requires either removing use of sys/mount.h
Daniel P. Berrangé 342547
or linux/fs.h, despite QEMU needing declarations from
Daniel P. Berrangé 342547
both.
Daniel P. Berrangé 342547
Daniel P. Berrangé 342547
This patch removes linux/fs.h, meaning we have to define
Daniel P. Berrangé 342547
various FS_IOC constants that are now unavailable.
Daniel P. Berrangé 342547
Daniel P. Berrangé 342547
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Daniel P. Berrangé 342547
---
Daniel P. Berrangé 342547
 linux-user/syscall.c | 18 ++++++++++++++++++
Daniel P. Berrangé 342547
 meson.build          |  2 ++
Daniel P. Berrangé 342547
 2 files changed, 20 insertions(+)
Daniel P. Berrangé 342547
Daniel P. Berrangé 342547
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
Daniel P. Berrangé 342547
index b27a6552aa..52d178afe7 100644
Daniel P. Berrangé 342547
--- a/linux-user/syscall.c
Daniel P. Berrangé 342547
+++ b/linux-user/syscall.c
Daniel P. Berrangé 342547
@@ -95,7 +95,25 @@
Daniel P. Berrangé 342547
 #include <linux/soundcard.h>
Daniel P. Berrangé 342547
 #include <linux/kd.h>
Daniel P. Berrangé 342547
 #include <linux/mtio.h>
Daniel P. Berrangé 342547
+
Daniel P. Berrangé 342547
+#ifdef HAVE_SYS_MOUNT_FSCONFIG
Daniel P. Berrangé 342547
+/*
Daniel P. Berrangé 342547
+ * glibc >= 2.36 linux/mount.h conflicts with sys/mount.h,
Daniel P. Berrangé 342547
+ * which in turn prevents use of linux/fs.h. So we have to
Daniel P. Berrangé 342547
+ * define the constants ourselves for now.
Daniel P. Berrangé 342547
+ */
Daniel P. Berrangé 342547
+#define FS_IOC_GETFLAGS                _IOR('f', 1, long)
Daniel P. Berrangé 342547
+#define FS_IOC_SETFLAGS                _IOW('f', 2, long)
Daniel P. Berrangé 342547
+#define FS_IOC_GETVERSION              _IOR('v', 1, long)
Daniel P. Berrangé 342547
+#define FS_IOC_SETVERSION              _IOW('v', 2, long)
Daniel P. Berrangé 342547
+#define FS_IOC_FIEMAP                  _IOWR('f', 11, struct fiemap)
Daniel P. Berrangé 342547
+#define FS_IOC32_GETFLAGS              _IOR('f', 1, int)
Daniel P. Berrangé 342547
+#define FS_IOC32_SETFLAGS              _IOW('f', 2, int)
Daniel P. Berrangé 342547
+#define FS_IOC32_GETVERSION            _IOR('v', 1, int)
Daniel P. Berrangé 342547
+#define FS_IOC32_SETVERSION            _IOW('v', 2, int)
Daniel P. Berrangé 342547
+#else
Daniel P. Berrangé 342547
 #include <linux/fs.h>
Daniel P. Berrangé 342547
+#endif
Daniel P. Berrangé 342547
 #include <linux/fd.h>
Daniel P. Berrangé 342547
 #if defined(CONFIG_FIEMAP)
Daniel P. Berrangé 342547
 #include <linux/fiemap.h>
Daniel P. Berrangé 342547
diff --git a/meson.build b/meson.build
Daniel P. Berrangé 342547
index 294e9a8f32..30a380752c 100644
Daniel P. Berrangé 342547
--- a/meson.build
Daniel P. Berrangé 342547
+++ b/meson.build
Daniel P. Berrangé 342547
@@ -1963,6 +1963,8 @@ config_host_data.set('HAVE_OPTRESET',
Daniel P. Berrangé 342547
                      cc.has_header_symbol('getopt.h', 'optreset'))
Daniel P. Berrangé 342547
 config_host_data.set('HAVE_IPPROTO_MPTCP',
Daniel P. Berrangé 342547
                      cc.has_header_symbol('netinet/in.h', 'IPPROTO_MPTCP'))
Daniel P. Berrangé 342547
+config_host_data.set('HAVE_SYS_MOUNT_FSCONFIG',
Daniel P. Berrangé 342547
+                     cc.has_header_symbol('sys/mount.h', 'FSCONFIG_SET_FLAG'))
Daniel P. Berrangé 342547
 
Daniel P. Berrangé 342547
 # has_member
Daniel P. Berrangé 342547
 config_host_data.set('HAVE_SIGEV_NOTIFY_THREAD_ID',
Daniel P. Berrangé 342547
-- 
Daniel P. Berrangé 342547
2.37.1
Daniel P. Berrangé 342547