Skip to contentSkip to conversation

share xfs_ondisk.h with userspace

PATCH In review Christoph Hellwig 3 participants 5 messages Dec 4, 2023 – Dec 6, 2023 XFS filesystem

lore
Share & tools
lore
#0 lore raw

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(-)
#1 lore raw

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
index 21a7e350b4c58e..d9c988c5ad692e 100644
@@ -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
#2 lore raw

PATCH 2/2 xfs: move xfs_ondisk.h to libxfs/

In reply to Christoph Hellwig

Move 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
similarity index 100%
rename from fs/xfs/xfs_ondisk.h
rename to fs/xfs/libxfs/xfs_ondisk.h
Signature · 1 line
2.39.2
Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] xfs: move xfs_ondisk.h to libxfs/

Quoted 5 lines · Christoph Hellwig

Move 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.

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 -0
similarity index 100%
rename from fs/xfs/xfs_ondisk.h
rename to fs/xfs/libxfs/xfs_ondisk.h
Signature · 1 line
2.39.2
maintainer Reviewed-by
#4 lore raw
In reply to Christoph Hellwig
Quoted 5 lines · Christoph Hellwig

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.

Thanks Christoph!

Quoted 5 lines

Diffstat:

 xfs_ondisk.h |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)