diff mbox series

[06/15] btrfs: move static_assert() for btrfs_super_block into fs.c

Message ID 6b462dc4d7ceffe2ba9141f46bf28350be7c7f4a.1663196541.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs: strip out btrfs_fs_info dependencies | expand

Commit Message

Josef Bacik Sept. 14, 2022, 11:04 p.m. UTC
We shouldn't have static_assert()'s in header files in general, but
especially since btrfs_super_block isn't defined in ctree.h.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.h | 1 -
 fs/btrfs/fs.c    | 2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)

Comments

Anand Jain Sept. 15, 2022, 10:42 a.m. UTC | #1
On 15/09/2022 07:04, Josef Bacik wrote:
> We shouldn't have static_assert()'s in header files in general, but
> especially since btrfs_super_block isn't defined in ctree.h.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: Anand Jain <anand.jain@oracle.com>
Johannes Thumshirn Sept. 15, 2022, 2:45 p.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
David Sterba Sept. 19, 2022, 8:54 p.m. UTC | #3
On Wed, Sep 14, 2022 at 07:04:42PM -0400, Josef Bacik wrote:
> We shouldn't have static_assert()'s in header files in general,

Why? Since we have the _Static_assert support in all compilers we can do
the header compile-time checks.

> but
> especially since btrfs_super_block isn't defined in ctree.h.
> 
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/ctree.h | 1 -
>  fs/btrfs/fs.c    | 2 ++
>  2 files changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
> index a790c58b4c73..3cb4e0aca058 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -56,7 +56,6 @@ struct btrfs_ioctl_encoded_io_args;
>  
>  #define BTRFS_SUPER_INFO_OFFSET			SZ_64K
>  #define BTRFS_SUPER_INFO_SIZE			4096
> -static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
>  
> +
> +static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);

This can be dropped as the same assert is right after the super block
definition and this is IMO the intended usage pattern. This catches any
accidental changes to the structure.
diff mbox series

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index a790c58b4c73..3cb4e0aca058 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -56,7 +56,6 @@  struct btrfs_ioctl_encoded_io_args;
 
 #define BTRFS_SUPER_INFO_OFFSET			SZ_64K
 #define BTRFS_SUPER_INFO_SIZE			4096
-static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);
 
 /*
  * The reserved space at the beginning of each device.
diff --git a/fs/btrfs/fs.c b/fs/btrfs/fs.c
index a95d86679d14..c54ee0f943ce 100644
--- a/fs/btrfs/fs.c
+++ b/fs/btrfs/fs.c
@@ -106,3 +106,5 @@  int __btrfs_fs_compat_ro(struct btrfs_fs_info *fs_info, u64 flag)
 	disk_super = fs_info->super_copy;
 	return !!(btrfs_super_compat_ro_flags(disk_super) & flag);
 }
+
+static_assert(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE);