xfstest: add detection for ext4.h presence in configure.ac
PATCH v2 1/1 xfstest: add detection for ext4.h presence in configure.ac
In some distributions, __u64 is already defined in system header files, causing compilation errors when building xfstest.
# make
[CC] ext4_resize
ext4_resize.c:17:28: error: conflicting types for '__u64'
typedef unsigned long long __u64;
^~~~~
In file included from /usr/include/asm/types.h:26:0,
from /usr/include/linux/types.h:5,
from /usr/include/linux/mount.h:4,
from /usr/include/sys/mount.h:32,
from ext4_resize.c:15:
/usr/include/asm-generic/int-l64.h:30:23: note: previous declaration of '__u64' was here
typedef unsigned long __u64;
^~~~~To address this issue, configure.ac now checks for the presence and compilability of <linux/ext4.h>. If found and compilable, the macro HAVE_LINUX_EXT4_H is defined. If not, a warning message is displayed. The commit also updates src/ext4_resize.c to conditionally include <linux/ext4.h> based on the presence of the header, ensuring compatibility with systems where ext4.h is either present or not. This change enhances the configure process and improves code consistency.
The changes were tested on various distributions on Power architecture, by successfully compiling xfstest. Additionally, verified the compatibility by running ext4/033 and ext4/056 tests, both of which use ext4_resize and observed successful test execution.
# make
[CC] detached_mounts_propagation
[CC] ext4_resize
[CC] t_readdir_3---
Changelog:
v1 -> v2
Drop usage of uint64_t to match the definition in the kernel uapi headers. Use <linux/ext4.h> or <linux/types.h> based on the presence of the header to get the __u64 definition as suggested by Darrick.
Link to v1:
https://lore.kernel.org/fstests/[email protected]/T/#u
configure.ac | 8 ++++++++ src/ext4_resize.c | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-)
configure.ac +8 -0
@@ -35,6 +35,14 @@ AC_CHECK_HEADERS([ assert.h \ sys/mman.h \ ]) +AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([#include <linux/ext4.h>], []) +], [ + AC_DEFINE([HAVE_LINUX_EXT4_H], [1], [Define if ext4.h is present]) +], [ + AC_MSG_WARN([ext4.h not found or not compilable.]) +]) + AC_CHECK_HEADERS([xfs/xfs_log_format.h],,,[ #define _GNU_SOURCE #include <xfs/libxfs.h>])
src/ext4_resize.c +5 -1
@@ -14,7 +14,11 @@#include <sys/ioctl.h> #include <sys/mount.h> -typedef unsigned long long __u64 ; +#ifdef HAVE_LINUX_EXT4_H +#include <linux/ext4.h> +#else +#include <linux/types.h> +#endif #ifndef EXT4_IOC_RESIZE_FS #define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64)
Signature · 1 line
2.39.1
Quoted 59 lines · Disha Goel
In some distributions,
__u64is already defined in system header files, causing compilation errors when building xfstest.# make [CC] ext4_resize ext4_resize.c:17:28: error: conflicting types for '__u64' typedef unsigned long long __u64; ^~~~~ In file included from /usr/include/asm/types.h:26:0, from /usr/include/linux/types.h:5, from /usr/include/linux/mount.h:4, from /usr/include/sys/mount.h:32, from ext4_resize.c:15: /usr/include/asm-generic/int-l64.h:30:23: note: previous declaration of '__u64' was here typedef unsigned long __u64; ^~~~~To address this issue, configure.ac now checks for the presence and compilability of <
linux/ext4.h>. If found and compilable, the macroHAVE_LINUX_EXT4_His defined. If not, a warning message is displayed. The commit also updatessrc/ext4_resize.cto conditionally include <linux/ext4.h> based on the presence of the header, ensuring compatibility with systems whereext4.his either present or not. This change enhances the configure process and improves code consistency.The changes were tested on various distributions on Power architecture, by successfully compiling xfstest. Additionally, verified the compatibility by running ext4/033 and ext4/056 tests, both of which use
ext4_resizeand observed successful test execution.# make [CC] detached_mounts_propagation [CC] ext4_resize [CC] t_readdir_3Signed-off-by Disha Goel <[email protected]>---
Changelog:
v1 -> v2
Drop usage ofuint64_tto match the definition in the kernel uapi headers. Use <linux/ext4.h> or <linux/types.h> based on the presence of the header to get the__u64definition as suggested by Darrick.Link to v1:
https://lore.kernel.org/fstests/[email protected]/T/#uconfigure.ac | 8 ++++++++ src/ext4_resize.c | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-)configure.ac +0
-0
configure.ac AC_CHECK_HEADERS([ assert.h \ · line 44
Quoted 10 lines
configure.ac +7
-0@@ -35,6 +35,14 @@ AC_CHECK_HEADERS([ assert.h \ sys/mman.h \ ]) +AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([#include <linux/ext4.h>], []) +], [ + AC_DEFINE([HAVE_LINUX_EXT4_H], [1], [Define if ext4.h is present]) +], [ + AC_MSG_WARN([ext4.h not found or not compilable.]) +])
AC_CHECK_HEADERS does this.
Quoted 9 lines
configure.ac +1
-0+ AC_CHECK_HEADERS([xfs/xfs_log_format.h],,,[ #define _GNU_SOURCE #include <xfs/libxfs.h>])src/ext4_resize.c +0
-0
src/ext4_resize.c line 20
Quoted 8 lines
src/ext4_resize.c +4
-1@@ -14,7 +14,11 @@#include <sys/ioctl.h> #include <sys/mount.h> -typedef unsigned long long __u64 ; +#ifdef HAVE_LINUX_EXT4_H +#include <linux/ext4.h> +#else +#include <linux/types.h>
You might as well include this unconditionally; there's no penalty for including it multiple times.
--D
Quoted 7 lines
src/ext4_resize.c +1
-0+#endif #ifndef EXT4_IOC_RESIZE_FS #define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64)Signature · 1 line
2.39.1
Quoted 41 lines · Darrick J. Wong
Quoted 9 lines
configure.ac | 8 ++++++++ src/ext4_resize.c | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-)configure.ac +0
-0configure.ac AC_CHECK_HEADERS([ assert.h \ · line 44
Quoted 10 lines
configure.ac +7
-0@@ -35,6 +35,14 @@ AC_CHECK_HEADERS([ assert.h \ sys/mman.h \ ]) +AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([#include <linux/ext4.h>], []) +], [ + AC_DEFINE([HAVE_LINUX_EXT4_H], [1], [Define if ext4.h is present]) +], [ + AC_MSG_WARN([ext4.h not found or not compilable.]) +])
AC_CHECK_HEADERSdoes this.Quoted 9 lines
configure.ac +1
-0+ AC_CHECK_HEADERS([xfs/xfs_log_format.h],,,[ #define _GNU_SOURCE #include <xfs/libxfs.h>])src/ext4_resize.c +0
-0src/ext4_resize.c line 20
Quoted 8 lines
src/ext4_resize.c +4
-1@@ -14,7 +14,11 @@#include <sys/ioctl.h> #include <sys/mount.h> -typedef unsigned long long __u64 ; +#ifdef HAVE_LINUX_EXT4_H +#include <linux/ext4.h> +#else +#include <linux/types.h> You might as well include this unconditionally; there's no penalty for including it multiple times.
Quoted 1 line
--D
Thanks for reviewing the patch. I have addressed this in v3.
Thanks
Quoted 7 lines
Quoted 7 lines
src/ext4_resize.c +1
-0+#endif #ifndef EXT4_IOC_RESIZE_FS #define EXT4_IOC_RESIZE_FS _IOW('f', 16, __u64)Signature · 1 line
2.39.1