All of lore.kernel.org
 help / color / mirror / Atom feed
* share xfs_ondisk.h with userspace
@ 2023-12-04 20:07 ` Christoph Hellwig
  2023-12-04 20:07   ` [PATCH 1/2] xfs: use static_assert to check struct sizes and offsets Christoph Hellwig
                     ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Christoph Hellwig @ 2023-12-04 20:07 UTC (permalink / raw)
  To: Chandan Babu R; +Cc: Darrick J. Wong, linux-xfs

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(-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] xfs: use static_assert to check struct sizes and offsets
  2023-12-04 20:07 ` share xfs_ondisk.h with userspace Christoph Hellwig
@ 2023-12-04 20:07   ` Christoph Hellwig
  2023-12-04 20:07   ` [PATCH 2/2] xfs: move xfs_ondisk.h to libxfs/ Christoph Hellwig
  2023-12-06  8:49   ` share xfs_ondisk.h with userspace Carlos Maiolino
  2 siblings, 0 replies; 5+ messages in thread
From: Christoph Hellwig @ 2023-12-04 20:07 UTC (permalink / raw)
  To: Chandan Babu R; +Cc: Darrick J. Wong, linux-xfs

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.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
---
 fs/xfs/xfs_ondisk.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/xfs_ondisk.h
index 21a7e350b4c58e..d9c988c5ad692e 100644
--- a/fs/xfs/xfs_ondisk.h
+++ b/fs/xfs/xfs_ondisk.h
@@ -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
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] xfs: move xfs_ondisk.h to libxfs/
  2023-12-04 20:07 ` share xfs_ondisk.h with userspace Christoph Hellwig
  2023-12-04 20:07   ` [PATCH 1/2] xfs: use static_assert to check struct sizes and offsets Christoph Hellwig
@ 2023-12-04 20:07   ` Christoph Hellwig
  2023-12-04 20:36     ` Darrick J. Wong
  2023-12-06  8:49   ` share xfs_ondisk.h with userspace Carlos Maiolino
  2 siblings, 1 reply; 5+ messages in thread
From: Christoph Hellwig @ 2023-12-04 20:07 UTC (permalink / raw)
  To: Chandan Babu R; +Cc: Darrick J. Wong, linux-xfs

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.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/xfs/{ => libxfs}/xfs_ondisk.h | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename fs/xfs/{ => libxfs}/xfs_ondisk.h (100%)

diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/libxfs/xfs_ondisk.h
similarity index 100%
rename from fs/xfs/xfs_ondisk.h
rename to fs/xfs/libxfs/xfs_ondisk.h
-- 
2.39.2


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] xfs: move xfs_ondisk.h to libxfs/
  2023-12-04 20:07   ` [PATCH 2/2] xfs: move xfs_ondisk.h to libxfs/ Christoph Hellwig
@ 2023-12-04 20:36     ` Darrick J. Wong
  0 siblings, 0 replies; 5+ messages in thread
From: Darrick J. Wong @ 2023-12-04 20:36 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Chandan Babu R, linux-xfs

On Mon, Dec 04, 2023 at 09:07:19PM +0100, Christoph Hellwig wrote:
> 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.
> 
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Yay build time checks!
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  fs/xfs/{ => libxfs}/xfs_ondisk.h | 0
>  1 file changed, 0 insertions(+), 0 deletions(-)
>  rename fs/xfs/{ => libxfs}/xfs_ondisk.h (100%)
> 
> diff --git a/fs/xfs/xfs_ondisk.h b/fs/xfs/libxfs/xfs_ondisk.h
> similarity index 100%
> rename from fs/xfs/xfs_ondisk.h
> rename to fs/xfs/libxfs/xfs_ondisk.h
> -- 
> 2.39.2
> 
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: share xfs_ondisk.h with userspace
  2023-12-04 20:07 ` share xfs_ondisk.h with userspace Christoph Hellwig
  2023-12-04 20:07   ` [PATCH 1/2] xfs: use static_assert to check struct sizes and offsets Christoph Hellwig
  2023-12-04 20:07   ` [PATCH 2/2] xfs: move xfs_ondisk.h to libxfs/ Christoph Hellwig
@ 2023-12-06  8:49   ` Carlos Maiolino
  2 siblings, 0 replies; 5+ messages in thread
From: Carlos Maiolino @ 2023-12-06  8:49 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Chandan Babu R, Darrick J. Wong, linux-xfs

On Mon, Dec 04, 2023 at 09:07:17PM +0100, Christoph Hellwig wrote:
> 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!

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>


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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-12-06  8:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <P2n4rCzfWQ4WXEZsETZ3TkSW3tDwzcQuEbmsjhb_BAObmT_7sYjfvdqc1VIwUn0MnFNUjQp-d3EFYwlLoAtydA==@protonmail.internalid>
2023-12-04 20:07 ` share xfs_ondisk.h with userspace Christoph Hellwig
2023-12-04 20:07   ` [PATCH 1/2] xfs: use static_assert to check struct sizes and offsets Christoph Hellwig
2023-12-04 20:07   ` [PATCH 2/2] xfs: move xfs_ondisk.h to libxfs/ Christoph Hellwig
2023-12-04 20:36     ` Darrick J. Wong
2023-12-06  8:49   ` share xfs_ondisk.h with userspace Carlos Maiolino

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.