share xfs_ondisk.h with userspace
Hi all,
this series switches xfs_ondisk.h to use static_assert instead of the kernel-specific BUILD_BUG_ON_MSG and then moves it to libxfs so that userspace can share the same struct sanity checks.
Diffstat:
xfs_ondisk.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
PATCH 1/2 xfs: use static_assert to check struct sizes and offsets
Use the compiler-provided static_assert built-in from C11 instead of the kernel-specific BUILD_BUG_ON_MSG for the structure size and offset checks in xfs_ondisk. This not only gives slightly nicer error messages in case things go south, but can also be trivially used as-is in userspace.
--- fs/xfs/xfs_ondisk.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
fs/xfs/xfs_ondisk.h +4 -4
@@ -7,16 +7,16 @@#define __XFS_ONDISK_H#define XFS_CHECK_STRUCT_SIZE (structname, size) \ - BUILD_BUG_ON_MSG(sizeof(structname) != (size), "XFS: sizeof(" \ - #structname ") is wrong, expected " #size) + static_assert(sizeof(structname) == (size), \ + "XFS: sizeof(" #structname ") is wrong, expected " #size)#define XFS_CHECK_OFFSET (structname, member, off) \ - BUILD_BUG_ON_MSG(offsetof(structname, member) != (off), \ + static_assert(offsetof(structname, member) == (off), \ "XFS: offsetof(" #structname ", " #member ") is wrong, " \ "expected " #off)#define XFS_CHECK_VALUE (value, expected) \ - BUILD_BUG_ON_MSG((value) != (expected), \ + static_assert((value) == (expected), \ "XFS: value of " #value " is wrong, expected " #expected) static inline void __init
Signature · 1 line
2.39.2
PATCH 2/2 xfs: move xfs_ondisk.h to libxfs/
In reply to Christoph HellwigMove xfs_ondisk.h to libxfs so that we can do the struct sanity checks in userspace libxfs as well. This should allow us to retire the somewhat fragile xfs/122 test on xfstests.
---
fs/xfs/{ => libxfs}/xfs_ondisk.h | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename fs/xfs/{ => libxfs}/xfs_ondisk.h (100%)fs/xfs/libxfs/xfs_ondisk.h renamed from fs/xfs/xfs_ondisk.h +0 -0
Signature · 1 line
2.39.2
Re: [PATCH 2/2] xfs: move xfs_ondisk.h to libxfs/
Quoted 5 lines · Christoph Hellwig
Move
xfs_ondisk.hto libxfs so that we can do the struct sanity checks in userspace libxfs as well. This should allow us to retire the somewhat fragile xfs/122 test on xfstests.Signed-off-by Christoph Hellwig <[email protected]>
Yay build time checks!
--D
Quoted 13 lines
--- fs/xfs/{ => libxfs}/xfs_ondisk.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename fs/xfs/{ => libxfs}/xfs_ondisk.h (100%)fs/xfs/libxfs/xfs_ondisk.h renamed from fs/xfs/xfs_ondisk.h +0
-0Signature · 1 line
2.39.2
Quoted 5 lines · Christoph Hellwig
Hi all,
this series switches
xfs_ondisk.hto usestatic_assertinstead of the kernel-specificBUILD_BUG_ON_MSGand then moves it to libxfs so that userspace can share the same struct sanity checks.
Thanks Christoph!
Quoted 5 lines
Diffstat:
xfs_ondisk.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)